private static void WriteIl2CppOutputProjectFile(
            BuildTargetGroup buildTargetGroup,
            string projectTemplate,
            string projectItems,
            string filterItems,
            string targetPath,
            string additionalDefines,
            IIl2CppPlatformProvider il2cppPlatformProvider)
        {
            string[]             buildingIl2CppArguments = IL2CPPUtils.GetBuildingIL2CPPArguments(il2cppPlatformProvider, buildTargetGroup);
            string[]             debuggerIl2CppArguments = IL2CPPUtils.GetDebuggerIL2CPPArguments(il2cppPlatformProvider, buildTargetGroup);
            string               str1               = ((IEnumerable <string>)debuggerIl2CppArguments).Any <string>() ? ((IEnumerable <string>)debuggerIl2CppArguments).Aggregate <string>((Func <string, string, string>)((x, y) => x + " " + y)) : string.Empty;
            IEnumerable <string> second             = ((IEnumerable <string>)additionalDefines.Split(';')).Select <string, string>((Func <string, string>)(d => "--additional-defines=" + d));
            string               str2               = ((IEnumerable <string>)buildingIl2CppArguments).Concat <string>(second).Aggregate <string>((Func <string, string, string>)((x, y) => x + " " + y));
            string               netProfileArgument = IL2CPPUtils.ApiCompatibilityLevelToDotNetProfileArgument(PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup));
            string               str3               = ((IEnumerable <string>)IL2CPPUtils.GetBuilderDefinedDefines(il2cppPlatformProvider, buildTargetGroup)).Aggregate <string>((Func <string, string, string>)((x, y) => x + ";" + y)) + ";" + additionalDefines;
            string               contents1          = string.Format(projectTemplate, (object)projectItems, (object)str3, (object)str2, (object)netProfileArgument, (object)str1);

            FileUtil.DeleteFileOrDirectory(targetPath);
            File.WriteAllText(targetPath, contents1, Encoding.UTF8);
            string path      = targetPath + ".filters";
            string contents2 = string.Format(VisualStudioProjectHelpers.GetFiltersTemplate(), (object)filterItems);

            FileUtil.DeleteFileOrDirectory(path);
            File.WriteAllText(path, contents2, Encoding.UTF8);
        }
Exemplo n.º 2
0
        LinkerConfig LinkerConfigFor(BuildPostProcessArgs args)
        {
            var namedBuildTarget = GetNamedBuildTarget(args);
            var strippingLevel   = PlayerSettings.GetManagedStrippingLevel(namedBuildTarget);

            // IL2CPP does not support a managed stripping level of disabled. If the player settings
            // do try this (which should not be possible from the editor), use Low instead.
            if (GetUseIl2Cpp(args) && strippingLevel == ManagedStrippingLevel.Disabled)
            {
                strippingLevel = ManagedStrippingLevel.Minimal;
            }

            if (strippingLevel > ManagedStrippingLevel.Disabled)
            {
                var rcr = args.usedClassRegistry;

                var additionalArgs = new List <string>();

                var diagArgs = Debug.GetDiagnosticSwitch("VMUnityLinkerAdditionalArgs").value as string;
                if (!string.IsNullOrEmpty(diagArgs))
                {
                    additionalArgs.Add(diagArgs.Trim('\''));
                }

                var engineStrippingFlags = new List <string>();

                if (UnityEngine.Connect.UnityConnectSettings.enabled)
                {
                    engineStrippingFlags.Add("EnableUnityConnect");
                }
                if (UnityEngine.Analytics.PerformanceReporting.enabled)
                {
                    engineStrippingFlags.Add("EnablePerformanceReporting");
                }
                if (UnityEngine.Analytics.Analytics.enabled)
                {
                    engineStrippingFlags.Add("EnableAnalytics");
                }
                if (UnityEditor.CrashReporting.CrashReportingSettings.enabled)
                {
                    engineStrippingFlags.Add("EnableCrashReporting");
                }

                NPath managedAssemblyFolderPath = $"{args.stagingAreaData}/Managed";
                var   linkerRunInformation      = new UnityLinkerRunInformation(managedAssemblyFolderPath.MakeAbsolute().ToString(), null, args.target,
                                                                                rcr, strippingLevel, null, args.report);
                AssemblyStripper.WriteEditorData(linkerRunInformation);

                return(new LinkerConfig
                {
                    LinkXmlFiles = AssemblyStripper.GetLinkXmlFiles(linkerRunInformation).ToArray(),
                    EditorToLinkerData = linkerRunInformation.EditorToLinkerDataPath.ToNPath().MakeAbsolute().ToString(),
                    AssembliesToProcess = rcr.GetUserAssemblies()
                                          .Where(s => rcr.IsDLLUsed(s))
                                          .ToArray(),
                    Runtime = GetUseIl2Cpp(args) ? "il2cpp" : "mono",
                    Profile = IL2CPPUtils.ApiCompatibilityLevelToDotNetProfileArgument(
                        PlayerSettings.GetApiCompatibilityLevel(namedBuildTarget), args.target),
                    Ruleset = strippingLevel switch
                    {
                        ManagedStrippingLevel.Minimal => "Minimal",
                        ManagedStrippingLevel.Low => "Conservative",
                        ManagedStrippingLevel.Medium => "Aggressive",
                        ManagedStrippingLevel.High => "Experimental",
                        _ => throw new ArgumentException($"Unhandled {nameof(ManagedStrippingLevel)} value")
                    },