예제 #1
0
        public override bool Execute()
        {
            try
            {
                List <ITaskItem> computed = new List <ITaskItem>();
                UpdateDepends = false;

                //
                // Compare the command log files to detect changes in build options.
                //
                string log0       = string.Format(CommandLog);
                string log1       = string.Format(Path.ChangeExtension(CommandLog, ".0.log"));
                bool   logChanged = false;
                if (!File.Exists(log1))
                {
                    logChanged = true;
                    Log.LogMessage(MessageImportance.Low,
                                   string.Format("Build required because command log file: {0} doesn't exists",
                                                 TaskUtil.MakeRelative(WorkingDirectory, log1)));
                }
                else if (!FileCompare(log0, log1))
                {
                    logChanged = true;
                    Log.LogMessage(
                        MessageImportance.Low, "Build required because builder options changed");
                }

                if (File.Exists(log1))
                {
                    File.Delete(log1);
                }
                File.Move(log0, log1);

                FileInfo sliceCompiler = new FileInfo(SliceCompiler);

                XmlDocument dependsDoc   = new XmlDocument();
                bool        dependExists = File.Exists(DependFile);

                //
                // If command log file changed we don't need to compute dependencies as all
                // files must be rebuild
                //
                if (!logChanged)
                {
                    if (dependExists)
                    {
                        try
                        {
                            dependsDoc.Load(DependFile);
                        }
                        catch (XmlException)
                        {
                            try
                            {
                                File.Delete(DependFile);
                            }
                            catch (IOException)
                            {
                            }
                            Log.LogMessage(MessageImportance.Low,
                                           string.Format("Build required because depend file: {0} has some invalid data",
                                                         TaskUtil.MakeRelative(WorkingDirectory, DependFile)));
                        }
                    }
                    else
                    {
                        Log.LogMessage(MessageImportance.Low,
                                       string.Format("Build required because depend file: {0} doesn't exists",
                                                     TaskUtil.MakeRelative(WorkingDirectory, DependFile)));
                    }
                }

                foreach (ITaskItem source in Sources)
                {
                    bool skip = !logChanged && dependExists;
                    Log.LogMessage(MessageImportance.Low,
                                   string.Format("Computing dependencies for {0}", source.GetMetadata("Identity")));

                    ITaskItem[] generatedItems = GeneratedItems(source);

                    FileInfo 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;
                    }

                    FileInfo generatedInfo = null;
                    //
                    // Check if the Slice compiler is older than the source file
                    //
                    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),
                                                             Path.GetFileName(SliceCompiler)));
                                skip = false;
                                break;
                            }
                        }
                    }

                    if (skip)
                    {
                        foreach (ITaskItem item in generatedItems)
                        {
                            generatedInfo = new FileInfo(item.GetMetadata("FullPath"));
                            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;
                            }
                            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 depends = dependsDoc.DocumentElement.SelectNodes(
                            string.Format("/dependencies/source[@name='{0}']/dependsOn", source.GetMetadata("Identity")));

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

                    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");
                    computed.Add(computedSource);

                    UpdateDepends = UpdateDepends || !skip;
                }
                ComputedSources = computed.ToArray();
                return(true);
            }
            catch (Exception ex)
            {
                Log.LogError(ex.ToString());
                throw;
            }
        }
예제 #2
0
        public override bool Execute()
        {
            List <ITaskItem> computed = new List <ITaskItem>();

            UpdateDepends = false;

            String dependFile = Path.Combine(OutputDir, DependFile);

            XmlDocument dependsDoc   = new XmlDocument();
            bool        dependExists = File.Exists(dependFile);

            if (dependExists)
            {
                try
                {
                    dependsDoc.Load(dependFile);
                }
                catch (XmlException)
                {
                    try
                    {
                        File.Delete(dependFile);
                    }
                    catch (IOException)
                    {
                    }
                    Log.LogMessage(MessageImportance.Low,
                                   String.Format("Build required because depend file: {0} has some invalid data",
                                                 TaskUtil.MakeRelative(WorkingDirectory, dependFile)));
                }
            }
            else
            {
                Log.LogMessage(MessageImportance.Low,
                               String.Format("Build required because depend file: {0} doesn't exists",
                                             TaskUtil.MakeRelative(WorkingDirectory, dependFile)));
            }

            foreach (ITaskItem source in Sources)
            {
                bool skip = true;
                if (!dependExists)
                {
                    skip = false;
                }
                Log.LogMessage(MessageImportance.Low,
                               String.Format("Computing dependencies for {0}", source.GetMetadata("Identity")));

                ITaskItem[] generatedItems = GeneratedItems(source);

                FileInfo 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;
                }

                FileInfo generatedInfo = null;

                if (skip)
                {
                    foreach (ITaskItem item in generatedItems)
                    {
                        generatedInfo = new FileInfo(item.GetMetadata("FullPath"));
                        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;
                        }
                        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 depends = dependsDoc.DocumentElement.SelectNodes(
                        String.Format("/dependencies/source[@name='{0}']/dependsOn", source.GetMetadata("Identity")));
                    if (depends != null)
                    {
                        List <String> dependPaths = new List <String>();
                        foreach (XmlNode depend in depends)
                        {
                            dependPaths.Add(depend.Attributes["name"].Value);
                        }

                        foreach (String path in dependPaths)
                        {
                            FileInfo dependencyInfo = new FileInfo(path);
                            if (!dependencyInfo.Exists)
                            {
                                skip = false;
                                Log.LogMessage(MessageImportance.Low,
                                               String.Format("Build required because dependency: {0} doesn't exists",
                                                             TaskUtil.MakeRelative(WorkingDirectory, dependencyInfo.FullName)));
                                break;
                            }
                            else if (dependencyInfo.LastWriteTime > generatedInfo.LastWriteTime)
                            {
                                skip = false;
                                Log.LogMessage(MessageImportance.Low,
                                               String.Format("Build required because source: {0} is older than target {1}",
                                                             source.GetMetadata("Identity"),
                                                             TaskUtil.MakeRelative(WorkingDirectory, dependencyInfo.FullName)));
                                break;
                            }
                        }
                    }
                }

                if (skip)
                {
                    Log.LogMessage(MessageImportance.Normal,
                                   String.Format(
                                       "Skipping {0} -> {1}.{2} up to date",
                                       source.GetMetadata("Identity"),
                                       TaskUtil.MakeRelative(WorkingDirectory, Path.Combine(OutputDir, source.GetMetadata("Filename"))),
                                       (ToolName.Equals("slice2cpp.exe") ? "[h,cpp] are" : "cs is")));
                }

                ITaskItem computedSource = new TaskItem(source.ItemSpec);
                source.CopyMetadataTo(computedSource);
                computedSource.SetMetadata("BuildRequired", skip ? "False" : "True");
                computed.Add(computedSource);

                if (!UpdateDepends && !skip)
                {
                    UpdateDepends = true;
                }
            }
            ComputedSources = computed.ToArray();
            return(true);
        }