OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 using System; | 4 using System; |
5 using System.Collections.Generic; | 5 using System.Collections.Generic; |
6 using System.Text; | 6 using System.Text; |
7 using System.Collections; | 7 using System.Collections; |
8 using System.IO; | 8 using System.IO; |
9 using System.Reflection; | 9 using System.Reflection; |
10 using System.Resources; | 10 using System.Resources; |
11 using System.Windows.Forms; | 11 using System.Windows.Forms; |
12 using Microsoft.Build.Framework; | 12 using Microsoft.Build.Framework; |
13 using Microsoft.Win32; | 13 using Microsoft.Win32; |
14 using Microsoft.Build.Utilities; | 14 using Microsoft.Build.Utilities; |
15 using System.Collections.Specialized; | 15 using System.Collections.Specialized; |
16 | 16 |
17 using System.Diagnostics; | 17 using System.Diagnostics; |
18 | 18 |
19 namespace NaCl.Build.CPPTasks | 19 namespace NaCl.Build.CPPTasks |
20 { | 20 { |
21 public abstract class NaClToolTask : ToolTask | 21 public abstract class NaClToolTask : ToolTask |
22 { | 22 { |
23 protected NaClToolTask(ResourceManager taskResources) : base(taskResourc
es) { } | 23 protected NaClToolTask(ResourceManager taskResources) : base(taskResourc
es) { } |
| 24 public bool BuildingInIDE { get; set; } |
24 protected ITaskItem[] excludedInputPaths; | 25 protected ITaskItem[] excludedInputPaths; |
25 private ITaskItem[] tlogReadFiles; | 26 private ITaskItem[] tlogReadFiles; |
26 private ITaskItem tlogCommandFile; | 27 private ITaskItem tlogCommandFile; |
27 private ITaskItem[] tlogWriteFiles; | 28 private ITaskItem[] tlogWriteFiles; |
28 private CanonicalTrackedInputFiles trackedInputFiles; | 29 private CanonicalTrackedInputFiles trackedInputFiles; |
29 private bool skippedExecution; | 30 private bool skippedExecution; |
30 private bool minimalRebuildFromTracking; | 31 private bool minimalRebuildFromTracking; |
31 private bool trackFileAccess; | 32 private bool trackFileAccess; |
32 protected ITaskItem[] compileSourceList; | 33 protected ITaskItem[] compileSourceList; |
33 protected XamlParser xamlParser; | 34 protected XamlParser xamlParser; |
34 | 35 |
35 protected abstract CanonicalTrackedOutputFiles OutputWriteTLog(ITaskItem
[] compiledSources); | |
36 protected abstract void OutputReadTLog(ITaskItem[] compiledSources, Cano
nicalTrackedOutputFiles outputs); | |
37 protected abstract void OutputCommandTLog(ITaskItem[] compiledSources); | |
38 | |
39 [Required] | 36 [Required] |
40 public string TrackerLogDirectory { get; set; } | 37 public string TrackerLogDirectory { get; set; } |
41 | 38 |
42 [Required] | 39 [Required] |
43 public virtual ITaskItem[] Sources { get; set; } | 40 public virtual ITaskItem[] Sources { get; set; } |
44 | 41 |
| 42 [Required] |
| 43 public bool OutputCommandLine { get; set; } |
| 44 |
| 45 [Required] |
| 46 public string Platform { get; set; } |
| 47 |
| 48 public virtual string OutputFile { get; set; } |
45 | 49 |
46 // Override default StandardOutputLoggingImportance so that we see the s
tdout from the | 50 // Override default StandardOutputLoggingImportance so that we see the s
tdout from the |
47 // toolchain from within visual studio. | 51 // toolchain from within visual studio. |
48 protected override MessageImportance StandardOutputLoggingImportance | 52 protected override MessageImportance StandardOutputLoggingImportance |
49 { | 53 { |
50 get { return MessageImportance.Normal; } | 54 get { return MessageImportance.Normal; } |
51 } | 55 } |
52 | 56 |
53 protected bool ForcedRebuildRequired() | 57 protected bool ForcedRebuildRequired() |
54 { | 58 { |
(...skipping 25 matching lines...) Expand all Loading... |
80 protected override bool SkipTaskExecution() | 84 protected override bool SkipTaskExecution() |
81 { | 85 { |
82 return this.skippedExecution; | 86 return this.skippedExecution; |
83 } | 87 } |
84 | 88 |
85 protected string BaseTool() | 89 protected string BaseTool() |
86 { | 90 { |
87 return Path.GetFileNameWithoutExtension(ToolName); | 91 return Path.GetFileNameWithoutExtension(ToolName); |
88 } | 92 } |
89 | 93 |
| 94 protected bool IsPNaCl() |
| 95 { |
| 96 return Platform.Equals("pnacl", StringComparison.OrdinalIgnoreCase); |
| 97 } |
| 98 |
90 protected bool Setup() | 99 protected bool Setup() |
91 { | 100 { |
92 this.SkippedExecution = false; | 101 this.SkippedExecution = false; |
93 | 102 |
94 if (!ValidateParameters()) | 103 if (!ValidateParameters()) |
95 { | 104 { |
96 return false; | 105 return false; |
97 } | 106 } |
98 | 107 |
| 108 if (IsPNaCl()) |
| 109 { |
| 110 if (!SDKUtilities.FindPython()) |
| 111 { |
| 112 Log.LogError("PNaCl linking requires python in your executab
le path."); |
| 113 return false; |
| 114 } |
| 115 } |
| 116 |
99 if (this.TrackFileAccess || this.MinimalRebuildFromTracking) | 117 if (this.TrackFileAccess || this.MinimalRebuildFromTracking) |
100 { | 118 { |
101 this.SetTrackerLogPaths(); | 119 this.SetTrackerLogPaths(); |
102 } | 120 } |
103 | 121 |
104 if (this.ForcedRebuildRequired() || this.MinimalRebuildFromTracking
== false) | 122 if (this.ForcedRebuildRequired() || this.MinimalRebuildFromTracking
== false) |
105 { | 123 { |
106 if (this.Sources == null || this.Sources.Length == 0) | 124 if (this.Sources == null || this.Sources.Length == 0) |
107 { | 125 { |
108 this.SkippedExecution = true; | 126 this.SkippedExecution = true; |
109 } | 127 } |
110 } | 128 } |
111 | 129 |
112 return true; | 130 return true; |
113 } | 131 } |
114 | 132 |
| 133 protected virtual CanonicalTrackedOutputFiles OutputWriteTLog(ITaskItem[
] inputs) |
| 134 { |
| 135 string path = Path.Combine(TlogDirectory, WriteTLogFilename); |
| 136 TaskItem item = new TaskItem(path); |
| 137 CanonicalTrackedOutputFiles trackedFiles = |
| 138 new CanonicalTrackedOutputFiles(new TaskItem[] { item }); |
| 139 |
| 140 foreach (ITaskItem sourceItem in Sources) |
| 141 { |
| 142 //remove this entry associated with compiled source which is abo
ut to be recomputed |
| 143 trackedFiles.RemoveEntriesForSource(sourceItem); |
| 144 |
| 145 //add entry with updated information |
| 146 string upper = Path.GetFullPath(sourceItem.ItemSpec).ToUpperInva
riant(); |
| 147 trackedFiles.AddComputedOutputForSourceRoot(upper, OutputFile); |
| 148 } |
| 149 |
| 150 //output tlog |
| 151 trackedFiles.SaveTlog(); |
| 152 |
| 153 return trackedFiles; |
| 154 } |
| 155 |
| 156 protected virtual void OutputReadTLog(ITaskItem[] compiledSources, |
| 157 CanonicalTrackedOutputFiles output
s) |
| 158 { |
| 159 string trackerPath = Path.GetFullPath(TlogDirectory + ReadTLogFilena
mes[0]); |
| 160 |
| 161 using (var writer = new StreamWriter(trackerPath, false, Encoding.Un
icode)) |
| 162 { |
| 163 string sourcePath = ""; |
| 164 foreach (ITaskItem source in Sources) |
| 165 { |
| 166 if (sourcePath != "") |
| 167 sourcePath += "|"; |
| 168 sourcePath += Path.GetFullPath(source.ItemSpec).ToUpperInvar
iant(); |
| 169 } |
| 170 |
| 171 writer.WriteLine("^" + sourcePath); |
| 172 foreach (ITaskItem source in Sources) |
| 173 { |
| 174 writer.WriteLine(Path.GetFullPath(source.ItemSpec).ToUpperIn
variant()); |
| 175 } |
| 176 writer.WriteLine(Path.GetFullPath(OutputFile).ToUpperInvariant()
); |
| 177 } |
| 178 } |
| 179 |
| 180 protected virtual void OutputCommandTLog(ITaskItem[] compiledSources) |
| 181 { |
| 182 string fullpath = TLogCommandFile.GetMetadata("FullPath"); |
| 183 using (var writer = new StreamWriter(fullpath, false, Encoding.Unico
de)) |
| 184 { |
| 185 string cmds = GenerateResponseFileCommands(); |
| 186 string sourcePath = ""; |
| 187 foreach (ITaskItem source in Sources) |
| 188 { |
| 189 if (sourcePath != "") |
| 190 sourcePath += "|"; |
| 191 sourcePath += Path.GetFullPath(source.ItemSpec).ToUpperInvar
iant(); |
| 192 } |
| 193 |
| 194 writer.WriteLine("^" + sourcePath); |
| 195 writer.WriteLine(cmds); |
| 196 } |
| 197 } |
| 198 |
115 public override bool Execute() | 199 public override bool Execute() |
116 { | 200 { |
117 bool returnResult = base.Execute(); | 201 bool returnResult = base.Execute(); |
118 | 202 |
119 // Update tracker log files if execution occurred | 203 // Update tracker log files if execution occurred |
120 //if (this.skippedExecution == false) | 204 //if (this.skippedExecution == false) |
121 { | 205 { |
122 CanonicalTrackedOutputFiles outputs = OutputWriteTLog(compileSou
rceList); | 206 CanonicalTrackedOutputFiles outputs = OutputWriteTLog(compileSou
rceList); |
123 OutputReadTLog(compileSourceList, outputs); | 207 OutputReadTLog(compileSourceList, outputs); |
124 OutputCommandTLog(compileSourceList); | 208 OutputCommandTLog(compileSourceList); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 } | 371 } |
288 } | 372 } |
289 | 373 |
290 protected virtual string WriteTLogFilename | 374 protected virtual string WriteTLogFilename |
291 { | 375 { |
292 get | 376 get |
293 { | 377 { |
294 return BaseTool() + ".compile.write.1.tlog"; | 378 return BaseTool() + ".compile.write.1.tlog"; |
295 } | 379 } |
296 } | 380 } |
| 381 |
| 382 public virtual string PlatformToolset |
| 383 { |
| 384 get |
| 385 { |
| 386 return "GCC"; |
| 387 } |
| 388 } |
| 389 |
| 390 protected override string GenerateFullPathToTool() |
| 391 { |
| 392 return this.ToolName; |
| 393 } |
297 } | 394 } |
298 } | 395 } |
OLD | NEW |