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; }
/// <summary> /// Searches multiple directories for a file. /// </summary> /// <param name="paths">An array of paths to search. Each path is assumed to be a directory.</param> /// <param name="file">The file to search for. Any root or directory portion is ignored. Wildcards are not allowed.</param> /// <returns>An array of just the paths that contain the file, in the same order as the passed in array.</returns> public static ParsedPathList FindFileInPaths(ParsedPathList paths, ParsedPath file) { ParsedPathList foundPaths = new ParsedPathList(); foreach (ParsedPath path in paths) { try { ParsedPath fullPath = new ParsedPath(path, PathParts.VolumeAndDirectory).Append(file); if (File.Exists(fullPath)) foundPaths.Add(fullPath); } catch (ArgumentException) { // If there is a bad path in the list, ignore it } } return foundPaths; }
private void LoadCompilerClasses() { CompilerClasses = new List <CompilerClass>(); NewestAssemblyWriteTime = DateTime.MinValue; ParsedPathList assemblyPaths = new ParsedPathList(); foreach (var rawAssembly in ContentFile.CompilerAssemblies) { ParsedPath pathSpec = null; try { pathSpec = new ParsedPath(Properties.ExpandVariables(rawAssembly.Value), PathType.File); } catch (KeyNotFoundException e) { throw new ContentFileException(rawAssembly, e); } assemblyPaths.Add(pathSpec); } for (int i = 0; i < assemblyPaths.Count; i++) { var assemblyPath = assemblyPaths[i]; Assembly assembly = null; try { // We use Assembly.Load so that the test assembly and subsequently loaded // assemblies end up in the correct load context. If the assembly cannot be // found it will raise a AssemblyResolve event where we will search for the // assembly. assembly = Assembly.LoadFrom(assemblyPath); } catch (Exception e) { throw new ContentFileException(this.ContentFile.CompilerAssemblies[i], e); } Type[] types; // We won't get dependency errors until we actually try to reflect on all the types in the assembly try { types = assembly.GetTypes(); } catch (ReflectionTypeLoadException e) { string message = "Unable to reflect on assembly '{0}'".CultureFormat(assemblyPath); // There is one entry in the exceptions array for each null in the types array, // and they correspond positionally. foreach (Exception ex in e.LoaderExceptions) { message += Environment.NewLine + " " + ex.Message; } // Not being able to reflect on classes in the compiler assembly is a critical error throw new ContentFileException(this.ContentFile.CompilerAssemblies[i], message, e); } int compilerCount = 0; // Go through all the types in the test assembly and find all the // compiler classes, those that inherit from IContentCompiler. foreach (var type in types) { Type interfaceType = type.GetInterface(typeof(IContentCompiler).ToString()); if (interfaceType == null) { continue; } CompilerClass compilerClass = new CompilerClass(this.ContentFile.CompilerAssemblies[i], assembly, type, interfaceType); CompilerClasses.Add(compilerClass); compilerCount++; } DateTime dateTime = File.GetLastWriteTime(assembly.Location); if (dateTime > NewestAssemblyWriteTime) { NewestAssemblyWriteTime = dateTime; } WriteMessage("Loaded {0} compilers from assembly '{1}'".CultureFormat(compilerCount, assembly.Location)); } }
private void LoadCompilerClasses() { CompilerClasses = new List<CompilerClass>(); NewestAssemblyWriteTime = DateTime.MinValue; ParsedPathList assemblyPaths = new ParsedPathList(); foreach (var rawAssembly in ContentFile.CompilerAssemblies) { ParsedPath pathSpec = null; try { pathSpec = new ParsedPath(Properties.ExpandVariables(rawAssembly.Value), PathType.File); } catch (KeyNotFoundException e) { throw new ContentFileException(rawAssembly, e); } assemblyPaths.Add(pathSpec); } for (int i = 0; i < assemblyPaths.Count; i++) { var assemblyPath = assemblyPaths[i]; Assembly assembly = null; try { // We use Assembly.Load so that the test assembly and subsequently loaded // assemblies end up in the correct load context. If the assembly cannot be // found it will raise a AssemblyResolve event where we will search for the // assembly. assembly = Assembly.LoadFrom(assemblyPath); } catch (Exception e) { throw new ContentFileException(this.ContentFile.CompilerAssemblies[i], e); } Type[] types; // We won't get dependency errors until we actually try to reflect on all the types in the assembly try { types = assembly.GetTypes(); } catch (ReflectionTypeLoadException e) { string message = "Unable to reflect on assembly '{0}'".CultureFormat(assemblyPath); // There is one entry in the exceptions array for each null in the types array, // and they correspond positionally. foreach (Exception ex in e.LoaderExceptions) message += Environment.NewLine + " " + ex.Message; // Not being able to reflect on classes in the compiler assembly is a critical error throw new ContentFileException(this.ContentFile.CompilerAssemblies[i], message, e); } int compilerCount = 0; // Go through all the types in the test assembly and find all the // compiler classes, those that inherit from IContentCompiler. foreach (var type in types) { Type interfaceType = type.GetInterface(typeof(IContentCompiler).ToString()); if (interfaceType == null) continue; CompilerClass compilerClass = new CompilerClass(this.ContentFile.CompilerAssemblies[i], assembly, type, interfaceType); CompilerClasses.Add(compilerClass); compilerCount++; } DateTime dateTime = File.GetLastWriteTime(assembly.Location); if (dateTime > NewestAssemblyWriteTime) NewestAssemblyWriteTime = dateTime; WriteMessage("Loaded {0} compilers from assembly '{1}'".CultureFormat(compilerCount, assembly.Location)); } }
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); }