Skip to content

Commit

Permalink
Revert "[clang][Driver] Correct tool search path priority"
Browse files Browse the repository at this point in the history
Revert 028571d to investigate
MacOS failure.
(also the review link was incorrect, should be
https://reviews.llvm.org/D79842)
  • Loading branch information
DavidSpickett committed Jun 22, 2020
1 parent 7960837 commit f570d58
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 131 deletions.
39 changes: 16 additions & 23 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4717,11 +4717,13 @@ void Driver::generatePrefixedToolNames(
}

static bool ScanDirForExecutable(SmallString<128> &Dir,
const std::string &Name) {
llvm::sys::path::append(Dir, Name);
if (llvm::sys::fs::can_execute(Twine(Dir)))
return true;
llvm::sys::path::remove_filename(Dir);
ArrayRef<std::string> Names) {
for (const auto &Name : Names) {
llvm::sys::path::append(Dir, Name);
if (llvm::sys::fs::can_execute(Twine(Dir)))
return true;
llvm::sys::path::remove_filename(Dir);
}
return false;
}

Expand All @@ -4734,9 +4736,8 @@ std::string Driver::GetProgramPath(StringRef Name, const ToolChain &TC) const {
for (const auto &PrefixDir : PrefixDirs) {
if (llvm::sys::fs::is_directory(PrefixDir)) {
SmallString<128> P(PrefixDir);
for (const auto &TargetSpecificExecutable : TargetSpecificExecutables)
if (ScanDirForExecutable(P, TargetSpecificExecutable))
return std::string(P.str());
if (ScanDirForExecutable(P, TargetSpecificExecutables))
return std::string(P.str());
} else {
SmallString<128> P((PrefixDir + Name).str());
if (llvm::sys::fs::can_execute(Twine(P)))
Expand All @@ -4745,25 +4746,17 @@ std::string Driver::GetProgramPath(StringRef Name, const ToolChain &TC) const {
}

const ToolChain::path_list &List = TC.getProgramPaths();
for (const auto &TargetSpecificExecutable : TargetSpecificExecutables) {
// For each possible name of the tool look for it in
// program paths first, then the path.
// Higher priority names will be first, meaning that
// a higher priority name in the path will be found
// instead of a lower priority name in the program path.
// E.g. <triple>-gcc on the path will be found instead
// of gcc in the program path
for (const auto &Path : List) {
SmallString<128> P(Path);
if (ScanDirForExecutable(P, TargetSpecificExecutable))
return std::string(P.str());
}
for (const auto &Path : List) {
SmallString<128> P(Path);
if (ScanDirForExecutable(P, TargetSpecificExecutables))
return std::string(P.str());
}

// Fall back to the path
// If all else failed, search the path.
for (const auto &TargetSpecificExecutable : TargetSpecificExecutables)
if (llvm::ErrorOr<std::string> P =
llvm::sys::findProgramByName(TargetSpecificExecutable))
return *P;
}

return std::string(Name);
}
Expand Down
106 changes: 0 additions & 106 deletions clang/test/Driver/program-path-priority.c

This file was deleted.

2 changes: 0 additions & 2 deletions clang/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
config.substitutions.append(
('%src_include_dir', config.clang_src_dir + '/include'))

config.substitutions.append(
('%target_triple', config.target_triple))

# Propagate path to symbolizer for ASan/MSan.
llvm_config.with_system_environment(
Expand Down

0 comments on commit f570d58

Please sign in to comment.