public void RemoveDependencyFromEntry() { Console.WriteLine("Test: RemoveDependencyFromEntry"); // Prepare files DependencyTestHelper.WriteAll("TestFiles\\one1.h", ""); DependencyTestHelper.WriteAll("TestFiles\\one2.h", ""); DependencyTestHelper.WriteAll("TestFiles\\one3.h", ""); DependencyTestHelper.WriteAll("TestFiles\\one.cpp", ""); DependencyTestHelper.WriteAll("TestFiles\\one.obj", ""); DependencyTestHelper.WriteAll("TestFiles\\one.tlh", ""); DependencyTestHelper.WriteAll("TestFiles\\one.tli", ""); Thread.Sleep(sleepTimeMilliseconds); // need to wait since the timestamp check needs some time to register File.WriteAllLines("TestFiles\\one.read.tlog", new string[] { "#Command some-command", "^" + Path.GetFullPath("TestFiles\\one.cpp"), Path.GetFullPath("TestFiles\\one1.h"), Path.GetFullPath("TestFiles\\one2.h"), Path.GetFullPath("TestFiles\\one3.h"), Path.GetFullPath("TestFiles\\one3.obj"), Path.GetFullPath("TestFiles\\one3.tlh"), Path.GetFullPath("TestFiles\\one3.tli"), }); File.WriteAllLines("TestFiles\\one.write.tlog", new string[] { "#Command some-command", "^" + Path.GetFullPath("TestFiles\\one.cpp"), Path.GetFullPath("TestFiles\\one1.h"), Path.GetFullPath("TestFiles\\one2.h"), Path.GetFullPath("TestFiles\\one3.h"), Path.GetFullPath("TestFiles\\one3.obj"), Path.GetFullPath("TestFiles\\one3.tlh"), Path.GetFullPath("TestFiles\\one3.tli"), }); CanonicalTrackedOutputFiles compactOutputs = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.write.tlog"))); compactOutputs.RemoveDependencyFromEntry(new TaskItem(Path.GetFullPath("TestFiles\\one.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\one3.obj"))); compactOutputs.SaveTlog(); CanonicalTrackedOutputFiles writtenOutputs = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.write.tlog"))); Assert.False(writtenOutputs.DependencyTable[Path.GetFullPath("TestFiles\\one.cpp")].ContainsKey(Path.GetFullPath("TestFiles\\one3.obj"))); CanonicalTrackedInputFiles compactInputs = new CanonicalTrackedInputFiles ( DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.read.tlog")), DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.cpp")), null, compactOutputs, false, /* no minimal rebuild optimization */ false /* shred composite rooting markers */ ); compactInputs.RemoveDependencyFromEntry(new TaskItem(Path.GetFullPath("TestFiles\\one.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\one3.obj"))); compactInputs.SaveTlog(); CanonicalTrackedInputFiles writtenInputs = new CanonicalTrackedInputFiles ( DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.read.tlog")), DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.cpp")), null, writtenOutputs, false, /* no minimal rebuild optimization */ false /* shred composite rooting markers */ ); Assert.False(writtenInputs.DependencyTable[Path.GetFullPath("TestFiles\\one.cpp")].ContainsKey(Path.GetFullPath("TestFiles\\one3.obj"))); }
public void SaveCompactedWriteTlog() { Console.WriteLine("Test: SaveCompactedWriteTlog"); TaskItem fooItem = new TaskItem("foo"); ITaskItem[] sources = new TaskItem[] { new TaskItem(Path.GetFullPath("TestFiles\\one.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\two.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\three.cpp"))}; string rootMarker = FileTracker.FormatRootingMarker(sources); // Prepare files Thread.Sleep(sleepTimeMilliseconds); // need to wait since the timestamp check needs some time to register File.WriteAllLines("TestFiles\\one.tlog", new string[] { "#Command some-command", "^" + rootMarker, Path.GetFullPath("TestFiles\\oNe.obj"), "^" + fooItem.GetMetadata("Fullpath"), Path.GetFullPath("TestFiles\\foo1.bar"), Path.GetFullPath("TestFiles\\bar1.baz"), }); File.WriteAllLines("TestFiles\\two.tlog", new string[] { "#Command some-command", "^" + rootMarker, Path.GetFullPath("TestFiles\\two.obj"), Path.GetFullPath("TestFiles\\three.obj"), "^" + fooItem.GetMetadata("Fullpath"), Path.GetFullPath("TestFiles\\foo2.bar"), Path.GetFullPath("TestFiles\\bar2.baz"), }); ITaskItem[] tlogs = { new TaskItem("TestFiles\\one.tlog"), new TaskItem("TestFiles\\two.tlog") }; Thread.Sleep(sleepTimeMilliseconds); // need to wait since the timestamp check needs some time to register CanonicalTrackedOutputFiles d = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, tlogs); ITaskItem[] outputs = d.OutputsForSource(sources); Assert.Equal(3, outputs.Length); Assert.Equal(outputs[0].ItemSpec, Path.GetFullPath("TestFiles\\oNe.obj")); Assert.Equal(outputs[1].ItemSpec, Path.GetFullPath("TestFiles\\two.obj")); Assert.Equal(outputs[2].ItemSpec, Path.GetFullPath("TestFiles\\three.obj")); outputs = d.OutputsForSource(fooItem); Assert.Equal(4, outputs.Length); Assert.Equal(outputs[0].ItemSpec, Path.GetFullPath("TestFiles\\foo1.bar")); Assert.Equal(outputs[1].ItemSpec, Path.GetFullPath("TestFiles\\bar1.baz")); Assert.Equal(outputs[2].ItemSpec, Path.GetFullPath("TestFiles\\foo2.bar")); Assert.Equal(outputs[3].ItemSpec, Path.GetFullPath("TestFiles\\bar2.baz")); // Compact the tlog removing all entries for "foo" leaving the other entries intact d.RemoveEntriesForSource(fooItem); d.SaveTlog(); // All the tlogs need to still be there even after compaction // It's OK for them to be empty, but their absence might mean a partial clean // A missing tlog would mean a clean build Assert.True(Microsoft.Build.Utilities.TrackedDependencies.ItemsExist(tlogs)); // All log information should now be in the tlog[0] ITaskItem[] tlogs2 = { tlogs[0] }; CanonicalTrackedOutputFiles d2 = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, tlogs2); outputs = d2.OutputsForSource(fooItem); Assert.Equal(0, outputs.Length); outputs = d2.OutputsForSource(sources); Assert.Equal(3, outputs.Length); Assert.Equal(outputs[0].ItemSpec, Path.GetFullPath("TestFiles\\oNe.obj")); Assert.Equal(outputs[1].ItemSpec, Path.GetFullPath("TestFiles\\two.obj")); Assert.Equal(outputs[2].ItemSpec, Path.GetFullPath("TestFiles\\three.obj")); // There should be no difference even if we send in all the original tlogs CanonicalTrackedOutputFiles d3 = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, tlogs); outputs = d3.OutputsForSource(fooItem); Assert.Equal(0, outputs.Length); outputs = d3.OutputsForSource(sources); Assert.Equal(3, outputs.Length); Assert.Equal(outputs[0].ItemSpec, Path.GetFullPath("TestFiles\\oNe.obj")); Assert.Equal(outputs[1].ItemSpec, Path.GetFullPath("TestFiles\\two.obj")); Assert.Equal(outputs[2].ItemSpec, Path.GetFullPath("TestFiles\\three.obj")); }
public void MultipleCanonicalCLCompactMissingOnSuccessMultiEntry() { Console.WriteLine("Test: MultipleCanonicalCLCompactMissingOnSuccessMultiEntry"); // Prepare files DependencyTestHelper.WriteAll("TestFiles\\one1.h", ""); DependencyTestHelper.WriteAll("TestFiles\\one2.h", ""); DependencyTestHelper.WriteAll("TestFiles\\one3.h", ""); DependencyTestHelper.WriteAll("TestFiles\\one.cpp", ""); DependencyTestHelper.WriteAll("TestFiles\\one.obj", ""); Thread.Sleep(sleepTimeMilliseconds); // need to wait since the timestamp check needs some time to register File.WriteAllLines("TestFiles\\one.read.tlog", new string[] { "#Command some-command", "^" + Path.GetFullPath("TestFiles\\one.cpp"), Path.GetFullPath("TestFiles\\one1.h"), Path.GetFullPath("TestFiles\\one2.h"), Path.GetFullPath("TestFiles\\one3.h"), "^" + Path.GetFullPath("TestFiles\\two.cpp"), Path.GetFullPath("TestFiles\\two1.h"), Path.GetFullPath("TestFiles\\two2.h"), }); File.WriteAllLines("TestFiles\\one.write.tlog", new string[] { "#Command some-command", "^" + Path.GetFullPath("TestFiles\\one.cpp"), Path.GetFullPath("TestFiles\\one.obj"), Path.GetFullPath("TestFiles\\sometempfile.obj"), "^" + Path.GetFullPath("TestFiles\\two.cpp"), Path.GetFullPath("TestFiles\\two.obj"), Path.GetFullPath("TestFiles\\sometempfile2.obj") }); CanonicalTrackedOutputFiles compactOutputs = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.write.tlog"))); compactOutputs.RemoveDependenciesFromEntryIfMissing(new TaskItem(Path.GetFullPath("TestFiles\\one.cpp"))); compactOutputs.SaveTlog(); // Compact the read tlog CanonicalTrackedInputFiles compactInputs = new CanonicalTrackedInputFiles ( DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.read.tlog")), DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.cpp")), null, compactOutputs, false, /* no minimal rebuild optimization */ false /* shred composite rooting markers */ ); compactInputs.RemoveDependenciesFromEntryIfMissing(new TaskItem(Path.GetFullPath("TestFiles\\one.cpp"))); compactInputs.SaveTlog(); CanonicalTrackedOutputFiles writtenOutputs = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.write.tlog"))); CanonicalTrackedInputFiles writtenInputs = new CanonicalTrackedInputFiles ( DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.read.tlog")), DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.cpp")), null, writtenOutputs, false, /* no minimal rebuild optimization */ false /* shred composite rooting markers */ ); Assert.Equal(1, writtenOutputs.DependencyTable[Path.GetFullPath("TestFiles\\one.cpp")].Count); Assert.Equal(4, writtenInputs.DependencyTable[Path.GetFullPath("TestFiles\\one.cpp")].Count); // Everything to do with two.cpp should be left intact Assert.Equal(2, writtenOutputs.DependencyTable[Path.GetFullPath("TestFiles\\two.cpp")].Count); Assert.Equal(3, writtenInputs.DependencyTable[Path.GetFullPath("TestFiles\\two.cpp")].Count); }
public void MultipleCanonicalCLMissingOutputDependencyRemoved() { Console.WriteLine("Test: MultipleCanonicalCLMissingOutputDependencyRemoved"); // Prepare files DependencyTestHelper.WriteAll("TestFiles\\one1.h", ""); DependencyTestHelper.WriteAll("TestFiles\\one2.h", ""); DependencyTestHelper.WriteAll("TestFiles\\one3.h", ""); DependencyTestHelper.WriteAll("TestFiles\\one.cpp", ""); DependencyTestHelper.WriteAll("TestFiles\\two.cpp", ""); Thread.Sleep(sleepTimeMilliseconds); // need to wait since the timestamp check needs some time to register DependencyTestHelper.WriteAll("TestFiles\\one.obj", ""); DependencyTestHelper.WriteAll("TestFiles\\two.obj", ""); File.WriteAllLines("TestFiles\\one.read.tlog", new string[] { "#Command some-command", "^" + Path.GetFullPath("TestFiles\\one.cpp"), Path.GetFullPath("TestFiles\\one1.h"), Path.GetFullPath("TestFiles\\one2.h"), Path.GetFullPath("TestFiles\\one3.h"), "^" + Path.GetFullPath("TestFiles\\two.cpp"), Path.GetFullPath("TestFiles\\one1.h"), Path.GetFullPath("TestFiles\\one2.h"), }); File.WriteAllLines("TestFiles\\one.write.tlog", new string[] { "#Command some-command", "^" + Path.GetFullPath("TestFiles\\one.cpp"), Path.GetFullPath("TestFiles\\one.obj"), "^" + Path.GetFullPath("TestFiles\\two.cpp"), Path.GetFullPath("TestFiles\\two.obj"), Path.GetFullPath("TestFiles\\sometempfile2.obj") }); string missing = Path.GetFullPath("TestFiles\\sometempfile2.obj"); CanonicalTrackedOutputFiles compactOutputs = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.write.tlog"))); // Save out the compacted read log - our missing dependency will be compacted away // Use an anonymous method to encapsulate the contains check for the tlogs compactOutputs.SaveTlog(delegate (string fullTrackedPath) { // We need to answer the question "should fullTrackedPath be included in the TLog?" return (String.Compare(fullTrackedPath, missing, StringComparison.OrdinalIgnoreCase) != 0); }); // Read the Tlogs back in.. compactOutputs = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.write.tlog"))); // Compact the read tlog CanonicalTrackedInputFiles compactInputs = new CanonicalTrackedInputFiles ( DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.read.tlog")), new TaskItem[] { new TaskItem("TestFiles\\one.cpp"), new TaskItem("TestFiles\\two.cpp") }, null, compactOutputs, false, /* no minimal rebuild optimization */ false /* shred composite rooting markers */ ); compactInputs.SaveTlog(); ITaskItem[] outofDate = compactInputs.ComputeSourcesNeedingCompilation(); Assert.Equal(0, outofDate.Length); }
protected void CalcSourcesToBuild() { //check if full recompile is required otherwise perform incremental if (ForcedRebuildRequired() || MinimalRebuildFromTracking == false) { CompileSourceList = Sources; return; } //retrieve list of sources out of date due to command line changes List<ITaskItem> outOfDateSourcesFromCommandLine = GetOutOfDateSourcesFromCmdLineChanges(); //retrieve sources out of date due to tracking CanonicalTrackedOutputFiles outputs = new CanonicalTrackedOutputFiles(this, TLogWriteFiles); TrackedInputFiles = new CanonicalTrackedInputFiles(this, TLogReadFiles, Sources, ExcludedInputPaths, outputs, true, false); ITaskItem[] outOfDateSourcesFromTracking = TrackedInputFiles.ComputeSourcesNeedingCompilation(); //merge out of date lists CompileSourceList = MergeOutOfDateSources(outOfDateSourcesFromTracking, outOfDateSourcesFromCommandLine); if (CompileSourceList.Length == 0) { SkippedExecution = true; return; } //remove sources to compile from tracked file list TrackedInputFiles.RemoveEntriesForSource(CompileSourceList); outputs.RemoveEntriesForSource(CompileSourceList); TrackedInputFiles.SaveTlog(); outputs.SaveTlog(); }
public void MultipleCanonicalCLCompactMissingOnSuccess() { Console.WriteLine("Test: MultipleCanonicalCLCompactMissingOnSuccess"); // Prepare files DependencyTestHelper.WriteAll("TestFiles\\one1.h", ""); DependencyTestHelper.WriteAll("TestFiles\\one2.h", ""); DependencyTestHelper.WriteAll("TestFiles\\one3.h", ""); DependencyTestHelper.WriteAll("TestFiles\\one.cpp", ""); DependencyTestHelper.WriteAll("TestFiles\\one.obj", ""); Thread.Sleep(sleepTimeMilliseconds); // need to wait since the timestamp check needs some time to register File.WriteAllLines("TestFiles\\one.read.tlog", new string[] { "#Command some-command", "^" + Path.GetFullPath("TestFiles\\one.cpp"), Path.GetFullPath("TestFiles\\one1.h"), Path.GetFullPath("TestFiles\\one2.h"), Path.GetFullPath("TestFiles\\one3.h"), }); File.WriteAllLines("TestFiles\\one.write.tlog", new string[] { "#Command some-command", "^" + Path.GetFullPath("TestFiles\\one.cpp"), Path.GetFullPath("TestFiles\\one.obj"), Path.GetFullPath("TestFiles\\sometempfile.obj") }); CanonicalTrackedOutputFiles compactOutputs = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.write.tlog"))); compactOutputs.RemoveDependenciesFromEntryIfMissing(new TaskItem(Path.GetFullPath("TestFiles\\one.cpp"))); compactOutputs.SaveTlog(); // Compact the read tlog CanonicalTrackedInputFiles compactInputs = new CanonicalTrackedInputFiles ( DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.read.tlog")), DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.cpp")), null, compactOutputs, false, /* no minimal rebuild optimization */ false /* shred composite rooting markers */ ); compactInputs.RemoveDependenciesFromEntryIfMissing(new TaskItem(Path.GetFullPath("TestFiles\\one.cpp"))); compactInputs.SaveTlog(); CanonicalTrackedOutputFiles outputs = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.write.tlog"))); CanonicalTrackedInputFiles d = new CanonicalTrackedInputFiles ( DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.read.tlog")), DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.cpp")), null, outputs, false, /* no minimal rebuild optimization */ false /* shred composite rooting markers */ ); ITaskItem[] outofdate = d.ComputeSourcesNeedingCompilation(); Assert.Equal(0, outofdate.Length); }
private CanonicalTrackedOutputFiles ConstructWriteTLog( ITaskItem[] upToDateSources ) { // Remove any files we're about to compile from the log TaskItem item = new TaskItem( Path.Combine( TrackerIntermediateDirectory, WriteTLogNames[0] ) ); CanonicalTrackedOutputFiles files = new CanonicalTrackedOutputFiles( new TaskItem[] { item } ); files.RemoveEntriesForSource( Sources ); // Add in the files we're compiling right now. Essentially just updating their output object filenames. foreach ( ITaskItem sourceItem in upToDateSources ) { string sourcePath = Path.GetFullPath( sourceItem.ItemSpec ).ToUpperInvariant(); string objectFile = Path.GetFullPath( sourceItem.GetMetadata( "ObjectFileName" ) ).ToUpperInvariant(); files.AddComputedOutputForSourceRoot( sourcePath, objectFile ); } // Save it out files.SaveTlog(); // Pass onto the ReadTLog saving return files; }
protected virtual CanonicalTrackedOutputFiles OutputWriteTLog(ITaskItem[] inputs) { string path = Path.Combine(TlogDirectory, WriteTLogFilename); TaskItem item = new TaskItem(path); CanonicalTrackedOutputFiles trackedFiles = new CanonicalTrackedOutputFiles(new TaskItem[] { item }); foreach (ITaskItem sourceItem in Sources) { //remove this entry associated with compiled source which is about to be recomputed trackedFiles.RemoveEntriesForSource(sourceItem); //add entry with updated information string upper = Path.GetFullPath(sourceItem.ItemSpec).ToUpperInvariant(); trackedFiles.AddComputedOutputForSourceRoot(upper, OutputFile); } //output tlog trackedFiles.SaveTlog(); return trackedFiles; }
// private void BeginUnicodeOutput() // { // this.unicodePipeReadHandle = null; // this.unicodePipeWriteHandle = null; // this.unicodeOutputEnded = null; // if (this.UseUnicodeOutput) // { // NativeMethodsShared.SecurityAttributes lpPipeAttributes = new NativeMethodsShared.SecurityAttributes { // lpSecurityDescriptor = NativeMethodsShared.NullIntPtr, // bInheritHandle = true // }; // if (NativeMethodsShared.CreatePipe(out this.unicodePipeReadHandle, out this.unicodePipeWriteHandle, lpPipeAttributes, 0)) // { // List<string> list = new List<string>(); // if (base.EnvironmentVariables != null) // { // list.AddRange(base.EnvironmentVariables); // } // list.Add("VS_UNICODE_OUTPUT=" + this.unicodePipeWriteHandle.DangerousGetHandle()); // base.EnvironmentVariables = list.ToArray(); // this.unicodeOutputEnded = new AutoResetEvent(false); // ThreadPool.QueueUserWorkItem(new WaitCallback(this.ReadUnicodeOutput)); // } // else // { // base.Log.LogWarningWithCodeFromResources("TrackedVCToolTask.CreateUnicodeOutputPipeFailed", new object[] { this.ToolName }); // } // } // } /*internal*/ protected virtual bool ComputeOutOfDateSources() { if (this.TrackerIntermediateDirectory != null) { string trackerIntermediateDirectory = this.TrackerIntermediateDirectory; } if (this.MinimalRebuildFromTracking || this.TrackFileAccess) { this.AssignDefaultTLogPaths(); } if (this.MinimalRebuildFromTracking && !this.ForcedRebuildRequired()) { CanonicalTrackedOutputFiles outputs = new CanonicalTrackedOutputFiles(this, this.TLogWriteFiles); this.sourceDependencies = new CanonicalTrackedInputFiles(this, this.TLogReadFiles, this.TrackedInputFiles, this.ExcludedInputPaths, outputs, this.UseMinimalRebuildOptimization, this.MaintainCompositeRootingMarkers); ITaskItem[] sourcesOutOfDateThroughTracking = this.SourceDependencies.ComputeSourcesNeedingCompilation(false); List<ITaskItem> sourcesWithChangedCommandLines = this.GenerateSourcesOutOfDateDueToCommandLine(); this.SourcesCompiled = this.MergeOutOfDateSourceLists(sourcesOutOfDateThroughTracking, sourcesWithChangedCommandLines); if (this.SourcesCompiled.Length == 0) { this.SkippedExecution = true; return this.SkippedExecution; } this.SourcesCompiled = this.AssignOutOfDateSources(this.SourcesCompiled); this.SourceDependencies.RemoveEntriesForSource(this.SourcesCompiled); this.SourceDependencies.SaveTlog(); outputs.RemoveEntriesForSource(this.SourcesCompiled); outputs.SaveTlog(); } else { this.SourcesCompiled = this.TrackedInputFiles; if ((this.SourcesCompiled == null) || (this.SourcesCompiled.Length == 0)) { this.SkippedExecution = true; return this.SkippedExecution; } } if (this.TrackFileAccess) { this.RootSource = FileTracker.FormatRootingMarker(this.SourcesCompiled); } this.SkippedExecution = false; return this.SkippedExecution; }
protected override bool ComputeOutOfDateSources() { // Same as base class, other than the things commented out. // We're not using CustomTrackedVCToolTask's File Tracker, we're using our own. Hence these changes. if (this.TrackerIntermediateDirectory != null) { string trackerIntermediateDirectory = this.TrackerIntermediateDirectory; } if (this.MinimalRebuildFromTracking || this.TrackFileAccess) { this.AssignDefaultTLogPaths(); } if (this.MinimalRebuildFromTracking && !this.ForcedRebuildRequired()) { CanonicalTrackedOutputFiles outputs = new CanonicalTrackedOutputFiles(this, this.TLogWriteFiles); this.SourceDependencies = new CanonicalTrackedInputFiles(this, this.TLogReadFiles, this.Sources /*TrackedInputFiles*/, this.ExcludedInputPaths, outputs, /*this.UseMinimalRebuildOptimization*/ true, /*this.MaintainCompositeRootingMarkers*/ false); ITaskItem[] sourcesOutOfDateThroughTracking = this.SourceDependencies.ComputeSourcesNeedingCompilation(/*false*/); List<ITaskItem> sourcesWithChangedCommandLines = this.GenerateSourcesOutOfDateDueToCommandLine(); this.SourcesCompiled = this.MergeOutOfDateSourceLists(sourcesOutOfDateThroughTracking, sourcesWithChangedCommandLines); if (this.SourcesCompiled.Length == 0) { this.SkippedExecution = true; return this.SkippedExecution; } this.SourcesCompiled = this.AssignOutOfDateSources(this.SourcesCompiled); this.SourceDependencies.RemoveEntriesForSource(this.SourcesCompiled); this.SourceDependencies.SaveTlog(); outputs.RemoveEntriesForSource(this.SourcesCompiled); outputs.SaveTlog(); } else { this.SourcesCompiled = this.TrackedInputFiles; if ((this.SourcesCompiled == null) || (this.SourcesCompiled.Length == 0)) { this.SkippedExecution = true; return this.SkippedExecution; } } // if (this.TrackFileAccess) // { // this.RootSource = FileTracker.FormatRootingMarker(this.SourcesCompiled); // } this.SkippedExecution = false; return this.SkippedExecution; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// protected override bool Setup () { bool result = base.Setup (); OutOfDateSources = Sources; if (result && !SkippedExecution) { // // Retrieve list of sources considered out-of-date due to either command line changes or tracker flagging. // TODO: Switch use of CanonicalTracked* helpers to TrackedFileManager. // CanonicalTrackedOutputFiles trackedOutputFiles = new CanonicalTrackedOutputFiles (this, TLogWriteFiles); TrackedInputFiles = new CanonicalTrackedInputFiles (this, TLogReadFiles, Sources, ExcludedInputPaths, trackedOutputFiles, true, false);//true); ITaskItem [] outOfDateSourcesFromTracking = TrackedInputFiles.ComputeSourcesNeedingCompilation ();// (true); ITaskItem [] outOfDateSourcesFromCommandLine = GetOutOfDateSourcesFromCmdLineChanges (Sources); #if DEBUG Log.LogMessageFromText (string.Format ("[{0}] --> No. out-of-date sources (from tracking): {1}", ToolName, outOfDateSourcesFromTracking.Length), MessageImportance.Low); Log.LogMessageFromText (string.Format ("[{0}] --> No. out-of-date sources (command line differs): {1}", ToolName, outOfDateSourcesFromCommandLine.Length), MessageImportance.Low); #endif // // Merge out-of-date lists from both sources and assign these for compilation. // HashSet<ITaskItem> mergedOutOfDateSources = new HashSet<ITaskItem> (outOfDateSourcesFromTracking); foreach (ITaskItem item in outOfDateSourcesFromCommandLine) { if (!mergedOutOfDateSources.Contains (item)) { mergedOutOfDateSources.Add (item); } } OutOfDateSources = new ITaskItem [mergedOutOfDateSources.Count]; mergedOutOfDateSources.CopyTo (OutOfDateSources); if ((OutOfDateSources == null) || (OutOfDateSources.Length == 0)) { SkippedExecution = true; } else { // // Remove sources to compile from tracked file list. // TrackedInputFiles.RemoveEntriesForSource (OutOfDateSources); trackedOutputFiles.RemoveEntriesForSource (OutOfDateSources); TrackedInputFiles.SaveTlog (); trackedOutputFiles.SaveTlog (); } } #if DEBUG Log.LogMessageFromText (string.Format ("[{0}] --> Skipped execution: {1}", ToolName, SkippedExecution), MessageImportance.Low); for (int i = 0; i < OutOfDateSources.Length; ++i) { Log.LogMessageFromText (string.Format ("[{0}] --> Out-of-date Sources: [{1}] {2}", ToolName, i, OutOfDateSources [i].ToString ()), MessageImportance.Low); } #endif return result; }
protected int ExecuteTool2(string pathToTool, string responseFileCommands, string commandLineCommands) { int num = 0; try { num = this.TrackerExecuteTool(pathToTool, responseFileCommands, commandLineCommands); } finally { if (this.MinimalRebuildFromTracking || this.TrackFileAccess) { CanonicalTrackedOutputFiles outputs = new CanonicalTrackedOutputFiles(this.TLogWriteFiles); CanonicalTrackedInputFiles compactInputs = new CanonicalTrackedInputFiles(this.TLogReadFiles, this.TrackedInputFiles, this.ExcludedInputPaths, outputs, false, this.MaintainCompositeRootingMarkers); string[] strArray = null; IDictionary<string, string> sourcesToCommandLines = this.MapSourcesToCommandLines(); if (num != 0) { outputs.RemoveEntriesForSource(this.SourcesCompiled); outputs.SaveTlog(); compactInputs.RemoveEntriesForSource(this.SourcesCompiled); compactInputs.SaveTlog(); if (this.MaintainCompositeRootingMarkers) { sourcesToCommandLines.Remove(FileTracker.FormatRootingMarker(this.SourcesCompiled)); } else { foreach (ITaskItem item in this.SourcesCompiled) { sourcesToCommandLines.Remove(FileTracker.FormatRootingMarker(item)); } } this.WriteSourcesToCommandLinesTable(sourcesToCommandLines); } else { this.AddTaskSpecificOutputs(this.SourcesCompiled, outputs); this.RemoveTaskSpecificOutputs(outputs); outputs.RemoveDependenciesFromEntryIfMissing(this.SourcesCompiled); if (this.MaintainCompositeRootingMarkers) { strArray = outputs.RemoveRootsWithSharedOutputs(this.SourcesCompiled); foreach (string str in strArray) { compactInputs.RemoveEntryForSourceRoot(str); } } if ((this.TrackedOutputFilesToIgnore != null) && (this.TrackedOutputFilesToIgnore.Length > 0)) { Dictionary<string, ITaskItem> trackedOutputFilesToRemove = new Dictionary<string, ITaskItem>(StringComparer.OrdinalIgnoreCase); foreach (ITaskItem item2 in this.TrackedOutputFilesToIgnore) { trackedOutputFilesToRemove.Add(item2.GetMetadata("FullPath"), item2); } outputs.SaveTlog(delegate(string fullTrackedPath) { if (trackedOutputFilesToRemove.ContainsKey(fullTrackedPath)) { return false; } return true; }); } else { outputs.SaveTlog(); } this.RemoveTaskSpecificInputs(compactInputs); compactInputs.RemoveDependenciesFromEntryIfMissing(this.SourcesCompiled); if ((this.TrackedInputFilesToIgnore != null) && (this.TrackedInputFilesToIgnore.Length > 0)) { Dictionary<string, ITaskItem> trackedInputFilesToRemove = new Dictionary<string, ITaskItem>(StringComparer.OrdinalIgnoreCase); foreach (ITaskItem item3 in this.TrackedInputFilesToIgnore) { trackedInputFilesToRemove.Add(item3.GetMetadata("FullPath"), item3); } compactInputs.SaveTlog(delegate(string fullTrackedPath) { if (trackedInputFilesToRemove.ContainsKey(fullTrackedPath)) { return false; } return true; }); } else { compactInputs.SaveTlog(); } if (this.MaintainCompositeRootingMarkers) { string str2 = GenerateCommandLine(); sourcesToCommandLines[FileTracker.FormatRootingMarker(this.SourcesCompiled)] = str2; if (strArray != null) { foreach (string str3 in strArray) { sourcesToCommandLines.Remove(str3); } } } else { string str4 = this.SourcesPropertyName ?? "Sources"; string str5 = GenerateCommandLineExceptSwitches(new string[] { str4 }); foreach (ITaskItem item4 in this.SourcesCompiled) { sourcesToCommandLines[FileTracker.FormatRootingMarker(item4)] = str5 + " " + item4.GetMetadata("FullPath").ToUpperInvariant(); } } this.WriteSourcesToCommandLinesTable(sourcesToCommandLines); } } } return num; }
protected override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands) { responseFileCommands = responseFileCommands.Replace("[PackageName]", PackageName); commandLineCommands = commandLineCommands.Replace("[PackageName]", PackageName); string src = ""; foreach (var item in Sources) src += " " + item.ToString(); if (ShowCommandLine) Log.LogMessage(MessageImportance.High, pathToTool + " " + responseFileCommands + " " + commandLineCommands); else Log.LogMessage(MessageImportance.High, "Compiling" + src); /* return base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands); */ int num = 0; try { num = this.TrackerExecuteTool(pathToTool, responseFileCommands, commandLineCommands); return num; } finally { if (this.MinimalRebuildFromTracking || this.TrackFileAccess) { CanonicalTrackedOutputFiles trackedOutputFiles = new CanonicalTrackedOutputFiles(this.TLogWriteFiles); CanonicalTrackedInputFiles trackedInputFiles = new CanonicalTrackedInputFiles(this.TLogReadFiles, this.Sources, this.ExcludedInputPaths, trackedOutputFiles, true, this.MaintainCompositeRootingMarkers); DependencyFilter includeInTLog = new DependencyFilter(this.OutputDependencyFilter); DependencyFilter dependencyFilter = new DependencyFilter(this.InputDependencyFilter); this.trackedInputFilesToRemove = new Dictionary<string, ITaskItem>((IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase); if (this.TrackedInputFilesToIgnore != null) { foreach (ITaskItem taskItem in this.TrackedInputFilesToIgnore) this.trackedInputFilesToRemove.Add(taskItem.GetMetadata("FullPath"), taskItem); } this.trackedOutputFilesToRemove = new Dictionary<string, ITaskItem>((IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase); if (this.TrackedOutputFilesToIgnore != null) { foreach (ITaskItem taskItem in this.TrackedOutputFilesToIgnore) this.trackedOutputFilesToRemove.Add(taskItem.GetMetadata("FullPath"), taskItem); } trackedOutputFiles.RemoveDependenciesFromEntryIfMissing(this.SourcesCompiled); trackedInputFiles.RemoveDependenciesFromEntryIfMissing(this.SourcesCompiled); if (num != 0) { ITaskItem[] source1; ITaskItem[] upToDateSources; if (this.SourcesCompiled.Length > 1) { KeyValuePair<string, bool>[] keyValuePairArray = new KeyValuePair<string, bool>[]{ new KeyValuePair<string, bool>("ObjectFile", true), /* new KeyValuePair<string, bool>("BrowseInformationFile", this.BrowseInformation), new KeyValuePair<string, bool>("XMLDocumentationFileName", this.GenerateXMLDocumentationFiles) */ }; foreach (ITaskItem source2 in this.Sources) { string sourceKey = FileTracker.FormatRootingMarker(source2); foreach (KeyValuePair<string, bool> keyValuePair in keyValuePairArray) { string metadata = source2.GetMetadata(keyValuePair.Key); if (keyValuePair.Value && !string.IsNullOrEmpty(metadata)) trackedOutputFiles.AddComputedOutputForSourceRoot(sourceKey, metadata); } } source1 = trackedInputFiles.ComputeSourcesNeedingCompilation(); List<ITaskItem> taskItemList = new List<ITaskItem>(); int index = 0; foreach (ITaskItem taskItem in this.SourcesCompiled) { if (index >= source1.Length) taskItemList.Add(taskItem); else if (!source1[index].Equals((object) taskItem)) taskItemList.Add(taskItem); else ++index; } upToDateSources = taskItemList.ToArray(); foreach (ITaskItem source2 in this.Sources) { string sourceRoot = FileTracker.FormatRootingMarker(source2); foreach (KeyValuePair<string, bool> keyValuePair in keyValuePairArray) { string metadata = source2.GetMetadata(keyValuePair.Key); if (keyValuePair.Value && !string.IsNullOrEmpty(metadata)) trackedOutputFiles.RemoveOutputForSourceRoot(sourceRoot, metadata); } } } else { source1 = this.SourcesCompiled; upToDateSources = new ITaskItem[0]; } //trackedOutputFiles.RemoveEntriesForSource(source1, this.preprocessOutput); trackedOutputFiles.SaveTlog(includeInTLog); trackedInputFiles.RemoveEntriesForSource(source1); trackedInputFiles.SaveTlog(dependencyFilter); this.ConstructCommandTLog(upToDateSources, dependencyFilter); } else { this.RemoveTaskSpecificInputs(trackedInputFiles); trackedOutputFiles.SaveTlog(includeInTLog); trackedInputFiles.SaveTlog(dependencyFilter); this.ConstructCommandTLog(this.SourcesCompiled, dependencyFilter); } TrackedVCToolTask.DeleteEmptyFile(this.TLogWriteFiles); TrackedVCToolTask.DeleteEmptyFile(this.TLogReadFiles); } } }
private void GetResourcesToProcess(out List<ITaskItem> inputsToProcess, out List<ITaskItem> outputsToProcess) { CanonicalTrackedInputFiles files2; inputsToProcess = new List<ITaskItem>(); outputsToProcess = new List<ITaskItem>(); for (int i = 0; i < this.Sources.Length; i++) { this.Sources[i].CopyMetadataTo(this.OutputResources[i]); this.Sources[i].SetMetadata("OutputResource", this.OutputResources[i].ItemSpec); } if (!this.MinimalRebuildFromTracking) { for (int j = 0; j < this.Sources.Length; j++) { inputsToProcess.Add(this.Sources[j]); outputsToProcess.Add(this.OutputResources[j]); } return; } ITaskItem[] readTLogs = TrackedDependencies.ExpandWildcards(this.TLogReadFiles); ITaskItem[] writeTLogs = TrackedDependencies.ExpandWildcards(this.TLogWriteFiles); if (((this.AdditionalInputs != null) && (this.AdditionalInputs.Length > 0)) && this.AnyAdditionalInputOutOfDate(readTLogs, writeTLogs)) { for (int k = 0; k < this.Sources.Length; k++) { inputsToProcess.Add(this.Sources[k]); outputsToProcess.Add(this.OutputResources[k]); } return; } CanonicalTrackedOutputFiles outputs = new CanonicalTrackedOutputFiles(this, writeTLogs, false); foreach (ITaskItem item in this.Sources) { string sourceKey = FileTracker.FormatRootingMarker(item); outputs.AddComputedOutputForSourceRoot(sourceKey, item.GetMetadata(outputFileMetadataName)); } if (this.StronglyTypedLanguage != null) { try { if (this.StronglyTypedFileName == null) { CodeDomProvider provider = null; if (ProcessResourceFiles.TryCreateCodeDomProvider(base.Log, this.StronglyTypedLanguage, out provider)) { this.StronglyTypedFileName = ProcessResourceFiles.GenerateDefaultStronglyTypedFilename(provider, this.OutputResources[0].ItemSpec); } } if (this.StronglyTypedFileName != null) { string str2 = FileTracker.FormatRootingMarker(this.Sources[0]); outputs.AddComputedOutputForSourceRoot(str2, this.StronglyTypedFileName); goto Label_01F8; } this.unsuccessfullyCreatedOutFiles.Add(this.OutputResources[0].ItemSpec); } catch (Exception exception) { if (Microsoft.Build.Shared.ExceptionHandling.NotExpectedException(exception)) { throw; } base.Log.LogErrorWithCodeFromResources("GenerateResource.CannotWriteSTRFile", new object[] { this.StronglyTypedFileName, exception.Message }); this.unsuccessfullyCreatedOutFiles.Add(this.OutputResources[0].ItemSpec); } return; } Label_01F8: files2 = new CanonicalTrackedInputFiles(this, readTLogs, this.Sources, this.ExcludedInputPaths, outputs, true, false); ITaskItem[] source = files2.ComputeSourcesNeedingCompilation(); if (source.Length == 0) { if (!string.IsNullOrEmpty(this.StronglyTypedLanguage)) { this.stronglyTypedResourceSuccessfullyCreated = true; } } else { foreach (ITaskItem item2 in source) { inputsToProcess.Add(item2); ITaskItem2 item3 = item2 as ITaskItem2; if (item3 != null) { outputsToProcess.Add(new TaskItem(item3.GetMetadataValueEscaped("OutputResource"))); } else { outputsToProcess.Add(new TaskItem(Microsoft.Build.Shared.EscapingUtilities.Escape(item2.GetMetadata("OutputResource")))); } } try { files2.RemoveEntriesForSource(source); files2.SaveTlog(); outputs = new CanonicalTrackedOutputFiles(this, this.TLogWriteFiles); outputs.RemoveEntriesForSource(source); outputs.SaveTlog(); } catch (Exception exception2) { if (Microsoft.Build.Shared.ExceptionHandling.NotExpectedException(exception2) && !(exception2 is UnauthorizedAccessException)) { throw; } base.Log.LogErrorFromException(exception2); } } }
private void CompactTrackingLogs(bool taskSucceeded) { CanonicalTrackedOutputFiles outputs = new CanonicalTrackedOutputFiles(this.TLogWriteFiles); CanonicalTrackedInputFiles files2 = new CanonicalTrackedInputFiles(this.TLogReadFiles, this.Sources, this.ExcludedInputPaths, outputs, true, false); outputs.RemoveDependenciesFromEntryIfMissing(this.Sources); files2.RemoveDependenciesFromEntryIfMissing(this.Sources); if (!taskSucceeded) { foreach (ITaskItem item in this.Sources) { string sourceKey = FileTracker.FormatRootingMarker(item); outputs.AddComputedOutputForSourceRoot(sourceKey, item.GetMetadata(outputFileMetadataName)); } ITaskItem[] source = files2.ComputeSourcesNeedingCompilation(); foreach (ITaskItem item2 in this.Sources) { string sourceRoot = FileTracker.FormatRootingMarker(item2); outputs.RemoveOutputForSourceRoot(sourceRoot, item2.GetMetadata(outputFileMetadataName)); } outputs.RemoveEntriesForSource(source); files2.RemoveEntriesForSource(source); } if (!string.IsNullOrEmpty(this.StronglyTypedFileName) && this.stronglyTypedResourceSuccessfullyCreated) { string stronglyTypedFileName = this.StronglyTypedFileName; foreach (ITaskItem item3 in this.Sources) { string str4 = FileTracker.FormatRootingMarker(item3); outputs.AddComputedOutputForSourceRoot(str4, stronglyTypedFileName); } } files2.SaveTlog(); outputs.SaveTlog(); }