static string[] GetCachedSystemLibraryReferences(ApiCompatibilityLevel apiCompatibilityLevel) { // We cache the references because they are computed by getting files in directories on disk, // which is very slow. if (cachedApiCompatibilityLevelReferences.TryGetValue(apiCompatibilityLevel, out var cachedReferences)) { return(cachedReferences); } var references = new List <string>(); if (apiCompatibilityLevel == ApiCompatibilityLevel.NET_Standard) { references.AddRange(GetNetStandardClassLibraries()); } else if (apiCompatibilityLevel == ApiCompatibilityLevel.NET_Unity_4_8) { var monoAssemblyDirectories = GetSystemReferenceDirectories(apiCompatibilityLevel); var referenceFileNames = GetSystemReferences().Concat(GetNet46SystemReferences()).Concat(GetMonoProfileNetstandardFacadeReferences()).Distinct(); references.AddRange(referenceFileNames.FindReferencesInDirectories(monoAssemblyDirectories)); references.AddRange(Directory.GetFiles(Path.Combine(GetUnityReferenceProfileDirectory(), "Facades"), "*.dll")); } else { var monoAssemblyDirectories = GetSystemReferenceDirectories(apiCompatibilityLevel); references.AddRange(GetSystemReferences().FindReferencesInDirectories(monoAssemblyDirectories)); } var apiCompatibilityLevelReference = references.ToArray(); cachedApiCompatibilityLevelReferences[apiCompatibilityLevel] = apiCompatibilityLevelReference; return(apiCompatibilityLevelReference); }
internal static string ApiCompatibilityLevelToDotNetProfileArgument(ApiCompatibilityLevel compatibilityLevel) { switch (compatibilityLevel) { case ApiCompatibilityLevel.NET_2_0: { string result = "net20"; return(result); } case ApiCompatibilityLevel.NET_2_0_Subset: { string result = "legacyunity"; return(result); } case ApiCompatibilityLevel.NET_4_6: { string result = "net45"; return(result); } case ApiCompatibilityLevel.NET_Standard_2_0: { string result = "unityaot"; return(result); } } throw new NotSupportedException(string.Format("ApiCompatibilityLevel.{0} is not supported by IL2CPP!", compatibilityLevel)); }
static SetApiLevel() { BuildTarget target = EditorUserBuildSettings.activeBuildTarget; BuildTargetGroup group = BuildPipeline.GetBuildTargetGroup(target); #if UNITY_2018_1_OR_NEWER ApiCompatibilityLevel level = ApiCompatibilityLevel.NET_4_6; #else ApiCompatibilityLevel level = ApiCompatibilityLevel.NET_2_0; #endif #if UNITY_STANDALONE_WIN ScriptingImplementation scriptingBackend = ScriptingImplementation.Mono2x; #else ScriptingImplementation scriptingBackend = PlayerSettings.GetScriptingBackend(group); #endif //Debug.Log("API level: " + PlayerSettings.GetApiCompatibilityLevel(group)); //Debug.Log("Scripting backend: " + PlayerSettings.GetScriptingBackend(group)); if (PlayerSettings.GetApiCompatibilityLevel(group) != level || PlayerSettings.GetScriptingBackend(group) != scriptingBackend) { PlayerSettings.SetApiCompatibilityLevel(group, level); PlayerSettings.SetScriptingBackend(group, scriptingBackend); Debug.Log("API level changed to '" + level + "' (" + scriptingBackend + ")"); } }
private void GatherCurrentSettings() { BuildTarget buildTarget = EditorUserBuildSettings.activeBuildTarget; buildTargetGroup = BuildPipeline.GetBuildTargetGroup(buildTarget); currentLevel = PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup); }
public override string GetNamespace(string filePath, string definedSymbols) { var targetAssemblyFromPath = EditorCompilationInterface.Instance.GetTargetAssemblyFromPath(filePath); var definedSymbolsSplit = definedSymbols.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] fullListOfDefines = new string[definedSymbolsSplit.Length + (targetAssemblyFromPath?.Defines?.Length ?? 0)]; Array.Copy(definedSymbolsSplit, fullListOfDefines, definedSymbolsSplit.Length); if (targetAssemblyFromPath?.Defines != null) { Array.Copy(targetAssemblyFromPath.Defines, 0, fullListOfDefines, definedSymbolsSplit.Length, targetAssemblyFromPath.Defines.Length); } var rspFile = targetAssemblyFromPath?.GetResponseFiles()?.FirstOrDefault(); ApiCompatibilityLevel compatibilityLevel = ApiCompatibilityLevel.NET_4_6; string[] rspDefines = null; if (!string.IsNullOrEmpty(rspFile)) { rspDefines = ScriptCompilerBase.ParseResponseFileFromFile( rspFile, Application.dataPath, GetSystemReferenceDirectories(compatibilityLevel)).Defines; } return(GetNamespaceNewRuntime(filePath, fullListOfDefines, rspDefines)); }
internal static void SetApiCompatibilityLevel(BuildTargetGroup targetGroup, ApiCompatibilityLevel apiCompatibility) { #if UNITY_5_6_OR_NEWER PlayerSettings.SetApiCompatibilityLevel(targetGroup, apiCompatibility); #else PlayerSettings.apiCompatibilityLevel = apiCompatibility; #endif }
public static void CheckAPICompatibility() { ApiCompatibilityLevel level = PlayerSettings.GetApiCompatibilityLevel(BuildTargetGroup.Standalone); if (level == ApiCompatibilityLevel.NET_2_0_Subset) { PlayerSettings.SetApiCompatibilityLevel(BuildTargetGroup.Standalone, ApiCompatibilityLevel.NET_2_0); } }
private static void CheckAPICompatibility() { ApiCompatibilityLevel level = PlayerSettings.GetApiCompatibilityLevel(BuildTargetGroup.Standalone); if (level == ApiCompatibilityLevel.NET_2_0_Subset) { PlayerSettings.SetApiCompatibilityLevel(BuildTargetGroup.Standalone, ApiCompatibilityLevel.NET_2_0); } Helper.SetDefineSymbol(DEFINE_SYMBOLE_API_NET_TWO, true, true); }
public static string[] GetSystemLibraryReferences(ApiCompatibilityLevel apiCompatibilityLevel, SupportedLanguage supportedLanguage) { // The language may not be compatible with these additional references if (supportedLanguage != null && !supportedLanguage.CompilerRequiresAdditionalReferences()) { return(new string[0]); } return(GetCachedSystemLibraryReferences(apiCompatibilityLevel)); }
private static string GetMonoProfileLibDirectory(ApiCompatibilityLevel apiCompatibilityLevel) { var buildPipelineType = typeof(BuildPipeline); var compatibilityProfileToClassLibFolderMethodInfo = buildPipelineType.GetMethod("CompatibilityProfileToClassLibFolder", BindingFlags.NonPublic | BindingFlags.Static); string profile = (string)compatibilityProfileToClassLibFolderMethodInfo.Invoke(null, new object[] { apiCompatibilityLevel }); var apiCompatibilityLevelNet46 = (ApiCompatibilityLevel)3; string monoInstallation = apiCompatibilityLevel != apiCompatibilityLevelNet46 ? "Mono" : "MonoBleedingEdge"; return(GetProfileDirectory(profile, monoInstallation)); }
public MonoIsland(BuildTarget target, ApiCompatibilityLevel api_compatibility_level, string[] files, string[] references, string[] defines, string output) { this._target = target; this._development_player = false; this._editor = false; this._api_compatibility_level = api_compatibility_level; this._files = files; this._references = references; this._defines = defines; this._output = output; }
void IApplyToTest.ApplyToTest(Test test) { test.Properties.Add(PropertyNames.Category, string.Format("ApiProfile({0})", string.Join(", ", apiProfiles.Select(p => p.ToString()).OrderBy(p => p).ToArray()))); ApiCompatibilityLevel testProfile = PlayerSettings.GetApiCompatibilityLevel(EditorUserBuildSettings.activeBuildTargetGroup); if (!apiProfiles.Contains(testProfile)) { string skipReason = "Skipping test as it requires a compatible api profile set: " + string.Join(", ", apiProfiles.Select(p => p.ToString()).ToArray()); test.RunState = RunState.Skipped; test.Properties.Add(PropertyNames.SkipReason, skipReason); } }
public MonoIsland(BuildTarget target, bool editor, bool development_player, bool allowUnsafeCode, ApiCompatibilityLevel api_compatibility_level, string[] files, string[] references, string[] defines, string output) { _target = target; _development_player = development_player; _editor = editor; _allowUnsafeCode = allowUnsafeCode; _api_compatibility_level = api_compatibility_level; _files = files; _references = references; _defines = defines; _output = output; }
static string GetSystemReference(ApiCompatibilityLevel apiCompatibilityLevel) { if (apiCompatibilityLevel == ApiCompatibilityLevel.NET_Unity_4_8) { return(GetUnityReferenceProfileDirectory()); } if (apiCompatibilityLevel == ApiCompatibilityLevel.NET_2_0) { return(MonoInstallationFinder.GetProfileDirectory("2.0-api", MonoInstallationFinder.MonoBleedingEdgeInstallation)); } return(MonoInstallationFinder.GetProfileDirectory(BuildPipeline.CompatibilityProfileToClassLibFolder(apiCompatibilityLevel), MonoInstallationFinder.MonoBleedingEdgeInstallation)); }
private bool IsCompatibilitySet() { #if UNITY_2017_1_OR_NEWER // Get current api setting ApiCompatibilityLevel level = PlayerSettings.GetApiCompatibilityLevel(EditorUserBuildSettings.selectedBuildTargetGroup); // Check for accepted apis return(level == ApiCompatibilityLevel.NET_2_0 || level == ApiCompatibilityLevel.NET_4_6); #else return(PlayerSettings.apiCompatibilityLevel == ApiCompatibilityLevel.NET_2_0); #endif }
static void BackupSettings() { GetInput("Horizontal"); GetLayers(); GetQuality(); GetBuildSettings(); initial_RenderPath = PlayerSettings.renderingPath; initial_ColorSpace = PlayerSettings.colorSpace; initial_DefaultIsFullScreen = PlayerSettings.defaultIsFullScreen; initial_APICompatibilityLevel = PlayerSettings.apiCompatibilityLevel; initial_CompanyName = PlayerSettings.companyName; initial_ProductName = PlayerSettings.productName; }
public static string[] GetSystemLibraryReferences(ApiCompatibilityLevel apiCompatibilityLevel, BuildTarget buildTarget, SupportedLanguage supportedLanguage, bool buildingForEditor, string assemblyName) { if (WSAHelpers.BuildingForDotNet(buildTarget, buildingForEditor, assemblyName)) { return(new string[0]); } // The language may not be compatible with these additional references if (supportedLanguage != null && !supportedLanguage.CompilerRequiresAdditionalReferences()) { return(new string[0]); } return(GetCachedSystemLibraryReferences(apiCompatibilityLevel)); }
public static string GetSystemReferenceDirectory(ApiCompatibilityLevel apiCompatibilityLevel) { if (apiCompatibilityLevel == ApiCompatibilityLevel.NET_Standard_2_0) { return(""); } else if (apiCompatibilityLevel == ApiCompatibilityLevel.NET_4_6) { return(MonoInstallationFinder.GetProfileDirectory("4.7.1-api", MonoInstallationFinder.MonoBleedingEdgeInstallation)); } else if (apiCompatibilityLevel == ApiCompatibilityLevel.NET_2_0) { return(MonoInstallationFinder.GetProfileDirectory("2.0-api", MonoInstallationFinder.MonoBleedingEdgeInstallation)); } return(MonoInstallationFinder.GetProfileDirectory(BuildPipeline.CompatibilityProfileToClassLibFolder(apiCompatibilityLevel), MonoInstallationFinder.MonoBleedingEdgeInstallation)); }
static string[] GetCachedSystemLibraryReferences(ApiCompatibilityLevel apiCompatibilityLevel) { // We cache the references because they are computed by getting files in directories on disk, // which is very slow. if (cachedReferences != null && cachedReferences.ApiCompatibilityLevel == apiCompatibilityLevel) { return(cachedReferences.References); } var references = new List <string>(); var monoAssemblyDirectories = GetSystemReferenceDirectories(apiCompatibilityLevel); if (apiCompatibilityLevel == ApiCompatibilityLevel.NET_Standard) { references.AddRange(GetNetStandardClassLibraries()); } else if (apiCompatibilityLevel == ApiCompatibilityLevel.NET_Unity_4_8) { var systemReferences = GetSystemReferences().FindReferencesInDirectories(monoAssemblyDirectories); var net46References = GetNet46SystemReferences().FindReferencesInDirectories(monoAssemblyDirectories); var additionalSystemReferences = FindAllFilesInDirectories(monoAssemblyDirectories, "System.*.dll"); var facades = Directory.GetFiles(Path.Combine(GetUnityReferenceProfileDirectory(), "Facades"), "*.dll"); // Look in the mono assembly directory for a facade folder and get a list of all the DLL's to be // used later by the language compilers. references.AddRange(systemReferences .Concat(net46References) .Concat(additionalSystemReferences) .Concat(facades) .Distinct()); } else { references.AddRange(GetSystemReferences().FindReferencesInDirectories(monoAssemblyDirectories)); } cachedReferences = new CachedReferences { ApiCompatibilityLevel = apiCompatibilityLevel, References = references.ToArray() }; return(cachedReferences.References); }
internal static string ApiCompatibilityLevelToDotNetProfileArgument(ApiCompatibilityLevel compatibilityLevel) { switch (compatibilityLevel) { case ApiCompatibilityLevel.NET_2_0_Subset: return("legacyunity"); case ApiCompatibilityLevel.NET_2_0: return("net20"); case ApiCompatibilityLevel.NET_4_6: case ApiCompatibilityLevel.NET_Standard_2_0: return("unityaot"); default: throw new NotSupportedException(string.Format("ApiCompatibilityLevel.{0} is not supported by IL2CPP!", compatibilityLevel)); } }
internal static string ApiCompatibilityLevelToDotNetProfileArgument(ApiCompatibilityLevel compatibilityLevel, BuildTarget target) { switch (compatibilityLevel) { case ApiCompatibilityLevel.NET_2_0_Subset: return("legacyunity"); case ApiCompatibilityLevel.NET_2_0: return("net20"); case ApiCompatibilityLevel.NET_Unity_4_8: case ApiCompatibilityLevel.NET_Standard: return("unityaot-" + BuildTargetDiscovery.GetPlatformProfileSuffix(target)); default: throw new NotSupportedException(string.Format("ApiCompatibilityLevel.{0} is not supported by IL2CPP!", compatibilityLevel)); } }
static SetApiLevel() { #if UNITY_2018_2_OR_NEWER && UNITY_STANDALONE ApiCompatibilityLevel level = ApiCompatibilityLevel.NET_4_6; BuildTarget target = EditorUserBuildSettings.activeBuildTarget; BuildTargetGroup group = BuildPipeline.GetBuildTargetGroup(target); //Debug.Log("API level: " + PlayerSettings.GetApiCompatibilityLevel(group)); if (PlayerSettings.GetApiCompatibilityLevel(group) != level) { PlayerSettings.SetApiCompatibilityLevel(group, level); Debug.Log("API level changed to '" + level + "'"); } #endif }
static string[] GetCachedSystemLibraryReferences(ApiCompatibilityLevel apiCompatibilityLevel) { // We cache the references because they are computed by getting files in directories on disk, // which is very slow. if (cachedReferences != null && cachedReferences.ApiCompatibilityLevel == apiCompatibilityLevel) { return(cachedReferences.References); } var references = new List <string>(); var monoAssemblyDirectories = GetSystemReferenceDirectories(apiCompatibilityLevel); if (apiCompatibilityLevel == ApiCompatibilityLevel.NET_Standard_2_0) { references.AddRange(GetNetStandardClassLibraries()); } else if (apiCompatibilityLevel == ApiCompatibilityLevel.NET_4_6) { references.AddRange(GetSystemReferences().FindReferencesInDirectories(monoAssemblyDirectories)); references.AddRange(GetNet46SystemReferences().FindReferencesInDirectories(monoAssemblyDirectories)); // Look in the mono assembly directory for a facade folder and get a list of all the DLL's to be // used later by the language compilers. var monoAssemblyDirectory = MonoInstallationFinder.GetProfileDirectory("4.7.1-api", MonoInstallationFinder.MonoBleedingEdgeInstallation); references.AddRange(Directory.GetFiles(Path.Combine(monoAssemblyDirectory, "Facades"), "*.dll")); references.AddRange(GetBooAndUsReferences().Select(dll => Path.Combine(MonoInstallationFinder.GetProfileDirectory("unityscript", MonoInstallationFinder.MonoBleedingEdgeInstallation), dll))); } else { references.AddRange(GetSystemReferences().FindReferencesInDirectories(monoAssemblyDirectories)); references.AddRange(GetBooAndUsReferences().FindReferencesInDirectories(monoAssemblyDirectories)); } cachedReferences = new CachedReferences { ApiCompatibilityLevel = apiCompatibilityLevel, References = references.ToArray() }; return(cachedReferences.References); }
private void SetCompatibility() { #if UNITY_2017_1_OR_NEWER ApiCompatibilityLevel level = PlayerSettings.GetApiCompatibilityLevel(EditorUserBuildSettings.selectedBuildTargetGroup); // Check for 2.0 if (level == ApiCompatibilityLevel.NET_2_0_Subset) { // Change to full api PlayerSettings.SetApiCompatibilityLevel(EditorUserBuildSettings.selectedBuildTargetGroup, ApiCompatibilityLevel.NET_2_0); } else { // Change to 4.6 api because other apis are not supported PlayerSettings.SetApiCompatibilityLevel(EditorUserBuildSettings.selectedBuildTargetGroup, ApiCompatibilityLevel.NET_4_6); } #else PlayerSettings.apiCompatibilityLevel = ApiCompatibilityLevel.NET_2_0; #endif }
static SetApiLevel() { //TODO add new entries from Unity 2019 ApiCompatibilityLevel level = ApiCompatibilityLevel.NET_2_0; BuildTarget target = EditorUserBuildSettings.activeBuildTarget; BuildTargetGroup group = BuildPipeline.GetBuildTargetGroup(target); //Debug.Log("API level: " + PlayerSettings.GetApiCompatibilityLevel(group)); if (!PlayerSettings.GetApiCompatibilityLevel(group).ToString().Equals("NET_4_6") && PlayerSettings.GetApiCompatibilityLevel(group) != level #if UNITY_2018 || UNITY_2019 && PlayerSettings.GetApiCompatibilityLevel(group) != ApiCompatibilityLevel.NET_Standard_2_0 #endif ) { PlayerSettings.SetApiCompatibilityLevel(group, level); Debug.Log("API level changed to '" + level + "'"); } }
internal static string ApiCompatibilityLevelToDotNetProfileArgument(ApiCompatibilityLevel compatibilityLevel) { string result; switch (compatibilityLevel) { case ApiCompatibilityLevel.NET_2_0: result = "Net20"; break; case ApiCompatibilityLevel.NET_2_0_Subset: result = "Unity"; break; case ApiCompatibilityLevel.NET_4_6: result = "Net45"; break; default: throw new NotSupportedException(string.Format("ApiCompatibilityLevel.{0} is not supported by IL2CPP!", compatibilityLevel)); } return(result); }
private static void CheckApiCompatibilitySetting() { if (!PtSettings.Instance.warnOfApiCompatibility) { return; } BuildTargetGroup target = EditorUserBuildSettings.selectedBuildTargetGroup; ApiCompatibilityLevel apiCompat = PlayerSettings.GetApiCompatibilityLevel(target); ScriptingImplementation scriptBackend = PlayerSettings.GetScriptingBackend(target); // If the user is trying to build for the IL2CPP backend, and has something other than .NET 2.0 full // selected as API compatibility level, warn them. if (scriptBackend == ScriptingImplementation.IL2CPP && apiCompat != ApiCompatibilityLevel.NET_2_0) { EditorUtility.DisplayDialog("API Compatibility", "Warning: You are building for the IL2CPP script " + "backend (AOT compilation) and have '.NET 2.0 Subset' selected as API compatibility level.\n\n" + "Poly Toolkit runtime needs '.NET 2.0' (full) when compiling for IL2CPP, or runtime errors " + "may occur.\n\n" + "If you see problems, go to Player Settings and change your API compatibility level " + "to '.NET 2.0', and try to build again.\n\n" + "(You can silence this warning in Poly Toolkit settings if it's not useful)", "OK"); } }
public static string[] GetSystemReferenceDirectories(ApiCompatibilityLevel apiCompatibilityLevel) { if (apiCompatibilityLevel == ApiCompatibilityLevel.NET_Standard) { var systemReferenceDirectories = new List <string>(); systemReferenceDirectories.Add(NetStandardFinder.GetReferenceDirectory()); systemReferenceDirectories.Add(NetStandardFinder.GetNetStandardCompatShimsDirectory()); systemReferenceDirectories.Add(NetStandardFinder.GetNetStandardExtensionsDirectory()); systemReferenceDirectories.Add(NetStandardFinder.GetDotNetFrameworkCompatShimsDirectory()); return(systemReferenceDirectories.ToArray()); } if (apiCompatibilityLevel == ApiCompatibilityLevel.NET_Unity_4_8) { var systemReferenceDirectories = new List <string>(); var frameworkDirectory = GetSystemReference(apiCompatibilityLevel); systemReferenceDirectories.Add(frameworkDirectory); systemReferenceDirectories.Add(Path.Combine(frameworkDirectory, "Facades")); return(systemReferenceDirectories.ToArray()); } return(new[] { GetSystemReference(apiCompatibilityLevel) }); }
private static void SetCorrectDefine() { var haveChange = false; var symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone).Split(';').ToList(); ApiCompatibilityLevel apiLevel = PlayerSettings.GetApiCompatibilityLevel(EditorUserBuildSettings.selectedBuildTargetGroup); if (apiLevel == ApiCompatibilityLevel.NET_4_6 || apiLevel == ApiCompatibilityLevel.NET_Standard_2_0) { if (!File.Exists(Path.Combine(Application.dataPath, "csc.rsp")) || !File.ReadAllLines(Path.Combine(Application.dataPath, "csc.rsp")).Contains("-r:System.IO.Compression.FileSystem.dll")) { File.AppendAllText(Path.Combine(Application.dataPath, "csc.rsp"), "-r:System.IO.Compression.FileSystem.dll\n"); haveChange = true; symbols.Add("ZIP_AVAILABLE"); } } else { if (File.Exists(Path.Combine(Application.dataPath, "csc.rsp"))) { var allLine = File.ReadAllLines(Path.Combine(Application.dataPath, "csc.rsp")).ToList(); if (allLine.Contains("-r:System.IO.Compression.FileSystem.dll")) { allLine.Remove("-r:System.IO.Compression.FileSystem.dll"); File.WriteAllLines(Path.Combine(Application.dataPath, "csc.rsp"), allLine); haveChange = true; symbols.Remove("ZIP_AVAILABLE"); EditorUtility.DisplayDialog("NuGet importer", "NuGet importer work only .NET 4.x Equivalent.", "OK"); } } } if (haveChange) { PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, string.Join(";", symbols)); } }
/// <summary> /// Creates an editor <see cref="CompilationPlatformInfo"/> (think Assembly-CSharp-Editor). /// </summary> /// <returns>The editor <see cref="CompilationPlatformInfo"/>.</returns> public static CompilationPlatformInfo GetEditorPlatform() { ApiCompatibilityLevel cached = PlayerSettings.GetApiCompatibilityLevel(BuildTargetGroup.Unknown); PlayerSettings.SetApiCompatibilityLevel(BuildTargetGroup.Unknown, ApiCompatibilityLevel.NET_4_6); try { AssemblyBuilder builder = new AssemblyBuilder("editor.dll", new string[] { @"Editor\dummy.cs" }) { buildTarget = BuildTarget.NoTarget, buildTargetGroup = BuildTargetGroup.Unknown, flags = AssemblyBuilderFlags.EditorAssembly }; return(new CompilationPlatformInfo("Editor", BuildTarget.NoTarget, new HashSet <string>(), null, new HashSet <string>(builder.defaultDefines), new List <string>(), null, new List <string>(FilterOutProjectReferences(builder.defaultReferences)))); } finally { PlayerSettings.SetApiCompatibilityLevel(BuildTargetGroup.Unknown, cached); } }
static void ParseDLLs(string editorLogPath, bool wasWebBuild, string buildFilePath, string projectAssetsPath, string editorAppContentsPath, ApiCompatibilityLevel monoLevel, StrippingLevel codeStrippingLevel, out BuildReportTool.SizePart[] includedDLLs, out BuildReportTool.SizePart[] scriptDLLs) { List<BuildReportTool.SizePart> includedDLLsList = new List<BuildReportTool.SizePart>(); List<BuildReportTool.SizePart> scriptDLLsList = new List<BuildReportTool.SizePart>(); string buildManagedDLLsFolder = BuildReportTool.Util.GetBuildManagedFolder(buildFilePath); string buildScriptDLLsFolder = buildManagedDLLsFolder; string buildManagedDLLsFolderHigherPriority = ""; bool wasAndroidApkBuild = buildFilePath.EndsWith(".apk"); if (wasWebBuild) { string tryPath; bool success = BuildReportTool.Util.AttemptGetWebTempStagingArea(projectAssetsPath, out tryPath); if (success) { buildManagedDLLsFolder = tryPath; buildScriptDLLsFolder = tryPath; } } else if (wasAndroidApkBuild) { string tryPath; bool success = BuildReportTool.Util.AttemptGetAndroidTempStagingArea(projectAssetsPath, out tryPath); if (success) { buildManagedDLLsFolder = tryPath; buildScriptDLLsFolder = tryPath; } } string unityFolderManagedDLLs; bool unityfoldersSuccess = BuildReportTool.Util.AttemptGetUnityFolderMonoDLLs(wasWebBuild, wasAndroidApkBuild, editorAppContentsPath, monoLevel, codeStrippingLevel, out unityFolderManagedDLLs, out buildManagedDLLsFolderHigherPriority); //Debug.Log("buildManagedDLLsFolder: " + buildManagedDLLsFolder); //Debug.Log("Application.dataPath: " + Application.dataPath); if (unityfoldersSuccess && (string.IsNullOrEmpty(buildManagedDLLsFolder) || !Directory.Exists(buildManagedDLLsFolder))) { #if BRT_SHOW_MINOR_WARNINGS Debug.LogWarning("Could not find build folder. Using Unity install folder instead for getting mono DLL file sizes."); #endif buildManagedDLLsFolder = unityFolderManagedDLLs; } #if BRT_SHOW_MINOR_WARNINGS if (!Directory.Exists(buildManagedDLLsFolder)) { Debug.LogWarning("Could not find folder for getting DLL file sizes. Got: \"" + buildManagedDLLsFolder + "\""); } #endif const string PREFIX_REMOVE = "Dependency assembly - "; BuildReportTool.SizePart inPart; const string MONO_DLL_KEY = "Mono dependencies included in the build"; foreach (string line in DldUtil.BigFileReader.ReadFile(editorLogPath, MONO_DLL_KEY)) { // blank line signifies end of dll list if (string.IsNullOrEmpty(line) || line == "\n" || line == "\r\n") { break; } if (line.IndexOf(MONO_DLL_KEY) != -1) { continue; } string filename = line; filename = BuildReportTool.Util.RemovePrefix(PREFIX_REMOVE, filename); string filepath; if (BuildReportTool.Util.IsAScriptDLL(filename)) { filepath = buildScriptDLLsFolder + filename; //Debug.LogWarning("Script \"" + filepath + "\"."); } else { filepath = buildManagedDLLsFolder + filename; if (!File.Exists(filepath) && unityfoldersSuccess && (buildManagedDLLsFolder != unityFolderManagedDLLs)) { #if BRT_SHOW_MINOR_WARNINGS Debug.LogWarning("Failed to find file \"" + filepath + "\". Attempting to get from Unity folders."); #endif filepath = unityFolderManagedDLLs + filename; if (!string.IsNullOrEmpty(buildManagedDLLsFolderHigherPriority) && File.Exists(buildManagedDLLsFolderHigherPriority + filename)) { filepath = buildManagedDLLsFolderHigherPriority + filename; } } } if ((buildManagedDLLsFolder == unityFolderManagedDLLs) && !string.IsNullOrEmpty(buildManagedDLLsFolderHigherPriority) && File.Exists(buildManagedDLLsFolderHigherPriority + filename)) { filepath = buildManagedDLLsFolderHigherPriority + filename; } //Debug.Log(filename + " " + filepath); inPart = BuildReportTool.Util.CreateSizePartFromFile(filename, filepath); //gotTotalSizeBytes += inPart.SizeBytes; bool shouldGoInScriptDLLList = BuildReportTool.Util.IsAScriptDLL(filename); if (!File.Exists(unityFolderManagedDLLs + filename)) { shouldGoInScriptDLLList = true; } if (shouldGoInScriptDLLList) { //gotScriptTotalSizeBytes += inPart.SizeBytes; scriptDLLsList.Add(inPart); } else { includedDLLsList.Add(inPart); } } // somehow, the editor logfile // doesn't include UnityEngine.dll // even though it gets included in the final build (for desktop builds) // // for web builds though, it makes sense not to put UnityEngine.dll in the build. and it isn't. // Instead, it's likely residing in the browser plugin to save bandwidth. // // begs the question though, why not have the whole Mono Web Subset DLLs be // installed alongside the Unity web browser plugin? // no need to bundle Mono DLLs in the web build itself. // would have shaved 1 whole MB when a game uses System.Xml.dll for example // //if (!wasWebBuild) { string filename = "UnityEngine.dll"; string filepath = buildManagedDLLsFolder + filename; if (File.Exists(filepath)) { inPart = BuildReportTool.Util.CreateSizePartFromFile(filename, filepath); //gotTotalSizeBytes += inPart.SizeBytes; includedDLLsList.Add(inPart); } } //Debug.Log("total size: " + EditorUtility.FormatBytes(gotTotalSizeBytes) + " (" + gotTotalSizeBytes + " bytes)"); //Debug.Log("total assembly size: " + EditorUtility.FormatBytes(gotScriptTotalSizeBytes) + " (" + gotScriptTotalSizeBytes + " bytes)"); //Debug.Log("total size without assembly: " + EditorUtility.FormatBytes(gotTotalSizeBytes - gotScriptTotalSizeBytes) + " (" + (gotTotalSizeBytes-gotScriptTotalSizeBytes) + " bytes)"); includedDLLs = includedDLLsList.ToArray(); scriptDLLs = scriptDLLsList.ToArray(); }
public static bool AttemptGetUnityFolderMonoDLLs(bool wasWebBuild, bool wasAndroidApkBuild, string editorAppContentsPath, ApiCompatibilityLevel monoLevel, StrippingLevel codeStrippingLevel, out string path, out string higherPriorityPath) { bool success = false; // more hackery // attempt to get DLL size info // from Unity install folder // // this only happens in: // 1. Web build // 2. Android build // 3. Custom builders // string[] pathTries = new string[] { editorAppContentsPath + "/Frameworks/Mono/lib/mono", editorAppContentsPath + "/Mono/lib/mono", "/Applications/Unity/Unity.app/Contents/Frameworks/Mono/lib/mono", "C:/Program Files (x86)/Unity/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity/Editor/Data/Mono/lib/mono", #if UNITY_3_5 "/Applications/Unity3/Unity.app/Contents/Frameworks/Mono/lib/mono", "/Applications/Unity 3/Unity.app/Contents/Frameworks/Mono/lib/mono", "/Applications/Unity3.5/Unity.app/Contents/Frameworks/Mono/lib/mono", "/Applications/Unity 3.5/Unity.app/Contents/Frameworks/Mono/lib/mono", "C:/Program Files (x86)/Unity3/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity 3/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity3.5/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity 3.5/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity3/Editor/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity 3/Editor/Data/Mono/lib/mono", #endif #if UNITY_4_AND_GREATER "/Applications/Unity4/Unity.app/Contents/Frameworks/Mono/lib/mono", "/Applications/Unity 4/Unity.app/Contents/Frameworks/Mono/lib/mono", "C:/Program Files (x86)/Unity4/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity 4/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity4/Editor/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity 4/Editor/Data/Mono/lib/mono", #endif }; string tryPath = ""; for (int n = 0, len = pathTries.Length; n < len; ++n) { tryPath = pathTries[n]; if (Directory.Exists(tryPath)) { break; } tryPath = ""; } if (!string.IsNullOrEmpty(tryPath)) { success = true; // "unity_web" is obviously for the web build. Presumably, this one has DLLs removed that can compromise web security. // "2.0" is likely the full featured Mono libraries // "unity" is most likely the one used when selecting 2.0 subset in the player settings. this is the setting by default. // "micro" is probably the one used in StrippingLevel.UseMicroMSCorlib. only makes sense to be here when building on Android. // since in iOS, we already have the DLL files. No need for this hackery in iOS. But since in Android we do not have a project folder, // we resort to this. if (wasWebBuild) { path = tryPath + "/unity_web/"; } else if (monoLevel == ApiCompatibilityLevel.NET_2_0_Subset) { path = tryPath + "/unity/"; } else { path = tryPath + "/2.0/"; } if (wasAndroidApkBuild && codeStrippingLevel == StrippingLevel.UseMicroMSCorlib) { higherPriorityPath = tryPath + "/micro/"; } else { higherPriorityPath = ""; } } else { path = ""; higherPriorityPath = ""; } return success; }