diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2018-11-05 15:25:59 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2018-11-05 15:25:59 +0200 |
commit | be2774dd81da77661511280fda868a02e4be87eb (patch) | |
tree | b01c55a25027573049d7d051264b749cc2de9676 | |
parent | 3585bd0ea3e7a32f8dc3e634b4358d822d9ee018 (diff) |
Only search for external tools (compilers, linkers, etc) in PATH
Specifically, omit the current executable's directory on Windows since there
is no reason for them to be found there automagically and this can lead to
surprising behavior (for example, our MinGW GCC being used instead of the
user's even though the user's is in PATH before ours).
-rw-r--r-- | build2/bin/guess.cxx | 17 | ||||
-rw-r--r-- | build2/cc/guess.cxx | 8 | ||||
-rw-r--r-- | build2/cli/init.cxx | 8 | ||||
-rw-r--r-- | build2/test/rule.cxx | 2 | ||||
-rw-r--r-- | build2/utility.cxx | 7 | ||||
-rw-r--r-- | build2/utility.hxx | 11 |
6 files changed, 42 insertions, 11 deletions
diff --git a/build2/bin/guess.cxx b/build2/bin/guess.cxx index ab7edf6..913736d 100644 --- a/build2/bin/guess.cxx +++ b/build2/bin/guess.cxx @@ -52,7 +52,10 @@ namespace build2 dr << info << "use config.bin.ar to override"; }); - arp = run_search (ar, true, fallback); + // Only search in PATH (specifically, omitting the current + // executable's directory on Windows). + // + arp = run_search (ar, true, fallback, true /* path_only */); } if (rl != nullptr) @@ -63,7 +66,7 @@ namespace build2 dr << info << "use config.bin.ranlib to override"; }); - rlp = run_search (*rl, true, fallback); + rlp = run_search (*rl, true, fallback, true /* path_only */); } // Binutils, LLVM, and FreeBSD ar/ranlib all recognize the --version @@ -269,7 +272,10 @@ namespace build2 dr << info << "use config.bin.ld to override"; }); - pp = run_search (ld, true, fallback); + // Only search in PATH (specifically, omitting the current + // executable's directory on Windows). + // + pp = run_search (ld, true, fallback, true /* path_only */); } // Binutils ld recognizes the --version option. Microsoft's link.exe @@ -397,7 +403,10 @@ namespace build2 dr << info << "use config.bin.rc to override"; }); - pp = run_search (rc, true, fallback); + // Only search in PATH (specifically, omitting the current + // executable's directory on Windows). + // + pp = run_search (rc, true, fallback, true /* path_only */); } // Binutils windres recognizes the --version option. diff --git a/build2/cc/guess.cxx b/build2/cc/guess.cxx index 6ce46a2..919aeab 100644 --- a/build2/cc/guess.cxx +++ b/build2/cc/guess.cxx @@ -360,7 +360,13 @@ namespace build2 dr << info << "use config." << xm << " to override"; }); - xp = run_search (xc, false /* init */); // Note: cached. + // Only search in PATH (specifically, omitting the current + // executable's directory on Windows). + // + xp = run_search (xc, + false /* init */, // Note: result is cached. + dir_path () /* fallback */, + true /* path_only */); } using type = compiler_type; diff --git a/build2/cli/init.cxx b/build2/cli/init.cxx index bad2533..d9fec08 100644 --- a/build2/cli/init.cxx +++ b/build2/cli/init.cxx @@ -118,7 +118,13 @@ namespace build2 try { - pp = process::path_search (cli, true); // Can throw. + // Only search in PATH (specifically, omitting the current + // executable's directory on Windows). + // + pp = process::path_search (cli, + true /* init */, + dir_path () /* fallback */, + true /* path_only */); args[0] = pp.recall_string (); if (verb >= 3) diff --git a/build2/test/rule.cxx b/build2/test/rule.cxx index 0b67d68..ba93378 100644 --- a/build2/test/rule.cxx +++ b/build2/test/rule.cxx @@ -765,7 +765,7 @@ namespace build2 args.push_back (nullptr); } - process_path pp (run_search (p, true)); + process_path pp (run_search (p, true /* init */)); args.push_back (pp.recall_string ()); // Do we have options and/or arguments? diff --git a/build2/utility.cxx b/build2/utility.cxx index 4da2195..b5f5e29 100644 --- a/build2/utility.cxx +++ b/build2/utility.cxx @@ -148,10 +148,10 @@ namespace build2 } process_path - run_search (const char*& args0, const location& l) + run_search (const char*& args0, bool path_only, const location& l) try { - return process::path_search (args0); + return process::path_search (args0, dir_path () /* fallback */, path_only); } catch (const process_error& e) { @@ -162,10 +162,11 @@ namespace build2 run_search (const path& f, bool init, const dir_path& fallback, + bool path_only, const location& l) try { - return process::path_search (f, init, fallback); + return process::path_search (f, init, fallback, path_only); } catch (const process_error& e) { diff --git a/build2/utility.hxx b/build2/utility.hxx index 6527d3a..8157c02 100644 --- a/build2/utility.hxx +++ b/build2/utility.hxx @@ -150,12 +150,21 @@ namespace build2 // case of an error. // process_path - run_search (const char*& args0, const location& = location ()); + run_search (const char*& args0, + bool path_only, + const location& = location ()); + + inline process_path + run_search (const char*& args0, const location& l = location ()) + { + return run_search (args0, false, l); + } process_path run_search (const path&, bool init = false, const dir_path& fallback = dir_path (), + bool path_only = false, const location& = location ()); // Wait for process termination. Issue diagnostics and throw failed in case |