protected ManagedProgram StartCompiler(BuildTarget target, string compiler, List <string> arguments)
        {
            base.AddCustomResponseFileIfPresent(arguments, Path.GetFileNameWithoutExtension(compiler) + ".rsp");
            string monodistro = (!PlayerSettingsEditor.IsLatestApiCompatibility(this._island._api_compatibility_level)) ? MonoInstallationFinder.GetMonoInstallation() : MonoInstallationFinder.GetMonoBleedingEdgeInstallation();

            return(this.StartCompiler(target, compiler, arguments, true, monodistro));
        }
Esempio n. 2
0
        protected string GetMonoProfileLibDirectory()
        {
            string profile          = BuildPipeline.CompatibilityProfileToClassLibFolder(this._island._api_compatibility_level);
            string monoInstallation = (!PlayerSettingsEditor.IsLatestApiCompatibility(this._island._api_compatibility_level)) ? "Mono" : "MonoBleedingEdge";

            return(MonoInstallationFinder.GetProfileDirectory(profile, monoInstallation));
        }
Esempio n. 3
0
        protected string GetMonoProfileLibDirectory()
        {
            var profile = BuildPipeline.CompatibilityProfileToClassLibFolder(m_Island._api_compatibility_level);

            var monoInstall = PlayerSettingsEditor.IsLatestApiCompatibility(m_Island._api_compatibility_level)
                ? MonoInstallationFinder.MonoBleedingEdgeInstallation
                : MonoInstallationFinder.MonoInstallation;

            return(MonoInstallationFinder.GetProfileDirectory(profile, monoInstall));
        }
Esempio n. 4
0
        protected ManagedProgram StartCompiler(BuildTarget target, string compiler, List <string> arguments, string profileDirectory)
        {
            AddCustomResponseFileIfPresent(arguments, Path.GetFileNameWithoutExtension(compiler) + ".rsp");

            var monoInstallation = PlayerSettingsEditor.IsLatestApiCompatibility(m_Island._api_compatibility_level)
                ? MonoInstallationFinder.GetMonoBleedingEdgeInstallation()
                : MonoInstallationFinder.GetMonoInstallation();

            return(StartCompiler(target, compiler, arguments, profileDirectory, true, monoInstallation));
        }
Esempio n. 5
0
        private string ProjectHeader(MonoIsland island, string[] additionalDefines)
        {
            string            text     = "v3.5";
            string            text2    = "4";
            string            text3    = "4.0";
            string            text4    = "10.0.20506";
            string            text5    = ".";
            ScriptingLanguage language = SolutionSynchronizer.ScriptingLanguageFor(island);

            if (PlayerSettingsEditor.IsLatestApiCompatibility(island._api_compatibility_level))
            {
                text  = "v4.6";
                text2 = "6";
            }
            else if (ScriptEditorUtility.GetScriptEditorFromPreferences() == ScriptEditorUtility.ScriptEditor.Rider)
            {
                text = "v4.5";
            }
            else if (this._settings.VisualStudioVersion == 9)
            {
                text3 = "3.5";
                text4 = "9.0.21022";
            }
            object[] array = new object[]
            {
                text3,
                text4,
                this.ProjectGuid(island._output),
                this._settings.EngineAssemblyPath,
                this._settings.EditorAssemblyPath,
                string.Join(";", new string[]
                {
                    "DEBUG",
                    "TRACE"
                }.Concat(this._settings.Defines).Concat(island._defines).Concat(additionalDefines).Distinct <string>().ToArray <string>()),
                SolutionSynchronizer.MSBuildNamespaceUri,
                Path.GetFileNameWithoutExtension(island._output),
                EditorSettings.projectGenerationRootNamespace,
                text,
                text2,
                text5
            };
            string result;

            try
            {
                result = string.Format(this._settings.GetProjectHeaderTemplate(language), array);
            }
            catch (Exception)
            {
                throw new NotSupportedException("Failed creating c# project because the c# project header did not have the correct amount of arguments, which is " + array.Length);
            }
            return(result);
        }
        private string ProjectHeader(MonoIsland island,
                                     ScriptCompilerBase.ResponseFileData responseFileData)
        {
            string            targetframeworkversion = "v3.5";
            string            targetLanguageVersion  = "4";
            string            toolsversion           = "4.0";
            string            productversion         = "10.0.20506";
            string            baseDirectory          = ".";
            ScriptingLanguage language = ScriptingLanguageFor(island);

            if (PlayerSettingsEditor.IsLatestApiCompatibility(island._api_compatibility_level))
            {
                if (ScriptEditorUtility.GetScriptEditorFromPreferences() == ScriptEditorUtility.ScriptEditor.Rider ||
                    ScriptEditorUtility.GetScriptEditorFromPreferences() == ScriptEditorUtility.ScriptEditor.VisualStudioCode)
                {
                    targetframeworkversion = "v4.5";
                }
                else
                {
                    targetframeworkversion = "v4.7.1";
                }
                targetLanguageVersion = "7.2";
            }
            else if (_settings.VisualStudioVersion == 9)
            {
                toolsversion   = "3.5";
                productversion = "9.0.21022";
            }

            var arguments = new object[]
            {
                toolsversion, productversion, ProjectGuid(island._output),
                _settings.EngineAssemblyPath,
                _settings.EditorAssemblyPath,
                string.Join(";", new[] { "DEBUG", "TRACE" }.Concat(island._defines).Concat(responseFileData.Defines).Distinct().ToArray()),
                MSBuildNamespaceUri,
                Path.GetFileNameWithoutExtension(island._output),
                EditorSettings.projectGenerationRootNamespace,
                targetframeworkversion,
                targetLanguageVersion,
                baseDirectory,
                island._allowUnsafeCode | responseFileData.Unsafe
            };

            try
            {
                return(string.Format(_settings.GetProjectHeaderTemplate(language), arguments));
            }
            catch (Exception)
            {
                throw new System.NotSupportedException("Failed creating c# project because the c# project header did not have the correct amount of arguments, which is " + arguments.Length);
            }
        }
Esempio n. 7
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)
        {
            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=\"" + outputFolder + "\"",
                "-x=\"" + GetModuleWhitelist("Core", platformProvider.moduleStrippingInformationFolder) + "\"",
            };

            args.AddRange(additionalBlacklist.Select(path => "-x \"" + path + "\""));

            args.AddRange(searchDirs.Select(d => "-d \"" + d + "\""));
            args.AddRange(assemblies.Select(assembly => "--include-unity-root-assembly=\"" + 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)}");

            // One final check to make sure we only run high on latest runtime.
            if ((managedStrippingLevel == ManagedStrippingLevel.High) && (PlayerSettingsEditor.IsLatestApiCompatibility(PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup))))
            {
                // Prepare the arguments to run the UnityLinker.  When in high mode, need to also
                // supply the IL2CPP compiler platform and compiler architecture.  When the scripting backend
                // is not IL2CPP, we have to map those strings and use a utility function to figure out proper strings.

                // Currently only need to do this on the non aot platforms of Android, Windows, Mac, Linux.
                var compilerPlatform     = "";
                var compilerArchitecture = "";
                Il2CppNativeCodeBuilder il2cppNativeCodeBuilder = platformProvider.CreateIl2CppNativeCodeBuilder();
                if (il2cppNativeCodeBuilder != null)
                {
                    compilerPlatform     = il2cppNativeCodeBuilder.CompilerPlatform;
                    compilerArchitecture = il2cppNativeCodeBuilder.CompilerArchitecture;
                }
                else
                {
                    GetUnityLinkerPlatformStringsFromBuildTarget(platformProvider.target, out compilerPlatform, out compilerArchitecture);
                }

                args.Add($"--platform={compilerPlatform}");
                if (platformProvider.target != BuildTarget.Android)
                {
                    args.Add($"--architecture={compilerArchitecture}");
                }
            }

            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));
        }
Esempio n. 8
0
        private string ProjectHeader(MonoIsland island,
                                     IEnumerable <ResponseFileData> responseFilesData)
        {
            string            targetframeworkversion = "v3.5";
            string            targetLanguageVersion  = "4";
            string            toolsversion           = "4.0";
            string            productversion         = "10.0.20506";
            string            baseDirectory          = ".";
            string            cscToolPath            = "$(CscToolPath)";
            string            cscToolExe             = "$(CscToolExe)";
            ScriptingLanguage language = ScriptingLanguageFor(island);

            if (PlayerSettingsEditor.IsLatestApiCompatibility(island._api_compatibility_level))
            {
                targetframeworkversion = "v4.7.1";
                targetLanguageVersion  = "latest";

                cscToolPath = Paths.Combine(EditorApplication.applicationContentsPath, "Tools", "RoslynScripts");
                if (Application.platform == RuntimePlatform.WindowsEditor)
                {
                    cscToolExe = "unity_csc.bat";
                }
                else
                {
                    cscToolExe = "unity_csc.sh";
                }

                cscToolPath = Paths.UnifyDirectorySeparator(cscToolPath);
            }
            else if (_settings.VisualStudioVersion == 9)
            {
                toolsversion   = "3.5";
                productversion = "9.0.21022";
            }

            var arguments = new object[]
            {
                toolsversion, productversion, ProjectGuid(island._output),
                _settings.EngineAssemblyPath,
                _settings.EditorAssemblyPath,
                string.Join(";", new[] { "DEBUG", "TRACE" }.Concat(island._defines).Concat(responseFilesData.SelectMany(x => x.Defines)).Distinct().ToArray()),
                MSBuildNamespaceUri,
                Utility.FileNameWithoutExtension(island._output),
                EditorSettings.projectGenerationRootNamespace,
                targetframeworkversion,
                targetLanguageVersion,
                baseDirectory,
                island._allowUnsafeCode | responseFilesData.Any(x => x.Unsafe),
                cscToolPath,
                cscToolExe,
            };

            try
            {
                return(string.Format(_settings.GetProjectHeaderTemplate(language), arguments));
            }
            catch (Exception)
            {
                throw new System.NotSupportedException("Failed creating c# project because the c# project header did not have the correct amount of arguments, which is " + arguments.Length);
            }
        }
Esempio n. 9
0
        private static void RunAssemblyStripper(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(rcr, platformProvider.target),
                    AssemblyStripper.WriteUnityEngineBlackList(),
                    MonoAssemblyStripping.GenerateLinkXmlToPreserveDerivedTypes(managedAssemblyFolderPath, rcr)
                });
            }
            if (PlayerSettingsEditor.IsLatestApiCompatibility(PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup)))
            {
                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);
        }
Esempio n. 10
0
        private static void RunAssemblyStripper(IEnumerable assemblies, string managedAssemblyFolderPath, string[] assembliesToStrip, string[] searchDirs, string monoLinkerPath, IIl2CppPlatformProvider platformProvider, RuntimeClassRegistry rcr)
        {
            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;
            IEnumerable <string> blacklists = Il2CppBlacklistPaths;

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

            if (PlayerSettingsEditor.IsLatestApiCompatibility(PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup)))
            {
                var il2cppFolder = Path.Combine(platformProvider.il2CppFolder, "LinkerDescriptors");
                blacklists = blacklists.Concat(Directory.GetFiles(il2cppFolder, "*45.xml"));
            }
            if (isMono)
            {
                // Apply mono-specific assembly whitelists, taken from old Mono assembly stripping code path.
                var il2cppFolder = Path.Combine(platformProvider.il2CppFolder, "LinkerDescriptors");
                blacklists = blacklists.Concat(Directory.GetFiles(il2cppFolder, "*_mono.xml"));

                // The old Mono assembly stripper uses per-platform link.xml files if available. Apply these here.
                var platformDescriptor = Path.Combine(BuildPipeline.GetBuildToolsDirectory(platformProvider.target), "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 });
                }
            }

            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))
                {
                    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)));
            }
            Directory.Delete(tempStripPath);
        }