Пример #1
0
        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);
        }
Пример #2
0
        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();
        }
Пример #3
0
        protected override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands)
        {
            if (!File.Exists(pathToTool))
            {
                base.Log.LogMessageFromText("Could not find GCC compiler: " + pathToTool, MessageImportance.High);
                return(-1);
            }

            int retCode = 0;

            try
            {
                retCode = CompileWithGCC(pathToTool);
            }
            finally
            {
                // Update tlog files
                CanonicalTrackedOutputFiles outputs = ConstructWriteTLog(SourcesCompiled);
                ConstructReadTLog(SourcesCompiled, outputs);
                ConstructCommandTLog(SourcesCompiled, null);
            }
            return(retCode);
        }
Пример #4
0
        private void ConstructReadTLog(ITaskItem[] upToDateSources, CanonicalTrackedOutputFiles outputs)
        {
            string readTrackerPath = Path.GetFullPath(TrackerIntermediateDirectory + "\\" + ReadTLogNames[0]);

            // Rewrite out read log, with the sources we're *not* compiling right now.
            TaskItem readTrackerItem         = new TaskItem(readTrackerPath);
            CanonicalTrackedInputFiles files = new CanonicalTrackedInputFiles(new TaskItem[] { readTrackerItem }, Sources, outputs, false, false);

            files.RemoveEntriesForSource(Sources);
            files.SaveTlog();

            // Now append onto the read log the sources we're compiling. It'll parse the .d files for each compiled file, so we know the
            // dependency header files associated with it, these will be recorded in the logfile.
            using (StreamWriter writer = new StreamWriter(readTrackerPath, true, Encoding.Unicode))
            {
                foreach (ITaskItem sourceItem in upToDateSources)
                {
                    string itemSpec     = sourceItem.ItemSpec;
                    string sourcePath   = Path.GetFullPath(sourceItem.ItemSpec).ToUpperInvariant();
                    string objectFile   = Path.GetFullPath(sourceItem.GetMetadata("ObjectFileName"));
                    string dotDFile     = Path.GetFullPath(Path.GetDirectoryName(objectFile) + "\\" + Path.GetFileNameWithoutExtension(objectFile) + ".d");
                    string pchOutputH   = Path.GetFullPath(sourceItem.GetMetadata("PrecompiledHeaderOutputFile"));
                    string pchOutputGCH = pchOutputH + ".gch";
                    string pchSetting   = sourceItem.GetMetadata("PrecompiledHeader").ToLowerInvariant();

                    try
                    {
                        List <string> dependencies = new List <string>();

                        dependencies.Add("^" + sourcePath);

                        // don't add an entry if the object file wasn't built
                        if (!File.Exists(objectFile))
                        {
                            continue;
                        }

                        if (!File.Exists(dotDFile))
                        {
                            throw new Exception("File " + sourcePath + " is missing it's .d file: " + dotDFile);
                        }

                        DepFileParse depFileParse = new DepFileParse(dotDFile);

                        foreach (string dependentFile in depFileParse.DependentFiles)
                        {
                            if (dependentFile != sourcePath)
                            {
                                if (File.Exists(dependentFile) == false)
                                {
                                    throw new Exception("File " + sourcePath + " is missing dependent file: " + dependentFile);
                                }

                                dependencies.Add(dependentFile);
                            }
                        }

                        if (pchSetting == "use")
                        {
                            dependencies.Add(pchOutputH.ToUpperInvariant());
                            dependencies.Add(pchOutputGCH.ToUpperInvariant());
                        }

                        // Done with this .d file. So delete it
                        try
                        {
                            File.Delete(dotDFile);
                        }
                        finally
                        {
                        }

                        // Finally write out the file and its dependencies, must ensure success before doing this
                        foreach (var dep in dependencies)
                        {
                            writer.WriteLine(dep);
                        }
                    }
                    catch (Exception)
                    {
                        Log.LogError("Failed processing dependencies in: " + dotDFile);
                    }
                }
            }
        }
Пример #5
0
 protected virtual void RemoveTaskSpecificOutputs(
     CanonicalTrackedOutputFiles compactOutputs)
 {
 }
Пример #6
0
 protected virtual void AddTaskSpecificOutputs(
     ITaskItem[] sources, CanonicalTrackedOutputFiles compactOutputs)
 {
 }
Пример #7
0
        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);
            }
        }
Пример #8
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        protected virtual int PostExecuteTool(int exitCode, string responseFileCommands, string commandLineCommands)
        {
            TrackedOutputFiles = new CanonicalTrackedOutputFiles(this, TLogWriteFiles);

            TrackedInputFiles = new CanonicalTrackedInputFiles(this, TLogReadFiles, OutOfDateInputFiles, ExcludedInputPaths, TrackedOutputFiles, true, false);

            switch (exitCode)
            {
            case 0:
            {
                //
                // Successful build. Begin by collating known output files. (We have a manual workaround for instances where TrackedOutputFiles can't find rooted output.)
                //

                OutputFiles = TrackedOutputFiles.OutputsForSource(OutOfDateInputFiles);

                /*if (OutputFiles?.Length == 0)
                 * {
                 * var fileWrites = TrackerUtilities.ParseTrackerLogForCommandMapping(TrackedDependencies.ExpandWildcards(TLogWriteFiles));
                 *
                 * var writtenFiles = new HashSet<ITaskItem>();
                 *
                 * foreach (var keypair in fileWrites)
                 * {
                 *  writtenFiles.UnionWith(keypair.Value);
                 * }
                 *
                 * OutputFiles = writtenFiles.ToArray();
                 * }*/

                if (OutputFiles != null)
                {
                    foreach (var outfile in OutputFiles)
                    {
                        outfile.ItemSpec = PathUtils.GetExactPathName(outfile.ItemSpec.ToLowerInvariant());
                    }
                }

                //
                // Remove any instances where "input files" (sources which existed before this build) are shown as read/touched/written.
                //

                TrackedOutputFiles.RemoveDependenciesFromEntryIfMissing(OutOfDateInputFiles);

                TrackedInputFiles.RemoveDependenciesFromEntryIfMissing(OutOfDateInputFiles);

                //
                // Crunch the logs. This will erradicate un-rooted tracking data.
                //

                TrackedOutputFiles.SaveTlog();

                TrackedInputFiles.SaveTlog();

                break;
            }

            default:
            {
                //
                // Task failed. Remove any potentially processed file outputs to refresh clean state.
                //

                TrackedOutputFiles.RemoveEntriesForSource(OutOfDateInputFiles);

                TrackedInputFiles.RemoveEntriesForSource(OutOfDateInputFiles);

                TrackedOutputFiles.SaveTlog();

                TrackedInputFiles.SaveTlog();

                break;
            }
            }

            if (TLogCommandFiles != null)
            {
                OutputCommandTLog(TLogCommandFiles[0], responseFileCommands, commandLineCommands);
            }

            return(exitCode);
        }
Пример #9
0
        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);
        }
Пример #10
0
        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);
                }
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        protected override bool SkipTaskExecution()
        {
            //
            // Check there are actually sources to build, otherwise we can skip execution.
            //

            bool shouldSkipTaskExecution = base.SkipTaskExecution();

            if (MinimalRebuildFromTracking && !ForcedRebuildRequired())
            {
                TrackedOutputFiles = new CanonicalTrackedOutputFiles(this, TLogWriteFiles);

                TrackedInputFiles = new CanonicalTrackedInputFiles(this, TLogReadFiles, InputFiles, ExcludedInputPaths, TrackedOutputFiles, true, false);

                var outOfDateSourcesFromTracking = TrackedInputFiles.ComputeSourcesNeedingCompilation(true);

                var outOfDateSourcesFromCommandLine = GetOutOfDateSourcesFromCmdLineChanges(GenerateUnionFileCommands(), InputFiles);

#if DEBUG
                Log.LogMessageFromText($"[{GetType().Name}] Out of date sources (from tracking): {outOfDateSourcesFromTracking.Length}", MessageImportance.Low);

                Log.LogMessageFromText($"[{GetType().Name}] Out of date sources (command line differs): {outOfDateSourcesFromCommandLine.Length}", MessageImportance.Low);
#endif

                //
                // Merge out-of-date lists from both sources and assign these for compilation.
                //

                var mergedOutOfDateSources = new HashSet <ITaskItem>(outOfDateSourcesFromTracking);

                mergedOutOfDateSources.UnionWith(outOfDateSourcesFromCommandLine);

                OutOfDateInputFiles = mergedOutOfDateSources.ToArray();

                SkippedExecution = OutOfDateInputFiles == null || OutOfDateInputFiles.Length == 0;

                if (SkippedExecution)
                {
                    return(SkippedExecution);
                }

                //
                // Remove out-of-date files from tracked file list. Thus they are missing and need re-processing.
                //

                TrackedInputFiles.RemoveEntriesForSource(OutOfDateInputFiles);

                TrackedInputFiles.SaveTlog();

                TrackedOutputFiles.RemoveEntriesForSource(OutOfDateInputFiles);

                TrackedOutputFiles.SaveTlog();

                SkippedExecution = false;

                return(SkippedExecution);
            }

            //
            // Consider nothing out of date. Process everything.
            //

            OutOfDateInputFiles = InputFiles;

            SkippedExecution = false;

            return(SkippedExecution);
        }
Пример #12
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        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);
        }
Пример #13
0
        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);
        }
Пример #14
0
        protected override void OutputReadTLog(ITaskItem[] compiledSources, CanonicalTrackedOutputFiles outputs)
        {
            string trackerPath = Path.GetFullPath(TlogDirectory + ReadTLogFilenames[0]);

            //save tlog for sources not compiled during this execution
            TaskItem readTrackerItem         = new TaskItem(trackerPath);
            CanonicalTrackedInputFiles files = new CanonicalTrackedInputFiles(new TaskItem[] { readTrackerItem }, Sources, outputs, false, false);

            files.RemoveEntriesForSource(compiledSources);
            files.SaveTlog();

            //add tlog information for compiled sources
            using (StreamWriter writer = new StreamWriter(trackerPath, true, Encoding.Unicode))
            {
                foreach (ITaskItem source in compiledSources)
                {
                    string sourcePath     = Path.GetFullPath(source.ItemSpec).ToUpperInvariant();
                    string objectFilePath = GetObjectFile(source);
                    string depFilePath    = Path.ChangeExtension(objectFilePath, ".d");

                    try
                    {
                        if (File.Exists(depFilePath) == false)
                        {
                            Log.LogMessage(MessageImportance.High, depFilePath + " not found");
                        }
                        else
                        {
                            writer.WriteLine("^" + sourcePath);
                            DependencyParser parser = new DependencyParser(depFilePath);

                            foreach (string filename in parser.Dependencies)
                            {
                                //source itself not required
                                if (filename == sourcePath)
                                {
                                    continue;
                                }

                                if (File.Exists(filename) == false)
                                {
                                    Log.LogMessage(MessageImportance.High, "File " + sourcePath + " is missing dependency " + filename);
                                }

                                string fname = filename.ToUpperInvariant();
                                fname = Path.GetFullPath(fname);
                                writer.WriteLine(fname);
                            }

                            //remove d file
                            try
                            {
                                File.Delete(depFilePath);
                            }
                            finally
                            {
                            }
                        }
                    }
                    catch (Exception)
                    {
                        Log.LogError("Failed to update " + readTrackerItem + " for " + sourcePath);
                    }
                }
            }
        }
Пример #15
0
        private void ConstructReadTLog(ITaskItem[] upToDateSources, CanonicalTrackedOutputFiles outputs)
        {
            string readTrackerPath = Path.GetFullPath(TrackerIntermediateDirectory + "\\" + ReadTLogNames[0]);

            // Rewrite out read log, with the sources we're *not* compiling right now.
            TaskItem readTrackerItem         = new TaskItem(readTrackerPath);
            CanonicalTrackedInputFiles files = new CanonicalTrackedInputFiles(new TaskItem[] { readTrackerItem }, Sources, outputs, false, false);

            files.RemoveEntriesForSource(Sources);
            files.SaveTlog();

            // Now append onto the read log the sources we're compiling. It'll parse the .d files for each compiled file, so we know the
            // dependency header files associated with it, these will be recorded in the logfile.
            using (StreamWriter writer = new StreamWriter(readTrackerPath, true, Encoding.Unicode))
            {
                foreach (ITaskItem sourceItem in upToDateSources)
                {
                    string itemSpec   = sourceItem.ItemSpec;
                    string sourcePath = Path.GetFullPath(sourceItem.ItemSpec).ToUpperInvariant();
                    string objectFile = Path.GetFullPath(sourceItem.GetMetadata("ObjectFileName"));
                    string dotDFile   = Path.GetFullPath(Path.GetDirectoryName(objectFile) + "\\" + Path.GetFileNameWithoutExtension(objectFile) + ".d");

                    try
                    {
                        writer.WriteLine("^" + sourcePath);
                        if (File.Exists(dotDFile))
                        {
                            DepFileParse depFileParse = new DepFileParse(dotDFile);

                            foreach (string dependentFile in depFileParse.DependentFiles)
                            {
                                if (dependentFile != sourcePath)
                                {
                                    if (File.Exists(dependentFile) == false)
                                    {
                                        Log.LogMessage(MessageImportance.High, "File " + sourcePath + " is missing dependent file: " + dependentFile);
                                    }

                                    writer.WriteLine(dependentFile);
                                }
                            }

                            // Done with this .d file. So delete it
                            try
                            {
                                File.Delete(dotDFile);
                            }
                            finally
                            {
                            }
                        }
                        else if (File.Exists(objectFile))
                        {
                            Log.LogMessage(MessageImportance.High, "File " + sourcePath + " is missing it's .d file: " + dotDFile);
                        }
                    }
                    catch (Exception)
                    {
                        Log.LogError("Failed processing dependencies in: " + dotDFile);
                    }
                }
            }
        }