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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1  1
2 using System; 2 using System;
3 using System.Collections.Generic; 3 using System.Collections.Generic;
4 using System.Text; 4 using System.Text;
5 using System.Collections; 5 using System.Collections;
6 using System.IO; 6 using System.IO;
7 using System.Reflection; 7 using System.Reflection;
8 using System.Resources; 8 using System.Resources;
9 using Microsoft.Build.Framework; 9 using Microsoft.Build.Framework;
10 using Microsoft.Build.Utilities; 10 using Microsoft.Build.Utilities;
11 using System.Collections.Specialized;
11 12
12 using System.Diagnostics; 13 using System.Diagnostics;
13 14
14 namespace NaCl.Build.CPPTasks 15 namespace NaCl.Build.CPPTasks
15 { 16 {
16 public class NaClCompile : ToolTask 17 public class NaClCompile : ToolTask
17 { 18 {
18 private XamlParser m_XamlParser; 19 private XamlParser m_XamlParser;
19 private ITaskItem[] excludedInputPaths; 20 private ITaskItem[] excludedInputPaths;
20 private ITaskItem[] tlogReadFiles; 21 private ITaskItem[] tlogReadFiles;
(...skipping 11 matching lines...) Expand all
32 [Required] 33 [Required]
33 public string PropertiesFile { get; set; } 34 public string PropertiesFile { get; set; }
34 35
35 [Required] 36 [Required]
36 public ITaskItem[] Sources { get; set; } 37 public ITaskItem[] Sources { get; set; }
37 38
38 [Required] 39 [Required]
39 public string NaCLCompilerPath { get; set; } 40 public string NaCLCompilerPath { get; set; }
40 41
41 [Required] 42 [Required]
42 public string OutputCommandLine { get; set; } 43 public bool OutputCommandLine { get; set; }
44
45 public int ProcessorNumber { get; set; }
43 46
44 [Required] 47 [Required]
45 public string TrackerLogDirectory { get; set; } 48 public string TrackerLogDirectory { get; set; }
46 49
50 protected override StringDictionary EnvironmentOverride
51 {
52 get {
53 string show = OutputCommandLine ? "1" : "0";
54 string cores = Convert.ToString(ProcessorNumber);
55 return new StringDictionary() {
56 {"NACL_GCC_CORES", cores},
57 {"NACL_GCC_SHOW_COMMANDS", show }
58 };
59 }
60 }
47 61
48 protected override string GenerateFullPathToTool() { return ToolName; } 62 protected override string GenerateFullPathToTool() { return ToolName; }
49 63
50 public NaClCompile() 64 public NaClCompile()
51 : base(new ResourceManager("NaCl.Build.CPPTasks.Properties.Resources ", Assembly.GetExecutingAssembly())) 65 : base(new ResourceManager("NaCl.Build.CPPTasks.Properties.Resources ", Assembly.GetExecutingAssembly()))
52 { 66 {
53 this.pathToLog = string.Empty; 67 this.pathToLog = string.Empty;
54 this.EnvironmentVariables = new string []{"CYGWIN=nodosfilewarning", "LC_CTYPE=C"}; 68 this.EnvironmentVariables = new string[] { "CYGWIN=nodosfilewarning" , "LC_CTYPE=C" };
55 } 69 }
56 70
57 protected IDictionary<string, string> GenerateCommandLinesFromTlog() 71 protected IDictionary<string, string> GenerateCommandLinesFromTlog()
58 { 72 {
59 IDictionary<string, string> cmdLineDictionary = new Dictionary<strin g, string>(StringComparer.OrdinalIgnoreCase); 73 IDictionary<string, string> cmdLineDictionary = new Dictionary<strin g, string>(StringComparer.OrdinalIgnoreCase);
60 string tlogFilename = this.TLogCommandFile.GetMetadata("FullPath"); 74 string tlogFilename = this.TLogCommandFile.GetMetadata("FullPath");
61 if (File.Exists(tlogFilename)) 75 if (File.Exists(tlogFilename))
62 { 76 {
63 using (StreamReader reader = File.OpenText(tlogFilename)) 77 using (StreamReader reader = File.OpenText(tlogFilename))
64 { 78 {
65 string filename = string.Empty; 79 string filename = string.Empty;
66 for (string lineStr = reader.ReadLine(); lineStr != null; li neStr = reader.ReadLine()) 80 for (string lineStr = reader.ReadLine(); lineStr != null; li neStr = reader.ReadLine())
67 { 81 {
68 if (lineStr.Length == 0 || 82 if (lineStr.Length == 0 ||
69 (lineStr[0] == '^' && lineStr.Length == 1)) 83 (lineStr[0] == '^' && lineStr.Length == 1))
70 { 84 {
71 Log.LogMessage(MessageImportance.High, "Invalid line in command tlog"); 85 Log.LogError("Invalid line in command tlog");
72 break; 86 break;
73 } 87 }
74 else if (lineStr[0] == '^') 88 else if (lineStr[0] == '^')
75 { 89 {
76 filename = lineStr.Substring(1); 90 filename = lineStr.Substring(1);
77 } 91 }
78 else 92 else
79 { 93 {
80 cmdLineDictionary[filename] = lineStr; 94 cmdLineDictionary[filename] = lineStr;
81 } 95 }
82 } 96 }
83 } 97 }
84 } 98 }
85 return cmdLineDictionary; 99 return cmdLineDictionary;
86 } 100 }
87 101
88 protected override void LogEventsFromTextOutput(string singleLine, Messa geImportance messageImportance) 102 protected override void LogEventsFromTextOutput(string singleLine, Messa geImportance messageImportance)
89 { 103 {
90 base.LogEventsFromTextOutput(GCCUtilities.Convert_Output_GCC_to_VS(s ingleLine), messageImportance); 104 base.LogEventsFromTextOutput(GCCUtilities.Convert_Output_GCC_to_VS(s ingleLine), messageImportance);
91 } 105 }
92 106
107 static string GetObjectFile(ITaskItem source)
108 {
109 string objectFilePath = Path.GetFullPath(source.GetMetadata("ObjectF ileName"));
110 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.
111 {
112 objectFilePath = Path.Combine(objectFilePath, Path.GetFileName(s ource.ItemSpec));
113 objectFilePath = Path.ChangeExtension(objectFilePath, ".obj");
114 }
115 return objectFilePath;
116 }
117
93 private void ConstructReadTLog(ITaskItem[] compiledSources, CanonicalTra ckedOutputFiles outputs) 118 private void ConstructReadTLog(ITaskItem[] compiledSources, CanonicalTra ckedOutputFiles outputs)
94 { 119 {
95 string trackerPath = Path.GetFullPath(TlogDirectory + ReadTLogFilena mes[0]); 120 string trackerPath = Path.GetFullPath(TlogDirectory + ReadTLogFilena mes[0]);
96 121
97 //save tlog for sources not compiled during this execution 122 //save tlog for sources not compiled during this execution
98 TaskItem readTrackerItem = new TaskItem(trackerPath); 123 TaskItem readTrackerItem = new TaskItem(trackerPath);
99 CanonicalTrackedInputFiles files = new CanonicalTrackedInputFiles(ne w TaskItem[] { readTrackerItem }, Sources, outputs, false, false); 124 CanonicalTrackedInputFiles files = new CanonicalTrackedInputFiles(ne w TaskItem[] { readTrackerItem }, Sources, outputs, false, false);
100 files.RemoveEntriesForSource(compiledSources); 125 files.RemoveEntriesForSource(compiledSources);
101 files.SaveTlog(); 126 files.SaveTlog();
102 127
103 //add tlog information for compiled sources 128 //add tlog information for compiled sources
104 using (StreamWriter writer = new StreamWriter(trackerPath, true, Enc oding.Unicode)) 129 using (StreamWriter writer = new StreamWriter(trackerPath, true, Enc oding.Unicode))
105 { 130 {
106 foreach (ITaskItem source in compiledSources) 131 foreach (ITaskItem source in compiledSources)
107 { 132 {
108 string sourcePath = Path.GetFullPath(source.ItemSpec).ToUppe rInvariant(); 133 string sourcePath = Path.GetFullPath(source.ItemSpec).ToUppe rInvariant();
109 134 string objectFilePath = GetObjectFile(source);
110 string objectFilePath = Path.GetFullPath(source.GetMetadata( "ObjectFileName"));
111 string depFilePath = Path.ChangeExtension(objectFilePath, ". d"); 135 string depFilePath = Path.ChangeExtension(objectFilePath, ". d");
112 136
113 try 137 try
114 { 138 {
115 if (File.Exists(depFilePath) == false) 139 if (File.Exists(depFilePath) == false)
116 { 140 {
117 Log.LogMessage(MessageImportance.High, depFilePath + " not found"); 141 Log.LogMessage(MessageImportance.High, depFilePath + " not found");
118 } 142 }
119 else 143 else
120 { 144 {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 } 226 }
203 } 227 }
204 } 228 }
205 229
206 protected string GenerateCommandLineFromProps(ITaskItem sourceFile) 230 protected string GenerateCommandLineFromProps(ITaskItem sourceFile)
207 { 231 {
208 StringBuilder commandLine = new StringBuilder(GCCUtilities.s_Command LineLength); 232 StringBuilder commandLine = new StringBuilder(GCCUtilities.s_Command LineLength);
209 233
210 if (sourceFile != null) 234 if (sourceFile != null)
211 { 235 {
212 string sourcePath = GCCUtilities.Convert_Path_Windows_To_Posix(s ourceFile.ToString());
213
214 // Remove rtti items as they are not relevant in C compilation a nd will produce warnings 236 // Remove rtti items as they are not relevant in C compilation a nd will produce warnings
215 if (SourceIsC(sourceFile.ToString())) 237 if (SourceIsC(sourceFile.ToString()))
216 { 238 {
217 commandLine.Replace("-fno-rtti", ""); 239 commandLine.Replace("-fno-rtti", "");
218 commandLine.Replace("-frtti", ""); 240 commandLine.Replace("-frtti", "");
219 } 241 }
220 242
221 //build command line from components and add required switches 243 //build command line from components and add required switches
222 string props = m_XamlParser.Parse(sourceFile); 244 string props = m_XamlParser.Parse(sourceFile);
223 commandLine.Append(props); 245 commandLine.Append(props);
224 commandLine.Append(" -MD -c "); 246 commandLine.Append(" -MD -c ");
225 commandLine.Append("\"" + sourcePath + "\"");
226 } 247 }
227 248
228 return commandLine.ToString(); 249 return commandLine.ToString();
229 } 250 }
230 251
231 protected ITaskItem[] MergeOutOfDateSources(ITaskItem[] outOfDateSources FromTracking, List<ITaskItem> outOfDateSourcesFromCommandLineChanges) 252 protected ITaskItem[] MergeOutOfDateSources(ITaskItem[] outOfDateSources FromTracking, List<ITaskItem> outOfDateSourcesFromCommandLineChanges)
232 { 253 {
233 List<ITaskItem> mergedSources = new List<ITaskItem>(outOfDateSources FromTracking); 254 List<ITaskItem> mergedSources = new List<ITaskItem>(outOfDateSources FromTracking);
234 255
235 foreach (ITaskItem item in outOfDateSourcesFromCommandLineChanges) 256 foreach (ITaskItem item in outOfDateSourcesFromCommandLineChanges)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 else 288 else
268 { 289 {
269 return false; 290 return false;
270 } 291 }
271 } 292 }
272 293
273 private int Compile(string pathToTool) 294 private int Compile(string pathToTool)
274 { 295 {
275 int returnCode = 0; 296 int returnCode = 0;
276 297
277 foreach (ITaskItem sourceFileItem in CompileSourceList) 298 // Compute sources that can be compiled together.
299 Dictionary<string, List<ITaskItem>> srcGroups = new Dictionary<strin g, List<ITaskItem>>();
binji 2012/10/03 22:52:13 nit: wrap line
Sam Clegg 2012/10/04 22:57:57 Done.
300 foreach (ITaskItem sourceItem in CompileSourceList)
278 { 301 {
302 string commandLine = GenerateCommandLineFromProps(sourceItem);
303 if (srcGroups.ContainsKey(commandLine))
304 {
305 srcGroups[commandLine].Add(sourceItem);
306 }
307 else
308 {
309 srcGroups.Add(commandLine, new List<ITaskItem> {sourceItem}) ;
310 }
311 }
312
313 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
314 string pythonScript = Path.GetDirectoryName(Path.GetDirectoryName(Pr opertiesFile));
315 pythonScript = Path.Combine(pythonScript, "compiler_wrapper.py");
316
317 foreach (KeyValuePair<string, List<ITaskItem>> entry in srcGroups)
318 {
319 string commandLine = entry.Key;
320 string cmd = "\"" + pathToTool + "\" " + commandLine + "--";
321 List<ITaskItem> sources = entry.Value;
322
323 foreach (ITaskItem sourceItem in sources)
324 {
325 string sourcePath = GCCUtilities.Convert_Path_Windows_To_Pos ix(sourceItem.ToString());
binji 2012/10/03 22:52:13 nit: wrap line
Sam Clegg 2012/10/04 22:57:57 Done.
326 cmd += " \"" + sourcePath + "\"";
327 }
328
279 try 329 try
280 { 330 {
281 string commandLine = GenerateCommandLineFromProps(sourceFile Item); 331 // compile this group of sources
282 332 returnCode = base.ExecuteTool(pythonExe, cmd, "\"" + pythonS cript + "\"");
283 base.Log.LogMessageFromText(Path.GetFileName(sourceFileItem. ToString()), MessageImportance.High);
284
285 if (OutputCommandLine == "true")
286 {
287 string logMessage = pathToTool + " " + commandLine;
288 Log.LogMessageFromText(logMessage, MessageImportance.Hig h);
289 }
290
291
292 // compile
293 returnCode = base.ExecuteTool(pathToTool, commandLine, strin g.Empty);
294 } 333 }
295 catch (Exception) 334 catch (Exception e)
296 { 335 {
336 Log.LogMessage("compiler exception: {0}", e);
297 returnCode = base.ExitCode; 337 returnCode = base.ExitCode;
298 } 338 }
299 339
300 //abort if an error was encountered 340 //abort if an error was encountered
301 if (returnCode != 0) 341 if (returnCode != 0)
302 { 342 break;
303 return returnCode;
304 }
305 } 343 }
344
345 Log.LogMessage(MessageImportance.Low, "compiler returned: {0}", retu rnCode);
306 return returnCode; 346 return returnCode;
307 } 347 }
308 348
309 protected override int ExecuteTool(string pathToTool, string responseFil eCommands, string commandLineCommands) 349 protected override int ExecuteTool(string pathToTool, string responseFil eCommands, string commandLineCommands)
310 { 350 {
311 if (File.Exists(pathToTool) == false) 351 if (File.Exists(pathToTool) == false)
312 { 352 {
313 base.Log.LogMessageFromText("Unable to find NaCL compiler: " + p athToTool, MessageImportance.High); 353 base.Log.LogMessageFromText("Unable to find NaCL compiler: " + p athToTool, MessageImportance.High);
314 return -1; 354 return -1;
315 } 355 }
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 675
636 protected override Encoding ResponseFileEncoding 676 protected override Encoding ResponseFileEncoding
637 { 677 {
638 get 678 get
639 { 679 {
640 return Encoding.ASCII; 680 return Encoding.ASCII;
641 } 681 }
642 } 682 }
643 } 683 }
644 } 684 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698