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

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: 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..3470f03c20187df905d82729dbf61f06ae072f38 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;
@@ -7,7 +7,8 @@ using System.IO;
using System.Reflection;
using System.Resources;
using Microsoft.Build.Framework;
-using Microsoft.Build.Utilities;
+using Microsoft.Build.Utilities;
+using System.Collections.Specialized;
using System.Diagnostics;
@@ -39,19 +40,32 @@ namespace NaCl.Build.CPPTasks
public string NaCLCompilerPath { get; set; }
[Required]
- public string OutputCommandLine { get; set; }
+ public bool OutputCommandLine { get; set; }
- [Required]
- public string TrackerLogDirectory { 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; }
public NaClCompile()
: base(new ResourceManager("NaCl.Build.CPPTasks.Properties.Resources", Assembly.GetExecutingAssembly()))
{
- this.pathToLog = string.Empty;
- this.EnvironmentVariables = new string []{"CYGWIN=nodosfilewarning", "LC_CTYPE=C"};
+ this.pathToLog = string.Empty;
+ 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] == '^')
@@ -90,6 +104,17 @@ namespace NaCl.Build.CPPTasks
base.LogEventsFromTextOutput(GCCUtilities.Convert_Output_GCC_to_VS(singleLine), messageImportance);
}
+ static string GetObjectFile(ITaskItem source)
+ {
+ string objectFilePath = Path.GetFullPath(source.GetMetadata("ObjectFileName"));
+ if ((File.GetAttributes(objectFilePath) & FileAttributes.Directory) != 0)
binji 2012/10/03 22:52:13 might be nice to have a comment here explaining wh
Sam Clegg 2012/10/04 22:57:57 Done.
+ {
+ objectFilePath = Path.Combine(objectFilePath, Path.GetFileName(source.ItemSpec));
+ objectFilePath = Path.ChangeExtension(objectFilePath, ".obj");
+ }
+ return objectFilePath;
+ }
+
private void ConstructReadTLog(ITaskItem[] compiledSources, CanonicalTrackedOutputFiles outputs)
{
string trackerPath = Path.GetFullPath(TlogDirectory + ReadTLogFilenames[0]);
@@ -106,8 +131,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 +233,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 +244,6 @@ namespace NaCl.Build.CPPTasks
string props = m_XamlParser.Parse(sourceFile);
commandLine.Append(props);
commandLine.Append(" -MD -c ");
- commandLine.Append("\"" + sourcePath + "\"");
}
return commandLine.ToString();
@@ -272,37 +293,56 @@ namespace NaCl.Build.CPPTasks
private int Compile(string pathToTool)
{
- int returnCode = 0;
+ 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>>();
binji 2012/10/03 22:52:13 nit: wrap line
Sam Clegg 2012/10/04 22:57:57 Done.
+ foreach (ITaskItem sourceItem in CompileSourceList)
{
- try
+ string commandLine = GenerateCommandLineFromProps(sourceItem);
+ if (srcGroups.ContainsKey(commandLine))
+ {
+ srcGroups[commandLine].Add(sourceItem);
+ }
+ else
{
- string commandLine = GenerateCommandLineFromProps(sourceFileItem);
+ 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";
binji 2012/10/03 22:52:13 Probably need a better way to find the python exe.
Sam Clegg 2012/10/04 22:57:57 Yup.. will be sure to find a better way before I l
+ 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 sourcePath = GCCUtilities.Convert_Path_Windows_To_Posix(sourceItem.ToString());
binji 2012/10/03 22:52:13 nit: wrap line
Sam Clegg 2012/10/04 22:57:57 Done.
+ cmd += " \"" + sourcePath + "\"";
+ }
- // 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