pass env block to cl helper
authorEvan Martin <martine@danga.com>
Wed, 15 Aug 2012 03:54:59 +0000 (20:54 -0700)
committerEvan Martin <martine@danga.com>
Wed, 15 Aug 2012 03:55:12 +0000 (20:55 -0700)
src/msvc_helper-win32.cc
src/msvc_helper.h
src/msvc_helper_test.cc

index 624bc2d..8e440fe 100644 (file)
@@ -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");
   }
index 41b9f9b..f623520 100644 (file)
@@ -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<string> includes_;
 };
index b65d66f..29fefd4 100644 (file)
@@ -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);
+}