コード例 #1
0
ファイル: Tasks.cs プロジェクト: ming-hai/ice-builder-msbuild
 protected override void TraceGenerated()
 {
     foreach (ITaskItem source in Sources)
     {
         string message = string.Format("Compiling {0} Generating -> ", source.GetMetadata("Identity"));
         message += TaskUtil.MakeRelative(WorkingDirectory, GetGeneratedPath(source, OutputDir, ".cs"));
         Log.LogMessage(MessageImportance.High, message);
     }
 }
コード例 #2
0
ファイル: Tasks.cs プロジェクト: ming-hai/ice-builder-msbuild
        protected override void TraceGenerated()
        {
            var headerOutputDir = string.IsNullOrEmpty(HeaderOutputDir) ? OutputDir : HeaderOutputDir;

            foreach (ITaskItem source in Sources)
            {
                var cppSource = GetGeneratedPath(source, OutputDir, SourceExt);
                var cppHeader = GetGeneratedPath(source, headerOutputDir, HeaderExt);
                Log.LogMessage(MessageImportance.High,
                               string.Format("Compiling {0} Generating -> {1} and {2}",
                                             source.GetMetadata("Identity"),
                                             TaskUtil.MakeRelative(WorkingDirectory, cppSource),
                                             TaskUtil.MakeRelative(WorkingDirectory, cppHeader)));
            }
        }
コード例 #3
0
ファイル: Tasks.cs プロジェクト: ming-hai/ice-builder-msbuild
        public override bool Execute()
        {
            List <ITaskItem> computed = new List <ITaskItem>();

            foreach (ITaskItem source in Sources)
            {
                bool skip = true;
                Log.LogMessage(MessageImportance.Low,
                               string.Format("Computing dependencies for {0}", source.GetMetadata("Identity")));
                var sourceInfo = new FileInfo(source.GetMetadata("FullPath"));
                if (!sourceInfo.Exists)
                {
                    Log.LogMessage(MessageImportance.Low,
                                   string.Format("Build required because source: {0} doesn't exists",
                                                 source.GetMetadata("Identity")));
                    skip = false;
                }

                var      generatedItems = GeneratedItems(source);
                FileInfo generatedInfo  = null;
                FileInfo dependInfo     = null;
                //
                // Check if the Slice compiler is older than the source file
                //
                var sliceCompiler = new FileInfo(Path.Combine(IceToolsPath, ToolName));
                if (skip)
                {
                    foreach (ITaskItem item in generatedItems)
                    {
                        generatedInfo = new FileInfo(item.GetMetadata("FullPath"));

                        if (generatedInfo.Exists &&
                            sliceCompiler.LastWriteTime.ToFileTime() > generatedInfo.LastWriteTime.ToFileTime())
                        {
                            Log.LogMessage(MessageImportance.Low,
                                           string.Format("Build required because target: {0} is older than Slice compiler: {1}",
                                                         TaskUtil.MakeRelative(WorkingDirectory, generatedInfo.FullName),
                                                         ToolName));
                            skip = false;
                            break;
                        }
                    }
                }

                XmlDocument dependsDoc = new XmlDocument();
                if (skip)
                {
                    dependInfo = new FileInfo(Path.Combine(WorkingDirectory, source.GetMetadata("OutputDir"),
                                                           string.Format("SliceCompile.{0}.d", Path.GetFileNameWithoutExtension(sourceInfo.Name))));
                    //
                    // Check that the depdend file exists
                    //
                    if (!dependInfo.Exists)
                    {
                        Log.LogMessage(MessageImportance.Low,
                                       string.Format("Build required because depend file: {0} doesn't exists",
                                                     TaskUtil.MakeRelative(WorkingDirectory, dependInfo.FullName)));
                        skip = false;
                    }
                    //
                    // Check that the depend file is older than the corresponding Slice source
                    //
                    else if (sourceInfo.LastWriteTime.ToFileTime() > dependInfo.LastWriteTime.ToFileTime())
                    {
                        Log.LogMessage(MessageImportance.Low,
                                       string.Format("Build required because source: {0} is older than depend file {1}",
                                                     source.GetMetadata("Identity"),
                                                     TaskUtil.MakeRelative(WorkingDirectory, dependInfo.FullName)));
                        skip = false;
                    }
                    else
                    {
                        try
                        {
                            dependsDoc.Load(dependInfo.FullName);
                        }
                        catch (XmlException)
                        {
                            try
                            {
                                File.Delete(dependInfo.FullName);
                            }
                            catch (IOException)
                            {
                            }
                            Log.LogMessage(MessageImportance.Low,
                                           string.Format("Build required because depend file: {0} has some invalid data",
                                                         TaskUtil.MakeRelative(WorkingDirectory, dependInfo.FullName)));
                            skip = false;
                        }
                    }
                }

                if (skip)
                {
                    foreach (ITaskItem item in generatedItems)
                    {
                        generatedInfo = new FileInfo(item.GetMetadata("FullPath"));
                        //
                        // Check that the generated file exists
                        //
                        if (!generatedInfo.Exists)
                        {
                            Log.LogMessage(MessageImportance.Low,
                                           string.Format("Build required because generated: {0} doesn't exists",
                                                         TaskUtil.MakeRelative(WorkingDirectory, generatedInfo.FullName)));
                            skip = false;
                            break;
                        }
                        //
                        // Check that the generated file is older than the corresponding Slice source
                        //
                        else if (sourceInfo.LastWriteTime.ToFileTime() > generatedInfo.LastWriteTime.ToFileTime())
                        {
                            Log.LogMessage(MessageImportance.Low,
                                           string.Format("Build required because source: {0} is older than target {1}",
                                                         source.GetMetadata("Identity"),
                                                         TaskUtil.MakeRelative(WorkingDirectory, generatedInfo.FullName)));
                            skip = false;
                            break;
                        }
                    }
                }

                if (skip)
                {
                    XmlNodeList options = dependsDoc.DocumentElement.SelectNodes(
                        string.Format("/dependencies/source[@name='{0}']/options/child::node()",
                                      source.GetMetadata("Identity")));
                    if (options != null)
                    {
                        var newOptions = GetOptions(source);
                        var oldOptions = options.Cast <XmlNode>().Select(node => new
                        {
                            node.Name,
                            node.InnerXml
                        }).ToDictionary(t => t.Name, t => t.InnerXml);

                        if (newOptions.Except(oldOptions).Any() || oldOptions.Except(newOptions).Any())
                        {
                            Log.LogMessage(MessageImportance.Low,
                                           string.Format("Build required because source: {0} build options change",
                                                         source.GetMetadata("Identity")));
                            skip = false;
                        }
                    }
                }

                if (skip)
                {
                    XmlNodeList depends = dependsDoc.DocumentElement.SelectNodes(
                        string.Format("/dependencies/source[@name='{0}']/dependsOn", source.GetMetadata("Identity")));

                    if (depends != null)
                    {
                        var inputs = new List <string>();
                        foreach (XmlNode depend in depends)
                        {
                            string   path           = depend.Attributes["name"].Value;
                            FileInfo dependencyInfo = new FileInfo(path);
                            if (!dependencyInfo.Exists)
                            {
                                Log.LogMessage(MessageImportance.Low,
                                               string.Format("Build required because dependency: {0} doesn't exists",
                                                             TaskUtil.MakeRelative(WorkingDirectory, dependencyInfo.FullName)));
                                skip = false;
                                break;
                            }
                            else if (dependencyInfo.LastWriteTime > generatedInfo.LastWriteTime)
                            {
                                Log.LogMessage(MessageImportance.Low,
                                               string.Format("Build required because source: {0} is older than target: {1}",
                                                             source.GetMetadata("Identity"),
                                                             TaskUtil.MakeRelative(WorkingDirectory, dependencyInfo.FullName)));
                                skip = false;
                                break;
                            }

                            inputs.Add(Path.GetFullPath(depend.Attributes["name"].Value).ToUpper());
                        }
                        inputs.Add(source.GetMetadata("FullPath").ToUpper());
                        inputs.Add(sliceCompiler.FullName.ToUpper());

                        var outputs = GeneratedItems(source).Select(item => item.GetMetadata("FullPath").ToUpper());
                        source.SetMetadata("Outputs", string.Join(";", outputs));
                        source.SetMetadata("Inputs", string.Join(";", inputs));
                    }
                }

                if (skip)
                {
                    string message = string.Format("Skipping {0} -> ", source.GetMetadata("Identity"));
                    message += generatedItems[0].GetMetadata("Identity");
                    if (generatedItems.Length > 1)
                    {
                        message += " and ";
                        message += generatedItems[1].GetMetadata("Identity");
                        message += " are ";
                    }
                    else
                    {
                        message += " is ";
                    }
                    message += "up to date";

                    Log.LogMessage(MessageImportance.Normal, message);
                }

                ITaskItem computedSource = new TaskItem(source.ItemSpec);
                source.CopyMetadataTo(computedSource);
                computedSource.SetMetadata("BuildRequired", skip ? "False" : "True");
                computedSource.SetMetadata("OutputDir", computedSource.GetMetadata("OutputDir").TrimEnd('\\'));
                computed.Add(computedSource);
            }
            ComputedSources = computed.ToArray();
            return(true);
        }