public FilteredFileEnumerator(IFileEnumerator fileEnumerator, Predicate <FileInfo> predicate) { sourceFileEnumerator = fileEnumerator; sourceFileEnumerator.EnumerationFilter = predicate; files = sourceFileEnumerator.Enumerate().ToList(); sourceFileEnumerator.EnumerationFilter = null; }
public void Compile(IFileEnumerator files) { if (!options.IsAOT) { throw ErrorHelper.CreateError(0099, "Internal error \"AOTBundle with aot: {0}\" Please file a bug report with a test case (http://bugzilla.xamarin.com).", options.CompilationType); } var monoEnv = new string [] { "MONO_PATH", files.RootDir }; List <string> filesToAOT = GetFilesToAOT(files); Parallel.ForEach(filesToAOT, ParallelOptions, file => { string command = String.Format("--aot{0} {1}{2}", options.IsHybridAOT ? "=hybrid" : "", IsModern ? "--runtime=mobile " : "", StringUtils.Quote(file)); if (RunCommand(MonoPath, command, monoEnv) != 0) { throw ErrorHelper.CreateError(3001, "Could not AOT the assembly '{0}'", file); } }); if (IsRelease && options.IsHybridAOT) { Parallel.ForEach(filesToAOT, ParallelOptions, file => { if (RunCommand(StripCommand, StringUtils.Quote(file)) != 0) { throw ErrorHelper.CreateError(3001, "Could not strip the assembly '{0}'", file); } }); } }
/// <summary> /// Inizializza una nuova istanza di <see cref="FileIndex"/> /// </summary> /// <param name="keyGenerator">Generatore di chiave per i file</param> /// <param name="enumerator">Enumeratore per i file da indicizzare</param> public FileIndex(IKeyGenerator <string, string> keyGenerator, IFileEnumerator enumerator) { _enumerator = enumerator; _keyGenerator = keyGenerator; WorkerReportsProgress = true; WorkerSupportsCancellation = true; }
/// <summary> /// Adds a directory enumerator to the compound file enumerator. The directory enumerator simply enumerates the files contained in the given directory. /// </summary> /// <param name="directoryPath">Path of the directory, whose content should be enumerated.</param> /// <param name="recursive">Specifies, whether the directory should be enumerated recursively.</param> /// <returns>CompoundFileEnumeratorBuilder creating the current compound file enumerator.</returns> public CompoundFileEnumeratorBuilder DirectoryEnumerator(string directoryPath, bool recursive) { NextEnumerator(); mCurrentEnumerator = new DirectoryFileEnumerator(directoryPath, recursive); return(this); }
/// <summary> /// Adds a fixed file enumerator to the compound file enumerator. This enumerator just enumerates the provided list of files. /// </summary> /// <param name="files">List of file which should be enumerated by the fixed file enumerator.</param> /// <returns>CompoundFileEnumeratorBuilder creating the current compound file enumerator.</returns> public CompoundFileEnumeratorBuilder FileEnumerator(params string[] files) { NextEnumerator(); mCurrentEnumerator = new FixedFileEnumerator(files); return(this); }
/// <summary> /// Adds a directory enumerator to the compound file enumerator. The directory enumerator simply enumerates the files contained in the given directory. /// </summary> /// <param name="directoryPath">Path of the directory, whose content should be enumerated.</param> /// <param name="recursive">Specifies, whether the directory should be enumerated recursively.</param> /// <param name="wildcardPatterns">List of wild card patterns, for the files, which should be listed by the directory enumerator.</param> /// <returns>CompoundFileEnumeratorBuilder creating the current compound file enumerator.</returns> public CompoundFileEnumeratorBuilder DirectoryEnumerator(string directoryPath, bool recursive, params string[] wildcardPatterns) { NextEnumerator(); mCurrentEnumerator = new DirectoryFileEnumerator(directoryPath, recursive); WildcardFilter(wildcardPatterns); return(this); }
/// <summary> /// Constructs a <see cref="Runner"/> object with all its dependencies /// </summary> /// <param name="paramReader"></param> /// <param name="fileEnumerator"></param> /// <param name="reader"></param> /// <param name="filter"></param> /// <param name="logger"></param> /// <param name="stdOutput"></param> public Runner(IParamReader paramReader, IFileEnumerator fileEnumerator, IReader reader, IDependencyFilter filter, ILogger logger, TextWriter stdOutput) { this.paramReader = paramReader; this.fileEnumerator = fileEnumerator; this.reader = reader; this.filter = filter; this.logger = logger; this.stdOutput = stdOutput; }
public void Compile(IFileEnumerator files) { if (!options.IsAOT) { throw ErrorHelper.CreateError(0099, Errors.MX0099, $"\"AOTBundle with aot: {options.CompilationType}\" "); } var monoEnv = new Dictionary <string, string> { { "MONO_PATH", files.RootDir } }; List <string> filesToAOT = GetFilesToAOT(files); Parallel.ForEach(filesToAOT, ParallelOptions, file => { var cmd = new List <string> (); cmd.Add(options.IsHybridAOT ? "--aot=hybrid" : "--aot"); if (IsModern) { cmd.Add("--runtime=mobile"); } cmd.Add(file); if (RunCommand(MonoPath, cmd, monoEnv) != 0) { throw ErrorHelper.CreateError(3001, Errors.MX3001, "AOT", file); } }); if (IsRelease && options.IsHybridAOT) { Parallel.ForEach(filesToAOT, ParallelOptions, file => { if (RunCommand(StripCommand, new [] { file }) != 0) { throw ErrorHelper.CreateError(3001, Errors.MX3001, "strip", file); } }); } if (IsRelease) { // mono --aot creates .dll.dylib.dSYM directories for each assembly AOTed // There isn't an easy was to disable this behavior // We move them (cheap) so they can be archived for release builds foreach (var file in filesToAOT) { var source = file + ".dylib.dSYM/"; if (Directory.Exists(source)) { var dest = Path.GetFullPath(Path.Combine(source, "..", "..", "..", "..", Path.GetFileName(file) + ".dylib.dSYM/")); if (Directory.Exists(dest)) { Directory.Delete(dest, true); } Directory.Move(source, dest); } } } }
/// <summary> /// Starts a new file enumerator entry. /// </summary> private void NextEnumerator() { if (mCurrentEnumerator != null) { mCompoundFileEnumerator.FileEnumerators.Add(new KeyValuePair <IFileEnumerator, IFilterChain>(mCurrentEnumerator, mCurrentFilterChain)); mCurrentEnumerator = null; mCurrentFilterChain = null; } }
/// <summary> /// Adds a file enumerator of a given type to the compound enumerator. /// </summary> /// <param name="enumeratorType">Type of the file enumerator to be added to the compound enumerator.</param> /// <param name="constructorArguments">Constructor arguments to be passed to the file enumerator constructor.</param> /// <returns>CompoundFileEnumeratorBuilder creating the current compound file enumerator.</returns> public CompoundFileEnumeratorBuilder FileEnumerator(Type enumeratorType, params object[] constructorArguments) { if (enumeratorType == null || !typeof(IFileEnumerator).IsAssignableFrom(enumeratorType)) { return(this); } NextEnumerator(); mCurrentEnumerator = Activator.CreateInstance(enumeratorType, constructorArguments) as IFileEnumerator; return(this); }
private static void RegisterServices() { var collection = new ServiceCollection(); collection.AddScoped <IFileEnumerator, FileEnumerator>(); collection.AddScoped <ICsvProcessor, CSVProcessor>(); var serviceProvider = collection.BuildServiceProvider(); _fileEnumerator = serviceProvider.GetService <IFileEnumerator>(); _csvProcessor = serviceProvider.GetService <ICsvProcessor>(); }
/// <summary> /// Adds a file catalogue enumerator of a given type to the compound enumerator. /// </summary> /// <typeparam name="FILECATALGOUE_ENUMERATOR_TYPE">Type of the file catalogue enumerator to be added to the compound file enumerator.</typeparam> /// <param name="fileCatalgouePath">Path of the file catalogue, which should be enumerated by the file catalogue enumerator.</param> /// <param name="recursive">Indicates, whether the file catalogue enumerator should enumerate files recursively.</param> /// <param name="constructorArguments">Constructor arguments to be passed to the file catalogue enumerator constructor.</param> /// <returns>CompoundFileEnumeratorBuilder creating the current compound file enumerator.</returns> public CompoundFileEnumeratorBuilder FileCatalogueEnumerator <FILECATALGOUE_ENUMERATOR_TYPE>(string fileCatalgouePath, bool recursive, params object[] constructorArguments) where FILECATALGOUE_ENUMERATOR_TYPE : IFileCatalogueEnumerator { NextEnumerator(); var fileCatalogueEnumerator = Activator.CreateInstance(typeof(FILECATALGOUE_ENUMERATOR_TYPE), constructorArguments) as IFileCatalogueEnumerator; fileCatalogueEnumerator.FileCataloguePath = fileCatalgouePath; fileCatalogueEnumerator.Recursive = recursive; mCurrentEnumerator = fileCatalogueEnumerator; return(this); }
/// <summary> /// Adds a file enumerator to the compound file enumerator. /// </summary> /// <param name="fileEnumerator">File enumerator to be added.</param> /// <returns>CompoundFileEnumeratorBuilder creating the current compound file enumerator.</returns> public CompoundFileEnumeratorBuilder FileEnumerator(IFileEnumerator fileEnumerator) { if (fileEnumerator == null) { return(this); } NextEnumerator(); mCurrentEnumerator = fileEnumerator; return(this); }
public DependencyParser(IFileEnumerator enumerator, IUnitBuilder builder) { if (enumerator == null) { throw new ArgumentNullException("enumerator"); } if (builder == null) { throw new ArgumentNullException("builder"); } _enumerator = enumerator; _builder = builder; _units = new List<PascalUnit>(); }
public void Compile(IFileEnumerator files) { if (!options.IsAOT) { throw ErrorHelper.CreateError(0099, Errors.MX0099, $"\"AOTBundle with aot: {options.CompilationType}\" "); } var monoEnv = new Dictionary <string, string> { { "MONO_PATH", files.RootDir } }; List <string> filesToAOT = GetFilesToAOT(files); Parallel.ForEach(filesToAOT, ParallelOptions, file => { var cmd = new List <string> (); cmd.Add(options.IsHybridAOT ? "--aot=hybrid" : "--aot"); if (IsModern) { cmd.Add("--runtime=mobile"); } cmd.Add(file); if (RunCommand(MonoPath, cmd, monoEnv) != 0) { throw ErrorHelper.CreateError(3001, Errors.MX3001, "AOT", file); } }); if (IsRelease && options.IsHybridAOT) { Parallel.ForEach(filesToAOT, ParallelOptions, file => { if (RunCommand(StripCommand, new [] { file }) != 0) { throw ErrorHelper.CreateError(3001, Errors.MX3001, "strip", file); } }); } if (IsRelease) { // mono --aot creates .dll.dylib.dSYM directories for each assembly AOTed // There isn't an easy was to disable this behavior, so clean up under release Parallel.ForEach(filesToAOT, ParallelOptions, file => { if (RunCommand(DeleteDebugSymbolCommand, new [] { "-r", file + ".dylib.dSYM/" }, monoEnv) != 0) { throw ErrorHelper.CreateError(3001, Errors.MX3001, "delete debug info from", file); } }); } }
public void Compile(IFileEnumerator files) { if (!options.IsAOT) { throw ErrorHelper.CreateError(0099, "Internal error \"AOTBundle with aot: {0}\" Please file a bug report with a test case (http://bugzilla.xamarin.com).", options.CompilationType); } var monoEnv = new string [] { "MONO_PATH", files.RootDir }; Parallel.ForEach(GetFilesToAOT(files), ParallelOptions, file => { if (RunCommand(MonoPath, String.Format("--aot{0} {1}", options.IsHybridAOT ? "=hybrid" : "", Quote(file)), monoEnv) != 0) { throw ErrorHelper.CreateError(3001, "Could not AOT the assembly '{0}'", file); } }); }
/// <summary> /// Adds a directory enumerator to the compound file enumerator. The directory enumerator simply enumerates the files contained in the given directory. /// </summary> /// <param name="directoryPath">Path of the directory, whose content should be enumerated.</param> /// <param name="recursive">Specifies, whether the directory should be enumerated recursively.</param> /// <param name="includeWildcardPatterns">List of wild card patterns, for the files, which should be listed by the directory enumerator.</param> /// <param name="excludeWildcardPatterns">List of wild card patterns, for files, which should be excluded by the directory enumerator.</param> /// <returns>CompoundFileEnumeratorBuilder creating the current compound file enumerator.</returns> public CompoundFileEnumeratorBuilder DirectoryEnumerator(string directoryPath, bool recursive, string[] includeWildcardPatterns, string[] excludeWildcardPatterns) { NextEnumerator(); mCurrentEnumerator = new DirectoryFileEnumerator(directoryPath, recursive); if (includeWildcardPatterns != null && includeWildcardPatterns.Length > 0) { WildcardFilter(FileFilterMode.Inclusive, includeWildcardPatterns); } if (excludeWildcardPatterns != null && excludeWildcardPatterns.Length > 0) { WildcardFilter(FileFilterMode.Exclusive, excludeWildcardPatterns); } return(this); }
public void Compile(IFileEnumerator files) { if (!options.IsAOT) { throw ErrorHelper.CreateError(0099, "Internal error \"AOTBundle with aot: {0}\" Please file a bug report with a test case (https://github.com/xamarin/xamarin-macios/issues/new).", options.CompilationType); } var monoEnv = new string [] { "MONO_PATH", files.RootDir }; List <string> filesToAOT = GetFilesToAOT(files); Parallel.ForEach(filesToAOT, ParallelOptions, file => { var cmd = new List <string> (); cmd.Add(options.IsHybridAOT ? "--aot=hybrid" : "--aot"); if (IsModern) { cmd.Add("--runtime=mobile"); } cmd.Add(file); if (RunCommand(MonoPath, cmd, monoEnv) != 0) { throw ErrorHelper.CreateError(3001, "Could not AOT the assembly '{0}'", file); } }); if (IsRelease && options.IsHybridAOT) { Parallel.ForEach(filesToAOT, ParallelOptions, file => { if (RunCommand(StripCommand, new [] { file }) != 0) { throw ErrorHelper.CreateError(3001, "Could not strip the assembly '{0}'", file); } }); } if (IsRelease) { // mono --aot creates .dll.dylib.dSYM directories for each assembly AOTed // There isn't an easy was to disable this behavior, so clean up under release Parallel.ForEach(filesToAOT, ParallelOptions, file => { if (RunCommand(DeleteDebugSymbolCommand, new [] { "-r", file + ".dylib.dSYM/" }, monoEnv) != 0) { throw ErrorHelper.CreateError(3001, "Could not delete debug info from assembly '{0}'", file); } }); } }
public SelectImagesViewModel(IDispatcher dispatcher, ISelectImagesView view, ImageSelection model, IFileEnumerator fileEnumerator, ImageInspectViewModel imageInspectViewModel) : base(view) { if (dispatcher == null) { throw new ArgumentNullException("dispatcher"); } if (view == null) { throw new ArgumentNullException("view"); } if (fileEnumerator == null) { throw new ArgumentNullException("fileEnumerator"); } if (imageInspectViewModel == null) { throw new ArgumentNullException("imageInspectViewModel"); } _dispatcher = dispatcher; _model = model ?? new ImageSelection(); _fileEnumerator = fileEnumerator; _imageInspectViewModel = imageInspectViewModel; _selectImageCommand = new DelegateCommand( i => { var img = i as SelectableImage; if (img != null) { img.IsSelected = !img.IsSelected; } }); _previewImageCommand = new DelegateCommand( i => { var img = i as SelectableImage; if (img != null) { _imageInspectViewModel.Model = new ImageInspection { FullPath = img.FullPath }; _imageInspectViewModel.ShowView(); } }); }
/// <summary> /// Adds a file catalogue enumerator of a given type to the compound enumerator. /// </summary> /// <param name="fileCatalogueEnumeratorType">Type of the file catalogue enumerator to be added to the compound file enumerator.</param> /// <param name="fileCatalgouePath">Path of the file catalogue, which should be enumerated by the file catalogue enumerator.</param> /// <param name="recursive">Indicates, whether the file catalogue enumerator should enumerate files recursively.</param> /// <param name="constructorArguments">Constructor arguments to be passed to the file catalogue enumerator constructor.</param> /// <returns>CompoundFileEnumeratorBuilder creating the current compound file enumerator.</returns> public CompoundFileEnumeratorBuilder FileCatalogueEnumerator(Type fileCatalogueEnumeratorType, string fileCatalgouePath, bool recursive, params object[] constructorArguments) { if (fileCatalogueEnumeratorType == null || !typeof(IFileCatalogueEnumerator).IsAssignableFrom(fileCatalogueEnumeratorType)) { return(this); } NextEnumerator(); var fileCatalogueEnumerator = Activator.CreateInstance(fileCatalogueEnumeratorType, constructorArguments) as IFileCatalogueEnumerator; fileCatalogueEnumerator.FileCataloguePath = fileCatalgouePath; fileCatalogueEnumerator.Recursive = recursive; mCurrentEnumerator = fileCatalogueEnumerator; return(this); }
public void Compile(IFileEnumerator files) { if (!options.IsAOT) { throw ErrorHelper.CreateError(0099, "Internal error \"AOTBundle with aot: {0}\" Please file a bug report with a test case (http://bugzilla.xamarin.com).", options.CompilationType); } var monoEnv = new string [] { "MONO_PATH", files.RootDir }; List <string> filesToAOT = GetFilesToAOT(files); Parallel.ForEach(filesToAOT, ParallelOptions, file => { string command = String.Format("--aot{0} {1}{2}", options.IsHybridAOT ? "=hybrid" : "", IsModern ? "--runtime=mobile " : "", StringUtils.Quote(file)); if (RunCommand(MonoPath, command, monoEnv) != 0) { throw ErrorHelper.CreateError(3001, "Could not AOT the assembly '{0}'", file); } }); if (IsRelease && options.IsHybridAOT) { Parallel.ForEach(filesToAOT, ParallelOptions, file => { if (RunCommand(StripCommand, StringUtils.Quote(file)) != 0) { throw ErrorHelper.CreateError(3001, "Could not strip the assembly '{0}'", file); } }); } if (IsRelease) { // mono --aot creates .dll.dylib.dSYM directories for each assembly AOTed // There isn't an easy was to disable this behavior, so clean up under release Parallel.ForEach(filesToAOT, ParallelOptions, file => { if (RunCommand(DeleteDebugSymbolCommand, "-r " + StringUtils.Quote(file + ".dylib.dSYM/"), monoEnv) != 0) { throw ErrorHelper.CreateError(3001, "Could not delete debug info from assembly '{0}'", file); } }); } }
public SelectDriveViewModel(IDispatcher dispatcher, ISelectDriveView view, SelectedDrive model, IFileEnumerator fileEnumerator) : base(view) { if (dispatcher == null) { throw new ArgumentNullException("dispatcher"); } if (view == null) { throw new ArgumentNullException("view"); } if (fileEnumerator == null) { throw new ArgumentNullException("fileEnumerator"); } _dispatcher = dispatcher; _model = model ?? new SelectedDrive(); _fileEnumerator = fileEnumerator; Model.PropertyChanged += ModelPropertyChanged; }
internal static void ComposeFileEnumeratorImplementation(CompositionContainer container, IFileEnumerator item) { var batch = new CompositionBatch(); batch.AddExportedValue(item); container.Compose(batch); }
// pass target as null to build cooking rules disregarding targets public static Dictionary <string, CookingRules> Build(IFileEnumerator fileEnumerator, Target target) { var shouldRescanEnumerator = false; var pathStack = new Stack <string>(); var rulesStack = new Stack <CookingRules>(); var map = new Dictionary <string, CookingRules>(); pathStack.Push(""); var rootRules = new CookingRules(); rootRules.DeduceEffectiveRules(target); rulesStack.Push(rootRules); using (new DirectoryChanger(fileEnumerator.Directory)) { foreach (var fileInfo in fileEnumerator.Enumerate()) { var path = fileInfo.Path; while (!path.StartsWith(pathStack.Peek())) { rulesStack.Pop(); pathStack.Pop(); } if (Path.GetFileName(path) == CookingRulesFilename) { var dirName = Lime.AssetPath.GetDirectoryName(path); pathStack.Push(dirName == string.Empty ? "" : dirName + "/"); var rules = ParseCookingRules(rulesStack.Peek(), path, target); rules.SourceFilename = AssetPath.Combine(fileEnumerator.Directory, path); rulesStack.Push(rules); // Add 'ignore' cooking rules for this #CookingRules.txt itself var ignoreRules = rules.InheritClone(); ignoreRules.Ignore = true; map[path] = ignoreRules; var directoryName = pathStack.Peek(); if (!string.IsNullOrEmpty(directoryName)) { directoryName = directoryName.Remove(directoryName.Length - 1); // it is possible for map to not contain this directoryName since not every IFileEnumerator enumerates directories if (map.ContainsKey(directoryName)) { map[directoryName] = rules; } } } else { if (Path.GetExtension(path) == ".txt") { var filename = path.Remove(path.Length - 4); if (File.Exists(filename) || Directory.Exists(filename)) { continue; } } var rulesFile = path + ".txt"; var rules = rulesStack.Peek(); if (File.Exists(rulesFile)) { rules = ParseCookingRules(rulesStack.Peek(), rulesFile, target); rules.SourceFilename = AssetPath.Combine(fileEnumerator.Directory, rulesFile); // Add 'ignore' cooking rules for this cooking rules text file var ignoreRules = rules.InheritClone(); ignoreRules.Ignore = true; map[rulesFile] = ignoreRules; } if (rules.CommonRules.LastChangeTime > fileInfo.LastWriteTime) { try { File.SetLastWriteTime(path, rules.CommonRules.LastChangeTime); } catch (UnauthorizedAccessException) { // In case this is a folder } shouldRescanEnumerator = true; } map[path] = rules; } } } if (shouldRescanEnumerator) { fileEnumerator.Rescan(); } return(map); }
List <string> GetFilesToAOT(IFileEnumerator files) { var aotFiles = new List <string> (); foreach (var file in files.Files) { string fileName = Path.GetFileName(file); string extension = Path.GetExtension(file); if (extension != ".exe" && extension != ".dll") { continue; } if (excludedAssemblies.ContainsKey(fileName)) { excludedAssemblies[fileName] = true; continue; } if (includedAssemblies.ContainsKey(fileName)) { includedAssemblies[fileName] = true; aotFiles.Add(file); continue; } switch (aotType) { case AotType.All: aotFiles.Add(file); break; case AotType.SDK: string fileNameNoExtension = Path.GetFileNameWithoutExtension(fileName); if (Profile.IsSdkAssembly(fileNameNoExtension) || fileName == "Xamarin.Mac.dll") { aotFiles.Add(file); } break; case AotType.Core: if (fileName == "Xamarin.Mac.dll" || fileName == "System.dll" || fileName == "mscorlib.dll") { aotFiles.Add(file); } break; case AotType.Explicit: break; // In explicit, only included includedAssemblies included default: throw ErrorHelper.CreateError(0099, "Internal error \"GetFilesToAOT with aot: {0}\" Please file a bug report with a test case (http://bugzilla.xamarin.com).", aotType); } } var unusedIncludes = includedAssemblies.Where(pair => !pair.Value).Select(pair => pair.Key).ToList(); if (unusedIncludes.Count > 0) { throw ErrorHelper.CreateError(3009, "AOT of '{0}' was requested but was not found", String.Join(" ", unusedIncludes)); } var unusedExcludes = excludedAssemblies.Where(pair => !pair.Value).Select(pair => pair.Key).ToList(); if (unusedExcludes.Count > 0) { throw ErrorHelper.CreateError(3010, "Exclusion of AOT of '{0}' was requested but was not found", String.Join(" ", unusedExcludes)); } return(aotFiles); }
/// <summary> /// Adds a file enumerator of a given type to the compound enumerator. /// </summary> /// <typeparam name="ENUMERATOR_TYPE">Type of the file enumerator to be added to the compound enumerator.</typeparam> /// <param name="constructorArguments">Constructor arguments to be passed to the file enumerator constructor.</param> /// <returns>CompoundFileEnumeratorBuilder creating the current compound file enumerator.</returns> public CompoundFileEnumeratorBuilder FileEnumerator <ENUMERATOR_TYPE>(params object[] constructorArguments) where ENUMERATOR_TYPE : IFileEnumerator { NextEnumerator(); mCurrentEnumerator = Activator.CreateInstance(typeof(ENUMERATOR_TYPE), constructorArguments) as IFileEnumerator; return(this); }
public PhysicalFileOrganizer(FilesOrganizerOptions options, IFileMover mover, IFileEnumerator enumerator, IMapper mapper) { this.Options = options ?? throw new ArgumentNullException(nameof(options)); this.FileMover = mover ?? throw new ArgumentNullException(nameof(mover)); this.FileEnumerator = enumerator ?? throw new ArgumentNullException(nameof(enumerator)); this.Mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); }
public DirectoryParser(IFileEnumerator fileEnumerator) { this.fileEnumerator = fileEnumerator; Excludes = new List <string>(); }
public void Compile(IFileEnumerator files) { if (!options.IsAOT) { throw ErrorHelper.CreateError(0099, Errors.MX0099, $"\"AOTBundle with aot: {options.CompilationType}\" "); } var monoEnv = new Dictionary <string, string> { { "MONO_PATH", files.RootDir } }; List <string> filesToAOT = GetFilesToAOT(files); bool needsLipo = abis.Length > 1 && filesToAOT.Count > 0; string tempAotDir = needsLipo ? Path.GetDirectoryName(filesToAOT [0]) : null; if (needsLipo && Directory.Exists(tempAotDir)) { foreach (var abi in abis) { Directory.CreateDirectory(Path.Combine(tempAotDir, "aot", abi.AsArchString())); } } Parallel.ForEach(filesToAOT.SelectMany(f => abis, (file, abi) => new Tuple <string, Abi> (file, abi)), ParallelOptions, tuple => { var file = tuple.Item1; var abi = tuple.Item2; var cmd = new List <string> (); var aotArgs = new List <string> (); aotArgs.Add($"mtriple={abi.AsArchString ()}"); if (options.IsHybridAOT) { aotArgs.Add("hybrid"); } if (needsLipo) { aotArgs.Add($"outfile={Path.Combine (tempAotDir, "aot", abi.AsArchString (), Path.GetFileName (file) + ".dylib")}"); } cmd.Add($"--aot={string.Join (",", aotArgs)}"); if (IsModern) { cmd.Add("--runtime=mobile"); } cmd.Add(file); if (RunCommand(GetMonoPath(abi), cmd, monoEnv) != 0) { throw ErrorHelper.CreateError(3001, Errors.MX3001, "AOT", file); } }); // Lipo the result if (needsLipo) { Parallel.ForEach(filesToAOT, ParallelOptions, file => { string [] inputs = abis.Select(abi => Path.Combine(tempAotDir, "aot", abi.AsArchString(), Path.GetFileName(file) + ".dylib")).Where(File.Exists).ToArray(); string output = file + ".dylib"; if (inputs.Length > 0) { Driver.RunLipoAndCreateDsym(Driver.App, output, inputs); } }); } if (needsLipo && Directory.Exists(tempAotDir)) { Directory.Delete(Path.Combine(tempAotDir, "aot"), true); } if (IsRelease && options.IsHybridAOT) { Parallel.ForEach(filesToAOT, ParallelOptions, file => { if (RunCommand(StripCommand, new [] { file }) != 0) { throw ErrorHelper.CreateError(3001, Errors.MX3001, "strip", file); } }); } if (IsRelease) { // mono --aot creates .dll.dylib.dSYM directories for each assembly AOTed // There isn't an easy was to disable this behavior // We move them (cheap) so they can be archived for release builds foreach (var file in filesToAOT) { var source = file + ".dylib.dSYM/"; if (Directory.Exists(source)) { var dest = Path.GetFullPath(Path.Combine(source, "..", "..", "..", "..", Path.GetFileName(file) + ".dylib.dSYM/")); if (Directory.Exists(dest)) { Directory.Delete(dest, true); } Directory.Move(source, dest); } } } }
List <string> GetFilesToAOT(IFileEnumerator files) { // Make a dictionary of included/excluded files to track if we've missed some at the end Dictionary <string, bool> includedAssemblies = new Dictionary <string, bool> (); foreach (var item in options.IncludedAssemblies) { includedAssemblies [item] = false; } Dictionary <string, bool> excludedAssemblies = new Dictionary <string, bool> (); foreach (var item in options.ExcludedAssemblies) { excludedAssemblies [item] = false; } var aotFiles = new List <string> (); foreach (var file in files.Files) { string fileName = Path.GetFileName(file); string extension = Path.GetExtension(file); if (extension != ".exe" && extension != ".dll") { continue; } if (excludedAssemblies.ContainsKey(fileName)) { excludedAssemblies [fileName] = true; continue; } if (includedAssemblies.ContainsKey(fileName)) { includedAssemblies [fileName] = true; aotFiles.Add(file); continue; } switch (options.CompilationType) { case AOTCompilationType.All: aotFiles.Add(file); break; case AOTCompilationType.SDK: string fileNameNoExtension = Path.GetFileNameWithoutExtension(fileName); if (Profile.IsSdkAssembly(fileNameNoExtension) || fileName == "Xamarin.Mac.dll") { aotFiles.Add(file); } break; case AOTCompilationType.Core: if (fileName == "Xamarin.Mac.dll" || fileName == "System.dll" || fileName == "mscorlib.dll") { aotFiles.Add(file); } break; case AOTCompilationType.Explicit: break; // In explicit, only included includedAssemblies included default: throw ErrorHelper.CreateError(0099, "Internal error \"GetFilesToAOT with aot: {0}\" Please file a bug report with a test case (https://github.com/xamarin/xamarin-macios/issues/new).", options.CompilationType); } } var unusedIncludes = includedAssemblies.Where(pair => !pair.Value).Select(pair => pair.Key).ToList(); if (unusedIncludes.Count > 0) { throw ErrorHelper.CreateError(3009, "AOT of '{0}' was requested but was not found", String.Join(" ", unusedIncludes)); } var unusedExcludes = excludedAssemblies.Where(pair => !pair.Value).Select(pair => pair.Key).ToList(); if (unusedExcludes.Count > 0) { throw ErrorHelper.CreateError(3010, "Exclusion of AOT of '{0}' was requested but was not found", String.Join(" ", unusedExcludes)); } return(aotFiles); }
public void CompleteTest() { string rootPath = @"C:\Temp\FileSystems"; Assert.AreEqual(true, Directory.Exists(rootPath)); CleanUpFileSystem(rootPath); IFileSystem fileSystem = new LocalFileSystem(rootPath); IFileSystemConstant constants = fileSystem.WithFileSystemConstant(); IDirectory rootDirectory = fileSystem.RootDirectory; Assert.AreEqual('\\', constants.DirectorySeparatorChar); // Create directory IDirectory d1 = rootDirectory.WithDirectoryCreator().Create("D1"); Assert.AreEqual("D1", d1.Name); Assert.AreEqual(Path.Combine(rootPath, "D1"), d1.WithAbsolutePath().AbsolutePath); EnsureAncestors(d1.WithAncestorEnumerator(), "FileSystems", "Temp", "C:\\"); // Rename directory. d1.WithDirectoryRenamer().ChangeName("D1.1"); Assert.AreEqual("D1.1", d1.Name); Assert.AreEqual(Path.Combine(rootPath, "D1.1"), d1.WithAbsolutePath().AbsolutePath); Assert.AreEqual(false, Directory.Exists(Path.Combine(rootPath, "D1"))); Assert.AreEqual(true, Directory.Exists(Path.Combine(rootPath, "D1.1"))); // Create file IFile f1 = d1.WithFileCreator().Create("F1", "txt"); Assert.AreEqual(true, File.Exists(Path.Combine(rootPath, d1.Name, "F1.txt"))); Assert.AreEqual(Path.Combine(d1.WithAbsolutePath().AbsolutePath, "F1.txt"), f1.WithAbsolutePath().AbsolutePath); Assert.AreEqual("F1", f1.Name); Assert.AreEqual("txt", f1.Extension); Assert.AreEqual(0, f1.WithFileContentSize().FileSize); // Write to file f1.WithFileContentUpdater().SetContent("Text"); Assert.AreEqual("Text", File.ReadAllText(f1.WithAbsolutePath().AbsolutePath)); // Append to file f1.WithFileContentAppender().AppendContent(".T1"); Assert.AreEqual("Text.T1", File.ReadAllText(f1.WithAbsolutePath().AbsolutePath)); // Override file content f1.WithFileContentUpdater().SetContent("T2"); Assert.AreEqual("T2", File.ReadAllText(f1.WithAbsolutePath().AbsolutePath)); // Read file content Assert.AreEqual("T2", f1.WithFileContentReader().GetContent()); Assert.AreEqual(2, f1.WithFileContentSize().FileSize); // Rename file f1.WithFileRenamer().ChangeName("F1.1"); Assert.AreEqual("F1.1", f1.Name); Assert.AreEqual("txt", f1.Extension); Assert.AreEqual(Path.Combine(d1.WithAbsolutePath().AbsolutePath, "F1.1.txt"), f1.WithAbsolutePath().AbsolutePath); Assert.AreEqual(false, File.Exists(Path.Combine(d1.WithAbsolutePath().AbsolutePath, "F1.txt"))); Assert.AreEqual(true, File.Exists(Path.Combine(d1.WithAbsolutePath().AbsolutePath, "F1.1.txt"))); // Enumerate files. IFileEnumerator fe1 = d1.WithFileEnumerator(); Assert.AreEqual(1, fe1.Count()); // Create files and directories. IFile f2 = d1.WithFileCreator().Create("F2", "txt"); IFile f3 = d1.WithFileCreator().Create("F3", "rtf"); IFile f4 = d1.WithFileCreator().Create("f4", "rtf"); IDirectory d12 = d1.WithDirectoryCreator().Create("D2"); IFile f121 = d12.WithFileCreator().Create("F1", "txt"); IFile f122 = d12.WithFileCreator().Create("F2", "txt"); IFile f123 = d12.WithFileCreator().Create("F3", "rtf"); IFile f124 = d12.WithFileCreator().Create("f4", "rtf"); // Enumerate directories. IDirectoryEnumerator de1 = d1.WithDirectoryEnumerator(); Assert.AreEqual(1, de1.Count()); // Searching directories IEnumerable <IDirectory> s1 = rootDirectory.WithDirectoryNameSearch().FindDirectories(TextSearch.CreatePrefixed("D")); Assert.AreEqual(1, s1.Count()); IEnumerable <IDirectory> s2 = rootDirectory.WithDirectoryPathSearch().FindDirectories(TextSearch.CreatePrefixed("D")); Assert.AreEqual(2, s2.Count()); IEnumerable <IDirectory> s3 = rootDirectory.WithDirectoryPathSearch().FindDirectories(TextSearch.CreateSuffixed("2")); Assert.AreEqual(1, s3.Count()); IEnumerable <IDirectory> s4 = rootDirectory.WithDirectoryPathSearch().FindDirectories(TextSearch.CreateEmpty()); Assert.AreEqual(2, s4.Count()); // Searching files IEnumerable <IFile> s5 = rootDirectory.WithFileNameSearch().FindFiles(TextSearch.CreatePrefixed("f1"), TextSearch.CreateEmpty()); Assert.AreEqual(0, s5.Count()); IEnumerable <IFile> s6 = d1.WithFileNameSearch().FindFiles(TextSearch.CreatePrefixed("f1"), TextSearch.CreateEmpty()); Assert.AreEqual(1, s6.Count()); IEnumerable <IFile> s7 = d1.WithFileNameSearch().FindFiles(TextSearch.CreateEmpty(), TextSearch.CreateMatched("txt")); Assert.AreEqual(2, s7.Count()); IEnumerable <IFile> s8 = d1.WithFileNameSearch().FindFiles(TextSearch.CreateContained("f"), TextSearch.CreateEmpty()); Assert.AreEqual(4, s8.Count()); IEnumerable <IFile> s9 = rootDirectory.WithFilePathSearch().FindFiles(TextSearch.CreateSuffixed("2"), TextSearch.CreateEmpty()); Assert.AreEqual(2, s9.Count()); // Delete file f1.WithFileDeleter().Delete(); //Delete directory d1.WithDirectoryDeleter().Delete(); Assert.AreEqual(false, Directory.Exists(Path.Combine(rootPath, "T1"))); }