aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/blaze_util_posix.cc
diff options
context:
space:
mode:
authorGravatar Dmitry Lomov <dslomov@google.com>2015-08-11 16:44:21 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-08-12 15:22:10 +0000
commit78c0cc73d3fec13add33b3ac811748647d76b38f (patch)
tree71fdd959dec21ce52750b6fcf2a28f59733ab272 /src/main/cpp/blaze_util_posix.cc
parent3e791009408bcae7f52ba4ae84a14c6c2460fed1 (diff)
Avoid command line argument mangling on Windows.
exec(3) under mingw converts every command line argument that looks like Unix path into Windows path when executing non-mingw images (criteria for non-mingw image is that the image does not depend on msys-<version>.dll). This affects bazel labels (`//foo:bar` becomes `/foo:bar` for example). This CL: 1) Replaces usage of execv(3) with Windows-native CreateProcess. 2) Converts all command line arguments that are indeed paths into Windows paths. -- MOS_MIGRATED_REVID=100386350
Diffstat (limited to 'src/main/cpp/blaze_util_posix.cc')
-rw-r--r--src/main/cpp/blaze_util_posix.cc63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/main/cpp/blaze_util_posix.cc b/src/main/cpp/blaze_util_posix.cc
new file mode 100644
index 0000000000..ec6ea0ad46
--- /dev/null
+++ b/src/main/cpp/blaze_util_posix.cc
@@ -0,0 +1,63 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <limits.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "src/main/cpp/blaze_util.h"
+#include "src/main/cpp/blaze_util_platform.h"
+#include "src/main/cpp/util/errors.h"
+#include "src/main/cpp/util/exit_code.h"
+
+namespace blaze {
+
+using blaze_util::die;
+using blaze_util::pdie;
+
+using std::string;
+using std::vector;
+
+void ExecuteProgram(const string &exe, const vector<string> &args_vector) {
+ if (VerboseLogging()) {
+ string dbg;
+ for (const auto &s : args_vector) {
+ dbg.append(s);
+ dbg.append(" ");
+ }
+
+ char cwd[PATH_MAX] = {};
+ if (getcwd(cwd, sizeof(cwd)) == NULL) {
+ pdie(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "getcwd() failed");
+ }
+
+ fprintf(stderr, "Invoking binary %s in %s:\n %s\n", exe.c_str(), cwd,
+ dbg.c_str());
+ }
+
+ // Copy to a char* array for execv:
+ int n = args_vector.size();
+ const char **argv = new const char *[n + 1];
+ for (int i = 0; i < n; ++i) {
+ argv[i] = args_vector[i].c_str();
+ }
+ argv[n] = NULL;
+
+ execv(exe.c_str(), const_cast<char **>(argv));
+}
+
+std::string ConvertPath(const std::string &path) { return path; }
+
+std::string ListSeparator() { return ":"; }
+} // namespace blaze.