[VS Addin] Fix parallel building.

There was a bug in the calling code for compiler_wrapper.
New unit test added to prevent regression.

BUG=

Review URL: https://codereview.chromium.org/12248006

git-svn-id: https://nativeclient-sdk.googlecode.com/svn/trunk/src@1502 050acbb0-2703-11df-ab0a-9f3f633ae91d
diff --git a/NaCl.Build.CPPTasks/NaClCompile.cs b/NaCl.Build.CPPTasks/NaClCompile.cs
index 2b6bf40..30600d4 100644
--- a/NaCl.Build.CPPTasks/NaClCompile.cs
+++ b/NaCl.Build.CPPTasks/NaClCompile.cs
@@ -373,11 +373,12 @@
             foreach (KeyValuePair<string, List<ITaskItem>> entry in srcGroups)
             {
                 string commandLine = entry.Key;
-                string cmd = "\"" + pathToTool + "\" " + commandLine + "--";
+                string cmd = "\"" + pathToTool + "\" " + commandLine + " --";
                 List<ITaskItem> sources = entry.Value;
 
                 foreach (ITaskItem sourceItem in sources)
                 {
+                    cmd += " ";
                     cmd += GCCUtilities.ConvertPathWindowsToPosix(sourceItem.ToString());
                 }
 
diff --git a/TestingProjects/BlankValidSolution/NaClProject/multiprocess.props b/TestingProjects/BlankValidSolution/NaClProject/multiprocess.props
new file mode 100644
index 0000000..c5c0542
--- /dev/null
+++ b/TestingProjects/BlankValidSolution/NaClProject/multiprocess.props
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>

+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

+  <ImportGroup Label="PropertySheets" />

+  <PropertyGroup Label="UserMacros" />

+  <PropertyGroup />

+  <ItemDefinitionGroup>

+    <ClCompile>

+      <MultiProcessorCompilation>true</MultiProcessorCompilation>

+    </ClCompile>

+  </ItemDefinitionGroup>

+  <ItemGroup />

+</Project>
\ No newline at end of file
diff --git a/TestingProjects/BlankValidSolution/NaClProject/test_file.cpp b/TestingProjects/BlankValidSolution/NaClProject/test_file.cpp
new file mode 100644
index 0000000..5f813b1
--- /dev/null
+++ b/TestingProjects/BlankValidSolution/NaClProject/test_file.cpp
@@ -0,0 +1 @@
+// test file.
diff --git a/UnitTests/BaseCompileTest.cs b/UnitTests/BaseCompileTest.cs
new file mode 100644
index 0000000..ab7c58e
--- /dev/null
+++ b/UnitTests/BaseCompileTest.cs
@@ -0,0 +1,136 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+using System;
+using System.Text;
+using System.Collections.Generic;
+using EnvDTE;
+using EnvDTE80;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Microsoft.VisualStudio.VCProjectEngine;
+using NaCl.Build.CPPTasks;
+using NativeClientVSAddIn;
+
+namespace UnitTests
+{
+    [TestClass]
+    public class BaseCompileTest
+    {
+        /// <summary>
+        /// The main visual studio object.
+        /// </summary>
+        protected DTE2 dte_;
+
+        /// <summary>
+        /// The path to a NaCl solution used in compile tests.
+        /// </summary>
+        protected static string SolutionName_;
+
+        /// <summary>
+        /// This is run one time before any test methods are called. Here we set-up test-copies of
+        /// new NaCl solutions for use in the tests.
+        /// </summary>
+        /// <param name="testContext">Holds information about the current test run</param>
+        public static void ClassSetUp(TestContext testContext, string solutionBaseName)
+        {
+            DTE2 dte = TestUtilities.StartVisualStudioInstance();
+            try
+            {
+                SolutionName_ = TestUtilities.CreateBlankValidNaClSolution(
+                    dte,
+                    solutionBaseName,
+                    Strings.PepperPlatformName,
+                    Strings.NaCl64PlatformName,
+                    testContext);
+            }
+            finally
+            {
+                TestUtilities.CleanUpVisualStudioInstance(dte);
+            }
+        }
+
+        /// <summary>
+        /// This is run before each test to create test resources.
+        /// </summary>
+        [TestInitialize]
+        public void TestSetup()
+        {
+            dte_ = TestUtilities.StartVisualStudioInstance();
+            try
+            {
+                TestUtilities.AssertAddinLoaded(dte_, Strings.AddInName);
+            }
+            catch
+            {
+                TestUtilities.CleanUpVisualStudioInstance(dte_);
+                throw;
+            }
+        }
+
+        /// <summary>
+        /// Helper function which opens the given solution, sets the configuration and platform and
+        /// tries to compile, failing the test if the build does not succeed.
+        /// </summary>
+        /// <param name="solutionPath">Path to the solution to open.</param>
+        /// <param name="configName">Solution Configuration name (Debug or Release).</param>
+        /// <param name="platformName">Platform name.</param>
+        private void TryCompile(string configName, string platformName)
+        {
+            string failFormat = "Project compile failed for {0} platform {1} config."
+                              + "Build output: {2}";
+            string cygwinWarningFormat = "Did not pass cygwin nodosfilewarning environment var to"
+                                       + " tools Platform: {0}, configuration: {1}";
+            StringComparison ignoreCase = StringComparison.InvariantCultureIgnoreCase;
+
+            // Open Debug configuration and build.
+            TestUtilities.SetSolutionConfiguration(
+                dte_, TestUtilities.NaClProjectUniqueName, configName, platformName);
+            dte_.Solution.SolutionBuild.Build(true);
+
+            string compileOutput = TestUtilities.GetPaneText(
+                dte_.ToolWindows.OutputWindow.OutputWindowPanes.Item("Build"));
+            Assert.IsTrue(
+                compileOutput.Contains("Build succeeded.", ignoreCase),
+                string.Format(failFormat, platformName, configName, compileOutput));
+            Assert.IsFalse(
+                compileOutput.Contains("MS-DOS style path detected", ignoreCase),
+                string.Format(cygwinWarningFormat, platformName, configName));
+        }
+
+        /// <summary>
+        /// Set the type of the project: Executable, DynamicLibrary, StaticLibrary
+        /// </summary>
+        private void SetProjectType(string projectType, string platformName)
+        {
+            Project project = dte_.Solution.Projects.Item(TestUtilities.NaClProjectUniqueName);
+            VCConfiguration config;
+            IVCRulePropertyStorage rule;
+
+            config = TestUtilities.GetVCConfiguration(project, "Debug", platformName);
+            rule = config.Rules.Item("ConfigurationGeneral");
+            rule.SetPropertyValue("ConfigurationType", projectType);
+
+            config = TestUtilities.GetVCConfiguration(project, "Release", platformName);
+            rule = config.Rules.Item("ConfigurationGeneral");
+            rule.SetPropertyValue("ConfigurationType", projectType);
+        }
+
+        protected void CheckCompile(string platform, bool dll)
+        {
+            dte_.Solution.Open(SolutionName_);
+            SetProjectType("Executable", platform);
+            TryCompile("Debug", platform);
+            TryCompile("Release", platform);
+            SetProjectType("StaticLibrary", platform);
+            TryCompile("Debug", platform);
+            TryCompile("Release", platform);
+            if (dll)
+            {
+                SetProjectType("DynamicLibrary", platform);
+                TryCompile("Debug", platform);
+                TryCompile("Release", platform);
+            }
+            dte_.Solution.Close(true);
+        }
+    }
+}
diff --git a/UnitTests/CompileParallelTest.cs b/UnitTests/CompileParallelTest.cs
new file mode 100644
index 0000000..d8df3dc
--- /dev/null
+++ b/UnitTests/CompileParallelTest.cs
@@ -0,0 +1,62 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+using System;
+using System.Text;
+using System.Collections.Generic;
+using EnvDTE;
+using EnvDTE80;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Microsoft.VisualStudio.VCProjectEngine;
+using NaCl.Build.CPPTasks;
+using NativeClientVSAddIn;
+
+namespace UnitTests
+{
+    [TestClass]
+    public class CompileParallelTest : BaseCompileTest
+    {
+        private static string SolutionBaseName_ = "CompileParallelTest";
+
+        [ClassInitialize]
+        public new static void ClassSetUp(TestContext testContext)
+        {
+            BaseCompileTest.ClassSetUp(testContext, SolutionBaseName_);
+        }
+
+        /// <summary>
+        /// This is run after each test to clean up things created in TestSetup().
+        /// </summary>
+        [TestCleanup]
+        public void ClassTearDown()
+        {
+            TestUtilities.CleanUpVisualStudioInstance(dte_);
+        }
+
+        /// <summary>
+        /// Test that parallel compilation works.
+        /// </summary>
+        [TestMethod]
+        public void CheckParallelCompile()
+        {
+            string platform = TestUtilities.NaClProjectUniqueName;
+            dte_.Solution.Open(SolutionName_);
+            Project project = dte_.Solution.Projects.Item(platform);
+
+            // Add property sheet that enables multiprocessing
+            VCConfiguration config;
+            IVCRulePropertyStorage rule;
+            config = TestUtilities.GetVCConfiguration(project, "Debug", platform);
+            config.AddPropertySheet("multiprocess.props");
+            config = TestUtilities.GetVCConfiguration(project, "Release", platform);
+            config.AddPropertySheet("multiprocess.props");
+
+            // Add a second file
+            project.ProjectItems.AddFromFile("test_file.cpp");
+
+            dte_.Solution.Close(true);
+
+            CheckCompile(Strings.NaCl64PlatformName, false);
+        }
+    }
+}
diff --git a/UnitTests/CompileTest.cs b/UnitTests/CompileTest.cs
index cb313d8..c721867 100644
--- a/UnitTests/CompileTest.cs
+++ b/UnitTests/CompileTest.cs
@@ -14,40 +14,14 @@
 namespace UnitTests
 {
     [TestClass]
-    public class CompileTest
+    public class ComileTest : BaseCompileTest
     {
-        /// <summary>
-        /// The main visual studio object.
-        /// </summary>
-        private DTE2 dte_;
+        private static string SolutionBaseName_ = "CompileTest";
 
-        /// <summary>
-        /// The path to a NaCl solution used in compile tests.
-        /// </summary>
-        private static string SolutionName_;
-
-        /// <summary>
-        /// This is run one time before any test methods are called. Here we set-up test-copies of
-        /// new NaCl solutions for use in the tests.
-        /// </summary>
-        /// <param name="testContext">Holds information about the current test run</param>
         [ClassInitialize]
-        public static void ClassSetUp(TestContext testContext)
+        public new static void ClassSetUp(TestContext testContext)
         {
-            DTE2 dte = TestUtilities.StartVisualStudioInstance();
-            try
-            {
-                SolutionName_ = TestUtilities.CreateBlankValidNaClSolution(
-                    dte,
-                    "CompileTest",
-                    Strings.PepperPlatformName,
-                    Strings.NaCl64PlatformName,
-                    testContext);
-            }
-            finally
-            {
-                TestUtilities.CleanUpVisualStudioInstance(dte);
-            }
+            BaseCompileTest.ClassSetUp(testContext, SolutionBaseName_);
         }
 
         /// <summary>
@@ -60,77 +34,6 @@
         }
 
         /// <summary>
-        /// This is run before each test to create test resources.
-        /// </summary>
-        [TestInitialize]
-        public void TestSetup()
-        {
-            dte_ = TestUtilities.StartVisualStudioInstance();
-            try
-            {
-                TestUtilities.AssertAddinLoaded(dte_, Strings.AddInName);
-            }
-            catch
-            {
-                TestUtilities.CleanUpVisualStudioInstance(dte_);
-                throw;
-            }
-        }
-
-        /// <summary>
-        /// Helper function which opens the given solution, sets the configuration and platform and
-        /// tries to compile, failing the test if the build does not succeed.
-        /// </summary>
-        /// <param name="solutionPath">Path to the solution to open.</param>
-        /// <param name="configName">Solution Configuration name (Debug or Release).</param>
-        /// <param name="platformName">Platform name.</param>
-        private void TryCompile(string configName, string platformName)
-        {
-            string failFormat = "Project compile failed for {0} platform {1} config."
-                              + "Build output: {2}";
-            string cygwinWarningFormat = "Did not pass cygwin nodosfilewarning environment var to"
-                                       + " tools Platform: {0}, configuration: {1}";
-            StringComparison ignoreCase = StringComparison.InvariantCultureIgnoreCase;
-
-            // Open Debug configuration and build.
-            dte_.Solution.Open(SolutionName_);
-            TestUtilities.SetSolutionConfiguration(
-                dte_, TestUtilities.NaClProjectUniqueName, configName, platformName);
-            dte_.Solution.SolutionBuild.Build(true);
-
-            string compileOutput = TestUtilities.GetPaneText(
-                dte_.ToolWindows.OutputWindow.OutputWindowPanes.Item("Build"));
-            Assert.IsTrue(
-                compileOutput.Contains("Build succeeded.", ignoreCase),
-                string.Format(failFormat, platformName, configName, compileOutput));
-            Assert.IsFalse(
-                compileOutput.Contains("MS-DOS style path detected", ignoreCase),
-                string.Format(cygwinWarningFormat, platformName, configName));
-
-            dte_.Solution.Close(true);
-        }
-
-        /// <summary>
-        /// Set the type of the project: Executable, DynamicLibrary, StaticLibrary
-        /// </summary>
-        private void SetProjectType(string projectType, string platformName)
-        {
-            dte_.Solution.Open(SolutionName_);
-            Project project = dte_.Solution.Projects.Item(TestUtilities.NaClProjectUniqueName);
-            VCConfiguration config;
-            IVCRulePropertyStorage rule;
-
-            config = TestUtilities.GetVCConfiguration(project, "Debug", platformName);
-            rule = config.Rules.Item("ConfigurationGeneral");
-            rule.SetPropertyValue("ConfigurationType", projectType);
-
-            config = TestUtilities.GetVCConfiguration(project, "Release", platformName);
-            rule = config.Rules.Item("ConfigurationGeneral");
-            rule.SetPropertyValue("ConfigurationType", projectType);
-            dte_.Solution.Close(true);
-        }
-
-        /// <summary>
         /// Test method to check that the NaCl platform compiles a test project.
         /// </summary>
         [TestMethod]
@@ -176,20 +79,5 @@
             CheckCompile(Strings.PNaClPlatformName, false);
         }
 
-        private void CheckCompile(string platform, bool dll)
-        {
-            SetProjectType("Executable", platform);
-            TryCompile("Debug", platform);
-            TryCompile("Release", platform);
-            SetProjectType("StaticLibrary", platform);
-            TryCompile("Debug", platform);
-            TryCompile("Release", platform);
-            if (dll)
-            {
-                SetProjectType("DynamicLibrary", platform);
-                TryCompile("Debug", platform);
-                TryCompile("Release", platform);
-            }
-        }
     }
 }
diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj
index e87ce19..6846056 100644
--- a/UnitTests/UnitTests.csproj
+++ b/UnitTests/UnitTests.csproj
@@ -76,6 +76,8 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="ComMessageFilter.cs" />
+    <Compile Include="CompileParallelTest.cs" />
+    <Compile Include="CompileTest.cs" />
     <Compile Include="MockProcessSearcher.cs" />
     <Compile Include="PluginDebuggerGDBTest.cs" />
     <Compile Include="PluginDebuggerVSTest.cs" />
@@ -84,7 +86,7 @@
     <Compile Include="MockPropertyManager.cs" />
     <Compile Include="PropertyManagerTest.cs" />
     <Compile Include="TestUtilities.cs" />
-    <Compile Include="CompileTest.cs" />
+    <Compile Include="BaseCompileTest.cs" />
     <Compile Include="WebServerTest.cs" />
   </ItemGroup>
   <ItemGroup>