if (!CreateProcessA(NULL, (char*)command.c_str(), NULL, NULL,
/* inherit handles */ TRUE, 0,
- NULL, NULL,
+ env_block_, NULL,
&startup_info, &process_info)) {
Win32Fatal("CreateProcess");
}
/// 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.
/// Exposed for testing.
static bool FilterInputFilename(const string& line);
+ void* env_block_;
vector<string> includes_;
};
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);
+}