Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(777)

Unified Diff: visual_studio/NativeClientVSAddIn/NaCl.Build.CPPTasks/NaClCompile.cs

Issue 11044024: Implement multi-core builds in MSVS (Closed) Base URL: http://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: fix nits Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: visual_studio/NativeClientVSAddIn/NaCl.Build.CPPTasks/NaClCompile.cs
diff --git a/visual_studio/NativeClientVSAddIn/NaCl.Build.CPPTasks/NaClCompile.cs b/visual_studio/NativeClientVSAddIn/NaCl.Build.CPPTasks/NaClCompile.cs
index 272353f6ba38eb256f5b9d58575193318ba59699..b0560599754e9bf5ee60599cc7c9da55c24bd5b2 100644
--- a/visual_studio/NativeClientVSAddIn/NaCl.Build.CPPTasks/NaClCompile.cs
+++ b/visual_studio/NativeClientVSAddIn/NaCl.Build.CPPTasks/NaClCompile.cs
@@ -1,4 +1,4 @@
-
+
using System;
using System.Collections.Generic;
using System.Text;
@@ -8,6 +8,7 @@ using System.Reflection;
using System.Resources;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
+using System.Collections.Specialized;
using System.Diagnostics;
@@ -39,11 +40,24 @@ namespace NaCl.Build.CPPTasks
public string NaCLCompilerPath { get; set; }
[Required]
- public string OutputCommandLine { get; set; }
+ public bool OutputCommandLine { get; set; }
+
+ public int ProcessorNumber { get; set; }
[Required]
public string TrackerLogDirectory { get; set; }
+ protected override StringDictionary EnvironmentOverride
+ {
+ get {
+ string show = OutputCommandLine ? "1" : "0";
+ string cores = Convert.ToString(ProcessorNumber);
+ return new StringDictionary() {
+ {"NACL_GCC_CORES", cores},
+ {"NACL_GCC_SHOW_COMMANDS", show }
+ };
+ }
+ }
protected override string GenerateFullPathToTool() { return ToolName; }
@@ -51,7 +65,7 @@ namespace NaCl.Build.CPPTasks
: base(new ResourceManager("NaCl.Build.CPPTasks.Properties.Resources", Assembly.GetExecutingAssembly()))
{
this.pathToLog = string.Empty;
- this.EnvironmentVariables = new string []{"CYGWIN=nodosfilewarning", "LC_CTYPE=C"};
+ this.EnvironmentVariables = new string[] { "CYGWIN=nodosfilewarning", "LC_CTYPE=C" };
}
protected IDictionary<string, string> GenerateCommandLinesFromTlog()
@@ -68,7 +82,7 @@ namespace NaCl.Build.CPPTasks
if (lineStr.Length == 0 ||
(lineStr[0] == '^' && lineStr.Length == 1))
{
- Log.LogMessage(MessageImportance.High, "Invalid line in command tlog");
+ Log.LogError("Invalid line in command tlog");
break;
}
else if (lineStr[0] == '^')
@@ -87,7 +101,21 @@ namespace NaCl.Build.CPPTasks
protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance)
{
- base.LogEventsFromTextOutput(GCCUtilities.Convert_Output_GCC_to_VS(singleLine), messageImportance);
+ base.LogEventsFromTextOutput(GCCUtilities.ConvertGCCOutput(singleLine), messageImportance);
+ }
+
+ static string GetObjectFile(ITaskItem source)
+ {
+ string objectFilePath = Path.GetFullPath(source.GetMetadata("ObjectFileName"));
+ // cl.exe will accept a folder name as the ObjectFileName in which case
+ // the objectfile is created as <ObjectFileName>/<basename>.obj. Here
+ // we mimic this behaviour.
+ if ((File.GetAttributes(objectFilePath) & FileAttributes.Directory) != 0)
+ {
+ objectFilePath = Path.Combine(objectFilePath, Path.GetFileName(source.ItemSpec));
+ objectFilePath = Path.ChangeExtension(objectFilePath, ".obj");
+ }
+ return objectFilePath;
}
private void ConstructReadTLog(ITaskItem[] compiledSources, CanonicalTrackedOutputFiles outputs)
@@ -106,8 +134,7 @@ namespace NaCl.Build.CPPTasks
foreach (ITaskItem source in compiledSources)
{
string sourcePath = Path.GetFullPath(source.ItemSpec).ToUpperInvariant();
-
- string objectFilePath = Path.GetFullPath(source.GetMetadata("ObjectFileName"));
+ string objectFilePath = GetObjectFile(source);
string depFilePath = Path.ChangeExtension(objectFilePath, ".d");
try
@@ -209,8 +236,6 @@ namespace NaCl.Build.CPPTasks
if (sourceFile != null)
{
- string sourcePath = GCCUtilities.Convert_Path_Windows_To_Posix(sourceFile.ToString());
-
// Remove rtti items as they are not relevant in C compilation and will produce warnings
if (SourceIsC(sourceFile.ToString()))
{
@@ -222,7 +247,6 @@ namespace NaCl.Build.CPPTasks
string props = m_XamlParser.Parse(sourceFile);
commandLine.Append(props);
commandLine.Append(" -MD -c ");
- commandLine.Append("\"" + sourcePath + "\"");
}
return commandLine.ToString();
@@ -274,35 +298,56 @@ namespace NaCl.Build.CPPTasks
{
int returnCode = 0;
- foreach (ITaskItem sourceFileItem in CompileSourceList)
+ // Compute sources that can be compiled together.
+ Dictionary<string, List<ITaskItem>> srcGroups =
+ new Dictionary<string, List<ITaskItem>>();
+
+ foreach (ITaskItem sourceItem in CompileSourceList)
{
- try
+ string commandLine = GenerateCommandLineFromProps(sourceItem);
+ if (srcGroups.ContainsKey(commandLine))
{
- string commandLine = GenerateCommandLineFromProps(sourceFileItem);
+ srcGroups[commandLine].Add(sourceItem);
+ }
+ else
+ {
+ srcGroups.Add(commandLine, new List<ITaskItem> {sourceItem});
+ }
+ }
- base.Log.LogMessageFromText(Path.GetFileName(sourceFileItem.ToString()), MessageImportance.High);
+ string pythonExe = "C:\\python_26_amd64\\files\\python.exe";
+ string pythonScript = Path.GetDirectoryName(Path.GetDirectoryName(PropertiesFile));
+ pythonScript = Path.Combine(pythonScript, "compiler_wrapper.py");
- if (OutputCommandLine == "true")
- {
- string logMessage = pathToTool + " " + commandLine;
- Log.LogMessageFromText(logMessage, MessageImportance.High);
- }
+ foreach (KeyValuePair<string, List<ITaskItem>> entry in srcGroups)
+ {
+ string commandLine = entry.Key;
+ string cmd = "\"" + pathToTool + "\" " + commandLine + "--";
+ List<ITaskItem> sources = entry.Value;
+ foreach (ITaskItem sourceItem in sources)
+ {
+ string src = GCCUtilities.ConvertPathWindowsToPosix(sourceItem.ToString());
+ cmd += " \"" + src + "\"";
+ }
- // compile
- returnCode = base.ExecuteTool(pathToTool, commandLine, string.Empty);
+ try
+ {
+ // compile this group of sources
+ returnCode = base.ExecuteTool(pythonExe, cmd, "\"" + pythonScript + "\"");
}
- catch (Exception)
+ catch (Exception e)
{
+ Log.LogMessage("compiler exception: {0}", e);
returnCode = base.ExitCode;
}
//abort if an error was encountered
if (returnCode != 0)
- {
- return returnCode;
- }
+ break;
}
+
+ Log.LogMessage(MessageImportance.Low, "compiler returned: {0}", returnCode);
return returnCode;
}

Powered by Google App Engine
This is Rietveld 408576698