From: Evan Martin Date: Wed, 15 Aug 2012 03:54:59 +0000 (-0700) Subject: pass env block to cl helper X-Git-Tag: v1.0.0^2~46 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=59e0d69ec2775f1aa46d87ad7d14e6985e5187b6;p=platform%2Fupstream%2Fninja.git pass env block to cl helper --- diff --git a/src/msvc_helper-win32.cc b/src/msvc_helper-win32.cc index 624bc2d..8e440fe 100644 --- a/src/msvc_helper-win32.cc +++ b/src/msvc_helper-win32.cc @@ -92,7 +92,7 @@ int CLWrapper::Run(const string& command, string* extra_output) { if (!CreateProcessA(NULL, (char*)command.c_str(), NULL, NULL, /* inherit handles */ TRUE, 0, - NULL, NULL, + env_block_, NULL, &startup_info, &process_info)) { Win32Fatal("CreateProcess"); } diff --git a/src/msvc_helper.h b/src/msvc_helper.h index 41b9f9b..f623520 100644 --- a/src/msvc_helper.h +++ b/src/msvc_helper.h @@ -21,6 +21,12 @@ using namespace std; /// format when building with /showIncludes. This class wraps a CL /// process and parses that output to extract the file list. struct CLWrapper { + CLWrapper() : env_block_(NULL) {} + + /// Set the environment block (as suitable for CreateProcess) to be used + /// by Run(). + void SetEnvBlock(void* env_block) { env_block_ = env_block; } + /// Start a process and parse its output. Returns its exit code. /// Any non-parsed output is buffered into \a extra_output if provided, /// otherwise it is printed to stdout while the process runs. @@ -43,5 +49,6 @@ struct CLWrapper { /// Exposed for testing. static bool FilterInputFilename(const string& line); + void* env_block_; vector includes_; }; diff --git a/src/msvc_helper_test.cc b/src/msvc_helper_test.cc index b65d66f..29fefd4 100644 --- a/src/msvc_helper_test.cc +++ b/src/msvc_helper_test.cc @@ -72,3 +72,12 @@ TEST(MSVCHelperTest, RunSystemInclude) { ASSERT_EQ(1u, cl.includes_.size()); ASSERT_EQ("path.h", cl.includes_[0]); } + +TEST(MSVCHelperTest, EnvBlock) { + char env_block[] = "foo=bar\0"; + CLWrapper cl; + cl.SetEnvBlock(env_block); + string output; + cl.Run("cmd /c \"echo foo is %foo%", &output); + ASSERT_EQ("foo is bar\n", output); +}