private static string GetMethodPreserveBlacklistContents(RuntimeClassRegistry rcr) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("<linker>"); IEnumerable <IGrouping <string, RuntimeClassRegistry.MethodDescription> > enumerable = from m in rcr.GetMethodsToPreserve() group m by m.assembly; foreach (IGrouping <string, RuntimeClassRegistry.MethodDescription> current in enumerable) { stringBuilder.AppendLine(string.Format("\t<assembly fullname=\"{0}\">", current.Key)); IEnumerable <IGrouping <string, RuntimeClassRegistry.MethodDescription> > enumerable2 = from m in current group m by m.fullTypeName; foreach (IGrouping <string, RuntimeClassRegistry.MethodDescription> current2 in enumerable2) { stringBuilder.AppendLine(string.Format("\t\t<type fullname=\"{0}\">", current2.Key)); foreach (RuntimeClassRegistry.MethodDescription current3 in current2) { stringBuilder.AppendLine(string.Format("\t\t\t<method name=\"{0}\"/>", current3.methodName)); } stringBuilder.AppendLine("\t\t</type>"); } stringBuilder.AppendLine("\t</assembly>"); } stringBuilder.AppendLine("</linker>"); return(stringBuilder.ToString()); }
private static string GetMethodPreserveBlacklistContents(RuntimeClassRegistry rcr, BuildTarget target) { if (rcr.GetMethodsToPreserve().Count == 0) { return(null); } var sb = new StringBuilder(); sb.AppendLine("<linker>"); var groupedByAssembly = rcr.GetMethodsToPreserve().GroupBy(m => m.assembly); foreach (var assembly in groupedByAssembly) { var assemblyName = assembly.Key; sb.AppendLine(string.Format("\t<assembly fullname=\"{0}\" ignoreIfMissing=\"1\">", assemblyName)); var groupedByType = assembly.GroupBy(m => m.fullTypeName); foreach (var type in groupedByType) { sb.AppendLine(string.Format("\t\t<type fullname=\"{0}\">", type.Key)); foreach (var method in type) { sb.AppendLine(string.Format("\t\t\t<method name=\"{0}\"/>", method.methodName)); } sb.AppendLine("\t\t</type>"); } sb.AppendLine("\t</assembly>"); } sb.AppendLine("</linker>"); return(sb.ToString()); }
private static string WriteMethodsToPreserveBlackList(RuntimeClassRegistry rcr, BuildTarget target) { var methodPerserveBlackList = Path.GetTempFileName(); File.WriteAllText(methodPerserveBlackList, GetMethodPreserveBlacklistContents(rcr, target)); return(methodPerserveBlackList); }
private static string WriteMethodsToPreserveBlackList(RuntimeClassRegistry rcr, BuildTarget target) { string tempFileName = Path.GetTempFileName(); File.WriteAllText(tempFileName, AssemblyStripper.GetMethodPreserveBlacklistContents(rcr, target)); return(tempFileName); }
private static string GetMethodPreserveBlacklistContents(RuntimeClassRegistry rcr) { StringBuilder builder = new StringBuilder(); builder.AppendLine("<linker>"); if (< > f__am$cache5 == null) {
internal static void StripAssemblies(string managedAssemblyFolderPath, BaseUnityLinkerPlatformProvider unityLinkerPlatformProvider, IIl2CppPlatformProvider il2cppPlatformProvider, RuntimeClassRegistry rcr, ManagedStrippingLevel managedStrippingLevel) { var runInformation = new UnityLinkerRunInformation(managedAssemblyFolderPath, unityLinkerPlatformProvider, il2cppPlatformProvider.target, rcr, managedStrippingLevel, il2cppPlatformProvider); RunAssemblyStripper(runInformation); }
public IL2CPPBuilder(string tempFolder, string stagingAreaData, IIl2CppPlatformProvider platformProvider, Action <string> modifyOutputBeforeCompile, RuntimeClassRegistry runtimeClassRegistry) { this.m_TempFolder = tempFolder; this.m_StagingAreaData = stagingAreaData; this.m_PlatformProvider = platformProvider; this.m_ModifyOutputBeforeCompile = modifyOutputBeforeCompile; this.m_RuntimeClassRegistry = runtimeClassRegistry; }
public IL2CPPBuilder(string tempFolder, string stagingAreaData, IIl2CppPlatformProvider platformProvider, Action <string> modifyOutputBeforeCompile, RuntimeClassRegistry runtimeClassRegistry, bool buildForMonoRuntime) { m_TempFolder = tempFolder; m_StagingAreaData = stagingAreaData; m_PlatformProvider = platformProvider; m_ModifyOutputBeforeCompile = modifyOutputBeforeCompile; m_RuntimeClassRegistry = runtimeClassRegistry; m_BuildForMonoRuntime = buildForMonoRuntime; }
static public void InvokeFromBuildPlayer(BuildTarget buildTarget, RuntimeClassRegistry usedClasses, ManagedStrippingLevel managedStrippingLevel, BuildReport report) { var stagingAreaData = Paths.Combine("Temp", "StagingArea", "Data"); var platformProvider = new BaseIl2CppPlatformProvider(buildTarget, Path.Combine(stagingAreaData, "Libraries"), report); var managedAssemblyFolderPath = Path.GetFullPath(Path.Combine(stagingAreaData, "Managed")); AssemblyStripper.StripAssemblies(managedAssemblyFolderPath, platformProvider, usedClasses, managedStrippingLevel); }
public static void InvokeFromBuildPlayer(BuildTarget buildTarget, RuntimeClassRegistry usedClasses) { string text = Paths.Combine(new string[] { "Temp", "StagingArea", "Data" }); BaseIl2CppPlatformProvider platformProvider = new BaseIl2CppPlatformProvider(buildTarget, Path.Combine(text, "Libraries")); AssemblyStripper.StripAssemblies(text, platformProvider, usedClasses); }
private static List <string> GetUserAssemblies(RuntimeClassRegistry rcr, string managedDir) { // ISSUE: object of a compiler-generated type is created // ISSUE: variable of a compiler-generated type AssemblyStripper.\u003CGetUserAssemblies\u003Ec__AnonStorey66 assembliesCAnonStorey66 = new AssemblyStripper.\u003CGetUserAssemblies\u003Ec__AnonStorey66(); // ISSUE: reference to a compiler-generated field assembliesCAnonStorey66.rcr = rcr; // ISSUE: reference to a compiler-generated field assembliesCAnonStorey66.managedDir = managedDir; // ISSUE: reference to a compiler-generated field // ISSUE: reference to a compiler-generated method // ISSUE: reference to a compiler-generated method return(((IEnumerable <string>)assembliesCAnonStorey66.rcr.GetUserAssemblies()).Where <string>(new Func <string, bool>(assembliesCAnonStorey66.\u003C\u003Em__D9)).Select <string, string>(new Func <string, string>(assembliesCAnonStorey66.\u003C\u003Em__DA)).ToList <string>()); }
public void Execute(PostProcessorContext context) { if (((ScriptingImplementation)context.Get <ScriptingImplementation>("ScriptingBackend")) == ScriptingImplementation.IL2CPP) { if (this.OnProgress != null) { this.OnProgress(this, "Generating native assemblies"); } BuildTarget target = context.Get <BuildTarget>("BuildTarget"); string str = context.Get <string>("StagingArea"); string[] components = new string[] { str, "assets", "bin", "Data" }; string stagingAreaData = Paths.Combine(components); string[] textArray2 = new string[] { BuildPipeline.GetBuildToolsDirectory(target), "AndroidNativeLink.xml" }; string[] textArray3 = new string[] { stagingAreaData, "platform_native_link.xml" }; FileUtil.CopyFileOrDirectory(Paths.Combine(textArray2), Paths.Combine(textArray3)); AndroidTargetDevice device = context.Get <AndroidTargetDevice>("TargetDevice"); AndroidTargetDeviceType deviceType = new AndroidTargetDeviceARMv7(); if (device == AndroidTargetDevice.x86) { deviceType = new AndroidTargetDevicex86(); } if (this.OnProgress != null) { this.OnProgress(this, "Compiling native assemblies for " + deviceType.Architecture); } string tempFolder = Path.Combine(str, "Il2Cpp"); bool isDevelopmentBuild = context.Get <bool>("DevelopmentPlayer"); RuntimeClassRegistry runtimeClassRegistry = context.Get <RuntimeClassRegistry>("UsedClassRegistry"); AndroidIl2CppPlatformProvider platformProvider = new AndroidIl2CppPlatformProvider(target, deviceType, isDevelopmentBuild); IL2CPPUtils.RunIl2Cpp(tempFolder, stagingAreaData, platformProvider, null, runtimeClassRegistry, isDevelopmentBuild); AndroidTargetDeviceType type2 = null; if (device == AndroidTargetDevice.FAT) { type2 = new AndroidTargetDevicex86(); if (this.OnProgress != null) { this.OnProgress(this, "Compiling native assemblies for " + type2.Architecture); } platformProvider = new AndroidIl2CppPlatformProvider(target, type2, isDevelopmentBuild); IL2CPPUtils.RunCompileAndLink(tempFolder, stagingAreaData, platformProvider, null, runtimeClassRegistry, false); } this.FinalizeAndCleanup(str, stagingAreaData, tempFolder); this.CopySymbolMap(str, stagingAreaData, deviceType); if (type2 != null) { this.CopySymbolMap(str, stagingAreaData, type2); } } }
static public void StripForMonoBackend(BuildTarget buildTarget, RuntimeClassRegistry usedClasses, ManagedStrippingLevel managedStrippingLevel, BuildReport report) { if (managedStrippingLevel == ManagedStrippingLevel.Disabled) { return; } var stagingAreaData = Paths.Combine("Temp", "StagingArea", "Data"); var il2cppPlatformProvider = new MonoBackendIl2CppPlatformProvider(buildTarget, Path.Combine(stagingAreaData, "Libraries"), report); var platformProvider = new MonoBackendUnityLinkerPlatformProvider(buildTarget); var managedAssemblyFolderPath = Path.GetFullPath(Path.Combine(stagingAreaData, "Managed")); AssemblyStripper.StripAssemblies(managedAssemblyFolderPath, platformProvider, il2cppPlatformProvider, usedClasses, managedStrippingLevel); }
public UnityLinkerRunInformation(string managedAssemblyFolderPath, BaseUnityLinkerPlatformProvider platformProvider, BuildTarget buildTarget, RuntimeClassRegistry rcr, ManagedStrippingLevel managedStrippingLevel, IIl2CppPlatformProvider il2CppPlatformProvider) { this.managedAssemblyFolderPath = managedAssemblyFolderPath; target = buildTarget; this.platformProvider = platformProvider; this.rcr = rcr; this.managedStrippingLevel = managedStrippingLevel; this.il2CppPlatformProvider = il2CppPlatformProvider; pipelineData = new UnityLinkerBuildPipelineData(target, managedAssemblyFolderPath); buildTargetGroup = BuildPipeline.GetBuildTargetGroup(buildTarget); argumentProvider = new UnityLinkerArgumentValueProvider(this); isMonoBackend = PlayerSettings.GetScriptingBackend(buildTargetGroup) == ScriptingImplementation.Mono2x; engineStrippingSupported = platformProvider.supportsEngineStripping && !isMonoBackend; performEngineStripping = rcr != null && PlayerSettings.stripEngineCode && engineStrippingSupported; }
private static string WriteEditorData(string managedAssemblyDirectory, RuntimeClassRegistry rcr) { var items = GetTypesInScenesInformation(managedAssemblyDirectory, rcr); List <string> forceIncludeModules; List <string> forceExcludeModules; CollectIncludedAndExcludedModules(out forceIncludeModules, out forceExcludeModules); var editorToLinkerData = new EditorToLinkerData { typesInScenes = items.ToArray(), allNativeTypes = CollectNativeTypeData().ToArray(), forceIncludeModules = forceIncludeModules.ToArray(), forceExcludeModules = forceExcludeModules.ToArray() }; var dataPath = Path.Combine(managedAssemblyDirectory, "EditorToUnityLinkerData.json"); File.WriteAllText(dataPath, JsonUtility.ToJson(editorToLinkerData, true)); return(dataPath); }
private static string GetMethodPreserveBlacklistContents(RuntimeClassRegistry rcr) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("<linker>"); foreach (IGrouping <string, RuntimeClassRegistry.MethodDescription> source in rcr.GetMethodsToPreserve().GroupBy <RuntimeClassRegistry.MethodDescription, string>((Func <RuntimeClassRegistry.MethodDescription, string>)(m => m.assembly))) { stringBuilder.AppendLine(string.Format("\t<assembly fullname=\"{0}\">", (object)source.Key)); foreach (IGrouping <string, RuntimeClassRegistry.MethodDescription> grouping in source.GroupBy <RuntimeClassRegistry.MethodDescription, string>((Func <RuntimeClassRegistry.MethodDescription, string>)(m => m.fullTypeName))) { stringBuilder.AppendLine(string.Format("\t\t<type fullname=\"{0}\">", (object)grouping.Key)); foreach (RuntimeClassRegistry.MethodDescription methodDescription in (IEnumerable <RuntimeClassRegistry.MethodDescription>)grouping) { stringBuilder.AppendLine(string.Format("\t\t\t<method name=\"{0}\"/>", (object)methodDescription.methodName)); } stringBuilder.AppendLine("\t\t</type>"); } stringBuilder.AppendLine("\t</assembly>"); } stringBuilder.AppendLine("</linker>"); return(stringBuilder.ToString()); }
private static void RunAssemblyStripper(IEnumerable assemblies, string managedAssemblyFolderPath, string[] assembliesToStrip, string[] searchDirs, string monoLinkerPath, IIl2CppPlatformProvider platformProvider, RuntimeClassRegistry rcr, ManagedStrippingLevel managedStrippingLevel) { string output; string error; var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(platformProvider.target); bool isMono = PlayerSettings.GetScriptingBackend(buildTargetGroup) == ScriptingImplementation.Mono2x; bool stripEngineCode = rcr != null && PlayerSettings.stripEngineCode && platformProvider.supportsEngineStripping && !EditorUserBuildSettings.buildScriptsOnly; IEnumerable <string> blacklists = Il2CppBlacklistPaths; if (rcr != null) { blacklists = blacklists.Concat(new[] { WriteMethodsToPreserveBlackList(rcr, platformProvider.target), MonoAssemblyStripping.GenerateLinkXmlToPreserveDerivedTypes(managedAssemblyFolderPath, rcr) }); } if (isMono) { // The old Mono assembly stripper uses per-platform link.xml files if available. Apply these here. var buildToolsDirectory = BuildPipeline.GetBuildToolsDirectory(platformProvider.target); if (!string.IsNullOrEmpty(buildToolsDirectory)) { var platformDescriptor = Path.Combine(buildToolsDirectory, "link.xml"); if (File.Exists(platformDescriptor)) { blacklists = blacklists.Concat(new[] { platformDescriptor }); } } } if (!stripEngineCode) { // if we don't do stripping, add all modules blacklists. foreach (var file in Directory.GetFiles(platformProvider.moduleStrippingInformationFolder, "*.xml")) { blacklists = blacklists.Concat(new[] { file }); } } // Generated link xml files that would have been empty will be nulled out. Need to filter these out before running the linker blacklists = blacklists.Where(b => b != null); var tempStripPath = Path.GetFullPath(Path.Combine(managedAssemblyFolderPath, "tempStrip")); bool addedMoreBlacklists; do { addedMoreBlacklists = false; if (EditorUtility.DisplayCancelableProgressBar("Building Player", "Stripping assemblies", 0.0f)) { throw new OperationCanceledException(); } if (!StripAssembliesTo( assembliesToStrip, searchDirs, tempStripPath, managedAssemblyFolderPath, out output, out error, monoLinkerPath, platformProvider, blacklists, buildTargetGroup, managedStrippingLevel)) { throw new Exception("Error in stripping assemblies: " + assemblies + ", " + error); } if (platformProvider.supportsEngineStripping) { var icallSummaryPath = Path.Combine(managedAssemblyFolderPath, "ICallSummary.txt"); GenerateInternalCallSummaryFile(icallSummaryPath, managedAssemblyFolderPath, tempStripPath); if (stripEngineCode) { // Find which modules we must include in the build based on Assemblies HashSet <UnityType> nativeClasses; HashSet <string> nativeModules; CodeStrippingUtils.GenerateDependencies(tempStripPath, icallSummaryPath, rcr, stripEngineCode, out nativeClasses, out nativeModules, platformProvider); // Add module-specific blacklists. addedMoreBlacklists = AddWhiteListsForModules(nativeModules, ref blacklists, platformProvider.moduleStrippingInformationFolder); } } // If we had to add more whitelists, we need to run AssemblyStripper again with the added whitelists. }while (addedMoreBlacklists); // keep unstripped files for debugging purposes var tempUnstrippedPath = Path.GetFullPath(Path.Combine(managedAssemblyFolderPath, "tempUnstripped")); if (debugUnstripped) { Directory.CreateDirectory(tempUnstrippedPath); } foreach (var file in Directory.GetFiles(managedAssemblyFolderPath)) { var extension = Path.GetExtension(file); if (string.Equals(extension, ".dll", StringComparison.InvariantCultureIgnoreCase) || string.Equals(extension, ".winmd", StringComparison.InvariantCultureIgnoreCase) || string.Equals(extension, ".mdb", StringComparison.InvariantCultureIgnoreCase) || string.Equals(extension, ".pdb", StringComparison.InvariantCultureIgnoreCase)) { if (debugUnstripped) { File.Move(file, Path.Combine(tempUnstrippedPath, Path.GetFileName(file))); } else { File.Delete(file); } } } foreach (var file in Directory.GetFiles(tempStripPath)) { File.Move(file, Path.Combine(managedAssemblyFolderPath, Path.GetFileName(file))); } foreach (var dir in Directory.GetDirectories(tempStripPath)) { Directory.Move(dir, Path.Combine(managedAssemblyFolderPath, Path.GetFileName(dir))); } Directory.Delete(tempStripPath); }
private static void RunAssemblyStripper(string stagingAreaData, IEnumerable assemblies, string managedAssemblyFolderPath, string[] assembliesToStrip, string[] searchDirs, string monoLinkerPath, IIl2CppPlatformProvider platformProvider, RuntimeClassRegistry rcr, bool developmentBuild) { bool flag1 = rcr != null && PlayerSettings.stripEngineCode && platformProvider.supportsEngineStripping; IEnumerable <string> blacklists = (IEnumerable <string>)AssemblyStripper.Il2CppBlacklistPaths; if (rcr != null) { blacklists = blacklists.Concat <string>((IEnumerable <string>) new string[2] { AssemblyStripper.WriteMethodsToPreserveBlackList(stagingAreaData, rcr), MonoAssemblyStripping.GenerateLinkXmlToPreserveDerivedTypes(stagingAreaData, managedAssemblyFolderPath, rcr) }); } if (!flag1) { foreach (string file in Directory.GetFiles(platformProvider.moduleStrippingInformationFolder, "*.xml")) { blacklists = blacklists.Concat <string>((IEnumerable <string>) new string[1] { file }); } } string fullPath1 = Path.GetFullPath(Path.Combine(managedAssemblyFolderPath, "tempStrip")); bool flag2; do { flag2 = false; if (EditorUtility.DisplayCancelableProgressBar("Building Player", "Stripping assemblies", 0.0f)) { throw new OperationCanceledException(); } string output; string error; if (!AssemblyStripper.StripAssembliesTo(assembliesToStrip, searchDirs, fullPath1, managedAssemblyFolderPath, out output, out error, monoLinkerPath, platformProvider, blacklists, developmentBuild)) { throw new Exception("Error in stripping assemblies: " + (object)assemblies + ", " + error); } string icallsListFile = Path.Combine(managedAssemblyFolderPath, "ICallSummary.txt"); Runner.RunManagedProgram(Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Tools/InternalCallRegistrationWriter/InternalCallRegistrationWriter.exe"), string.Format("-assembly=\"{0}\" -output=\"{1}\" -summary=\"{2}\"", (object)Path.Combine(fullPath1, "UnityEngine.dll"), (object)Path.Combine(managedAssemblyFolderPath, "UnityICallRegistration.cpp"), (object)icallsListFile)); if (flag1) { HashSet <string> nativeClasses; HashSet <string> nativeModules; CodeStrippingUtils.GenerateDependencies(fullPath1, icallsListFile, rcr, out nativeClasses, out nativeModules); flag2 = AssemblyStripper.AddWhiteListsForModules((IEnumerable <string>)nativeModules, ref blacklists, platformProvider.moduleStrippingInformationFolder); } }while (flag2); string fullPath2 = Path.GetFullPath(Path.Combine(managedAssemblyFolderPath, "tempUnstripped")); Directory.CreateDirectory(fullPath2); foreach (string file in Directory.GetFiles(managedAssemblyFolderPath)) { string extension = Path.GetExtension(file); if (string.Equals(extension, ".dll", StringComparison.InvariantCultureIgnoreCase) || string.Equals(extension, ".mdb", StringComparison.InvariantCultureIgnoreCase)) { File.Move(file, Path.Combine(fullPath2, Path.GetFileName(file))); } } foreach (string file in Directory.GetFiles(fullPath1)) { File.Move(file, Path.Combine(managedAssemblyFolderPath, Path.GetFileName(file))); } Directory.Delete(fullPath1); }
private static string WriteMethodsToPreserveBlackList(string stagingAreaData, RuntimeClassRegistry rcr) { string path = (!Path.IsPathRooted(stagingAreaData) ? Directory.GetCurrentDirectory() + "/" : string.Empty) + stagingAreaData + "/methods_pointedto_by_uievents.xml"; File.WriteAllText(path, AssemblyStripper.GetMethodPreserveBlacklistContents(rcr)); return(path); }
internal static IL2CPPBuilder RunIl2Cpp(string stagingAreaData, IIl2CppPlatformProvider platformProvider, Action <string> modifyOutputBeforeCompile, RuntimeClassRegistry runtimeClassRegistry, bool developmentBuild) { IL2CPPBuilder iL2CPPBuilder = new IL2CPPBuilder(stagingAreaData, stagingAreaData, platformProvider, modifyOutputBeforeCompile, runtimeClassRegistry, developmentBuild); iL2CPPBuilder.Run(); return(iL2CPPBuilder); }
internal static void StripAssemblies(string stagingAreaData, IIl2CppPlatformProvider platformProvider, RuntimeClassRegistry rcr, bool developmentBuild) { string fullPath = Path.GetFullPath(Path.Combine(stagingAreaData, "Managed")); List <string> userAssemblies = AssemblyStripper.GetUserAssemblies(rcr, fullPath); string[] array = userAssemblies.ToArray(); string[] searchDirs = new string[1] { fullPath }; AssemblyStripper.RunAssemblyStripper(stagingAreaData, (IEnumerable)userAssemblies, fullPath, array, searchDirs, AssemblyStripper.MonoLinker2Path, platformProvider, rcr, developmentBuild); }
private static void RunAssemblyStripper(string stagingAreaData, IEnumerable assemblies, string managedAssemblyFolderPath, string[] assembliesToStrip, string[] searchDirs, string monoLinkerPath, IIl2CppPlatformProvider platformProvider, RuntimeClassRegistry rcr) { bool flag = rcr != null && PlayerSettings.stripEngineCode && platformProvider.supportsEngineStripping; IEnumerable <string> enumerable = AssemblyStripper.Il2CppBlacklistPaths; if (rcr != null) { enumerable = enumerable.Concat(new string[] { AssemblyStripper.WriteMethodsToPreserveBlackList(stagingAreaData, rcr), MonoAssemblyStripping.GenerateLinkXmlToPreserveDerivedTypes(stagingAreaData, managedAssemblyFolderPath, rcr) }); } BuildTargetGroup buildTargetGroup = BuildPipeline.GetBuildTargetGroup(platformProvider.target); if (PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup) == ApiCompatibilityLevel.NET_4_6) { string path = Path.Combine(platformProvider.il2CppFolder, "LinkerDescriptors"); enumerable = enumerable.Concat(Directory.GetFiles(path, "*45.xml")); } if (!flag) { string[] files = Directory.GetFiles(platformProvider.moduleStrippingInformationFolder, "*.xml"); for (int i = 0; i < files.Length; i++) { string text = files[i]; enumerable = enumerable.Concat(new string[] { text }); } } string fullPath = Path.GetFullPath(Path.Combine(managedAssemblyFolderPath, "tempStrip")); string text3; while (true) { bool flag2 = false; if (EditorUtility.DisplayCancelableProgressBar("Building Player", "Stripping assemblies", 0f)) { break; } string text2; if (!AssemblyStripper.StripAssembliesTo(assembliesToStrip, searchDirs, fullPath, managedAssemblyFolderPath, out text2, out text3, monoLinkerPath, platformProvider, enumerable)) { goto Block_7; } if (platformProvider.supportsEngineStripping) { string text4 = Path.Combine(managedAssemblyFolderPath, "ICallSummary.txt"); AssemblyStripper.GenerateInternalCallSummaryFile(text4, managedAssemblyFolderPath, fullPath); if (flag) { HashSet <UnityType> hashSet; HashSet <string> nativeModules; CodeStrippingUtils.GenerateDependencies(fullPath, text4, rcr, flag, out hashSet, out nativeModules, platformProvider); flag2 = AssemblyStripper.AddWhiteListsForModules(nativeModules, ref enumerable, platformProvider.moduleStrippingInformationFolder); } } if (!flag2) { goto Block_10; } } throw new OperationCanceledException(); Block_7: throw new Exception(string.Concat(new object[] { "Error in stripping assemblies: ", assemblies, ", ", text3 })); Block_10: string fullPath2 = Path.GetFullPath(Path.Combine(managedAssemblyFolderPath, "tempUnstripped")); Directory.CreateDirectory(fullPath2); string[] files2 = Directory.GetFiles(managedAssemblyFolderPath); for (int j = 0; j < files2.Length; j++) { string text5 = files2[j]; string extension = Path.GetExtension(text5); if (string.Equals(extension, ".dll", StringComparison.InvariantCultureIgnoreCase) || string.Equals(extension, ".winmd", StringComparison.InvariantCultureIgnoreCase) || string.Equals(extension, ".mdb", StringComparison.InvariantCultureIgnoreCase) || string.Equals(extension, ".pdb", StringComparison.InvariantCultureIgnoreCase)) { File.Move(text5, Path.Combine(fullPath2, Path.GetFileName(text5))); } } string[] files3 = Directory.GetFiles(fullPath); for (int k = 0; k < files3.Length; k++) { string text6 = files3[k]; File.Move(text6, Path.Combine(managedAssemblyFolderPath, Path.GetFileName(text6))); } Directory.Delete(fullPath); }
private static void RunAssemblyStripper(string stagingAreaData, IEnumerable assemblies, string managedAssemblyFolderPath, string[] assembliesToStrip, string[] searchDirs, string monoLinkerPath, IIl2CppPlatformProvider platformProvider, RuntimeClassRegistry rcr, bool developmentBuild) { bool flag = rcr != null && PlayerSettings.stripEngineCode && platformProvider.supportsEngineStripping; IEnumerable <string> enumerable = AssemblyStripper.Il2CppBlacklistPaths; if (rcr != null) { enumerable = enumerable.Concat(new string[] { AssemblyStripper.WriteMethodsToPreserveBlackList(stagingAreaData, rcr) }); } if (!flag) { string[] files = Directory.GetFiles(platformProvider.moduleStrippingInformationFolder, "*.xml"); for (int i = 0; i < files.Length; i++) { string text = files[i]; enumerable = enumerable.Concat(new string[] { text }); } } string fullPath = Path.GetFullPath(Path.Combine(managedAssemblyFolderPath, "tempStrip")); string text3; while (true) { bool flag2 = false; if (EditorUtility.DisplayCancelableProgressBar("Building Player", "Stripping assemblies", 0f)) { break; } string text2; if (!AssemblyStripper.StripAssembliesTo(assembliesToStrip, searchDirs, fullPath, managedAssemblyFolderPath, out text2, out text3, monoLinkerPath, platformProvider, enumerable, developmentBuild)) { goto Block_6; } string text4 = Path.Combine(managedAssemblyFolderPath, "ICallSummary.txt"); string exe = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Tools/InternalCallRegistrationWriter/InternalCallRegistrationWriter.exe"); string args = string.Format("-assembly=\"{0}\" -output=\"{1}\" -summary=\"{2}\"", Path.Combine(fullPath, "UnityEngine.dll"), Path.Combine(managedAssemblyFolderPath, "UnityICallRegistration.cpp"), text4); Runner.RunManagedProgram(exe, args); if (flag) { HashSet <string> hashSet; HashSet <string> nativeModules; CodeStrippingUtils.GenerateDependencies(fullPath, text4, rcr, out hashSet, out nativeModules); flag2 = AssemblyStripper.AddWhiteListsForModules(nativeModules, ref enumerable, platformProvider.moduleStrippingInformationFolder); } if (!flag2) { goto Block_8; } } throw new OperationCanceledException(); Block_6: throw new Exception(string.Concat(new object[] { "Error in stripping assemblies: ", assemblies, ", ", text3 })); Block_8: string fullPath2 = Path.GetFullPath(Path.Combine(managedAssemblyFolderPath, "tempUnstripped")); Directory.CreateDirectory(fullPath2); string[] files2 = Directory.GetFiles(managedAssemblyFolderPath); for (int j = 0; j < files2.Length; j++) { string text5 = files2[j]; string extension = Path.GetExtension(text5); if (string.Equals(extension, ".dll", StringComparison.InvariantCultureIgnoreCase) || string.Equals(extension, ".mdb", StringComparison.InvariantCultureIgnoreCase)) { File.Move(text5, Path.Combine(fullPath2, Path.GetFileName(text5))); } } string[] files3 = Directory.GetFiles(fullPath); for (int k = 0; k < files3.Length; k++) { string text6 = files3[k]; File.Move(text6, Path.Combine(managedAssemblyFolderPath, Path.GetFileName(text6))); } Directory.Delete(fullPath); }
private static List <string> GetUserAssemblies(RuntimeClassRegistry rcr, string managedDir) { return((from s in rcr.GetUserAssemblies() where rcr.IsDLLUsed(s) select Path.Combine(managedDir, s)).ToList <string>()); }
internal static void StripAssemblies(string stagingAreaData, IIl2CppPlatformProvider platformProvider, RuntimeClassRegistry rcr) { string fullPath = Path.GetFullPath(Path.Combine(stagingAreaData, "Managed")); List <string> userAssemblies = AssemblyStripper.GetUserAssemblies(rcr, fullPath); string[] assembliesToStrip = userAssemblies.ToArray(); string[] searchDirs = new string[] { fullPath }; AssemblyStripper.RunAssemblyStripper(stagingAreaData, userAssemblies, fullPath, assembliesToStrip, searchDirs, AssemblyStripper.MonoLinker2Path, platformProvider, rcr); }
internal static IL2CPPBuilder RunCompileAndLink(string tempFolder, string stagingAreaData, IIl2CppPlatformProvider platformProvider, Action <string> modifyOutputBeforeCompile, RuntimeClassRegistry runtimeClassRegistry) { var builder = new IL2CPPBuilder(tempFolder, stagingAreaData, platformProvider, modifyOutputBeforeCompile, runtimeClassRegistry, IL2CPPUtils.UseIl2CppCodegenWithMonoBackend(BuildPipeline.GetBuildTargetGroup(platformProvider.target))); builder.RunCompileAndLink(); return(builder); }
private static string WriteTypesInScenesBlacklist(string managedAssemblyDirectory, RuntimeClassRegistry rcr) { var items = rcr.GetAllManagedTypesInScenes(); var sb = new StringBuilder(); sb.AppendLine("<linker>"); foreach (var assemblyTypePair in items) { // Some how stuff for assemblies that will not be in the build make it into UsedTypePerUserAssembly such as // ex: [UnityEditor.TestRunner.dll] UnityEditor.TestTools.TestRunner.TestListCacheData // // Filter anything out where the assembly doesn't exist so that UnityLinker can be strict about preservations in link xml files if (!File.Exists(Path.Combine(managedAssemblyDirectory, assemblyTypePair.Key))) { continue; } sb.AppendLine($"\t<assembly fullname=\"{Path.GetFileNameWithoutExtension(assemblyTypePair.Key)}\">"); foreach (var type in assemblyTypePair.Value) { sb.AppendLine($"\t\t<type fullname=\"{type}\" preserve=\"nothing\"/>"); } sb.AppendLine("\t</assembly>"); } sb.AppendLine("</linker>"); var path = Path.Combine(managedAssemblyDirectory, "TypesInScenes.xml"); File.WriteAllText(path, sb.ToString()); return(path); }
static List <EditorToLinkerData.TypeInSceneData> GetTypesInScenesInformation(string managedAssemblyDirectory, RuntimeClassRegistry rcr) { var items = new List <EditorToLinkerData.TypeInSceneData>(); foreach (var nativeClass in rcr.GetAllNativeClassesIncludingManagersAsString()) { var unityType = UnityType.FindTypeByName(nativeClass); var managedName = RuntimeClassMetadataUtils.ScriptingWrapperTypeNameForNativeID(unityType.persistentTypeID); var usedInScenes = rcr.GetScenesForClass(unityType.persistentTypeID); bool noManagedType = unityType.persistentTypeID != 0 && managedName == "UnityEngine.Object"; var information = new EditorToLinkerData.TypeInSceneData( noManagedType ? null : "UnityEngine.dll", noManagedType ? null : managedName, nativeClass, unityType.module, usedInScenes != null ? usedInScenes.ToArray() : null); items.Add(information); } foreach (var userAssembly in rcr.UsedTypePerUserAssembly) { // Some how stuff for assemblies that will not be in the build make it into UsedTypePerUserAssembly such as // ex: [UnityEditor.TestRunner.dll] UnityEditor.TestTools.TestRunner.TestListCacheData // // Filter anything out where the assembly doesn't exist so that UnityLinker can be strict about being able to find // all of the types that are reported as being in the scene. if (!File.Exists(Path.Combine(managedAssemblyDirectory, userAssembly.Key))) { continue; } foreach (var type in userAssembly.Value) { items.Add(new EditorToLinkerData.TypeInSceneData(userAssembly.Key, type, null, null, null)); } } return(items); }
private static List <string> GetUserAssemblies(RuntimeClassRegistry rcr, string managedDir) { return(rcr.GetUserAssemblies().Where(s => rcr.IsDLLUsed(s)).Select(s => Path.Combine(managedDir, s)).ToList()); }
internal static void StripAssemblies(string managedAssemblyFolderPath, IIl2CppPlatformProvider platformProvider, RuntimeClassRegistry rcr, ManagedStrippingLevel managedStrippingLevel) { var assemblies = GetUserAssemblies(rcr, managedAssemblyFolderPath); assemblies.AddRange(Directory.GetFiles(managedAssemblyFolderPath, "I18N*.dll", SearchOption.TopDirectoryOnly)); var assembliesToStrip = assemblies.ToArray(); var searchDirs = new[] { managedAssemblyFolderPath }; RunAssemblyStripper(assemblies, managedAssemblyFolderPath, assembliesToStrip, searchDirs, UnityLinkerPath, platformProvider, rcr, managedStrippingLevel); }