OLD | NEW |
(Empty) | |
| 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 |
| 3 * found in the LICENSE file. |
| 4 */ |
| 5 using System; |
| 6 using System.Collections.Generic; |
| 7 using System.Text; |
| 8 using System.Collections; |
| 9 using System.IO; |
| 10 using System.Reflection; |
| 11 using System.Resources; |
| 12 using System.Windows.Forms; |
| 13 using Microsoft.Build.Framework; |
| 14 using Microsoft.Win32; |
| 15 using Microsoft.Build.Utilities; |
| 16 using System.Collections.Specialized; |
| 17 |
| 18 using System.Diagnostics; |
| 19 |
| 20 namespace NaCl.Build.CPPTasks |
| 21 { |
| 22 public abstract class NaClToolTask : ToolTask |
| 23 { |
| 24 protected NaClToolTask(ResourceManager taskResources) : base(taskResourc
es) { } |
| 25 protected ITaskItem[] excludedInputPaths; |
| 26 private ITaskItem[] tlogReadFiles; |
| 27 private ITaskItem tlogCommandFile; |
| 28 private ITaskItem[] tlogWriteFiles; |
| 29 private CanonicalTrackedInputFiles trackedInputFiles; |
| 30 private bool skippedExecution; |
| 31 private bool minimalRebuildFromTracking; |
| 32 private bool trackFileAccess; |
| 33 protected ITaskItem[] compileSourceList; |
| 34 protected XamlParser xamlParser; |
| 35 |
| 36 protected abstract CanonicalTrackedOutputFiles OutputWriteTLog(ITaskItem
[] compiledSources); |
| 37 protected abstract void OutputReadTLog(ITaskItem[] compiledSources, Cano
nicalTrackedOutputFiles outputs); |
| 38 protected abstract void OutputCommandTLog(ITaskItem[] compiledSources); |
| 39 |
| 40 [Required] |
| 41 public string TrackerLogDirectory { get; set; } |
| 42 |
| 43 [Required] |
| 44 public virtual ITaskItem[] Sources { get; set; } |
| 45 |
| 46 protected bool ForcedRebuildRequired() |
| 47 { |
| 48 string tlogCommandPath = null; |
| 49 |
| 50 try |
| 51 { |
| 52 tlogCommandPath = this.TLogCommandFile.GetMetadata("FullPath"); |
| 53 } |
| 54 catch (Exception exception) |
| 55 { |
| 56 if (exception is InvalidOperationException || exception is NullR
eferenceException) |
| 57 return true; |
| 58 else |
| 59 throw; |
| 60 } |
| 61 |
| 62 //if command tlog file does not exist then force rebuild is required |
| 63 if (File.Exists(tlogCommandPath) == false) |
| 64 { |
| 65 return true; |
| 66 } |
| 67 else |
| 68 { |
| 69 return false; |
| 70 } |
| 71 } |
| 72 |
| 73 protected override bool SkipTaskExecution() |
| 74 { |
| 75 return this.skippedExecution; |
| 76 } |
| 77 |
| 78 protected string BaseTool() |
| 79 { |
| 80 return Path.GetFileNameWithoutExtension(ToolName); |
| 81 } |
| 82 |
| 83 protected bool Setup() |
| 84 { |
| 85 this.SkippedExecution = false; |
| 86 |
| 87 if (!ValidateParameters()) |
| 88 { |
| 89 return false; |
| 90 } |
| 91 |
| 92 if (this.TrackFileAccess || this.MinimalRebuildFromTracking) |
| 93 { |
| 94 this.SetTrackerLogPaths(); |
| 95 } |
| 96 |
| 97 if (this.ForcedRebuildRequired() || this.MinimalRebuildFromTracking
== false) |
| 98 { |
| 99 if (this.Sources == null || this.Sources.Length == 0) |
| 100 { |
| 101 this.SkippedExecution = true; |
| 102 } |
| 103 } |
| 104 |
| 105 return true; |
| 106 } |
| 107 |
| 108 public override bool Execute() |
| 109 { |
| 110 bool returnResult = base.Execute(); |
| 111 |
| 112 // Update tracker log files if execution occurred |
| 113 //if (this.skippedExecution == false) |
| 114 { |
| 115 CanonicalTrackedOutputFiles outputs = OutputWriteTLog(compileSou
rceList); |
| 116 OutputReadTLog(compileSourceList, outputs); |
| 117 OutputCommandTLog(compileSourceList); |
| 118 } |
| 119 |
| 120 return returnResult; |
| 121 } |
| 122 |
| 123 protected override Encoding ResponseFileEncoding |
| 124 { |
| 125 get |
| 126 { |
| 127 return Encoding.ASCII; |
| 128 } |
| 129 } |
| 130 |
| 131 protected virtual void SetTrackerLogPaths() |
| 132 { |
| 133 if (this.TLogCommandFile == null) |
| 134 { |
| 135 string commandFile = Path.Combine(this.TlogDirectory, this.Comma
ndTLogFilename); |
| 136 this.TLogCommandFile = new TaskItem(commandFile); |
| 137 } |
| 138 |
| 139 if (this.TLogReadFiles == null) |
| 140 { |
| 141 this.TLogReadFiles = new ITaskItem[this.ReadTLogFilenames.Length
]; |
| 142 for (int n = 0; n < this.ReadTLogFilenames.Length; n++) |
| 143 { |
| 144 string readFile = Path.Combine(this.TlogDirectory, this.Read
TLogFilenames[n]); |
| 145 this.TLogReadFiles[n] = new TaskItem(readFile); |
| 146 } |
| 147 } |
| 148 |
| 149 if (this.TLogWriteFiles == null) |
| 150 { |
| 151 this.TLogWriteFiles = new ITaskItem[1]; |
| 152 string writeFile = Path.Combine(this.TlogDirectory, this.WriteTL
ogFilename); |
| 153 this.TLogWriteFiles[0] = new TaskItem(writeFile); |
| 154 } |
| 155 } |
| 156 |
| 157 [Output] |
| 158 public bool SkippedExecution |
| 159 { |
| 160 get |
| 161 { |
| 162 return this.skippedExecution; |
| 163 } |
| 164 set |
| 165 { |
| 166 this.skippedExecution = value; |
| 167 } |
| 168 } |
| 169 |
| 170 public ITaskItem TLogCommandFile |
| 171 { |
| 172 get |
| 173 { |
| 174 return this.tlogCommandFile; |
| 175 } |
| 176 set |
| 177 { |
| 178 this.tlogCommandFile = value; |
| 179 } |
| 180 } |
| 181 |
| 182 protected string TlogDirectory |
| 183 { |
| 184 get |
| 185 { |
| 186 if (this.TrackerLogDirectory != null) |
| 187 { |
| 188 return this.TrackerLogDirectory; |
| 189 } |
| 190 return string.Empty; |
| 191 } |
| 192 } |
| 193 |
| 194 public bool MinimalRebuildFromTracking |
| 195 { |
| 196 get |
| 197 { |
| 198 return this.minimalRebuildFromTracking; |
| 199 } |
| 200 set |
| 201 { |
| 202 this.minimalRebuildFromTracking = value; |
| 203 } |
| 204 } |
| 205 |
| 206 |
| 207 public ITaskItem[] TLogReadFiles |
| 208 { |
| 209 get |
| 210 { |
| 211 return this.tlogReadFiles; |
| 212 } |
| 213 set |
| 214 { |
| 215 this.tlogReadFiles = value; |
| 216 } |
| 217 } |
| 218 |
| 219 public ITaskItem[] TLogWriteFiles |
| 220 { |
| 221 get |
| 222 { |
| 223 return this.tlogWriteFiles; |
| 224 } |
| 225 set |
| 226 { |
| 227 this.tlogWriteFiles = value; |
| 228 } |
| 229 } |
| 230 |
| 231 public bool TrackFileAccess |
| 232 { |
| 233 get |
| 234 { |
| 235 return this.trackFileAccess; |
| 236 } |
| 237 set |
| 238 { |
| 239 this.trackFileAccess = value; |
| 240 } |
| 241 } |
| 242 |
| 243 protected CanonicalTrackedInputFiles TrackedInputFiles |
| 244 { |
| 245 get |
| 246 { |
| 247 return this.trackedInputFiles; |
| 248 } |
| 249 set |
| 250 { |
| 251 this.trackedInputFiles = value; |
| 252 } |
| 253 } |
| 254 |
| 255 public ITaskItem[] ExcludedInputPaths |
| 256 { |
| 257 get |
| 258 { |
| 259 return this.excludedInputPaths; |
| 260 } |
| 261 set |
| 262 { |
| 263 this.excludedInputPaths = value; |
| 264 } |
| 265 } |
| 266 |
| 267 protected virtual string CommandTLogFilename |
| 268 { |
| 269 get |
| 270 { |
| 271 return BaseTool() + ".compile.command.1.tlog"; |
| 272 } |
| 273 } |
| 274 |
| 275 protected virtual string[] ReadTLogFilenames |
| 276 { |
| 277 get |
| 278 { |
| 279 return new string[] { BaseTool() + ".compile.read.1.tlog" }; |
| 280 } |
| 281 } |
| 282 |
| 283 protected virtual string WriteTLogFilename |
| 284 { |
| 285 get |
| 286 { |
| 287 return BaseTool() + ".compile.write.1.tlog"; |
| 288 } |
| 289 } |
| 290 } |
| 291 } |
OLD | NEW |