Skip to content

Commit

Permalink
Don't silently ignore invalid external tool specifications (#3841)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke committed Oct 6, 2021
1 parent f9ba172 commit 3b81505
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
28 changes: 12 additions & 16 deletions driver/tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,22 @@ static std::string findProgramByName(llvm::StringRef name) {

//////////////////////////////////////////////////////////////////////////////

std::string getProgram(const char *name, const llvm::cl::opt<std::string> *opt,
std::string getProgram(const char *fallbackName,
const llvm::cl::opt<std::string> *opt,
const char *envVar) {
std::string path;

std::string name;
if (opt && !opt->empty()) {
path = findProgramByName(opt->c_str());
}

if (path.empty() && envVar) {
const std::string prog = env::get(envVar);
if (!prog.empty())
path = findProgramByName(prog);
}

if (path.empty()) {
path = findProgramByName(name);
name = *opt;
} else {
if (envVar)
name = env::get(envVar);
if (name.empty()) // no or empty env var
name = fallbackName;
}

const std::string path = findProgramByName(name);
if (path.empty()) {
error(Loc(), "failed to locate %s", name);
error(Loc(), "cannot find program `%s`", name.c_str());
fatal();
}

Expand Down Expand Up @@ -174,7 +170,7 @@ int executeToolAndWait(const std::string &tool_,
const std::vector<std::string> &args, bool verbose) {
const auto tool = findProgramByName(tool_);
if (tool.empty()) {
error(Loc(), "failed to locate %s", tool_.c_str());
error(Loc(), "cannot find program `%s`", tool_.c_str());
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion driver/tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern llvm::cl::opt<std::string> linker;
std::string getGcc();
void appendTargetArgsForGcc(std::vector<std::string> &args);

std::string getProgram(const char *name,
std::string getProgram(const char *fallbackName,
const llvm::cl::opt<std::string> *opt = nullptr,
const char *envVar = nullptr);

Expand Down
6 changes: 6 additions & 0 deletions tests/driver/missing_tool.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Test that LDC complains about a missing tool.

// RUN: not %ldc %s -gcc=IdontExist -linker=IdontExist 2>&1 | FileCheck %s
// CHECK: Error: cannot find program `IdontExist`

void main() {}

0 comments on commit 3b81505

Please sign in to comment.