[BuildSystem] Resolve executable paths, if necessary.
diff --git a/lib/BuildSystem/LaneBasedExecutionQueue.cpp b/lib/BuildSystem/LaneBasedExecutionQueue.cpp
index 0c6cbe5..40ceb05 100644
--- a/lib/BuildSystem/LaneBasedExecutionQueue.cpp
+++ b/lib/BuildSystem/LaneBasedExecutionQueue.cpp
@@ -16,6 +16,8 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Program.h"
#include <atomic>
#include <condition_variable>
@@ -166,7 +168,7 @@
posix_spawn_file_actions_adddup2(&fileActions, 1, 1);
posix_spawn_file_actions_adddup2(&fileActions, 2, 2);
- // Spawn the command.
+ // For the complete C-string command line.
std::vector<std::string> argsStorage(
commandLine.begin(), commandLine.end());
std::vector<const char*> args(argsStorage.size() + 1);
@@ -175,6 +177,19 @@
}
args[argsStorage.size()] = nullptr;
+ // Resolve the executable path, if necessary.
+ //
+ // FIXME: This should be cached.
+ if (!llvm::sys::path::is_absolute(args[0])) {
+ auto res = llvm::sys::findProgramByName(args[0]);
+ if (!res.getError()) {
+ argsStorage[0] = *res;
+ args[0] = argsStorage[0].c_str();
+ }
+ }
+
+ // Spawn the command.
+ //
// FIXME: Need to track spawned processes for the purposes of cancellation.
pid_t pid;
@@ -182,7 +197,7 @@
/*attrp=*/&attributes, const_cast<char**>(args.data()),
::environ) != 0) {
// FIXME: Error handling.
- fprintf(stderr, "error: unable to spawn process (%s)", strerror(errno));
+ fprintf(stderr, "error: unable to spawn process (%s)\n", strerror(errno));
return false;
}
@@ -195,7 +210,7 @@
result = waitpid(pid, &status, 0);
if (result == -1) {
// FIXME: Error handling.
- fprintf(stderr, "error: unable to wait for process (%s)",
+ fprintf(stderr, "error: unable to wait for process (%s)\n",
strerror(errno));
return false;
}
diff --git a/tests/BuildSystem/Build/basic.llbuild b/tests/BuildSystem/Build/basic.llbuild
index d5a5f17..31b5804 100644
--- a/tests/BuildSystem/Build/basic.llbuild
+++ b/tests/BuildSystem/Build/basic.llbuild
@@ -59,4 +59,4 @@
inputs: ["input A"]
outputs: ["output"]
# FIXME: Design a limited mechanism for substitution. Might be tool specific.
- args: ["/bin/cp", "input A", "output"]
+ args: ["cp", "input A", "output"]