コード例 #1
0
		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;
		}
コード例 #2
0
 private static bool StripAssembliesTo(string[] assemblies, string[] searchDirs, string outputFolder, string workingDirectory, out string output, out string error, string linkerPath, IIl2CppPlatformProvider platformProvider, IEnumerable<string> additionalBlacklist, bool developmentBuild)
 {
   // ISSUE: object of a compiler-generated type is created
   // ISSUE: variable of a compiler-generated type
   AssemblyStripper.\u003CStripAssembliesTo\u003Ec__AnonStorey65 assembliesToCAnonStorey65 = new AssemblyStripper.\u003CStripAssembliesTo\u003Ec__AnonStorey65();
   // ISSUE: reference to a compiler-generated field
   assembliesToCAnonStorey65.workingDirectory = workingDirectory;
   if (!Directory.Exists(outputFolder))
     Directory.CreateDirectory(outputFolder);
   // ISSUE: reference to a compiler-generated method
   additionalBlacklist = additionalBlacklist.Select<string, string>(new Func<string, string>(assembliesToCAnonStorey65.\u003C\u003Em__D4)).Where<string>(new Func<string, bool>(File.Exists));
   IEnumerable<string> userBlacklistFiles = AssemblyStripper.GetUserBlacklistFiles();
   foreach (string str in userBlacklistFiles)
     Console.WriteLine("UserBlackList: " + str);
   additionalBlacklist = additionalBlacklist.Concat<string>(userBlacklistFiles);
   List<string> stringList = new List<string>() { "-out \"" + outputFolder + "\"", "-l none", "-c link", "-b " + (object) developmentBuild, "-x \"" + AssemblyStripper.GetModuleWhitelist("Core", platformProvider.moduleStrippingInformationFolder) + "\"", "-f \"" + Path.Combine(platformProvider.il2CppFolder, "LinkerDescriptors") + "\"" };
   stringList.AddRange(additionalBlacklist.Select<string, string>((Func<string, string>) (path => "-x \"" + path + "\"")));
   stringList.AddRange(((IEnumerable<string>) searchDirs).Select<string, string>((Func<string, string>) (d => "-d \"" + d + "\"")));
   stringList.AddRange(((IEnumerable<string>) assemblies).Select<string, string>((Func<string, string>) (assembly => "-a  \"" + Path.GetFullPath(assembly) + "\"")));
   // ISSUE: reference to a compiler-generated field
   return AssemblyStripper.RunAssemblyLinker((IEnumerable<string>) stringList, out output, out error, linkerPath, assembliesToCAnonStorey65.workingDirectory);
 }
コード例 #3
0
 protected virtual void ProcessIl2CppOutputForSolution(BuildPostProcessArgs args, IIl2CppPlatformProvider il2cppPlatformProvider, IEnumerable <string> cppPlugins)
 {
     throw new NotSupportedException("CreateSolution is not supported on " + BuildPipeline.GetBuildTargetName(args.target));
 }
コード例 #4
0
        public static void WriteModuleAndClassRegistrationFile(string strippedAssemblyDir, string icallsListFile, string outputDir, RuntimeClassRegistry rcr, IEnumerable <UnityType> classesToSkip, IIl2CppPlatformProvider platformProvider, bool writeModuleRegistration = true, bool writeClassRegistration = true)
        {
            HashSet <UnityType> nativeClasses;
            HashSet <string>    nativeModules;
            // by default, we only care about il2cpp
            bool doStripping = PlayerSettings.stripEngineCode;

            GenerateDependencies(strippedAssemblyDir, icallsListFile, rcr, doStripping, out nativeClasses, out nativeModules, platformProvider);

            var outputClassRegistration = Path.Combine(outputDir, "UnityClassRegistration.cpp");

            using (TextWriter w = new StreamWriter(outputClassRegistration))
            {
                if (writeModuleRegistration)
                {
                    WriteFunctionRegisterStaticallyLinkedModulesGranular(w, nativeModules);
                }
                if (writeClassRegistration)
                {
                    WriteStaticallyLinkedModuleClassRegistration(w, nativeClasses, new HashSet <UnityType>(classesToSkip));
                }
                w.Close();
            }
        }
コード例 #5
0
        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 = GetRequiredAssemblies(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);
            }
        }
コード例 #6
0
        private static bool StripAssembliesTo(string[] assemblies, string[] searchDirs, string outputFolder, string workingDirectory, out string output, out string error, string linkerPath, IIl2CppPlatformProvider platformProvider, IEnumerable <string> additionalBlacklist, bool developmentBuild)
        {
            if (!Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }
            additionalBlacklist = (from s in additionalBlacklist
                                   select(!Path.IsPathRooted(s)) ? Path.Combine(workingDirectory, s) : s).Where(new Func <string, bool>(File.Exists));
            IEnumerable <string> userBlacklistFiles = AssemblyStripper.GetUserBlacklistFiles();

            foreach (string current in userBlacklistFiles)
            {
                Console.WriteLine("UserBlackList: " + current);
            }
            additionalBlacklist = additionalBlacklist.Concat(userBlacklistFiles);
            List <string> list = new List <string>
            {
                "-out \"" + outputFolder + "\"",
                "-l none",
                "-c link",
                "-b " + developmentBuild,
                "-x \"" + AssemblyStripper.GetModuleWhitelist("Core", platformProvider.moduleStrippingInformationFolder) + "\"",
                "-f \"" + Path.Combine(platformProvider.il2CppFolder, "LinkerDescriptors") + "\""
            };

            list.AddRange(from path in additionalBlacklist
                          select "-x \"" + path + "\"");
            list.AddRange(from d in searchDirs
                          select "-d \"" + d + "\"");
            list.AddRange(from assembly in assemblies
                          select "-a  \"" + Path.GetFullPath(assembly) + "\"");
            return(AssemblyStripper.RunAssemblyLinker(list, out output, out error, linkerPath, workingDirectory));
        }
コード例 #7
0
 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);
 }
コード例 #8
0
 internal static IL2CPPBuilder RunIl2Cpp(string stagingAreaData, IIl2CppPlatformProvider platformProvider, System.Action<string> modifyOutputBeforeCompile, RuntimeClassRegistry runtimeClassRegistry, bool developmentBuild)
 {
   IL2CPPBuilder il2CppBuilder = new IL2CPPBuilder(stagingAreaData, stagingAreaData, platformProvider, modifyOutputBeforeCompile, runtimeClassRegistry, developmentBuild);
   il2CppBuilder.Run();
   return il2CppBuilder;
 }
コード例 #9
0
        private static bool StripAssembliesTo(string[] assemblies, string[] searchDirs, string outputFolder, string workingDirectory, out string output, out string error, string linkerPath, IIl2CppPlatformProvider platformProvider, IEnumerable <string> additionalBlacklist, BuildTargetGroup buildTargetGroup, ManagedStrippingLevel managedStrippingLevel, bool stripEngineCode, string editorToLinkerDataPath)
        {
            if (!Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }

            additionalBlacklist = additionalBlacklist.Select(s => Path.IsPathRooted(s) ? s : Path.Combine(workingDirectory, s)).Where(File.Exists);

            var userBlackLists = GetUserBlacklistFiles();

            foreach (var ub in userBlackLists)
            {
                Console.WriteLine("UserBlackList: " + ub);
            }

            additionalBlacklist = additionalBlacklist.Concat(userBlackLists);

            var args = new List <string>
            {
                $"-out={CommandLineFormatter.PrepareFileName(outputFolder)}",
            };

            if (!UseUnityLinkerEngineModuleStripping)
            {
                args.Add($"-x={CommandLineFormatter.PrepareFileName(GetModuleWhitelist("Core", platformProvider.moduleStrippingInformationFolder))}");
            }

            args.AddRange(additionalBlacklist.Select(path => $"-x={CommandLineFormatter.PrepareFileName(path)}"));

            args.AddRange(searchDirs.Select(d => $"-d={CommandLineFormatter.PrepareFileName(d)}"));
            args.AddRange(assemblies.Select(assembly => $"--include-unity-root-assembly={CommandLineFormatter.PrepareFileName(Path.GetFullPath(assembly))}"));
            args.Add($"--dotnetruntime={GetRuntimeArgumentValueForLinker(buildTargetGroup)}");
            args.Add($"--dotnetprofile={GetProfileArgumentValueForLinker(buildTargetGroup)}");
            args.Add("--use-editor-options");
            args.Add($"--include-directory={CommandLineFormatter.PrepareFileName(workingDirectory)}");

            if (EditorUserBuildSettings.allowDebugging)
            {
                args.Add("--editor-settings-flag=AllowDebugging");
            }

            if (EditorUserBuildSettings.development)
            {
                args.Add("--editor-settings-flag=Development");
            }

            args.Add($"--rule-set={GetRuleSetForStrippingLevel(managedStrippingLevel)}");
            args.Add($"--editor-data-file={CommandLineFormatter.PrepareFileName(editorToLinkerDataPath)}");

            var compilerPlatform     = "";
            var compilerArchitecture = "";
            Il2CppNativeCodeBuilder il2cppNativeCodeBuilder = platformProvider.CreateIl2CppNativeCodeBuilder();

            if (il2cppNativeCodeBuilder != null)
            {
                compilerPlatform     = il2cppNativeCodeBuilder.CompilerPlatform;
                compilerArchitecture = il2cppNativeCodeBuilder.CompilerArchitecture;
            }
            else
            {
                // When the scripting backend is not IL2CPP, we have to map those strings and use a utility function to figure out proper strings.
                GetUnityLinkerPlatformStringsFromBuildTarget(platformProvider.target, out compilerPlatform, out compilerArchitecture);
            }

            args.Add($"--platform={compilerPlatform}");
            if (!string.IsNullOrEmpty(compilerArchitecture))
            {
                args.Add($"--architecture={compilerArchitecture}");
            }

            if (!UseUnityLinkerEngineModuleStripping)
            {
                args.Add("--disable-engine-module-support");
            }

            if (stripEngineCode)
            {
                args.Add("--enable-engine-module-stripping");

                if (UnityEngine.Connect.UnityConnectSettings.enabled)
                {
                    args.Add("--engine-stripping-flag=EnableUnityConnect");
                }

                if (UnityEngine.Analytics.PerformanceReporting.enabled)
                {
                    args.Add("--engine-stripping-flag=EnablePerformanceReporting");
                }

                if (UnityEngine.Analytics.Analytics.enabled)
                {
                    args.Add("--engine-stripping-flag=EnableAnalytics");
                }

                if (UnityEditor.CrashReporting.CrashReportingSettings.enabled)
                {
                    args.Add("--engine-stripping-flag=EnableCrashReporting");
                }

                if (UnityEditorInternal.VR.VRModule.ShouldInjectVRDependenciesForBuildTarget(platformProvider.target))
                {
                    args.Add("--engine-stripping-flag=EnableVR");
                }
            }

            var modulesAssetPath = Path.Combine(platformProvider.moduleStrippingInformationFolder, "../modules.asset");

            if (File.Exists(modulesAssetPath))
            {
                args.Add($"--engine-modules-asset-file={CommandLineFormatter.PrepareFileName(modulesAssetPath)}");
            }

            var additionalArgs = System.Environment.GetEnvironmentVariable("UNITYLINKER_ADDITIONAL_ARGS");

            if (!string.IsNullOrEmpty(additionalArgs))
            {
                args.Add(additionalArgs);
            }

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

            return(RunAssemblyLinker(args, out output, out error, linkerPath, workingDirectory));
        }
コード例 #10
0
        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   engineStrippingSupported = platformProvider.supportsEngineStripping && !isMono;
            bool   performEngineStripping   = rcr != null && PlayerSettings.stripEngineCode && engineStrippingSupported;
            IEnumerable <string> blacklists = Il2CppBlacklistPaths;

            if (rcr != null)
            {
                blacklists = blacklists.Concat(new[]
                {
                    WriteMethodsToPreserveBlackList(rcr, platformProvider.target),
                    MonoAssemblyStripping.GenerateLinkXmlToPreserveDerivedTypes(managedAssemblyFolderPath, rcr),
                    WriteTypesInScenesBlacklist(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 });
                    }
                }
            }

            string editorToLinkerDataPath = WriteEditorData(managedAssemblyFolderPath, rcr);

            if (!performEngineStripping && !UseUnityLinkerEngineModuleStripping)
            {
                // 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,
                        performEngineStripping,
                        editorToLinkerDataPath))
                {
                    throw new Exception("Error in stripping assemblies: " + assemblies + ", " + error);
                }

                if (engineStrippingSupported)
                {
                    var icallSummaryPath = Path.Combine(managedAssemblyFolderPath, "ICallSummary.txt");
                    GenerateInternalCallSummaryFile(icallSummaryPath, managedAssemblyFolderPath, tempStripPath);

                    if (performEngineStripping && !UseUnityLinkerEngineModuleStripping)
                    {
                        // Find which modules we must include in the build based on Assemblies
                        HashSet <UnityType> nativeClasses;
                        HashSet <string>    nativeModules;
                        CodeStrippingUtils.GenerateDependencies(tempStripPath, icallSummaryPath, rcr, performEngineStripping, out nativeClasses, out nativeModules, platformProvider);
                        // Add module-specific blacklists.
                        addedMoreBlacklists = AddWhiteListsForModules(nativeModules, ref blacklists, platformProvider.moduleStrippingInformationFolder);
                    }
                }

                if (performEngineStripping && UseUnityLinkerEngineModuleStripping)
                {
                    UpdateBuildReport(ReadLinkerToEditorData(tempStripPath), platformProvider);
                }

                // If we had to add more whitelists, we need to run AssemblyStripper again with the added whitelists.
            }while (addedMoreBlacklists && !UseUnityLinkerEngineModuleStripping);

            // 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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
 protected virtual void WriteIl2CppOutputProject(BuildPostProcessArgs args, string il2cppOutputProjectDirectory, IIl2CppPlatformProvider il2cppPlatformProvider)
 {
     throw new NotSupportedException("CreateSolution is not supported on " + BuildPipeline.GetBuildTargetName(args.target));
 }
コード例 #13
0
        internal static IL2CPPBuilder RunIl2Cpp(string tempFolder, string stagingAreaData, IIl2CppPlatformProvider platformProvider, Action <string> modifyOutputBeforeCompile, RuntimeClassRegistry runtimeClassRegistry)
        {
            IL2CPPBuilder iL2CPPBuilder = new IL2CPPBuilder(tempFolder, stagingAreaData, platformProvider, modifyOutputBeforeCompile, runtimeClassRegistry);

            iL2CPPBuilder.Run();
            return(iL2CPPBuilder);
        }
コード例 #14
0
        internal static IL2CPPBuilder RunCompileAndLink(string tempFolder, string stagingAreaData, IIl2CppPlatformProvider platformProvider, Action <string> modifyOutputBeforeCompile, RuntimeClassRegistry runtimeClassRegistry, string il2cppBuildCacheSource)
        {
            var builder = new IL2CPPBuilder(tempFolder, stagingAreaData, platformProvider, modifyOutputBeforeCompile, runtimeClassRegistry, IL2CPPUtils.UseIl2CppCodegenWithMonoBackend(platformProvider.namedBuildTarget));

            builder.RunCompileAndLink(il2cppBuildCacheSource);
            return(builder);
        }
コード例 #15
0
        public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker, string stagingAreaDataManaged, IIl2CppPlatformProvider platformProvider)
        {
            string text = Path.Combine(stagingAreaDataManaged, "ICallSummary.txt");
            IEnumerable <string> source = Directory.GetFiles(stagingAreaDataManaged, "UnityEngine.*Module.dll").Concat(new string[]
            {
                Path.Combine(stagingAreaDataManaged, "UnityEngine.dll")
            });
            string exe  = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Tools/InternalCallRegistrationWriter/InternalCallRegistrationWriter.exe");
            string args = string.Format("-assembly=\"{0}\" -summary=\"{1}\"", source.Aggregate((string dllArg, string next) => dllArg + ";" + next), text);

            Runner.RunManagedProgram(exe, args);
            HashSet <UnityType> hashSet;
            HashSet <string>    nativeModules;

            CodeStrippingUtils.GenerateDependencies(Path.GetDirectoryName(stagingAreaDataManaged), text, usedClassRegistry, stripping, out hashSet, out nativeModules, platformProvider);
            using (TextWriter textWriter = new StreamWriter(file))
            {
                string[]             assemblyFileNames   = checker.GetAssemblyFileNames();
                AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions();
                bool      flag      = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic;
                ArrayList arrayList = MonoAOTRegistration.BuildNativeMethodList(assemblyDefinitions);
                if (buildTarget == BuildTarget.iOS)
                {
                    textWriter.WriteLine("#include \"RegisterMonoModules.h\"");
                    textWriter.WriteLine("#include <stdio.h>");
                }
                textWriter.WriteLine("");
                textWriter.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR");
                textWriter.WriteLine("    #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))");
                textWriter.WriteLine("    #define REGISTER_USER_FUNC(f)\\");
                textWriter.WriteLine("        do {\\");
                textWriter.WriteLine("        if(f != NULL)\\");
                textWriter.WriteLine("            mono_dl_register_symbol(#f, (void*)f);\\");
                textWriter.WriteLine("        else\\");
                textWriter.WriteLine("            ::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\");
                textWriter.WriteLine("        }while(0)");
                textWriter.WriteLine("#else");
                textWriter.WriteLine("    #define DECL_USER_FUNC(f) void f() ");
                textWriter.WriteLine("    #if !defined(__arm64__)");
                textWriter.WriteLine("    #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)");
                textWriter.WriteLine("    #else");
                textWriter.WriteLine("        #define REGISTER_USER_FUNC(f)");
                textWriter.WriteLine("    #endif");
                textWriter.WriteLine("#endif");
                textWriter.WriteLine("extern \"C\"\n{");
                textWriter.WriteLine("    typedef void* gpointer;");
                textWriter.WriteLine("    typedef int gboolean;");
                if (buildTarget == BuildTarget.iOS)
                {
                    textWriter.WriteLine("    const char*         UnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion);
                    textWriter.WriteLine("    void                mono_dl_register_symbol (const char* name, void *addr);");
                    textWriter.WriteLine("#if !defined(__arm64__)");
                    textWriter.WriteLine("    extern int          mono_ficall_flag;");
                    textWriter.WriteLine("#endif");
                }
                textWriter.WriteLine("    void                mono_aot_register_module(gpointer *aot_info);");
                textWriter.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2");
                textWriter.WriteLine("#define DLL_EXPORT __declspec(dllexport)");
                textWriter.WriteLine("#else");
                textWriter.WriteLine("#define DLL_EXPORT");
                textWriter.WriteLine("#endif");
                textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)");
                textWriter.WriteLine("    extern gboolean     mono_aot_only;");
                for (int i = 0; i < assemblyFileNames.Length; i++)
                {
                    string arg   = assemblyFileNames[i];
                    string text2 = assemblyDefinitions[i].Name.Name;
                    text2 = text2.Replace(".", "_");
                    text2 = text2.Replace("-", "_");
                    text2 = text2.Replace(" ", "_");
                    textWriter.WriteLine("    extern gpointer*    mono_aot_module_{0}_info; // {1}", text2, arg);
                }
                textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)");
                IEnumerator enumerator = arrayList.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        string arg2 = (string)enumerator.Current;
                        textWriter.WriteLine("    DECL_USER_FUNC({0});", arg2);
                    }
                }
                finally
                {
                    IDisposable disposable;
                    if ((disposable = (enumerator as IDisposable)) != null)
                    {
                        disposable.Dispose();
                    }
                }
                textWriter.WriteLine("}");
                textWriter.WriteLine("DLL_EXPORT void RegisterMonoModules()");
                textWriter.WriteLine("{");
                textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
                textWriter.WriteLine("    mono_aot_only = true;");
                if (buildTarget == BuildTarget.iOS)
                {
                    textWriter.WriteLine("    mono_ficall_flag = {0};", (!flag) ? "false" : "true");
                }
                AssemblyDefinition[] array = assemblyDefinitions;
                for (int j = 0; j < array.Length; j++)
                {
                    AssemblyDefinition assemblyDefinition = array[j];
                    string             text3 = assemblyDefinition.Name.Name;
                    text3 = text3.Replace(".", "_");
                    text3 = text3.Replace("-", "_");
                    text3 = text3.Replace(" ", "_");
                    textWriter.WriteLine("    mono_aot_register_module(mono_aot_module_{0}_info);", text3);
                }
                textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
                textWriter.WriteLine("");
                if (buildTarget == BuildTarget.iOS)
                {
                    IEnumerator enumerator2 = arrayList.GetEnumerator();
                    try
                    {
                        while (enumerator2.MoveNext())
                        {
                            string arg3 = (string)enumerator2.Current;
                            textWriter.WriteLine("    REGISTER_USER_FUNC({0});", arg3);
                        }
                    }
                    finally
                    {
                        IDisposable disposable2;
                        if ((disposable2 = (enumerator2 as IDisposable)) != null)
                        {
                            disposable2.Dispose();
                        }
                    }
                }
                textWriter.WriteLine("}");
                textWriter.WriteLine("");
                if (buildTarget == BuildTarget.iOS)
                {
                    List <AssemblyDefinition> list = new List <AssemblyDefinition>();
                    for (int k = 0; k < assemblyDefinitions.Length; k++)
                    {
                        if (AssemblyHelper.IsUnityEngineModule(assemblyDefinitions[k]))
                        {
                            list.Add(assemblyDefinitions[k]);
                        }
                    }
                    MonoAOTRegistration.GenerateRegisterInternalCalls(list.ToArray(), textWriter);
                    MonoAOTRegistration.GenerateRegisterModules(hashSet, nativeModules, textWriter, stripping);
                    if (stripping && usedClassRegistry != null)
                    {
                        MonoAOTRegistration.GenerateRegisterClassesForStripping(hashSet, textWriter);
                    }
                    else
                    {
                        MonoAOTRegistration.GenerateRegisterClasses(hashSet, textWriter);
                    }
                }
                textWriter.Close();
            }
        }
コード例 #16
0
        private static void RunAssemblyStripper(string stagingAreaData, IEnumerable assemblies, string managedAssemblyFolderPath, string[] assembliesToStrip, string[] searchDirs, string monoLinkerPath, IIl2CppPlatformProvider platformProvider, RuntimeClassRegistry rcr)
        {
            BuildTargetGroup     buildTargetGroup = BuildPipeline.GetBuildTargetGroup(platformProvider.target);
            bool                 flag             = PlayerSettings.GetScriptingBackend(buildTargetGroup) == ScriptingImplementation.Mono2x;
            bool                 flag2            = 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)
                });
            }
            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 path2 = Path.Combine(platformProvider.il2CppFolder, "LinkerDescriptors");
                enumerable = enumerable.Concat(Directory.GetFiles(path2, "*_mono.xml"));
                string text = Path.Combine(BuildPipeline.GetBuildToolsDirectory(platformProvider.target), "link.xml");
                if (File.Exists(text))
                {
                    enumerable = enumerable.Concat(new string[]
                    {
                        text
                    });
                }
            }
            if (!flag2)
            {
                string[] files = Directory.GetFiles(platformProvider.moduleStrippingInformationFolder, "*.xml");
                for (int i = 0; i < files.Length; i++)
                {
                    string text2 = files[i];
                    enumerable = enumerable.Concat(new string[]
                    {
                        text2
                    });
                }
            }
            string fullPath = Path.GetFullPath(Path.Combine(managedAssemblyFolderPath, "tempStrip"));
            string text4;

            while (true)
            {
                bool flag3 = false;
                if (EditorUtility.DisplayCancelableProgressBar("Building Player", "Stripping assemblies", 0f))
                {
                    break;
                }
                string text3;
                if (!AssemblyStripper.StripAssembliesTo(assembliesToStrip, searchDirs, fullPath, managedAssemblyFolderPath, out text3, out text4, monoLinkerPath, platformProvider, enumerable))
                {
                    goto Block_9;
                }
                if (platformProvider.supportsEngineStripping)
                {
                    string text5 = Path.Combine(managedAssemblyFolderPath, "ICallSummary.txt");
                    AssemblyStripper.GenerateInternalCallSummaryFile(text5, managedAssemblyFolderPath, fullPath);
                    if (flag2)
                    {
                        HashSet <UnityType> hashSet;
                        HashSet <string>    nativeModules;
                        CodeStrippingUtils.GenerateDependencies(fullPath, text5, rcr, flag2, out hashSet, out nativeModules, platformProvider);
                        flag3 = AssemblyStripper.AddWhiteListsForModules(nativeModules, ref enumerable, platformProvider.moduleStrippingInformationFolder);
                    }
                }
                if (!flag3)
                {
                    goto Block_12;
                }
            }
            throw new OperationCanceledException();
Block_9:
            throw new Exception(string.Concat(new object[]
            {
                "Error in stripping assemblies: ",
                assemblies,
                ", ",
                text4
            }));
Block_12:
            string fullPath2 = Path.GetFullPath(Path.Combine(managedAssemblyFolderPath, "tempUnstripped"));

            if (AssemblyStripper.debugUnstripped)
            {
                Directory.CreateDirectory(fullPath2);
            }
            string[] files2 = Directory.GetFiles(managedAssemblyFolderPath);
            for (int j = 0; j < files2.Length; j++)
            {
                string text6     = files2[j];
                string extension = Path.GetExtension(text6);
                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 (AssemblyStripper.debugUnstripped)
                    {
                        File.Move(text6, Path.Combine(fullPath2, Path.GetFileName(text6)));
                    }
                    else
                    {
                        File.Delete(text6);
                    }
                }
            }
            string[] files3 = Directory.GetFiles(fullPath);
            for (int k = 0; k < files3.Length; k++)
            {
                string text7 = files3[k];
                File.Move(text7, Path.Combine(managedAssemblyFolderPath, Path.GetFileName(text7)));
            }
            Directory.Delete(fullPath);
        }
コード例 #17
0
        private static bool StripAssembliesTo(string[] assemblies, string[] searchDirs, string outputFolder, string workingDirectory, out string output, out string error, string linkerPath, IIl2CppPlatformProvider platformProvider, IEnumerable <string> additionalBlacklist)
        {
            if (!Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }
            IEnumerable <string> arg_50_0 = from s in additionalBlacklist
                                            select(!Path.IsPathRooted(s)) ? Path.Combine(workingDirectory, s) : s;

            if (AssemblyStripper.< > f__mg$cache0 == null)
            {
                AssemblyStripper.< > f__mg$cache0 = new Func <string, bool>(File.Exists);
            }
            additionalBlacklist = arg_50_0.Where(AssemblyStripper.< > f__mg$cache0);
            IEnumerable <string> userBlacklistFiles = AssemblyStripper.GetUserBlacklistFiles();

            foreach (string current in userBlacklistFiles)
            {
                Console.WriteLine("UserBlackList: " + current);
            }
            additionalBlacklist = additionalBlacklist.Concat(userBlacklistFiles);
            List <string> list = new List <string>
            {
                "--api=" + PlayerSettings.GetApiCompatibilityLevel(EditorUserBuildSettings.activeBuildTargetGroup).ToString(),
                "-out=\"" + outputFolder + "\"",
                "-l=none",
                "-c=link",
                "--link-symbols",
                "-x=\"" + AssemblyStripper.GetModuleWhitelist("Core", platformProvider.moduleStrippingInformationFolder) + "\"",
                "-f=\"" + Path.Combine(platformProvider.il2CppFolder, "LinkerDescriptors") + "\""
            };

            list.AddRange(from path in additionalBlacklist
                          select "-x \"" + path + "\"");
            list.AddRange(from d in searchDirs
                          select "-d \"" + d + "\"");
            list.AddRange(from assembly in assemblies
                          select "-a  \"" + Path.GetFullPath(assembly) + "\"");
            return(AssemblyStripper.RunAssemblyLinker(list, out output, out error, linkerPath, workingDirectory));
        }
コード例 #18
0
        internal static string[] GetBuilderDefinedDefines(IIl2CppPlatformProvider il2cppPlatformProvider, BuildTargetGroup buildTargetGroup)
        {
            List <string> defines = new List <string>();
            var           apiCompatibilityLevel = PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup);

            switch (apiCompatibilityLevel)
            {
            case ApiCompatibilityLevel.NET_2_0:
            case ApiCompatibilityLevel.NET_2_0_Subset:
                defines.AddRange(BaseDefines20);
                break;

            case ApiCompatibilityLevel.NET_4_6:
            case ApiCompatibilityLevel.NET_Standard_2_0:
                defines.AddRange(BaseDefines46);
                break;

            default:
                throw new InvalidOperationException($"IL2CPP doesn't support building with {apiCompatibilityLevel} API compatibility level!");
            }


            var target = il2cppPlatformProvider.target;

            if (target == BuildTarget.StandaloneWindows || target == BuildTarget.StandaloneWindows64 ||
                target == BuildTarget.XboxOne || target == BuildTarget.WSAPlayer)
            {
                defines.AddRange(BaseDefinesWindows);

                if (target == BuildTarget.WSAPlayer)
                {
                    defines.Add("WINAPI_FAMILY=WINAPI_FAMILY_APP");
                }
                else
                {
                    defines.Add("WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP");
                }
            }

            if (EnableIL2CPPDebugger(il2cppPlatformProvider, buildTargetGroup))
            {
                defines.Add("IL2CPP_MONO_DEBUGGER=1");
            }

            if (BuildPipeline.IsFeatureSupported("ENABLE_SCRIPTING_GC_WBARRIERS", target))
            {
                var hasGCBarrierValidation = PlayerSettings.gcWBarrierValidation;
                if (hasGCBarrierValidation)
                {
                    defines.Add("IL2CPP_ENABLE_STRICT_WRITE_BARRIERS=1");
                    defines.Add("IL2CPP_ENABLE_WRITE_BARRIER_VALIDATION=1");
                }

                var hasIncrementalGCTimeSlice = PlayerSettings.gcIncremental && (apiCompatibilityLevel == ApiCompatibilityLevel.NET_4_6 || apiCompatibilityLevel == ApiCompatibilityLevel.NET_Standard_2_0);

                if (hasGCBarrierValidation || hasIncrementalGCTimeSlice)
                {
                    var timeslice = hasIncrementalGCTimeSlice ? "3" : "0";
                    defines.Add("IL2CPP_ENABLE_WRITE_BARRIERS=1");
                    defines.Add($"IL2CPP_INCREMENTAL_TIME_SLICE={timeslice}");
                }
            }

            return(defines.ToArray());
        }
コード例 #19
0
		internal static IL2CPPBuilder RunIl2Cpp(string stagingAreaData, IIl2CppPlatformProvider platformProvider, Action<string> modifyOutputBeforeCompile, RuntimeClassRegistry runtimeClassRegistry)
		{
			IL2CPPBuilder iL2CPPBuilder = new IL2CPPBuilder(stagingAreaData, stagingAreaData, platformProvider, modifyOutputBeforeCompile, runtimeClassRegistry);
			iL2CPPBuilder.Run();
			return iL2CPPBuilder;
		}
コード例 #20
0
        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);
        }
コード例 #21
0
 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);
 }
コード例 #22
0
        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);
            }
            CodeStrippingUtils.ApplyManualStrippingOverrides(nativeClasses, nativeModules, strippingInfo);
            bool flag = true;

            if (platformProvider != null)
            {
                while (flag)
                {
                    flag = false;
                    foreach (string current2 in nativeModules.ToList <string>())
                    {
                        string[] moduleDependencies = ModuleMetadata.GetModuleDependencies(current2);
                        if (moduleDependencies != null)
                        {
                            string[] array2 = moduleDependencies;
                            for (int j = 0; j < array2.Length; j++)
                            {
                                string text = array2[j];
                                if (!nativeModules.Contains(text))
                                {
                                    nativeModules.Add(text);
                                    flag = true;
                                }
                                if (strippingInfo != null)
                                {
                                    string str = StrippingInfo.ModuleName(current2);
                                    strippingInfo.RegisterDependency(StrippingInfo.ModuleName(text), "Required by " + str);
                                    strippingInfo.SetIcon("Required by " + str, string.Format("package/com.unity.modules.{0}", current2.ToLower()));
                                }
                            }
                        }
                    }
                }
            }
            AssemblyReferenceChecker assemblyReferenceChecker = new AssemblyReferenceChecker();

            assemblyReferenceChecker.CollectReferencesFromRoots(strippedAssemblyDir, userAssemblies, true, 0f, true);
            if (strippingInfo != null)
            {
                foreach (string current3 in nativeModules)
                {
                    strippingInfo.AddModule(current3, true);
                }
                strippingInfo.AddModule("Core", true);
            }
            if (nativeClasses != null && strippingInfo != null)
            {
                CodeStrippingUtils.InjectCustomDependencies(platformProvider.target, strippingInfo, nativeClasses, nativeModules);
            }
        }
コード例 #23
0
        public static void WriteModuleAndClassRegistrationFile(string strippedAssemblyDir, string icallsListFile, string outputDir, RuntimeClassRegistry rcr, IEnumerable <UnityType> classesToSkip, IIl2CppPlatformProvider platformProvider)
        {
            bool stripEngineCode = PlayerSettings.stripEngineCode;
            HashSet <UnityType> nativeClasses;
            HashSet <string>    nativeModules;

            CodeStrippingUtils.GenerateDependencies(strippedAssemblyDir, icallsListFile, rcr, stripEngineCode, out nativeClasses, out nativeModules, platformProvider);
            string file = Path.Combine(outputDir, "UnityClassRegistration.cpp");

            CodeStrippingUtils.WriteModuleAndClassRegistrationFile(file, nativeModules, nativeClasses, new HashSet <UnityType>(classesToSkip));
        }
コード例 #24
0
        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),
                    MonoAssemblyStripping.GenerateLinkXmlToPreserveDerivedTypes(stagingAreaData, managedAssemblyFolderPath, 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, platformProvider.buildReport);
                    flag2 = AssemblyStripper.AddWhiteListsForModules(nativeModules, ref enumerable, platformProvider.moduleStrippingInformationFolder, platformProvider.buildReport);
                }
                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);
        }