private List<BuildTarget> PrepareBuildTargets(List<ContentFileV2.Target> rawTargets, ItemGroup globalItems, PropertyGroup globalProps)
        {
            List<BuildTarget> buildTargets = new List<BuildTarget>();

            foreach (var rawTarget in rawTargets)
            {
                try
                {
                    PropertyGroup targetProps = new PropertyGroup(globalProps);

                    targetProps.Set("TargetName", rawTarget.Name);

                    if (rawTarget.Properties != null)
                        targetProps.ExpandAndAddFromList(rawTarget.Properties, targetProps);

                    ItemGroup targetItems = new ItemGroup(globalItems);

                    ParsedPathList inputFiles = new ParsedPathList();
                    string[] list = rawTarget.Inputs.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                    foreach (var rawInputFile in list)
                    {
                        ParsedPath pathSpec = null;
                        string s = targetProps.ReplaceVariables(rawInputFile);

                        try
                        {
                            pathSpec = new ParsedPath(s, PathType.File).MakeFullPath();
                        }
                        catch (Exception e)
                        {
                            throw new ContentFileException("Bad path '{0}'".CultureFormat(s), e);
                        }

                        if (pathSpec.HasWildcards)
                        {
                            if (!Directory.Exists(pathSpec.VolumeAndDirectory))
                            {
                                throw new ContentFileException("Directory '{0}' does not exist".CultureFormat(pathSpec.VolumeAndDirectory));
                            }

                            IList<ParsedPath> files = DirectoryUtility.GetFiles(pathSpec, SearchScope.DirectoryOnly);

                            if (files.Count == 0)
                            {
                                throw new ContentFileException("Wildcard input refers to no files after expansion");
                            }

                            inputFiles = new ParsedPathList(inputFiles.Concat(files));
                        }
                        else
                        {
                            if (!File.Exists(pathSpec))
                            {
                                throw new ContentFileException("Input file '{0}' does not exist".CultureFormat(pathSpec));
                            }

                            inputFiles.Add(pathSpec);
                        }
                    }

                    ParsedPathList outputFiles = new ParsedPathList();

                    list = rawTarget.Outputs.Split(';');

                    foreach (var rawOutputFile in list)
                    {
                        string s = targetProps.ReplaceVariables(rawOutputFile);

                        try
                        {
                            ParsedPath outputFile = new ParsedPath(s, PathType.File).MakeFullPath();

                            outputFiles.Add(outputFile);
                        }
                        catch (Exception e)
                        {
                            throw new ContentFileException("Bad path '{0}'".CultureFormat(s), e);
                        }
                    }

                    targetItems.Set("TargetInputs", inputFiles);
                    targetItems.Set("TargetOutputs", outputFiles);

                    bool needsRebuild = IsCompileRequired(inputFiles, outputFiles);

                    if (!needsRebuild)
                        continue;

                    buildTargets.Add(new BuildTarget(rawTarget.LineNumber, targetProps, targetItems));
                }
                catch (Exception e)
                {
                    throw new ContentFileException(this.ContentPath, rawTarget.LineNumber, "Error preparing targets", e);
                }
            }

            return buildTargets;
        }
Esempio n. 2
0
        private List <BuildTarget> PrepareBuildTargets(List <ContentFileV2.Target> rawTargets, ItemGroup globalItems, PropertyGroup globalProps)
        {
            List <BuildTarget> buildTargets = new List <BuildTarget>();

            foreach (var rawTarget in rawTargets)
            {
                try
                {
                    PropertyGroup targetProps = new PropertyGroup(globalProps);

                    targetProps.Set("TargetName", rawTarget.Name);

                    if (rawTarget.Properties != null)
                    {
                        targetProps.ExpandAndAddFromList(rawTarget.Properties, targetProps);
                    }

                    ItemGroup targetItems = new ItemGroup(globalItems);

                    ParsedPathList inputFiles = new ParsedPathList();
                    string[]       list       = rawTarget.Inputs.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                    foreach (var rawInputFile in list)
                    {
                        ParsedPath pathSpec = null;
                        string     s        = targetProps.ReplaceVariables(rawInputFile);

                        try
                        {
                            pathSpec = new ParsedPath(s, PathType.File).MakeFullPath();
                        }
                        catch (Exception e)
                        {
                            throw new ContentFileException("Bad path '{0}'".CultureFormat(s), e);
                        }

                        if (pathSpec.HasWildcards)
                        {
                            if (!Directory.Exists(pathSpec.VolumeAndDirectory))
                            {
                                throw new ContentFileException("Directory '{0}' does not exist".CultureFormat(pathSpec.VolumeAndDirectory));
                            }

                            IList <ParsedPath> files = DirectoryUtility.GetFiles(pathSpec, SearchScope.DirectoryOnly);

                            if (files.Count == 0)
                            {
                                throw new ContentFileException("Wildcard input refers to no files after expansion");
                            }

                            inputFiles = new ParsedPathList(inputFiles.Concat(files));
                        }
                        else
                        {
                            if (!File.Exists(pathSpec))
                            {
                                throw new ContentFileException("Input file '{0}' does not exist".CultureFormat(pathSpec));
                            }

                            inputFiles.Add(pathSpec);
                        }
                    }

                    ParsedPathList outputFiles = new ParsedPathList();

                    list = rawTarget.Outputs.Split(';');

                    foreach (var rawOutputFile in list)
                    {
                        string s = targetProps.ReplaceVariables(rawOutputFile);

                        try
                        {
                            ParsedPath outputFile = new ParsedPath(s, PathType.File).MakeFullPath();

                            outputFiles.Add(outputFile);
                        }
                        catch (Exception e)
                        {
                            throw new ContentFileException("Bad path '{0}'".CultureFormat(s), e);
                        }
                    }

                    targetItems.Set("TargetInputs", inputFiles);
                    targetItems.Set("TargetOutputs", outputFiles);

                    bool needsRebuild = IsCompileRequired(inputFiles, outputFiles);

                    if (!needsRebuild)
                    {
                        continue;
                    }

                    buildTargets.Add(new BuildTarget(rawTarget.LineNumber, targetProps, targetItems));
                }
                catch (Exception e)
                {
                    throw new ContentFileException(this.ContentPath, rawTarget.LineNumber, "Error preparing targets", e);
                }
            }

            return(buildTargets);
        }