aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-08-21 10:39:22 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-08-21 10:39:22 +0200
commit7c7cd5c27bd92e5b837c33edb97fa3f0a0d9ad79 (patch)
tree0d577a9d3224a22b23bbbb2dc98376ce19096f66
parentfe55b14b627ad4d832261c68ea24d37d513e834e (diff)
Unset CL and _CL_ environment variables when detecting MSVC
-rw-r--r--build2/cc/guess.cxx11
-rw-r--r--build2/types.hxx1
-rw-r--r--build2/utility.cxx15
-rw-r--r--build2/utility.hxx24
-rw-r--r--build2/utility.txx4
5 files changed, 37 insertions, 18 deletions
diff --git a/build2/cc/guess.cxx b/build2/cc/guess.cxx
index 89030b5..e9b102f 100644
--- a/build2/cc/guess.cxx
+++ b/build2/cc/guess.cxx
@@ -451,7 +451,16 @@ namespace build2
return guess_result ();
};
- r = run<guess_result> (3, xp, f, false);
+ // One can pass extra options/arguments to cl.exe with the CL and _CL_
+ // environment variables. However, if such extra options are passed
+ // without anything to compile, then cl.exe no longer prints usage and
+ // exits successfully but instead issues an error and fails. So we are
+ // going to unset these variables for our test (interestingly, only CL
+ // seem to cause the problem but let's unset both, for good measure).
+ //
+ const char* env[] = {"CL=", "_CL_=", nullptr};
+
+ r = run<guess_result> (3, process_env (xp, env), f, false);
}
if (!r.empty ())
diff --git a/build2/types.hxx b/build2/types.hxx
index 0f2f95b..219608c 100644
--- a/build2/types.hxx
+++ b/build2/types.hxx
@@ -258,6 +258,7 @@ namespace build2
// <libbutl/fdstream.mxx>
//
using butl::process;
+ using butl::process_env;
using butl::process_path;
using butl::process_error;
diff --git a/build2/utility.cxx b/build2/utility.cxx
index 2d8e59b..4da2195 100644
--- a/build2/utility.cxx
+++ b/build2/utility.cxx
@@ -174,7 +174,7 @@ namespace build2
process
run_start (uint16_t verbosity,
- const process_path& pp,
+ const process_env& pe,
const char* args[],
int in,
int out,
@@ -183,12 +183,21 @@ namespace build2
const location& l)
try
{
- assert (args[0] == pp.recall_string ());
+ assert (args[0] == pe.path->recall_string ());
if (verb >= verbosity)
print_process (args, 0);
- return process (pp, args, in, out, (err ? 2 : 1), cwd.string ().c_str ());
+ return process (
+ *pe.path,
+ args,
+ in,
+ out,
+ (err ? 2 : 1),
+ (!cwd.empty ()
+ ? cwd.string ().c_str ()
+ : pe.cwd != nullptr ? pe.cwd->string ().c_str () : nullptr),
+ pe.vars);
}
catch (const process_error& e)
{
diff --git a/build2/utility.hxx b/build2/utility.hxx
index 0beec2e..cc34d59 100644
--- a/build2/utility.hxx
+++ b/build2/utility.hxx
@@ -187,7 +187,7 @@ namespace build2
//
process
run_start (uint16_t verbosity,
- const process_path&,
+ const process_env&, // Implicit-constructible from process_path.
const char* args[],
int in,
int out,
@@ -196,7 +196,7 @@ namespace build2
const location& = location ());
inline process
- run_start (const process_path& pp,
+ run_start (const process_env& pe, // Implicit-constructible from process_path.
const char* args[],
int in,
int out,
@@ -204,7 +204,7 @@ namespace build2
const dir_path& cwd = dir_path (),
const location& l = location ())
{
- return run_start (verb_never, pp, args, in, out, error, cwd, l);
+ return run_start (verb_never, pe, args, in, out, error, cwd, l);
}
inline void
@@ -292,7 +292,7 @@ namespace build2
template <typename T, typename F>
T
run (uint16_t verbosity,
- const process_path&,
+ const process_env&, // Implicit-constructible from process_path.
const char* args[],
F&&,
bool error = true,
@@ -301,7 +301,7 @@ namespace build2
template <typename T, typename F>
inline T
- run (const process_path& pp,
+ run (const process_env& pe, // Implicit-constructible from process_path.
const char* args[],
F&& f,
bool error = true,
@@ -309,7 +309,7 @@ namespace build2
sha256* checksum = nullptr)
{
return run<T> (
- verb_never, pp, args, forward<F> (f), error, ignore_exit, checksum);
+ verb_never, pe, args, forward<F> (f), error, ignore_exit, checksum);
}
template <typename T, typename F>
@@ -345,15 +345,15 @@ namespace build2
template <typename T, typename F>
inline T
run (uint16_t verbosity,
- const process_path& pp,
+ const process_env& pe, // Implicit-constructible from process_path.
F&& f,
bool error = true,
bool ignore_exit = false,
sha256* checksum = nullptr)
{
- const char* args[] = {pp.recall_string (), nullptr};
+ const char* args[] = {pe.path->recall_string (), nullptr};
return run<T> (
- verbosity, pp, args, forward<F> (f), error, ignore_exit, checksum);
+ verbosity, pe, args, forward<F> (f), error, ignore_exit, checksum);
}
// run <prog> <arg>
@@ -376,16 +376,16 @@ namespace build2
template <typename T, typename F>
inline T
run (uint16_t verbosity,
- const process_path& pp,
+ const process_env& pe, // Implicit-constructible from process_path.
const char* arg,
F&& f,
bool error = true,
bool ignore_exit = false,
sha256* checksum = nullptr)
{
- const char* args[] = {pp.recall_string (), arg, nullptr};
+ const char* args[] = {pe.path->recall_string (), arg, nullptr};
return run<T> (
- verbosity, pp, args, forward<F> (f), error, ignore_exit, checksum);
+ verbosity, pe, args, forward<F> (f), error, ignore_exit, checksum);
}
// Empty/nullopt string, path, and project name.
diff --git a/build2/utility.txx b/build2/utility.txx
index 7479b0a..1f65b76 100644
--- a/build2/utility.txx
+++ b/build2/utility.txx
@@ -59,7 +59,7 @@ namespace build2
template <typename T, typename F>
T
run (uint16_t verbosity,
- const process_path& pp,
+ const process_env& pe,
const char* args[],
F&& f,
bool err,
@@ -67,7 +67,7 @@ namespace build2
sha256* checksum)
{
process pr (run_start (verbosity,
- pp,
+ pe,
args,
0 /* stdin */,
-1 /* stdout */,