From 59e0d69ec2775f1aa46d87ad7d14e6985e5187b6 Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Tue, 14 Aug 2012 20:54:59 -0700 Subject: pass env block to cl helper --- src/msvc_helper-win32.cc | 2 +- src/msvc_helper.h | 7 +++++++ src/msvc_helper_test.cc | 9 +++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) 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); +} -- cgit v0.12