Example #1
0
 public void ExpandAndAddFromList(List <Tuple <string, string> > pairs, PropertyGroup propGroup)
 {
     foreach (var pair in pairs)
     {
         dictionary[pair.Item1] = propGroup.ReplaceVariables(pair.Item2);
     }
 }
Example #2
0
        public void ExpandAndAddFromList(List <ContentFileV2.Item> items, PropertyGroup propGroup)
        {
            foreach (var item in items)
            {
                ParsedPathList pathList;

                if (!dictionary.TryGetValue(item.Name, out pathList))
                {
                    pathList = new ParsedPathList();
                    dictionary.Add(item.Name, pathList);
                }

                string[] parts = item.Include.Split(';');

                foreach (var part in parts)
                {
                    ParsedPath     pathSpec = new ParsedPath(propGroup.ReplaceVariables(part), PathType.File);
                    ParsedPathList paths;

                    if (pathSpec.HasWildcards)
                    {
                        paths = new ParsedPathList(DirectoryUtility.GetFiles(pathSpec, SearchScope.DirectoryOnly));

                        foreach (var path in paths)
                        {
                            pathList.Add(path);
                        }
                    }
                    else
                    {
                        pathList.Add(pathSpec);
                    }
                }

                if (!String.IsNullOrEmpty(item.Exclude))
                {
                    parts = item.Exclude.Split(';');

                    foreach (var part in parts)
                    {
                        ParsedPath path = new ParsedPath(propGroup.ReplaceVariables(part), PathType.File);

                        pathList.Remove(path);
                    }
                }
            }
        }
Example #3
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);
        }