private static void AddNativeModuleInStrippingInfo(string moduleName, string requiredMessage, StrippingInfo strippingInfo, HashSet <string> nativeModules, string icon) { nativeModules.Add(moduleName); strippingInfo.AddModule(moduleName); strippingInfo.RegisterDependency(StrippingInfo.ModuleName(moduleName), requiredMessage); strippingInfo.SetIcon(requiredMessage, icon); }
public static void InjectCustomDependencies(BuildTarget target, StrippingInfo strippingInfo, HashSet <UnityType> nativeClasses, HashSet <string> nativeModules) { // This function can be used to inject user-readable dependency information for specific classes which would not be obvious otherwise. // Can also be used to set up dependencies to modules which cannot be derived by the build pipeline without custom rules const string connectSettingsName = "UnityConnectSettings"; var connectSettings = UnityType.FindTypeByName(connectSettingsName); const string cloudWebServicesManagerName = "CloudWebServicesManager"; var cloudWebServicesManager = UnityType.FindTypeByName(cloudWebServicesManagerName); if (nativeClasses.Contains(connectSettings) || nativeClasses.Contains(cloudWebServicesManager)) { if (PlayerSettings.submitAnalytics) { const string requiredMessage = "Required by HW Statistics (See Player Settings)"; strippingInfo.RegisterDependency(connectSettingsName, requiredMessage); strippingInfo.RegisterDependency(cloudWebServicesManagerName, requiredMessage); strippingInfo.SetIcon(requiredMessage, "class/PlayerSettings"); } } const string analyticsManagerName = "UnityAnalyticsManager"; var analyticsManager = UnityType.FindTypeByName(analyticsManagerName); if (nativeClasses.Contains(analyticsManager)) { if (UnityEditor.Analytics.AnalyticsSettings.enabled) { const string requiredMessage = "Required by Unity Analytics (See Services Window)"; strippingInfo.RegisterDependency(analyticsManagerName, requiredMessage); strippingInfo.SetIcon(requiredMessage, "class/PlayerSettings"); } } if (UnityEditorInternal.VR.VRModule.ShouldInjectVRDependenciesForBuildTarget(target)) { const string moduleName = "VR"; const string requiredMessage = "Required because VR is enabled in PlayerSettings"; nativeModules.Add(moduleName); strippingInfo.RegisterDependency(StrippingInfo.ModuleName(moduleName), requiredMessage); strippingInfo.SetIcon(requiredMessage, "class/PlayerSettings"); } foreach (string module in ModuleMetadata.GetModuleNames()) { if (!ModuleMetadata.IsStrippableModule(module)) { string requiredMessage = module + " is always required"; nativeModules.Add(module); strippingInfo.AddModule(module); strippingInfo.RegisterDependency(StrippingInfo.ModuleName(module), requiredMessage); strippingInfo.SetIcon(requiredMessage, "class/DefaultAsset"); } } }
private static void AddNativeModuleInStrippingInfo(string moduleName, string requiredMessage, StrippingInfo strippingInfo, HashSet <string> nativeModules, string icon) { if (AssemblyStripper.UseUnityLinkerEngineModuleStripping) { throw new NotSupportedException("Don't want to rely on this method when UnityLinker EMS is used"); } nativeModules.Add(moduleName); strippingInfo.AddModule(moduleName); strippingInfo.RegisterDependency(StrippingInfo.ModuleName(moduleName), requiredMessage); strippingInfo.SetIcon(requiredMessage, icon); }
public static void ApplyManualStrippingOverrides(HashSet <UnityType> nativeClasses, HashSet <string> nativeModules, StrippingInfo strippingInfo) { string[] moduleNames = ModuleMetadata.GetModuleNames(); for (int i = 0; i < moduleNames.Length; i++) { string text = moduleNames[i]; ModuleIncludeSetting moduleIncludeSettingForModule = ModuleMetadata.GetModuleIncludeSettingForModule(text); if (moduleIncludeSettingForModule == ModuleIncludeSetting.ForceInclude) { nativeModules.Add(text); UnityType[] moduleTypes = ModuleMetadata.GetModuleTypes(text); UnityType[] array = moduleTypes; for (int j = 0; j < array.Length; j++) { UnityType unityType = array[j]; nativeClasses.Add(unityType); if (strippingInfo != null) { strippingInfo.RegisterDependency(unityType.name, "Force included module"); strippingInfo.RegisterDependency(StrippingInfo.ModuleName(text), unityType.name); } } if (strippingInfo != null) { strippingInfo.RegisterDependency(StrippingInfo.ModuleName(text), "Force included module"); } } else if (moduleIncludeSettingForModule == ModuleIncludeSetting.ForceExclude) { if (nativeModules.Contains(text)) { nativeModules.Remove(text); UnityType[] moduleTypes2 = ModuleMetadata.GetModuleTypes(text); UnityType[] array2 = moduleTypes2; for (int k = 0; k < array2.Length; k++) { UnityType item = array2[k]; if (nativeClasses.Contains(item)) { nativeClasses.Remove(item); } } if (strippingInfo != null) { strippingInfo.modules.Remove(StrippingInfo.ModuleName(text)); } } } } }
public static void InjectCustomDependencies(BuildTarget target, StrippingInfo strippingInfo, HashSet <UnityType> nativeClasses, HashSet <string> nativeModules) { if (AssemblyStripper.UseUnityLinkerEngineModuleStripping) { throw new NotSupportedException("Don't want to rely on this method when UnityLinker EMS is used"); } // This function can be used to inject user-readable dependency information for specific classes which would not be obvious otherwise. // Can also be used to set up dependencies to modules which cannot be derived by the build pipeline without custom rules if (UnityEngine.Connect.UnityConnectSettings.enabled || UnityEditor.CrashReporting.CrashReportingSettings.enabled || UnityEngine.Analytics.PerformanceReporting.enabled || UnityEngine.Analytics.Analytics.enabled) { string requiredMessage = "Required by HW Statistics (See Player Settings)"; const string icon = "class/PlayerSettings"; if (UnityEngine.Analytics.Analytics.enabled || UnityEngine.Analytics.PerformanceReporting.enabled) { requiredMessage = "Required by Analytics Performance Reporting (See Analytics Services Window)"; AddNativeModuleInStrippingInfo("PerformanceReporting", requiredMessage, strippingInfo, nativeModules, icon); } requiredMessage = "Required by UnityAnalytics (See Services Window)"; AddNativeModuleInStrippingInfo("UnityAnalytics", requiredMessage, strippingInfo, nativeModules, icon); AddNativeModuleInStrippingInfo("UnityConnect", requiredMessage, strippingInfo, nativeModules, icon); strippingInfo.RegisterDependency("UnityConnectSettings", "Required by UnityAnalytics"); } if (CrashReporting.CrashReportingSettings.enabled) { AddNativeModuleInStrippingInfo("CrashReporting", "Required by Crash Reporting Service (See Services Window)", strippingInfo, nativeModules, "class/PlayerSettings"); } if (UnityEditorInternal.VR.VRModule.ShouldInjectVRDependenciesForBuildTarget(target)) { const string moduleName = "VR"; const string requiredMessage = "Required because VR is enabled in PlayerSettings"; nativeModules.Add(moduleName); strippingInfo.RegisterDependency(StrippingInfo.ModuleName(moduleName), requiredMessage); strippingInfo.SetIcon(requiredMessage, "class/PlayerSettings"); } foreach (string module in ModuleMetadata.GetModuleNames()) { if (!ModuleMetadata.IsStrippableModule(module)) { string requiredMessage = module + " is always required"; AddNativeModuleInStrippingInfo(module, requiredMessage, strippingInfo, nativeModules, "class/DefaultAsset"); } } }
private static HashSet <string> GetRequiredStrippableModules(HashSet <UnityType> nativeClasses, StrippingInfo strippingInfo) { if (AssemblyStripper.UseUnityLinkerEngineModuleStripping) { throw new NotSupportedException("Don't want to rely on this method when UnityLinker EMS is used"); } HashSet <UnityType> nativeClassesUsedInModules = new HashSet <UnityType>(); HashSet <string> nativeModules = new HashSet <string>(); foreach (string module in ModuleMetadata.GetModuleNames()) { if (ModuleMetadata.IsStrippableModule(module)) // Only handle strippable modules. Others are listed in RegisterStaticallyLinkedModulesGranular() { var moduleClasses = new HashSet <UnityType>(ModuleMetadata.GetModuleTypes(module)); if (nativeClasses.Overlaps(moduleClasses)) // Include module if at least one of its classes is present { nativeModules.Add(module); if (strippingInfo != null) { foreach (var klass in moduleClasses) { if (nativeClasses.Contains(klass)) { strippingInfo.RegisterDependency(StrippingInfo.ModuleName(module), klass.name); // Don't list GlobalGameManagers in a module will automatically be added if the module is added. nativeClassesUsedInModules.Add(klass); } } } } } } // Classes which have not been registered as belonging to a module belong to the Core module. if (strippingInfo != null) { foreach (var klass in nativeClasses) { if (!nativeClassesUsedInModules.Contains(klass)) { strippingInfo.RegisterDependency(StrippingInfo.ModuleName("Core"), klass.name); } } } return(nativeModules); }
public static void ApplyManualStrippingOverrides(HashSet <UnityType> nativeClasses, HashSet <string> nativeModules, StrippingInfo strippingInfo) { if (AssemblyStripper.UseUnityLinkerEngineModuleStripping) { throw new NotSupportedException("Don't want to rely on this method when UnityLinker EMS is used"); } // Apply manual stripping overrides foreach (var module in ModuleMetadata.GetModuleNames()) { var includeSetting = ModuleMetadata.GetModuleIncludeSettingForModule(module); if (includeSetting == ModuleIncludeSetting.ForceInclude) { nativeModules.Add(module); if (nativeClasses != null) { var moduleClasses = ModuleMetadata.GetModuleTypes(module); foreach (var klass in moduleClasses) { nativeClasses.Add(klass); if (strippingInfo != null) { strippingInfo.RegisterDependency(klass.name, "Force included module"); strippingInfo.RegisterDependency(StrippingInfo.ModuleName(module), klass.name); } } } if (strippingInfo != null) { strippingInfo.RegisterDependency(StrippingInfo.ModuleName(module), "Force included module"); } } else if (includeSetting == ModuleIncludeSetting.ForceExclude) { if (nativeModules.Contains(module)) { nativeModules.Remove(module); if (strippingInfo != null) { strippingInfo.modules.Remove(StrippingInfo.ModuleName(module)); } } } } }
public static void ApplyManualStrippingOverrides(HashSet <UnityType> nativeClasses, HashSet <string> nativeModules, StrippingInfo strippingInfo) { // Apply manual stripping overrides foreach (var module in ModuleMetadata.GetModuleNames()) { var includeSetting = ModuleMetadata.GetModuleIncludeSettingForModule(module); if (includeSetting == ModuleIncludeSetting.ForceInclude) { nativeModules.Add(module); var moduleClasses = ModuleMetadata.GetModuleTypes(module); foreach (var klass in moduleClasses) { nativeClasses.Add(klass); if (strippingInfo != null) { strippingInfo.RegisterDependency(klass.name, "Force included module"); strippingInfo.RegisterDependency(StrippingInfo.ModuleName(module), klass.name); } } if (strippingInfo != null) { strippingInfo.RegisterDependency(StrippingInfo.ModuleName(module), "Force included module"); } } else if (includeSetting == ModuleIncludeSetting.ForceExclude) { if (nativeModules.Contains(module)) { nativeModules.Remove(module); var moduleClasses = ModuleMetadata.GetModuleTypes(module); foreach (var klass in moduleClasses) { if (nativeClasses.Contains(klass)) { nativeClasses.Remove(klass); } } if (strippingInfo != null) { strippingInfo.modules.Remove(StrippingInfo.ModuleName(module)); } } } } }
private static void UpdateBuildReport(LinkerToEditorData dataFromLinker, IIl2CppPlatformProvider platformProvider) { var strippingInfo = platformProvider == null ? null : StrippingInfo.GetBuildReportData(platformProvider.buildReport); if (strippingInfo == null) { return; } foreach (var moduleInfo in dataFromLinker.report.modules) { strippingInfo.AddModule(moduleInfo.name); foreach (var moduleDependency in moduleInfo.dependencies) { strippingInfo.RegisterDependency(StrippingInfo.ModuleName(moduleInfo.name), moduleDependency.name); if (!string.IsNullOrEmpty(moduleDependency.icon)) { strippingInfo.SetIcon(moduleDependency.name, moduleDependency.icon); } // Hacky way to match the existing behavior if (moduleDependency.name == "UnityConnectSettings") { strippingInfo.RegisterDependency(moduleDependency.name, "Required by UnityAnalytics"); } foreach (var scene in moduleDependency.scenes) { strippingInfo.RegisterDependency(moduleDependency.name, scene); var klass = UnityType.FindTypeByName(moduleDependency.name); if (klass != null && !klass.IsDerivedFrom(CodeStrippingUtils.GameManagerTypeInfo)) { if (scene.EndsWith(".unity")) { strippingInfo.SetIcon(scene, "class/SceneAsset"); } else { strippingInfo.SetIcon(scene, "class/AssetBundle"); } } } } } }
public static void InjectCustomDependencies(BuildTarget target, StrippingInfo strippingInfo, HashSet <UnityType> nativeClasses, HashSet <string> nativeModules) { UnityType item = UnityType.FindTypeByName("UnityConnectSettings"); UnityType item2 = UnityType.FindTypeByName("CloudWebServicesManager"); if (nativeClasses.Contains(item) || nativeClasses.Contains(item2)) { if (PlayerSettings.submitAnalytics) { strippingInfo.RegisterDependency("UnityConnectSettings", "Required by HW Statistics (See Player Settings)"); strippingInfo.RegisterDependency("CloudWebServicesManager", "Required by HW Statistics (See Player Settings)"); strippingInfo.SetIcon("Required by HW Statistics (See Player Settings)", "class/PlayerSettings"); } } UnityType item3 = UnityType.FindTypeByName("UnityAnalyticsManager"); if (nativeClasses.Contains(item3)) { if (AnalyticsSettings.enabled) { strippingInfo.RegisterDependency("UnityAnalyticsManager", "Required by Unity Analytics (See Services Window)"); strippingInfo.SetIcon("Required by Unity Analytics (See Services Window)", "class/PlayerSettings"); } } if (VRModule.ShouldInjectVRDependenciesForBuildTarget(target)) { nativeModules.Add("VR"); strippingInfo.RegisterDependency(StrippingInfo.ModuleName("VR"), "Required because VR is enabled in PlayerSettings"); strippingInfo.SetIcon("Required because VR is enabled in PlayerSettings", "class/PlayerSettings"); } string[] moduleNames = ModuleMetadata.GetModuleNames(); for (int i = 0; i < moduleNames.Length; i++) { string text = moduleNames[i]; if (!ModuleMetadata.IsStrippableModule(text)) { string text2 = text + " is always required"; nativeModules.Add(text); strippingInfo.AddModule(text, true); strippingInfo.RegisterDependency(StrippingInfo.ModuleName(text), text2); strippingInfo.SetIcon(text2, "class/DefaultAsset"); } } }
private static HashSet <string> GetRequiredStrippableModules(HashSet <UnityType> nativeClasses, StrippingInfo strippingInfo) { HashSet <UnityType> hashSet = new HashSet <UnityType>(); HashSet <string> hashSet2 = new HashSet <string>(); string[] moduleNames = ModuleMetadata.GetModuleNames(); for (int i = 0; i < moduleNames.Length; i++) { string text = moduleNames[i]; if (ModuleMetadata.GetModuleStrippable(text)) { HashSet <UnityType> hashSet3 = new HashSet <UnityType>(ModuleMetadata.GetModuleTypes(text)); if (nativeClasses.Overlaps(hashSet3)) { hashSet2.Add(text); if (strippingInfo != null) { foreach (UnityType current in hashSet3) { if (nativeClasses.Contains(current)) { strippingInfo.RegisterDependency(StrippingInfo.ModuleName(text), current.name); hashSet.Add(current); } } } } } } if (strippingInfo != null) { foreach (UnityType current2 in nativeClasses) { if (!hashSet.Contains(current2)) { strippingInfo.RegisterDependency(StrippingInfo.ModuleName("Core"), current2.name); } } } return(hashSet2); }
public static void GenerateDependencies(string strippedAssemblyDir, string icallsListFile, RuntimeClassRegistry rcr, bool doStripping, out HashSet <UnityType> nativeClasses, out HashSet <string> nativeModules, IIl2CppPlatformProvider platformProvider) { if (AssemblyStripper.UseUnityLinkerEngineModuleStripping) { GenerateDependencies2(strippedAssemblyDir, doStripping, out nativeClasses, out nativeModules); return; } var strippingInfo = platformProvider == null ? null : StrippingInfo.GetBuildReportData(platformProvider.buildReport); var userAssemblies = GetUserAssemblies(strippedAssemblyDir); // [1] Extract native classes from scene and scripts nativeClasses = doStripping ? GenerateNativeClassList(rcr, strippedAssemblyDir, userAssemblies, strippingInfo) : null; // Exclude module managers (GlobalGameManager) if no dependent classes are used. if (nativeClasses != null) { ExcludeModuleManagers(ref nativeClasses); } // [2] Prepare a list of modules to register nativeModules = GetNativeModulesToRegister(nativeClasses, strippingInfo); if (nativeClasses != null && icallsListFile != null) { // Get required modules from icall list file var icallModules = GetModulesFromICalls(icallsListFile); // Add GameManager classes for modules foreach (var module in icallModules) { if (!nativeModules.Contains(module)) { if (strippingInfo != null) { strippingInfo.RegisterDependency(StrippingInfo.ModuleName(module), StrippingInfo.RequiredByScripts); } } var moduleClasses = ModuleMetadata.GetModuleTypes(module); foreach (var klass in moduleClasses) { if (klass.IsDerivedFrom(GameManagerTypeInfo)) { nativeClasses.Add(klass); } } } nativeModules.UnionWith(icallModules); } ApplyManualStrippingOverrides(nativeClasses, nativeModules, strippingInfo); bool didAdd = true; if (platformProvider != null) { while (didAdd) { didAdd = false; foreach (var module in nativeModules.ToList()) { var dependecies = ModuleMetadata.GetModuleDependencies(module); foreach (var dependentModule in dependecies) { if (!nativeModules.Contains(dependentModule)) { nativeModules.Add(dependentModule); didAdd = true; } if (strippingInfo != null) { var moduleName = StrippingInfo.ModuleName(module); strippingInfo.RegisterDependency(StrippingInfo.ModuleName(dependentModule), "Required by " + moduleName); strippingInfo.SetIcon("Required by " + moduleName, $"package/com.unity.modules.{module.ToLower()}"); } } } } } if (nativeClasses != null) { RemoveClassesFromRemovedModules(nativeClasses, nativeModules); } AssemblyReferenceChecker checker = new AssemblyReferenceChecker(); checker.CollectReferencesFromRoots(strippedAssemblyDir, userAssemblies, true, 0.0f, true); if (strippingInfo != null) { foreach (var module in nativeModules) { strippingInfo.AddModule(module); } strippingInfo.AddModule("Core"); } if (nativeClasses != null && strippingInfo != null && platformProvider != null) { InjectCustomDependencies(platformProvider.target, strippingInfo, nativeClasses, nativeModules); } }
public static void GenerateDependencies(string strippedAssemblyDir, string icallsListFile, RuntimeClassRegistry rcr, bool doStripping, out HashSet <UnityType> nativeClasses, out HashSet <string> nativeModules, IIl2CppPlatformProvider platformProvider) { StrippingInfo strippingInfo = (platformProvider != null) ? StrippingInfo.GetBuildReportData(platformProvider.buildReport) : null; string[] userAssemblies = CodeStrippingUtils.GetUserAssemblies(strippedAssemblyDir); nativeClasses = ((!doStripping) ? null : CodeStrippingUtils.GenerateNativeClassList(rcr, strippedAssemblyDir, userAssemblies, strippingInfo)); if (nativeClasses != null) { CodeStrippingUtils.ExcludeModuleManagers(ref nativeClasses); } nativeModules = CodeStrippingUtils.GetNativeModulesToRegister(nativeClasses, strippingInfo); if (nativeClasses != null && icallsListFile != null) { HashSet <string> modulesFromICalls = CodeStrippingUtils.GetModulesFromICalls(icallsListFile); foreach (string current in modulesFromICalls) { if (!nativeModules.Contains(current)) { if (strippingInfo != null) { strippingInfo.RegisterDependency(StrippingInfo.ModuleName(current), "Required by Scripts"); } } UnityType[] moduleTypes = ModuleMetadata.GetModuleTypes(current); UnityType[] array = moduleTypes; for (int i = 0; i < array.Length; i++) { UnityType unityType = array[i]; if (unityType.IsDerivedFrom(CodeStrippingUtils.GameManagerTypeInfo)) { nativeClasses.Add(unityType); } } } nativeModules.UnionWith(modulesFromICalls); } bool flag = true; if (platformProvider != null) { while (flag) { flag = false; foreach (string current2 in nativeModules.ToList <string>()) { string moduleWhitelist = CodeStrippingUtils.GetModuleWhitelist(current2, platformProvider.moduleStrippingInformationFolder); if (File.Exists(moduleWhitelist)) { foreach (string current3 in CodeStrippingUtils.GetDependentModules(moduleWhitelist)) { if (!nativeModules.Contains(current3)) { nativeModules.Add(current3); flag = true; } if (strippingInfo != null) { string text = StrippingInfo.ModuleName(current2); strippingInfo.RegisterDependency(StrippingInfo.ModuleName(current3), "Required by " + text); if (strippingInfo.icons.ContainsKey(text)) { strippingInfo.SetIcon("Required by " + text, strippingInfo.icons[text]); } } } } } } } AssemblyReferenceChecker assemblyReferenceChecker = new AssemblyReferenceChecker(); assemblyReferenceChecker.CollectReferencesFromRoots(strippedAssemblyDir, userAssemblies, true, 0f, true); if (strippingInfo != null) { foreach (string current4 in nativeModules) { strippingInfo.AddModule(StrippingInfo.ModuleName(current4)); } strippingInfo.AddModule(StrippingInfo.ModuleName("Core")); } if (nativeClasses != null && strippingInfo != null) { CodeStrippingUtils.InjectCustomDependencies(platformProvider.target, strippingInfo, nativeClasses, nativeModules); } }