Example #1
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);
        }
        private static void RunAssemblyStripper(string stagingAreaData, IEnumerable assemblies, string managedAssemblyFolderPath, string[] assembliesToStrip, string[] searchDirs, string monoLinkerPath, IIl2CppPlatformProvider platformProvider, RuntimeClassRegistry rcr)
        {
            bool flag = rcr != null && PlayerSettings.stripEngineCode && platformProvider.supportsEngineStripping;
            IEnumerable <string> enumerable = AssemblyStripper.Il2CppBlacklistPaths;

            if (rcr != null)
            {
                enumerable = enumerable.Concat(new string[]
                {
                    AssemblyStripper.WriteMethodsToPreserveBlackList(stagingAreaData, rcr),
                    MonoAssemblyStripping.GenerateLinkXmlToPreserveDerivedTypes(stagingAreaData, managedAssemblyFolderPath, rcr)
                });
            }
            BuildTargetGroup buildTargetGroup = BuildPipeline.GetBuildTargetGroup(platformProvider.target);

            if (PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup) == ApiCompatibilityLevel.NET_4_6)
            {
                string path = Path.Combine(platformProvider.il2CppFolder, "LinkerDescriptors");
                enumerable = enumerable.Concat(Directory.GetFiles(path, "*45.xml"));
            }
            if (!flag)
            {
                string[] files = Directory.GetFiles(platformProvider.moduleStrippingInformationFolder, "*.xml");
                for (int i = 0; i < files.Length; i++)
                {
                    string text = files[i];
                    enumerable = enumerable.Concat(new string[]
                    {
                        text
                    });
                }
            }
            string fullPath = Path.GetFullPath(Path.Combine(managedAssemblyFolderPath, "tempStrip"));
            string text3;

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

            Directory.CreateDirectory(fullPath2);
            string[] files2 = Directory.GetFiles(managedAssemblyFolderPath);
            for (int j = 0; j < files2.Length; j++)
            {
                string text5     = files2[j];
                string extension = Path.GetExtension(text5);
                if (string.Equals(extension, ".dll", StringComparison.InvariantCultureIgnoreCase) || string.Equals(extension, ".winmd", StringComparison.InvariantCultureIgnoreCase) || string.Equals(extension, ".mdb", StringComparison.InvariantCultureIgnoreCase) || string.Equals(extension, ".pdb", StringComparison.InvariantCultureIgnoreCase))
                {
                    File.Move(text5, Path.Combine(fullPath2, Path.GetFileName(text5)));
                }
            }
            string[] files3 = Directory.GetFiles(fullPath);
            for (int k = 0; k < files3.Length; k++)
            {
                string text6 = files3[k];
                File.Move(text6, Path.Combine(managedAssemblyFolderPath, Path.GetFileName(text6)));
            }
            Directory.Delete(fullPath);
        }
        private static void RunAssemblyStripper(string stagingAreaData, IEnumerable assemblies, string managedAssemblyFolderPath, string[] assembliesToStrip, string[] searchDirs, string monoLinkerPath, IIl2CppPlatformProvider platformProvider, RuntimeClassRegistry rcr, bool developmentBuild)
        {
            bool flag = rcr != null && PlayerSettings.stripEngineCode && platformProvider.supportsEngineStripping;
            IEnumerable <string> enumerable = AssemblyStripper.Il2CppBlacklistPaths;

            if (rcr != null)
            {
                enumerable = enumerable.Concat(new string[]
                {
                    AssemblyStripper.WriteMethodsToPreserveBlackList(stagingAreaData, rcr)
                });
            }
            if (!flag)
            {
                string[] files = Directory.GetFiles(platformProvider.moduleStrippingInformationFolder, "*.xml");
                for (int i = 0; i < files.Length; i++)
                {
                    string text = files[i];
                    enumerable = enumerable.Concat(new string[]
                    {
                        text
                    });
                }
            }
            string fullPath = Path.GetFullPath(Path.Combine(managedAssemblyFolderPath, "tempStrip"));
            string text3;

            while (true)
            {
                bool flag2 = false;
                if (EditorUtility.DisplayCancelableProgressBar("Building Player", "Stripping assemblies", 0f))
                {
                    break;
                }
                string text2;
                if (!AssemblyStripper.StripAssembliesTo(assembliesToStrip, searchDirs, fullPath, managedAssemblyFolderPath, out text2, out text3, monoLinkerPath, platformProvider, enumerable, developmentBuild))
                {
                    goto Block_6;
                }
                string text4 = Path.Combine(managedAssemblyFolderPath, "ICallSummary.txt");
                string exe   = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Tools/InternalCallRegistrationWriter/InternalCallRegistrationWriter.exe");
                string args  = string.Format("-assembly=\"{0}\" -output=\"{1}\" -summary=\"{2}\"", Path.Combine(fullPath, "UnityEngine.dll"), Path.Combine(managedAssemblyFolderPath, "UnityICallRegistration.cpp"), text4);
                Runner.RunManagedProgram(exe, args);
                if (flag)
                {
                    HashSet <string> hashSet;
                    HashSet <string> nativeModules;
                    CodeStrippingUtils.GenerateDependencies(fullPath, text4, rcr, out hashSet, out nativeModules);
                    flag2 = AssemblyStripper.AddWhiteListsForModules(nativeModules, ref enumerable, platformProvider.moduleStrippingInformationFolder);
                }
                if (!flag2)
                {
                    goto Block_8;
                }
            }
            throw new OperationCanceledException();
Block_6:
            throw new Exception(string.Concat(new object[]
            {
                "Error in stripping assemblies: ",
                assemblies,
                ", ",
                text3
            }));
Block_8:
            string fullPath2 = Path.GetFullPath(Path.Combine(managedAssemblyFolderPath, "tempUnstripped"));

            Directory.CreateDirectory(fullPath2);
            string[] files2 = Directory.GetFiles(managedAssemblyFolderPath);
            for (int j = 0; j < files2.Length; j++)
            {
                string text5     = files2[j];
                string extension = Path.GetExtension(text5);
                if (string.Equals(extension, ".dll", StringComparison.InvariantCultureIgnoreCase) || string.Equals(extension, ".mdb", StringComparison.InvariantCultureIgnoreCase))
                {
                    File.Move(text5, Path.Combine(fullPath2, Path.GetFileName(text5)));
                }
            }
            string[] files3 = Directory.GetFiles(fullPath);
            for (int k = 0; k < files3.Length; k++)
            {
                string text6 = files3[k];
                File.Move(text6, Path.Combine(managedAssemblyFolderPath, Path.GetFileName(text6)));
            }
            Directory.Delete(fullPath);
        }
Example #4
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   stripEngineCode          = rcr != null && PlayerSettings.stripEngineCode && platformProvider.supportsEngineStripping && !EditorUserBuildSettings.buildScriptsOnly;
            IEnumerable <string> blacklists = Il2CppBlacklistPaths;

            if (rcr != null)
            {
                blacklists = blacklists.Concat(new[]
                {
                    WriteMethodsToPreserveBlackList(rcr, platformProvider.target),
                    MonoAssemblyStripping.GenerateLinkXmlToPreserveDerivedTypes(managedAssemblyFolderPath, rcr)
                });
            }

            if (isMono)
            {
                // The old Mono assembly stripper uses per-platform link.xml files if available. Apply these here.
                var buildToolsDirectory = BuildPipeline.GetBuildToolsDirectory(platformProvider.target);
                if (!string.IsNullOrEmpty(buildToolsDirectory))
                {
                    var platformDescriptor = Path.Combine(buildToolsDirectory, "link.xml");
                    if (File.Exists(platformDescriptor))
                    {
                        blacklists = blacklists.Concat(new[] { platformDescriptor });
                    }
                }
            }

            if (!stripEngineCode)
            {
                // if we don't do stripping, add all modules blacklists.
                foreach (var file in Directory.GetFiles(platformProvider.moduleStrippingInformationFolder, "*.xml"))
                {
                    blacklists = blacklists.Concat(new[] { file });
                }
            }

            // Generated link xml files that would have been empty will be nulled out.  Need to filter these out before running the linker
            blacklists = blacklists.Where(b => b != null);

            var tempStripPath = Path.GetFullPath(Path.Combine(managedAssemblyFolderPath, "tempStrip"));

            bool addedMoreBlacklists;

            do
            {
                addedMoreBlacklists = false;

                if (EditorUtility.DisplayCancelableProgressBar("Building Player", "Stripping assemblies", 0.0f))
                {
                    throw new OperationCanceledException();
                }

                if (!StripAssembliesTo(
                        assembliesToStrip,
                        searchDirs,
                        tempStripPath,
                        managedAssemblyFolderPath,
                        out output,
                        out error,
                        monoLinkerPath,
                        platformProvider,
                        blacklists,
                        buildTargetGroup,
                        managedStrippingLevel))
                {
                    throw new Exception("Error in stripping assemblies: " + assemblies + ", " + error);
                }

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

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

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

            // keep unstripped files for debugging purposes
            var tempUnstrippedPath = Path.GetFullPath(Path.Combine(managedAssemblyFolderPath, "tempUnstripped"));

            if (debugUnstripped)
            {
                Directory.CreateDirectory(tempUnstrippedPath);
            }
            foreach (var file in Directory.GetFiles(managedAssemblyFolderPath))
            {
                var extension = Path.GetExtension(file);
                if (string.Equals(extension, ".dll", StringComparison.InvariantCultureIgnoreCase) ||
                    string.Equals(extension, ".winmd", StringComparison.InvariantCultureIgnoreCase) ||
                    string.Equals(extension, ".mdb", StringComparison.InvariantCultureIgnoreCase) ||
                    string.Equals(extension, ".pdb", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (debugUnstripped)
                    {
                        File.Move(file, Path.Combine(tempUnstrippedPath, Path.GetFileName(file)));
                    }
                    else
                    {
                        File.Delete(file);
                    }
                }
            }

            foreach (var file in Directory.GetFiles(tempStripPath))
            {
                File.Move(file, Path.Combine(managedAssemblyFolderPath, Path.GetFileName(file)));
            }
            foreach (var dir in Directory.GetDirectories(tempStripPath))
            {
                Directory.Move(dir, Path.Combine(managedAssemblyFolderPath, Path.GetFileName(dir)));
            }
            Directory.Delete(tempStripPath);
        }
        private static void RunAssemblyStripper(UnityLinkerRunInformation runInformation)
        {
            string output;
            string error;
            var    rcr = runInformation.rcr;
            var    managedAssemblyFolderPath = runInformation.managedAssemblyFolderPath;
            var    linkXmlFiles = new List <string>();

            linkXmlFiles.AddRange(Il2CppBlacklistPaths);

            if (rcr != null)
            {
                linkXmlFiles.Add(WriteMethodsToPreserveBlackList(rcr, runInformation.target));
                linkXmlFiles.Add(MonoAssemblyStripping.GenerateLinkXmlToPreserveDerivedTypes(managedAssemblyFolderPath, rcr));
                linkXmlFiles.Add(WriteTypesInScenesBlacklist(managedAssemblyFolderPath, rcr));
            }

            linkXmlFiles.AddRange(ProcessBuildPipelineGenerateAdditionalLinkXmlFiles(runInformation));
            linkXmlFiles.AddRange(GetUserBlacklistFiles());

            if (runInformation.isMonoBackend)
            {
                // The old Mono assembly stripper uses per-platform link.xml files if available. Apply these here.
                var buildToolsDirectory = BuildPipeline.GetBuildToolsDirectory(runInformation.target);
                if (!string.IsNullOrEmpty(buildToolsDirectory))
                {
                    var platformDescriptor = Path.Combine(buildToolsDirectory, "link.xml");
                    if (File.Exists(platformDescriptor))
                    {
                        linkXmlFiles.Add(platformDescriptor);
                    }
                }
            }

            WriteEditorData(runInformation);

            if (!runInformation.performEngineStripping && !UseUnityLinkerEngineModuleStripping)
            {
                // if we don't do stripping, add all modules blacklists.
                linkXmlFiles.AddRange(runInformation.GetModuleBlacklistFiles());
            }

            var tempStripPath = Path.GetFullPath(Path.Combine(managedAssemblyFolderPath, "tempStrip"));

            ProcessBuildPipelineOnBeforeRun(runInformation);

            bool addedMoreBlacklists;

            do
            {
                addedMoreBlacklists = false;

                if (EditorUtility.DisplayCancelableProgressBar("Building Player", "Stripping assemblies", 0.0f))
                {
                    throw new OperationCanceledException();
                }

                if (!StripAssembliesTo(
                        tempStripPath,
                        out output,
                        out error,
                        SanitizeLinkXmlFilePaths(linkXmlFiles, runInformation),
                        runInformation))
                {
                    throw new Exception("Error in stripping assemblies: " + runInformation.AssembliesToProcess() + ", " + error);
                }

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

                    if (runInformation.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, runInformation.performEngineStripping, out nativeClasses, out nativeModules, runInformation.il2CppPlatformProvider);
                        // Add module-specific blacklists.
                        addedMoreBlacklists = AddWhiteListsForModules(nativeModules, linkXmlFiles, runInformation.platformProvider.moduleStrippingInformationFolder);
                    }
                }

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

                // 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);

            ProcessBuildPipelineOnAfterRun(runInformation);
        }