Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't silently ignore invalid external tool specifications #3841

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {}