[clang] 8f1e215 - [WebAssembly] Find wasm-opt with GetProgramPath

Dan Gohman via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 2 11:48:59 PST 2019


Author: Dan Gohman
Date: 2019-12-02T11:48:36-08:00
New Revision: 8f1e2151b8e923345a18aa3025a7d074e134768b

URL: https://github.com/llvm/llvm-project/commit/8f1e2151b8e923345a18aa3025a7d074e134768b
DIFF: https://github.com/llvm/llvm-project/commit/8f1e2151b8e923345a18aa3025a7d074e134768b.diff

LOG: [WebAssembly] Find wasm-opt with GetProgramPath

Instead of just searching for wasm-opt in PATH, use GetProgramPath, which
checks the `COMPILER_PATH` environment variable, -B paths, and `PATH`.

Differential Revision: https://reviews.llvm.org/D70780

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/WebAssembly.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index 55b82592c09f..1bb7c35d0c52 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -92,10 +92,10 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
 
   C.addCommand(std::make_unique<Command>(JA, *this, Linker, CmdArgs, Inputs));
 
-  // When optimizing, if wasm-opt is in the PATH, run wasm-opt.
+  // When optimizing, if wasm-opt is available, run it.
   if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
-    if (llvm::ErrorOr<std::string> WasmOptPath =
-           llvm::sys::findProgramByName("wasm-opt")) {
+    auto WasmOptPath = getToolChain().GetProgramPath("wasm-opt");
+    if (WasmOptPath != "wasm-opt") {
       StringRef OOpt = "s";
       if (A->getOption().matches(options::OPT_O4) ||
           A->getOption().matches(options::OPT_Ofast))
@@ -106,7 +106,7 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
         OOpt = A->getValue();
 
       if (OOpt != "0") {
-        const char *WasmOpt = Args.MakeArgString(*WasmOptPath);
+        const char *WasmOpt = Args.MakeArgString(WasmOptPath);
         ArgStringList CmdArgs;
         CmdArgs.push_back(Output.getFilename());
         CmdArgs.push_back(Args.MakeArgString(llvm::Twine("-O") + OOpt));


        


More information about the cfe-commits mailing list