Bazel client: no longer needs <utime.h>
Also remove a lot of unused header files.
The only remaining header file not available on
Windows is <unistd.h>, but cutting that dependency
will be more complicated because we use read/write
and similar I/O functions from it.
--
MOS_MIGRATED_REVID=139439791
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 39d1165..53e3876 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -30,21 +30,13 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
-#include <sched.h>
-#include <signal.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/resource.h>
-#include <sys/select.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <sys/un.h>
#include <time.h>
#include <unistd.h>
-#include <utime.h>
#include <grpc/grpc.h>
#include <grpc/support/log.h>
@@ -905,8 +897,7 @@
// timestamp to change between Blaze releases so that the metadata cache
// knows that the files may have changed. This is important for actions that
// use embedded binaries as artifacts.
- struct utimbuf times = { future_time, future_time };
- if (utime(extracted_path, ×) == -1) {
+ if (!blaze_util::SetMtimeMillisec(it, future_time)) {
pdie(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
"failed to set timestamp on '%s'", extracted_path);
}
@@ -1104,8 +1095,8 @@
installation_path.c_str());
}
const time_t time_now = time(NULL);
- struct utimbuf times = { time_now, time_now };
- if (utime(globals->options->install_base.c_str(), ×) == -1) {
+ if (!blaze_util::SetMtimeMillisec(globals->options->install_base,
+ time_now)) {
pdie(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
"failed to set timestamp on '%s'",
globals->options->install_base.c_str());
diff --git a/src/main/cpp/util/file_platform.h b/src/main/cpp/util/file_platform.h
index fd72551..5cddc3d 100644
--- a/src/main/cpp/util/file_platform.h
+++ b/src/main/cpp/util/file_platform.h
@@ -43,6 +43,11 @@
// Returns -1 upon failure.
time_t GetMtimeMillisec(const std::string& path);
+// Sets the last modification time of `path` to the given value.
+// `mtime` must be milliseconds since the Epoch.
+// Returns true upon success.
+bool SetMtimeMillisec(const std::string& path, time_t mtime);
+
// Returns the current working directory.
std::string GetCwd();
diff --git a/src/main/cpp/util/file_posix.cc b/src/main/cpp/util/file_posix.cc
index 7691ee9..1cfc272 100644
--- a/src/main/cpp/util/file_posix.cc
+++ b/src/main/cpp/util/file_posix.cc
@@ -18,6 +18,8 @@
#include <limits.h> // PATH_MAX
#include <stdlib.h> // getenv
#include <unistd.h> // access
+#include <utime.h> // utime
+
#include <vector>
#include "src/main/cpp/util/errors.h"
@@ -87,6 +89,11 @@
}
}
+bool SetMtimeMillisec(const string& path, time_t mtime) {
+ struct utimbuf times = { mtime, mtime };
+ return utime(path.c_str(), ×) == 0;
+}
+
string GetCwd() {
char cwdbuf[PATH_MAX];
if (getcwd(cwdbuf, sizeof cwdbuf) == NULL) {
diff --git a/src/main/cpp/util/file_windows.cc b/src/main/cpp/util/file_windows.cc
index eb0efd2..6110bb5 100644
--- a/src/main/cpp/util/file_windows.cc
+++ b/src/main/cpp/util/file_windows.cc
@@ -15,42 +15,57 @@
#include <windows.h>
+#include "src/main/cpp/util/errors.h"
+
namespace blaze_util {
using std::string;
string Which(const string &executable) {
pdie(255, "blaze_util::Which is not implemented on Windows");
+ return "";
}
bool PathExists(const string& path) {
// TODO(bazel-team): implement this.
pdie(255, "blaze_util::PathExists is not implemented on Windows");
+ return false;
}
bool CanAccess(const string& path, bool read, bool write, bool exec) {
// TODO(bazel-team): implement this.
pdie(255, "blaze_util::CanAccess is not implemented on Windows");
+ return false;
}
bool IsDirectory(const string& path) {
// TODO(bazel-team): implement this.
pdie(255, "blaze_util::IsDirectory is not implemented on Windows");
+ return false;
}
time_t GetMtimeMillisec(const string& path) {
// TODO(bazel-team): implement this.
pdie(255, "blaze_util::GetMtimeMillisec is not implemented on Windows");
+ return -1;
+}
+
+bool SetMtimeMillisec(const string& path, time_t mtime) {
+ // TODO(bazel-team): implement this.
+ pdie(255, "blaze_util::SetMtimeMillisec is not implemented on Windows");
+ return false;
}
string GetCwd() {
// TODO(bazel-team): implement this.
pdie(255, "blaze_util::GetCwd is not implemented on Windows");
+ return "";
}
bool ChangeDirectory(const string& path) {
// TODO(bazel-team): implement this.
pdie(255, "blaze_util::ChangeDirectory is not implemented on Windows");
+ return false;
}
void ForEachDirectoryEntry(const string &path,