private void ConstructCommandTLog(ITaskItem[] upToDateSources, DependencyFilter inputFilter) { IDictionary <string, string> commandLines = this.MapSourcesToCommandLines(); if (upToDateSources != null) { string cmdLine = GenerateCommandLineCommands(VCToolTask.CommandLineFormat.ForTracking #if TOOLS_V14 || TOOLS_V15 , EscapeFormat.Default #endif ); foreach (ITaskItem upToDateSource in upToDateSources) { string metadata = upToDateSource.GetMetadata("FullPath"); if (inputFilter == null || inputFilter(metadata)) { commandLines[FileTracker.FormatRootingMarker(upToDateSource)] = cmdLine; } else { commandLines.Remove(FileTracker.FormatRootingMarker(upToDateSource)); } } } this.WriteSourcesToCommandLinesTable(commandLines); }
private void ConstructCommandTLog(ITaskItem[] upToDateSources, DependencyFilter inputFilter) { StringBuilder cmdLine = new StringBuilder(Utils.EST_MAX_CMDLINE_LEN); // This updates any newly built source files' command line in the tlog files. So the dep checker can see when we modify // compiler switches, that the command line changed and we have to rebuild the file. IDictionary <string, string> sourcesToCommandLines = MapSourcesToCommandLines(); if (upToDateSources != null) { foreach (ITaskItem item in upToDateSources) { m_currentSourceItem = item; string sourcePath = item.GetMetadata("FullPath"); if ((inputFilter == null) || inputFilter(sourcePath)) { // Add this newly built source files' command line into the tlog file cmdLine.Length = 0; cmdLine.Append(GenerateResponseFileCommands()); cmdLine.Append(" "); cmdLine.Append(sourcePath.ToUpperInvariant()); sourcesToCommandLines[FileTracker.FormatRootingMarker(item)] = cmdLine.ToString(); } else { sourcesToCommandLines.Remove(FileTracker.FormatRootingMarker(item)); } } } WriteSourcesToCommandLinesTable(sourcesToCommandLines); }
protected override void OutputCommandTLog(ITaskItem[] compiledSources) { IDictionary <string, string> commandLines = GenerateCommandLinesFromTlog(); // if (compiledSources != null) { foreach (ITaskItem source in compiledSources) { string rmSource = FileTracker.FormatRootingMarker(source); commandLines[rmSource] = TLogCommandForSource(source); } } //write tlog using (StreamWriter writer = new StreamWriter(this.TLogCommandFile.GetMetadata("FullPath"), false, Encoding.Unicode)) { foreach (KeyValuePair <string, string> p in commandLines) { string keyLine = "^" + p.Key; writer.WriteLine(keyLine); writer.WriteLine(p.Value); } } }
private void ConstructCommandTLog(ITaskItem[] upToDateSources, DependencyFilter inputFilter) { IDictionary <string, string> commandLines = this.MapSourcesToCommandLines(); if (upToDateSources != null) { string text = this.SourcesPropertyName ?? "Sources"; string cmdLine = base.GenerateCommandLineExceptSwitches(new string[1] { text }, CommandLineFormat.ForTracking #if TOOLS_V14 || TOOLS_V15 , EscapeFormat.Default #endif ); foreach (ITaskItem upToDateSource in upToDateSources) { string metadata = upToDateSource.GetMetadata("FullPath"); if (inputFilter == null || inputFilter(metadata)) { commandLines[FileTracker.FormatRootingMarker(upToDateSource)] = cmdLine + " " + metadata.ToUpperInvariant(); } else { commandLines.Remove(FileTracker.FormatRootingMarker(upToDateSource)); } } } this.WriteSourcesToCommandLinesTable(commandLines); }
protected List <ITaskItem> GetOutOfDateSourcesFromCmdLineChanges() { //get dictionary of source + command lines IDictionary <string, string> dictionary = GenerateCommandLinesFromTlog(); List <ITaskItem> outOfDateSources = new List <ITaskItem>(); //add sources to out of date list if the tlog dictionary string do not match the generated command line string StringBuilder currentCommandLine = new StringBuilder(GCCUtilities.s_CommandLineLength); foreach (ITaskItem sourceItem in Sources) { currentCommandLine.Length = 0; currentCommandLine.Append(TLogCommandForSource(sourceItem)); string tlogCommandLine = null; if (dictionary.TryGetValue(FileTracker.FormatRootingMarker(sourceItem), out tlogCommandLine)) { if (tlogCommandLine == null || !currentCommandLine.ToString().Equals(tlogCommandLine, StringComparison.Ordinal)) { outOfDateSources.Add(sourceItem); } } else { outOfDateSources.Add(sourceItem); } } return(outOfDateSources); }
protected internal virtual bool ComputeOutOfDateSources() { if (MinimalRebuildFromTracking || TrackFileAccess) { AssignDefaultTLogPaths(); } if (MinimalRebuildFromTracking && !ForcedRebuildRequired()) { var outputs = new CanonicalTrackedOutputFiles(this, TLogWriteFiles); SourceDependencies = new CanonicalTrackedInputFiles( this, TLogReadFiles, TrackedInputFiles, ExcludedInputPaths, outputs, UseMinimalRebuildOptimization, MaintainCompositeRootingMarkers); ITaskItem[] sourcesOutOfDateThroughTracking = SourceDependencies.ComputeSourcesNeedingCompilation(false); List <ITaskItem> sourcesWithChangedOptions = GenerateSourcesOutOfDateDueToOptions(); SourcesCompiled = MergeOutOfDateSourceLists( sourcesOutOfDateThroughTracking, sourcesWithChangedOptions); if (SourcesCompiled.Length == 0) { SkippedExecution = true; return(SkippedExecution); } SourcesCompiled = AssignOutOfDateSources(SourcesCompiled); SourceDependencies.RemoveEntriesForSource(SourcesCompiled); SourceDependencies.SaveTlog(); outputs.RemoveEntriesForSource(SourcesCompiled); outputs.SaveTlog(); } else { SourcesCompiled = TrackedInputFiles; if (SourcesCompiled == null || SourcesCompiled.Length == 0) { SkippedExecution = true; return(SkippedExecution); } } if (TrackFileAccess) { RootSource = FileTracker.FormatRootingMarker(SourcesCompiled); } SkippedExecution = false; return(SkippedExecution); }
protected virtual List <ITaskItem> GenerateSourcesOutOfDateDueToCommandLine() { IDictionary <string, string> dictionary = this.MapSourcesToCommandLines(); List <ITaskItem> list = new List <ITaskItem>(); if (dictionary.Count == 0) { foreach (ITaskItem item in this.TrackedInputFiles) { list.Add(item); } return(list); } if (this.MaintainCompositeRootingMarkers) { string str = this.ApplyPrecompareCommandFilter(base.GenerateCommandLine()); string str2 = null; if (dictionary.TryGetValue(FileTracker.FormatRootingMarker(this.TrackedInputFiles), out str2)) { str2 = this.ApplyPrecompareCommandFilter(str2); if ((str2 == null) || !str.Equals(str2, StringComparison.Ordinal)) { base.Log.LogMessageFromResources(MessageImportance.Low, "TrackedVCToolTask.RebuildingAllSourcesCommandLineChanged", new object[0]); foreach (ITaskItem item2 in this.TrackedInputFiles) { list.Add(item2); } } return(list); } foreach (ITaskItem item3 in this.TrackedInputFiles) { list.Add(item3); } return(list); } string str3 = this.SourcesPropertyName ?? "Sources"; string str4 = base.GenerateCommandLineExceptSwitches(new string[] { str3 }); foreach (ITaskItem item4 in this.TrackedInputFiles) { string str5 = this.ApplyPrecompareCommandFilter(str4 + " " + item4.GetMetadata("FullPath").ToUpperInvariant()); string str6 = null; if (dictionary.TryGetValue(FileTracker.FormatRootingMarker(item4), out str6)) { str6 = this.ApplyPrecompareCommandFilter(str6); if ((str6 == null) || !str5.Equals(str6, StringComparison.Ordinal)) { list.Add(item4); } } else { list.Add(item4); } } return(list); }
protected virtual List <ITaskItem> GenerateSourcesOutOfDateDueToOptions() { IDictionary <string, string> sourceMap = MapSourcesToOptions(); var outOfDateItems = new List <ITaskItem>(); if (sourceMap.Count == 0) { outOfDateItems.AddRange(TrackedInputFiles); return(outOfDateItems); } if (MaintainCompositeRootingMarkers) { string currOptions = ApplyPrecompareCommandFilter( GenerateOptions(OptionFormat.ForTracking)); if (sourceMap.TryGetValue(FileTracker.FormatRootingMarker(TrackedInputFiles), out var prevOptions)) { prevOptions = ApplyPrecompareCommandFilter(prevOptions); if (prevOptions == null || !currOptions.Equals(prevOptions, StringComparison.Ordinal)) { outOfDateItems.AddRange(TrackedInputFiles); } } else { outOfDateItems.AddRange(TrackedInputFiles); } } else { string cmdLine = GenerateOptionsExceptSources(OptionFormat.ForTracking); foreach (ITaskItem item in TrackedInputFiles) { string currOptions = ApplyPrecompareCommandFilter( cmdLine + " " + item.GetMetadata("FullPath").ToUpperInvariant()); if (sourceMap.TryGetValue(FileTracker.FormatRootingMarker(item), out var prevOptions)) { prevOptions = ApplyPrecompareCommandFilter(prevOptions); if (prevOptions == null || !currOptions.Equals(prevOptions, StringComparison.Ordinal)) { outOfDateItems.Add(item); } } else { outOfDateItems.Add(item); } } } return(outOfDateItems); }
protected bool PrepareWorkItems(Type taskType, string[] environmentVariables, ref Dictionary <string, MultiToolTaskWorkItem> workItems) { string currentDirectory = Environment.CurrentDirectory; var strBuilder = new StringBuilder(); foreach (var package in tasksPerPackage) { foreach (var taskItems in package.Value) { if (taskItems.Count > 0) { var task = CreateTask(taskType, taskItems, currentDirectory, environmentVariables); var cmdLine = GenerateCommandLine(task, ref strBuilder, taskItems, currentDirectory); bool toBeCompiled = false; bool outOfDateCommandLine = false; string sources = FileTracker.FormatRootingMarker(taskItems.ToArray(), null); bool minimalRebuldFromTracking = true; if (!bool.TryParse(taskItems[0].GetMetadata("MinimalRebuildFromTracking"), out minimalRebuldFromTracking)) { minimalRebuldFromTracking = true; } CheckCommandLineOutOfDate(minimalRebuldFromTracking, taskItems, sources, task, cmdLine, ref toBeCompiled, ref outOfDateCommandLine); string multiToolTaskDep = taskItems[0].GetMetadata("MultiToolTaskDependency"); // Update dependencies of the existing work items toBeCompiled = UpdateDependencies(toBeCompiled, ref workItems, sources, multiToolTaskDep); // Create WorkItem var workItemToAdd = new MultiToolTaskWorkItem { Sourcekey = sources, Dependency = multiToolTaskDep, ShouldAdd = toBeCompiled, Task = task, OutOfDateCommandLine = outOfDateCommandLine }; workItems.Add(sources, workItemToAdd); if (cts.IsCancellationRequested) { return(false); } } } } return(true); }
protected internal virtual bool ComputeOutOfDateSources() { if (this.TrackerIntermediateDirectory != null) { string intermediateDirectory = this.TrackerIntermediateDirectory; } else { string str = string.Empty; } if (this.MinimalRebuildFromTracking || this.TrackFileAccess) { this.AssignDefaultTLogPaths(); } if (this.MinimalRebuildFromTracking && !this.ForcedRebuildRequired()) { this.sourceOutputs = new CanonicalTrackedOutputFiles((ITask)this, this.TLogWriteFiles); this.sourceDependencies = new CanonicalTrackedInputFiles((ITask)this, this.TLogReadFiles, this.TrackedInputFiles, this.ExcludedInputPaths, this.sourceOutputs, this.UseMinimalRebuildOptimization, this.MaintainCompositeRootingMarkers); this.SourcesCompiled = this.MergeOutOfDateSourceLists(this.SourceDependencies.ComputeSourcesNeedingCompilation(false), this.GenerateSourcesOutOfDateDueToCommandLine()); 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(); if (this.DeleteOutputOnExecute) { TrackedVCToolTask.DeleteFiles(this.sourceOutputs.OutputsForSource(this.SourcesCompiled)); } this.sourceOutputs.RemoveEntriesForSource(this.SourcesCompiled); this.sourceOutputs.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 ComputeOutOfDateSources() { if (InputFiles[0].GetMetadata("PartialCompilation") != "true") { AssignDefaultTLogPaths(); SourceOutputs = new CanonicalTrackedOutputFiles(this, TLogWriteFiles); foreach (ITaskItem file in InputFiles) { SourceOutputs.AddComputedOutputForSourceRoot(FileTracker.FormatRootingMarker(file), file.GetMetadata("OutputFile")); } SourceOutputs.SaveTlog(); } return(base.ComputeOutOfDateSources()); }
private Source ConstructSource(ITaskItem a) { var task = ConstructTask(a); var src = ApplyPrecompareCommandFilter(FileTracker.FormatRootingMarker(a)); var cmd = ApplyPrecompareCommandFilter(task.GenerateCommandLineExceptSwitches( new[] { task.SourcesPropertyName }, CommandLineFormat.ForTracking, EscapeFormat.Default )) + " " + src.ToUpperInvariant(); return(new Source() { CommandLine = cmd, File = src, Metadata = task }); }
protected override List <ITaskItem> GenerateSourcesOutOfDateDueToCommandLine() { // Original TrackedVCToolTask code - START IDictionary <string, string> dictionary = this.MapSourcesToCommandLines(); List <ITaskItem> list = new List <ITaskItem>(); if (dictionary.Count == 0) { foreach (ITaskItem item in this.TrackedInputFiles) { list.Add(item); } return(list); } // Original TrackedVCToolTask code - END // Check the command lines for each source file. We'll build up a list of those with changed command lines, or those // that didn't exist in the original command tlog file at all. StringBuilder cmdLine = new StringBuilder(Utils.EST_MAX_CMDLINE_LEN); foreach (ITaskItem sourceFile in Sources) { cmdLine.Length = 0; m_currentSourceItem = sourceFile; cmdLine.Append(GenerateCommandLine()); cmdLine.Append(" "); cmdLine.Append(sourceFile.GetMetadata("FullPath").ToUpperInvariant()); string findCmdLine = null; if (dictionary.TryGetValue(FileTracker.FormatRootingMarker(sourceFile), out findCmdLine)) { if ((findCmdLine == null) || !cmdLine.ToString().Equals(findCmdLine, StringComparison.Ordinal)) { list.Add(sourceFile); } } else { list.Add(sourceFile); } } return(list); }
// 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 }); // } // } // } protected /*internal*/ 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 virtual int TrackedExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands) { // // Thread body. Generate required command line and launch tool. // int exitCode = -1; try { // // If response files arguments are used/supported, migrate shared flags to a file and strip them from the command line. // var commandLineSwitchesBuffer = new StringBuilder(commandLineCommands); var responseFileSwitchesBuffer = new StringBuilder(responseFileCommands); if (responseFileSwitchesBuffer.Length > 0) { commandLineSwitchesBuffer.Replace(responseFileSwitchesBuffer.ToString(), ""); } #if DEBUG Log.LogMessageFromText($"[{ToolName}] Tool: {pathToTool}", MessageImportance.High); Log.LogMessageFromText($"[{ToolName}] Command line: {commandLineSwitchesBuffer}", MessageImportance.High); Log.LogMessageFromText($"[{ToolName}] Response file commands: {responseFileSwitchesBuffer}", MessageImportance.High); #endif var trackerToolPath = FileTracker.GetTrackerPath(ExecutableType.Native64Bit); // @"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Tracker.exe"; var trackerCommandLineSwitches = FileTracker.TrackerCommandArguments(pathToTool, commandLineSwitchesBuffer.ToString()); if (!string.IsNullOrEmpty(trackerToolPath)) { var trackerRootingMarker = OutOfDateInputFiles.Length > 0 ? FileTracker.FormatRootingMarker(OutOfDateInputFiles) : null; var trackerResponseFileArguments = FileTracker.TrackerResponseFileArguments(FileTracker.GetFileTrackerPath(ExecutableType.Native64Bit), new TaskItemHelper(TrackerIntermediateDirectory).FullPath, trackerRootingMarker, null); var trackerResponseFile = Path.GetTempFileName(); File.WriteAllText(trackerResponseFile, trackerResponseFileArguments, ResponseFileEncoding); // /a : Enable extended tracking: GetFileAttributes, GetFileAttributesEx // /e : Enable extended tracking: GetFileAttributes, GetFileAttributesEx, RemoveDirectory, CreateDirectory // /k : Keep the full tool chain in tlog filenames. // /t : Track command lines (will expand response files specified with the '@filename' syntax) // (specifying /t will export *.command.*.tlog files) trackerCommandLineSwitches = $"{PathUtils.QuoteIfNeeded("@" + trackerResponseFile)} /k {trackerCommandLineSwitches}"; } #if DEBUG Log.LogMessageFromText($"[{ToolName}] Tracker tool: {trackerToolPath}", MessageImportance.High); Log.LogMessageFromText($"[{ToolName}] Tracker command line: {trackerCommandLineSwitches}", MessageImportance.High); #endif // // // responseFileSwitchesBuffer.Replace("\\", "\\\\"); responseFileSwitchesBuffer.Replace("\\\\\\\\ ", "\\\\ "); if (true) { exitCode = base.ExecuteTool(trackerToolPath, responseFileSwitchesBuffer.ToString(), trackerCommandLineSwitches); } #if false else { string responseFileSwitch = string.Empty; if (responseFileSwitchesBuffer.Length > 0) { string responseFilePath = Path.Combine(TrackerLogDirectory, string.Format("{0}_{1}.rsp", ToolName, Guid.NewGuid().ToString())); Directory.CreateDirectory(Path.GetDirectoryName(responseFilePath)); File.WriteAllText(responseFilePath, responseFileSwitchesBuffer.ToString(), ResponseFileEncoding); responseFileSwitch = GetResponseFileSwitch(responseFilePath); } using var trackedProcess = new Process(); trackedProcess.StartInfo = base.GetProcessStartInfo(trackerToolPath, trackerCommandLineSwitches, responseFileSwitch); trackedProcess.StartInfo.CreateNoWindow = true; trackedProcess.StartInfo.UseShellExecute = false; trackedProcess.StartInfo.ErrorDialog = false; trackedProcess.StartInfo.RedirectStandardOutput = true; trackedProcess.StartInfo.RedirectStandardError = true; trackedProcess.OutputDataReceived += (object sender, DataReceivedEventArgs args) => LogEventsFromTextOutput(args.Data, MessageImportance.Low); trackedProcess.ErrorDataReceived += (object sender, DataReceivedEventArgs args) => LogEventsFromTextOutput(args.Data, MessageImportance.Low); trackedProcess.EnableRaisingEvents = true; if (OutputCommandLine) { Log.LogMessageFromText(string.Format("[{0}] Process started: {1} {2}", ToolName, trackedProcess.StartInfo.FileName, trackedProcess.StartInfo.Arguments), MessageImportance.High); } if (!trackedProcess.Start()) { throw new InvalidOperationException("Could not start tracked child process."); } trackedProcess.BeginOutputReadLine(); trackedProcess.BeginErrorReadLine(); trackedProcess.WaitForExit(); exitCode = trackedProcess.ExitCode; } #endif } catch (Exception e) { Log.LogErrorFromException(e, true); exitCode = -1; } return(exitCode); }
protected virtual int PostExecuteTool(int exitCode) { if (this.MinimalRebuildFromTracking || this.TrackFileAccess) { this.SourceOutputs = new CanonicalTrackedOutputFiles(this.TLogWriteFiles); this.SourceDependencies = new CanonicalTrackedInputFiles(this.TLogReadFiles, this.TrackedInputFiles, this.ExcludedInputPaths, this.SourceOutputs, false, this.MaintainCompositeRootingMarkers); string[] strArray = (string[])null; IDictionary <string, string> sourcesToCommandLines = this.MapSourcesToCommandLines(); if (exitCode != 0) { this.SourceOutputs.RemoveEntriesForSource(this.SourcesCompiled); this.SourceOutputs.SaveTlog(); this.SourceDependencies.RemoveEntriesForSource(this.SourcesCompiled); this.SourceDependencies.SaveTlog(); if (this.TrackCommandLines) { if (this.MaintainCompositeRootingMarkers) { sourcesToCommandLines.Remove(FileTracker.FormatRootingMarker(this.SourcesCompiled)); } else { foreach (ITaskItem source in this.SourcesCompiled) { sourcesToCommandLines.Remove(FileTracker.FormatRootingMarker(source)); } } this.WriteSourcesToCommandLinesTable(sourcesToCommandLines); } } else { this.AddTaskSpecificOutputs(this.SourcesCompiled, this.SourceOutputs); this.RemoveTaskSpecificOutputs(this.SourceOutputs); this.SourceOutputs.RemoveDependenciesFromEntryIfMissing(this.SourcesCompiled); if (this.MaintainCompositeRootingMarkers) { strArray = this.SourceOutputs.RemoveRootsWithSharedOutputs(this.SourcesCompiled); foreach (string rootingMarker in strArray) { this.SourceDependencies.RemoveEntryForSourceRoot(rootingMarker); } } if (this.TrackedOutputFilesToIgnore != null && this.TrackedOutputFilesToIgnore.Length != 0) { Dictionary <string, ITaskItem> trackedOutputFilesToRemove = new Dictionary <string, ITaskItem>((IEqualityComparer <string>)StringComparer.OrdinalIgnoreCase); foreach (ITaskItem taskItem in this.TrackedOutputFilesToIgnore) { trackedOutputFilesToRemove.Add(taskItem.GetMetadata("FullPath"), taskItem); } this.SourceOutputs.SaveTlog((DependencyFilter)(fullTrackedPath => !trackedOutputFilesToRemove.ContainsKey(fullTrackedPath))); } else { this.SourceOutputs.SaveTlog(); } TrackedVCToolTask.DeleteEmptyFile(this.TLogWriteFiles); this.RemoveTaskSpecificInputs(this.SourceDependencies); this.SourceDependencies.RemoveDependenciesFromEntryIfMissing(this.SourcesCompiled); if (this.TrackedInputFilesToIgnore != null && this.TrackedInputFilesToIgnore.Length != 0) { Dictionary <string, ITaskItem> trackedInputFilesToRemove = new Dictionary <string, ITaskItem>((IEqualityComparer <string>)StringComparer.OrdinalIgnoreCase); foreach (ITaskItem taskItem in this.TrackedInputFilesToIgnore) { trackedInputFilesToRemove.Add(taskItem.GetMetadata("FullPath"), taskItem); } this.SourceDependencies.SaveTlog((DependencyFilter)(fullTrackedPath => !trackedInputFilesToRemove.ContainsKey(fullTrackedPath))); } else { this.SourceDependencies.SaveTlog(); } TrackedVCToolTask.DeleteEmptyFile(this.TLogReadFiles); if (this.TrackCommandLines) { if (this.MaintainCompositeRootingMarkers) { string str = this.GenerateCommandLine(VCToolTask.CommandLineFormat.ForTracking, VCToolTask.EscapeFormat.Default); sourcesToCommandLines[FileTracker.FormatRootingMarker(this.SourcesCompiled)] = str; if (strArray != null) { foreach (string key in strArray) { sourcesToCommandLines.Remove(key); } } } else { string str = this.GenerateCommandLineExceptSwitches(new string[1] { this.SourcesPropertyName ?? "Sources" }, VCToolTask.CommandLineFormat.ForTracking, VCToolTask.EscapeFormat.Default); foreach (ITaskItem source in this.SourcesCompiled) { sourcesToCommandLines[FileTracker.FormatRootingMarker(source)] = str + " " + source.GetMetadata("FullPath").ToUpperInvariant(); } } this.WriteSourcesToCommandLinesTable(sourcesToCommandLines); } } } return(exitCode); }
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 + " " + commandLineCommands + " " + responseFileCommands); } 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 FinishExecute(bool success) { if (!MinimalRebuildFromTracking && !TrackFileAccess) { return; } var outputs = new CanonicalTrackedOutputFiles(TLogWriteFiles); var compactInputs = new CanonicalTrackedInputFiles( TLogReadFiles, TrackedInputFiles, ExcludedInputPaths, outputs, false, MaintainCompositeRootingMarkers); IDictionary <string, string> sourcesToOptions = MapSourcesToOptions(); if (!success) { outputs.RemoveEntriesForSource(SourcesCompiled); outputs.SaveTlog(); compactInputs.RemoveEntriesForSource(SourcesCompiled); compactInputs.SaveTlog(); if (MaintainCompositeRootingMarkers) { sourcesToOptions.Remove( FileTracker.FormatRootingMarker(SourcesCompiled)); } else { foreach (ITaskItem item in SourcesCompiled) { sourcesToOptions.Remove( FileTracker.FormatRootingMarker(item)); } } WriteSourcesToOptionsTable(sourcesToOptions); } else { AddTaskSpecificOutputs(SourcesCompiled, outputs); RemoveTaskSpecificOutputs(outputs); outputs.RemoveDependenciesFromEntryIfMissing(SourcesCompiled); string[] roots = null; if (MaintainCompositeRootingMarkers) { roots = outputs.RemoveRootsWithSharedOutputs(SourcesCompiled); foreach (string marker in roots) { compactInputs.RemoveEntryForSourceRoot(marker); } } if (TrackedOutputFilesToIgnore != null && (TrackedOutputFilesToIgnore.Length > 0)) { var trackedOutputFilesToRemove = new Dictionary <string, ITaskItem>( StringComparer.OrdinalIgnoreCase); foreach (ITaskItem item in TrackedOutputFilesToIgnore) { trackedOutputFilesToRemove.Add(item.GetMetadata("FullPath"), item); } outputs.SaveTlog( fullTrackedPath => !trackedOutputFilesToRemove.ContainsKey(fullTrackedPath)); } else { outputs.SaveTlog(); } FileUtilities.DeleteEmptyFile(TLogWriteFiles); RemoveTaskSpecificInputs(compactInputs); compactInputs.RemoveDependenciesFromEntryIfMissing(SourcesCompiled); if (TrackedInputFilesToIgnore != null && TrackedInputFilesToIgnore.Length > 0) { var trackedInputFilesToRemove = new Dictionary <string, ITaskItem>( StringComparer.OrdinalIgnoreCase); foreach (ITaskItem item in TrackedInputFilesToIgnore) { trackedInputFilesToRemove.Add(item.GetMetadata("FullPath"), item); } compactInputs.SaveTlog( fullTrackedPath => !trackedInputFilesToRemove.ContainsKey(fullTrackedPath)); } else { compactInputs.SaveTlog(); } FileUtilities.DeleteEmptyFile(TLogReadFiles); if (MaintainCompositeRootingMarkers) { sourcesToOptions[FileTracker.FormatRootingMarker(SourcesCompiled)] = GenerateOptions(OptionFormat.ForTracking); if (roots != null) { foreach (string root in roots) { sourcesToOptions.Remove(root); } } } else { string options = GenerateOptionsExceptSources(OptionFormat.ForTracking); foreach (ITaskItem item in SourcesCompiled) { sourcesToOptions[FileTracker.FormatRootingMarker(item)] = options + " " + item.GetMetadata("FullPath").ToUpperInvariant(); } } WriteSourcesToOptionsTable(sourcesToOptions); } }
protected virtual int PostExecuteTool(int exitCode) { if (!MinimalRebuildFromTracking && !TrackFileAccess) { return(exitCode); } SourceOutputs = new CanonicalTrackedOutputFiles(TLogWriteFiles); SourceDependencies = new CanonicalTrackedInputFiles( TLogReadFiles, TrackedInputFiles, ExcludedInputPaths, SourceOutputs, false, MaintainCompositeRootingMarkers); IDictionary <string, string> sourcesToCommandLines = MapSourcesToCommandLines(); if (exitCode != 0) { SourceOutputs.RemoveEntriesForSource(SourcesCompiled); SourceOutputs.SaveTlog(); SourceDependencies.RemoveEntriesForSource(SourcesCompiled); SourceDependencies.SaveTlog(); if (TrackCommandLines) { if (MaintainCompositeRootingMarkers) { sourcesToCommandLines.Remove( FileTracker.FormatRootingMarker(SourcesCompiled)); } else { foreach (ITaskItem item in SourcesCompiled) { sourcesToCommandLines.Remove( FileTracker.FormatRootingMarker(item)); } } WriteSourcesToCommandLinesTable(sourcesToCommandLines); } } else { AddTaskSpecificOutputs(SourcesCompiled, SourceOutputs); RemoveTaskSpecificOutputs(SourceOutputs); SourceOutputs.RemoveDependenciesFromEntryIfMissing(SourcesCompiled); string[] roots = null; if (MaintainCompositeRootingMarkers) { roots = SourceOutputs.RemoveRootsWithSharedOutputs(SourcesCompiled); foreach (string marker in roots) { SourceDependencies.RemoveEntryForSourceRoot(marker); } } if (TrackedOutputFilesToIgnore != null && (TrackedOutputFilesToIgnore.Length > 0)) { var trackedOutputFilesToRemove = new Dictionary <string, ITaskItem>( StringComparer.OrdinalIgnoreCase); foreach (ITaskItem item in TrackedOutputFilesToIgnore) { trackedOutputFilesToRemove.Add(item.GetMetadata("FullPath"), item); } SourceOutputs.SaveTlog( fullTrackedPath => !trackedOutputFilesToRemove.ContainsKey(fullTrackedPath)); } else { SourceOutputs.SaveTlog(); } FileUtilities.DeleteEmptyFile(TLogWriteFiles); RemoveTaskSpecificInputs(SourceDependencies); SourceDependencies.RemoveDependenciesFromEntryIfMissing(SourcesCompiled); if (TrackedInputFilesToIgnore != null && TrackedInputFilesToIgnore.Length > 0) { var trackedInputFilesToRemove = new Dictionary <string, ITaskItem>( StringComparer.OrdinalIgnoreCase); foreach (ITaskItem item in TrackedInputFilesToIgnore) { trackedInputFilesToRemove.Add(item.GetMetadata("FullPath"), item); } SourceDependencies.SaveTlog( fullTrackedPath => !trackedInputFilesToRemove.ContainsKey(fullTrackedPath)); } else { SourceDependencies.SaveTlog(); } FileUtilities.DeleteEmptyFile(TLogReadFiles); if (MaintainCompositeRootingMarkers) { sourcesToCommandLines[FileTracker.FormatRootingMarker(SourcesCompiled)] = GenerateCommandLine(CommandLineFormat.ForTracking); if (roots != null) { foreach (string root in roots) { sourcesToCommandLines.Remove(root); } } } else { string cmdLine = GenerateCommandLineExceptSources( CommandLineFormat.ForTracking); foreach (ITaskItem item in SourcesCompiled) { sourcesToCommandLines[FileTracker.FormatRootingMarker(item)] = cmdLine + " " + item.GetMetadata("FullPath").ToUpperInvariant(); } } WriteSourcesToCommandLinesTable(sourcesToCommandLines); } return(exitCode); }
protected virtual List <ITaskItem> GenerateSourcesOutOfDateDueToCommandLine() { IDictionary <string, string> dictionary = this.MapSourcesToCommandLines(); List <ITaskItem> list = new List <ITaskItem>(); if (!this.TrackCommandLines) { return(list); } if (dictionary.Count == 0) { foreach (ITaskItem taskItem in this.TrackedInputFiles) { list.Add(taskItem); } } else if (this.MaintainCompositeRootingMarkers) { string str1 = this.ApplyPrecompareCommandFilter(this.GenerateCommandLine(VCToolTask.CommandLineFormat.ForTracking, VCToolTask.EscapeFormat.Default)); string str2 = (string)null; if (dictionary.TryGetValue(FileTracker.FormatRootingMarker(this.TrackedInputFiles), out str2)) { string str3 = this.ApplyPrecompareCommandFilter(str2); if (str3 == null || !str1.Equals(str3, StringComparison.Ordinal)) { foreach (ITaskItem taskItem in this.TrackedInputFiles) { list.Add(taskItem); } } } else { foreach (ITaskItem taskItem in this.TrackedInputFiles) { list.Add(taskItem); } } } else { string str1 = this.GenerateCommandLineExceptSwitches(new string[1] { this.SourcesPropertyName ?? "Sources" }, VCToolTask.CommandLineFormat.ForTracking, VCToolTask.EscapeFormat.Default); foreach (ITaskItem source in this.TrackedInputFiles) { string str2 = this.ApplyPrecompareCommandFilter(str1 + " " + source.GetMetadata("FullPath").ToUpperInvariant()); string str3 = (string)null; if (dictionary.TryGetValue(FileTracker.FormatRootingMarker(source), out str3)) { str3 = this.ApplyPrecompareCommandFilter(str3); if (str3 == null || !str2.Equals(str3, StringComparison.Ordinal)) { list.Add(source); } } else { list.Add(source); } } } return(list); }
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); }