/// <exception cref="IOException"/> /// <exception cref="BadImageFormatException" /> private AssemblyMetadata CreateAssemblyMetadata( FileKey fileKey, ModuleMetadata manifestModule, List <ITemporaryStreamStorage> storages, Func <FileKey, List <ITemporaryStreamStorage>, ModuleMetadata> moduleMetadataFactory) { var moduleBuilder = ArrayBuilder <ModuleMetadata> .GetInstance(); string assemblyDir = null; foreach (string moduleName in manifestModule.GetModuleNames()) { if (moduleBuilder.Count == 0) { moduleBuilder.Add(manifestModule); assemblyDir = Path.GetDirectoryName(fileKey.FullPath); } var moduleFileKey = FileKey.Create(PathUtilities.CombineAbsoluteAndRelativePaths(assemblyDir, moduleName)); var metadata = moduleMetadataFactory(moduleFileKey, storages); moduleBuilder.Add(metadata); } if (moduleBuilder.Count == 0) { moduleBuilder.Add(manifestModule); } return(AssemblyMetadata.Create( moduleBuilder.ToImmutableAndFree())); }
private AssemblyMetadata CreateAssemblyMetadata( FileKey fileKey, ModuleMetadata manifestModule, List <ITemporaryStreamStorage>?storages, Func <FileKey, List <ITemporaryStreamStorage>?, ModuleMetadata> moduleMetadataFactory) { var moduleBuilder = ArrayBuilder <ModuleMetadata> .GetInstance(); string?assemblyDir = null; foreach (var moduleName in manifestModule.GetModuleNames()) { if (assemblyDir is null) { moduleBuilder.Add(manifestModule); assemblyDir = Path.GetDirectoryName(fileKey.FullPath); } // Suppression should be removed or addressed https://github.com/dotnet/roslyn/issues/41636 var moduleFileKey = FileKey.Create(PathUtilities.CombineAbsoluteAndRelativePaths(assemblyDir, moduleName) !); var metadata = moduleMetadataFactory(moduleFileKey, storages); moduleBuilder.Add(metadata); } if (moduleBuilder.Count == 0) { moduleBuilder.Add(manifestModule); } return(AssemblyMetadata.Create( moduleBuilder.ToImmutableAndFree())); }
private ImmutableArray <ModuleMetadata> GetAllModules( ModuleMetadata manifestModule, string assemblyDir ) { ArrayBuilder <ModuleMetadata>?moduleBuilder = null; foreach (string moduleName in manifestModule.GetModuleNames()) { if (moduleBuilder == null) { moduleBuilder = ArrayBuilder <ModuleMetadata> .GetInstance(); moduleBuilder.Add(manifestModule); } var module = CreateModuleMetadata( PathUtilities.CombineAbsoluteAndRelativePaths(assemblyDir, moduleName) !, prefetchEntireImage: false ); moduleBuilder.Add(module); } return((moduleBuilder != null) ? moduleBuilder.ToImmutableAndFree() : ImmutableArray.Create(manifestModule)); }
/// <exception cref="IOException"/> /// <exception cref="BadImageFormatException" /> private AssemblyMetadata CreateAssemblyMetadata( FileKey fileKey, ModuleMetadata manifestModule, List <ITemporaryStreamStorage> storages, Func <FileKey, List <ITemporaryStreamStorage>, ModuleMetadata> moduleMetadataGetter) { ImmutableArray <ModuleMetadata> .Builder moduleBuilder = null; string assemblyDir = null; foreach (string moduleName in manifestModule.GetModuleNames()) { if (moduleBuilder == null) { moduleBuilder = ImmutableArray.CreateBuilder <ModuleMetadata>(); moduleBuilder.Add(manifestModule); assemblyDir = Path.GetDirectoryName(fileKey.FullPath); } var moduleFileKey = FileKey.Create(PathUtilities.CombineAbsoluteAndRelativePaths(assemblyDir, moduleName)); var metadata = moduleMetadataGetter(moduleFileKey, storages); moduleBuilder.Add(metadata); } var modules = (moduleBuilder != null) ? moduleBuilder.ToImmutable() : ImmutableArray.Create(manifestModule); return(AssemblyMetadata.Create(modules)); }
private AssemblyMetadata CreateAssemblyMetadata(FileStream manifestModuleCopyStream, string originalPath, string shadowCopyPath) { // We don't need to use the global metadata cache here since the shadow copy // won't change and is private to us - only users of the same shadow copy provider see it. ImmutableArray <ModuleMetadata> .Builder moduleBuilder = null; bool fault = true; ModuleMetadata manifestModule = null; try { manifestModule = CreateModuleMetadata(manifestModuleCopyStream); string originalDirectory = null, shadowCopyDirectory = null; foreach (string moduleName in manifestModule.GetModuleNames()) { if (moduleBuilder == null) { moduleBuilder = ImmutableArray.CreateBuilder <ModuleMetadata>(); moduleBuilder.Add(manifestModule); originalDirectory = Path.GetDirectoryName(originalPath); shadowCopyDirectory = Path.GetDirectoryName(shadowCopyPath); } FileStream moduleCopyStream = CopyFile( originalPath: Path.Combine(originalDirectory, moduleName), shadowCopyPath: Path.Combine(shadowCopyDirectory, moduleName)); moduleBuilder.Add(CreateModuleMetadata(moduleCopyStream)); } var modules = (moduleBuilder != null) ? moduleBuilder.ToImmutable() : ImmutableArray.Create(manifestModule); fault = false; return(AssemblyMetadata.Create(modules)); } finally { if (fault) { if (manifestModule != null) { manifestModule.Dispose(); } if (moduleBuilder != null) { for (int i = 1; i < moduleBuilder.Count; i++) { moduleBuilder[i].Dispose(); } } } } }
static public void WriteBuildData(string buildDataPath, BuildReport report, string[] scenes, string[] prefabs) { var developmentBuild = report.summary.options.HasFlag(BuildOptions.Development); var inputScenes = new List <BuildDataInputFile>(); foreach (var scene in scenes) { inputScenes.Add(new BuildDataInputFile(scene, developmentBuild)); } var inputFiles = new List <BuildDataInputFile>(); foreach (var scene in scenes) { inputFiles.Add(new BuildDataInputFile(scene, developmentBuild)); } foreach (var prefab in prefabs) { inputFiles.Add(new BuildDataInputFile(prefab, developmentBuild)); } foreach (var assetInfo in report.packedAssets.SelectMany(a => a.contents)) { if (assetInfo.sourceAssetPath.ToNPath().FileExists() && !assetInfo.sourceAssetPath.StartsWith(".")) { inputFiles.Add(new BuildDataInputFile(assetInfo.sourceAssetPath, developmentBuild)); } } foreach (var projectSetting in new NPath("ProjectSettings").Files("*.asset")) { inputFiles.Add(new BuildDataInputFile(projectSetting, developmentBuild)); } var buildData = new BuildData() { scenes = inputScenes.ToArray(), inputFiles = inputFiles.ToArray(), buildOptions = report.summary.options & BuildData.BuildOptionsMask, unityVersion = Application.unityVersion, resourcePaths = ResourcesAPIInternal.GetAllPaths("").OrderBy(p => p).ToArray(), enabledModules = ModuleMetadata.GetModuleNames() .Where(m => ModuleMetadata.GetModuleIncludeSettingForModule(m) != ModuleIncludeSetting.ForceExclude) .ToArray() }; buildDataPath.ToNPath().WriteAllText(JsonUtility.ToJson(buildData)); }
private ImmutableArray<ModuleMetadata> GetAllModules(ModuleMetadata manifestModule, string assemblyDir) { ArrayBuilder<ModuleMetadata> moduleBuilder = null; foreach (string moduleName in manifestModule.GetModuleNames()) { if (moduleBuilder == null) { moduleBuilder = ArrayBuilder<ModuleMetadata>.GetInstance(); moduleBuilder.Add(manifestModule); } var module = CreateModuleMetadata(PathUtilities.CombineAbsoluteAndRelativePaths(assemblyDir, moduleName), prefetchEntireImage: false); moduleBuilder.Add(module); } return (moduleBuilder != null) ? moduleBuilder.ToImmutableAndFree() : ImmutableArray.Create(manifestModule); }
bool DoCheckDirty() { if (Application.unityVersion != buildData.unityVersion) { Console.WriteLine($"Rebuilding Data files because they were built with a different Unity version {Application.unityVersion} vs {buildData.unityVersion}"); return(true); } if (!scenes.SequenceEqual(buildData.scenes.Select(f => f.path))) { Console.WriteLine("Rebuilding Data files because the scene list is dirty"); return(true); } if ((buildOptions & BuildData.BuildOptionsMask) != buildData.buildOptions) { Console.WriteLine("Rebuilding Data files because the build options have changed"); return(true); } if (buildData.inputFiles.Any(CheckAssetDirty)) { return(true); } var resourcePaths = ResourcesAPIInternal.GetAllPaths("").OrderBy(p => p).ToArray(); if (!resourcePaths.SequenceEqual(buildData.resourcePaths)) { for (int i = 0; i < resourcePaths.Length || i < buildData.resourcePaths.Length; i++) { string path; if (i >= resourcePaths.Length) { path = buildData.resourcePaths[i]; } else if (i >= buildData.resourcePaths.Length) { path = resourcePaths[i]; } else if (buildData.resourcePaths[i] != resourcePaths[i]) { path = resourcePaths[i]; } else { continue; } Console.WriteLine($"Rebuilding Data files because {path} is dirty (Resource file added or removed)"); return(true); } } var enabledModules = ModuleMetadata.GetModuleNames() .Where(m => ModuleMetadata.GetModuleIncludeSettingForModule(m) != ModuleIncludeSetting.ForceExclude); if (!enabledModules.SequenceEqual(buildData.enabledModules)) { Console.WriteLine($"Rebuilding Data files because enabled modules have changed"); return(true); } Console.WriteLine("Not rebuilding Data files -- no changes"); return(false); }
private AssemblyMetadata CreateAssemblyMetadata(ShadowCopy manifestModuleCopy) { // We don't need to use the global metadata cache here since the shadow copy // won't change and is private to us - only users of the same shadow copy provider see it. ArrayBuilder <ModuleMetadata> moduleBuilder = null; bool fault = true; ModuleMetadata manifestModule = null; try { manifestModule = CreateModuleMetadata(manifestModuleCopy); string originalDirectory = null, shadowCopyDirectory = null; foreach (string moduleName in manifestModule.GetModuleNames()) { if (moduleBuilder == null) { moduleBuilder = ArrayBuilder <ModuleMetadata> .GetInstance(); moduleBuilder.Add(manifestModule); originalDirectory = Path.GetDirectoryName(manifestModuleCopy.OriginalPath); shadowCopyDirectory = Path.GetDirectoryName(manifestModuleCopy.FullPath); } string originalPath = Path.Combine(originalDirectory, moduleName); string shadowCopyPath = Path.Combine(shadowCopyDirectory, moduleName); var moduleCopy = CopyFile(originalPath, shadowCopyPath); moduleBuilder.Add(CreateModuleMetadata(moduleCopy)); } var modules = (moduleBuilder != null) ? moduleBuilder.ToReadOnly() : ReadOnlyArray.Singleton(manifestModule); fault = false; return(new AssemblyMetadata(modules)); } finally { if (fault) { if (manifestModule != null) { manifestModule.Dispose(); } if (moduleBuilder != null) { for (int i = 1; i < moduleBuilder.Count; i++) { moduleBuilder[i].Dispose(); } } } if (moduleBuilder != null) { moduleBuilder.Free(); } } }