Exemple #1
0
        private string GetMonoBleedingEdgeExe()
        {
            var path = Path.Combine(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), "bin");

            return(Path.Combine(path, "mono"));
        }
        private Program StartCompilerImpl(List <string> arguments, string argsPrefix)
        {
            foreach (string dll in _island._references)
            {
                arguments.Add("/reference:" + PrepareFileName(dll));
            }

            foreach (string define in _island._defines.Distinct())
            {
                arguments.Add("/define:" + define);
            }

            var filePathMappings = new List <string>(_island._files.Length);

            foreach (var source in _island._files)
            {
                var f = PrepareFileName(source);
                if (Application.platform == RuntimePlatform.WindowsEditor)
                {
                    f = f.Replace('/', '\\');
                }
                else
                {
                    f = f.Replace('\\', '/');
                }

                arguments.Add(f);

                if (f != source)
                {
                    filePathMappings.Add(f + " => " + source);
                }
            }

            var useNetCore = true;
            var csc        = Paths.Combine(EditorApplication.applicationContentsPath, "Tools", "Roslyn", "csc.exe");

            if (Application.platform == RuntimePlatform.WindowsEditor)
            {
                csc = csc.Replace('/', '\\');
            }
            else
            {
                if (UseNetCoreCompiler())
                {
                    csc = Paths.Combine(EditorApplication.applicationContentsPath, "Tools", "Roslyn", "csc").Replace('\\', '/');
                }
                else
                {
                    useNetCore = false;
                    csc        = Paths.Combine(EditorApplication.applicationContentsPath, "Tools", "RoslynNet46", "csc.exe").Replace('\\', '/');
                }
            }


            if (!File.Exists(csc))
            {
                ThrowCompilerNotFoundException(csc);
            }

            var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(BuildTarget);

            if (!AddCustomResponseFileIfPresent(arguments, ReponseFilename) && PlayerSettings.GetScriptingBackend(buildTargetGroup) != ScriptingImplementation.WinRTDotNET)
            {
                if (AddCustomResponseFileIfPresent(arguments, "mcs.rsp"))
                {
                    UnityEngine.Debug.LogWarning(string.Format("Using obsolete custom response file 'mcs.rsp'. Please use '{0}' instead.", ReponseFilename));
                }
            }

            var responseFile = CommandLineFormatter.GenerateResponseFile(arguments);

            RunAPIUpdaterIfRequired(responseFile, filePathMappings);

            if (useNetCore)
            {
                var psi = new ProcessStartInfo()
                {
                    Arguments = argsPrefix + " /shared " + "@" + responseFile, FileName = csc, CreateNoWindow = true
                };
                var program = new Program(psi);
                program.Start();
                return(program);
            }
            else
            {
                var program = new ManagedProgram(
                    MonoInstallationFinder.GetMonoBleedingEdgeInstallation(),
                    "not needed",
                    csc,
                    argsPrefix + "@" + responseFile,
                    false,
                    null);
                program.Start();
                return(program);
            }
        }
 private static ManagedProgram ManagedProgramFor(string exe, string arguments)
 {
     return(new ManagedProgram(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), "4.0", exe, arguments, null));
 }
        static string[] GetCachedSystemLibraryReferences(ApiCompatibilityLevel apiCompatibilityLevel)
        {
            // We cache the references because they are computed by getting files in directories on disk,
            // which is very slow.
            if (cachedReferences != null && cachedReferences.ApiCompatibilityLevel == apiCompatibilityLevel)
            {
                return(cachedReferences.References);
            }

            var references            = new List <string>();
            var monoAssemblyDirectory = GetSystemReferenceDirectory(apiCompatibilityLevel);

            if (apiCompatibilityLevel == ApiCompatibilityLevel.NET_Standard_2_0)
            {
                references.AddRange(GetNetStandardClassLibraries());
            }
            else if (apiCompatibilityLevel == ApiCompatibilityLevel.NET_4_6)
            {
                references.AddRange(GetSystemReferences().Select(dll => Path.Combine(monoAssemblyDirectory, dll)));

                // Look in the mono assembly directory for a facade folder and get a list of all the DLL's to be
                // used later by the language compilers.
                references.AddRange(Directory.GetFiles(Path.Combine(monoAssemblyDirectory, "Facades"), "*.dll"));

                references.AddRange(GetBooAndUsReferences().Select(dll => Path.Combine(MonoInstallationFinder.GetProfileDirectory("unityscript", MonoInstallationFinder.MonoBleedingEdgeInstallation), dll)));
            }
            else
            {
                references.AddRange(GetSystemReferences().Select(dll => Path.Combine(monoAssemblyDirectory, dll)));
                references.AddRange(GetBooAndUsReferences().Select(dll => Path.Combine(monoAssemblyDirectory, dll)));
            }

            cachedReferences = new CachedReferences
            {
                ApiCompatibilityLevel = apiCompatibilityLevel,
                References            = references.ToArray()
            };


            return(cachedReferences.References);
        }
        public static void MonoLink(BuildTarget buildTarget, string managedLibrariesDirectory, string[] input, string[] allAssemblies, RuntimeClassRegistry usedClasses)
        {
            Process process             = MonoProcessUtility.PrepareMonoProcess(buildTarget, managedLibrariesDirectory);
            string  buildToolsDirectory = BuildPipeline.GetBuildToolsDirectory(buildTarget);
            string  text             = null;
            string  frameWorksFolder = MonoInstallationFinder.GetFrameWorksFolder();
            string  text2            = Path.Combine(frameWorksFolder, MonoAssemblyStripping.StripperExe());
            string  text3            = Path.Combine(Path.GetDirectoryName(text2), "link.xml");
            string  text4            = Path.Combine(managedLibrariesDirectory, "output");

            Directory.CreateDirectory(text4);
            process.StartInfo.Arguments = "\"" + text2 + "\" -l none -c link";
            for (int i = 0; i < input.Length; i++)
            {
                string           str     = input[i];
                ProcessStartInfo expr_82 = process.StartInfo;
                expr_82.Arguments = expr_82.Arguments + " -a \"" + str + "\"";
            }
            ProcessStartInfo expr_B5   = process.StartInfo;
            string           arguments = expr_B5.Arguments;

            expr_B5.Arguments = string.Concat(new string[]
            {
                arguments,
                " -out output -x \"",
                text3,
                "\" -d \"",
                managedLibrariesDirectory,
                "\""
            });
            string text5 = Path.Combine(buildToolsDirectory, "link.xml");

            if (File.Exists(text5))
            {
                ProcessStartInfo expr_112 = process.StartInfo;
                expr_112.Arguments = expr_112.Arguments + " -x \"" + text5 + "\"";
            }
            string text6 = Path.Combine(Path.GetDirectoryName(text2), "Core.xml");

            if (File.Exists(text6))
            {
                ProcessStartInfo expr_153 = process.StartInfo;
                expr_153.Arguments = expr_153.Arguments + " -x \"" + text6 + "\"";
            }
            string[] files = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "Assets"), "link.xml", SearchOption.AllDirectories);
            string[] array = files;
            for (int j = 0; j < array.Length; j++)
            {
                string           str2     = array[j];
                ProcessStartInfo expr_1A5 = process.StartInfo;
                expr_1A5.Arguments = expr_1A5.Arguments + " -x \"" + str2 + "\"";
            }
            if (usedClasses != null)
            {
                text = MonoAssemblyStripping.GenerateBlackList(managedLibrariesDirectory, usedClasses, allAssemblies);
                ProcessStartInfo expr_1EA = process.StartInfo;
                expr_1EA.Arguments = expr_1EA.Arguments + " -x \"" + text + "\"";
            }
            string path = Path.Combine(BuildPipeline.GetPlaybackEngineDirectory(EditorUserBuildSettings.activeBuildTarget, BuildOptions.None), "Whitelists");

            string[] files2 = Directory.GetFiles(path, "*.xml");
            for (int k = 0; k < files2.Length; k++)
            {
                string           str3     = files2[k];
                ProcessStartInfo expr_241 = process.StartInfo;
                expr_241.Arguments = expr_241.Arguments + " -x \"" + str3 + "\"";
            }
            MonoProcessUtility.RunMonoProcess(process, "assemblies stripper", Path.Combine(text4, "mscorlib.dll"));
            MonoAssemblyStripping.DeleteAllDllsFrom(managedLibrariesDirectory);
            MonoAssemblyStripping.CopyAllDlls(managedLibrariesDirectory, text4);
            string[] files3 = Directory.GetFiles(managedLibrariesDirectory);
            for (int l = 0; l < files3.Length; l++)
            {
                string text7 = files3[l];
                if (text7.Contains(".mdb"))
                {
                    string path2 = text7.Replace(".mdb", "");
                    if (!File.Exists(path2))
                    {
                        FileUtil.DeleteFileOrDirectory(text7);
                    }
                }
            }
            if (text != null)
            {
                FileUtil.DeleteFileOrDirectory(Path.Combine(managedLibrariesDirectory, text));
            }
            FileUtil.DeleteFileOrDirectory(text4);
        }
        public static void MonoLink(BuildTarget buildTarget, string managedLibrariesDirectory, string[] input, string[] allAssemblies, RuntimeClassRegistry usedClasses)
        {
            Process process             = MonoProcessUtility.PrepareMonoProcess(buildTarget, managedLibrariesDirectory);
            string  buildToolsDirectory = BuildPipeline.GetBuildToolsDirectory(buildTarget);
            string  path2 = (string)null;
            string  path1 = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), MonoAssemblyStripping.StripperExe());
            string  str1  = Path.Combine(Path.GetDirectoryName(path1), "link.xml");
            string  str2  = Path.Combine(managedLibrariesDirectory, "output");

            Directory.CreateDirectory(str2);
            process.StartInfo.Arguments = "\"" + path1 + "\" -l none -c link";
            foreach (string str3 in input)
            {
                ProcessStartInfo startInfo = process.StartInfo;
                string           str4      = startInfo.Arguments + " -a \"" + str3 + "\"";
                startInfo.Arguments = str4;
            }
            ProcessStartInfo startInfo1 = process.StartInfo;
            string           str5       = startInfo1.Arguments + " -out output -x \"" + str1 + "\" -d \"" + managedLibrariesDirectory + "\"";

            startInfo1.Arguments = str5;
            string path3 = Path.Combine(buildToolsDirectory, "link.xml");

            if (File.Exists(path3))
            {
                ProcessStartInfo startInfo2 = process.StartInfo;
                string           str3       = startInfo2.Arguments + " -x \"" + path3 + "\"";
                startInfo2.Arguments = str3;
            }
            string path4 = Path.Combine(Path.GetDirectoryName(path1), "Core.xml");

            if (File.Exists(path4))
            {
                ProcessStartInfo startInfo2 = process.StartInfo;
                string           str3       = startInfo2.Arguments + " -x \"" + path4 + "\"";
                startInfo2.Arguments = str3;
            }
            foreach (string file in Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "Assets"), "link.xml", SearchOption.AllDirectories))
            {
                ProcessStartInfo startInfo2 = process.StartInfo;
                string           str3       = startInfo2.Arguments + " -x \"" + file + "\"";
                startInfo2.Arguments = str3;
            }
            if (usedClasses != null)
            {
                path2 = MonoAssemblyStripping.GenerateBlackList(managedLibrariesDirectory, usedClasses, allAssemblies);
                ProcessStartInfo startInfo2 = process.StartInfo;
                string           str3       = startInfo2.Arguments + " -x \"" + path2 + "\"";
                startInfo2.Arguments = str3;
            }
            foreach (string file in Directory.GetFiles(Path.Combine(BuildPipeline.GetPlaybackEngineDirectory(EditorUserBuildSettings.activeBuildTarget, BuildOptions.None), "Whitelists"), "*.xml"))
            {
                ProcessStartInfo startInfo2 = process.StartInfo;
                string           str3       = startInfo2.Arguments + " -x \"" + file + "\"";
                startInfo2.Arguments = str3;
            }
            MonoProcessUtility.RunMonoProcess(process, "assemblies stripper", Path.Combine(str2, "mscorlib.dll"));
            MonoAssemblyStripping.DeleteAllDllsFrom(managedLibrariesDirectory);
            MonoAssemblyStripping.CopyAllDlls(managedLibrariesDirectory, str2);
            foreach (string file in Directory.GetFiles(managedLibrariesDirectory))
            {
                if (file.Contains(".mdb") && !File.Exists(file.Replace(".mdb", string.Empty)))
                {
                    FileUtil.DeleteFileOrDirectory(file);
                }
            }
            if (path2 != null)
            {
                FileUtil.DeleteFileOrDirectory(Path.Combine(managedLibrariesDirectory, path2));
            }
            FileUtil.DeleteFileOrDirectory(str2);
        }
 protected string GetProfileDirectory()
 {
     return(MonoInstallationFinder.GetProfileDirectory(this._island._target, this._island._classlib_profile));
 }
Exemple #8
0
        public static bool WeaveUNetInto(string assemblyPath, string destPath, string unityEngine, string unityUNet)
        {
            string text = Weaver.CommandLineArgsFor(assemblyPath, destPath, unityEngine);

            text = text + " -unity-unet=" + unityUNet;
            string frameWorksFolder = MonoInstallationFinder.GetFrameWorksFolder();

            Console.Write(string.Concat(new string[]
            {
                "WeaveUNetInto ",
                assemblyPath,
                " using ",
                frameWorksFolder,
                "/UNetWeaver/UNetWeaver.exe ",
                text
            }));
            bool result;

            using (ManagedProgram managedProgram = Weaver.UNetWeaverProgramWith(text, frameWorksFolder))
            {
                try
                {
                    managedProgram.Start();
                }
                catch
                {
                    managedProgram.LogProcessStartInfo();
                    throw new Exception("Could not start UNetWeaver.exe");
                }
                managedProgram.WaitForExit();
                Console.Write(managedProgram.GetAllOutput());
                if (managedProgram.ExitCode == 0)
                {
                    string   allOutput = managedProgram.GetAllOutput();
                    string   text2     = "COMPILE_WARNING ";
                    string[] array     = allOutput.Split(new char[]
                    {
                        '\n'
                    });
                    string[] array2 = array;
                    for (int i = 0; i < array2.Length; i++)
                    {
                        string text3 = array2[i];
                        if (text3.Length >= text2.Length)
                        {
                            if (text3.Substring(0, text2.Length) == text2)
                            {
                                string msg = text3.Substring(text2.Length);
                                EditorApplication.ReportUNetWeaver("file", msg, false);
                            }
                        }
                    }
                    result = true;
                }
                else
                {
                    string   allOutput2 = managedProgram.GetAllOutput();
                    string   text4      = "COMPILE_ERROR ";
                    string   text5      = "COMPILE_WARNING ";
                    string[] array3     = allOutput2.Split(new char[]
                    {
                        '\n'
                    });
                    string[] array4 = array3;
                    for (int j = 0; j < array4.Length; j++)
                    {
                        string text6 = array4[j];
                        if (text6.Length >= text5.Length)
                        {
                            if (text6.Substring(0, text4.Length) == text4)
                            {
                                string msg2 = text6.Substring(text4.Length);
                                EditorApplication.ReportUNetWeaver("file", msg2, true);
                            }
                            if (text6.Substring(0, text5.Length) == text5)
                            {
                                string msg3 = text6.Substring(text5.Length);
                                EditorApplication.ReportUNetWeaver("file", msg3, false);
                            }
                        }
                    }
                    result = false;
                }
            }
            return(result);
        }
Exemple #9
0
        /// <summary>
        /// ファイル配信サーバを起動する。
        /// </summary>
        /// <param name="port">ポート</param>
        /// <param name="serverRootPath">配信するディレクトリパス</param>
        /// <param name="serverPID">起動したサーバのプロセスID</param>
        /// <returns>true : サーバが正常に起動した</returns>
        public static bool RunServer(int port, string serverRootPath, ref int serverPID)
        {
            if (!Directory.Exists(serverRootPath))
            {
                UnityEngine.Debug.Log(" Unable Start Server process");
                serverPID = 0;
                return(false);
            }

            string pathToAssetServer = Path.GetFullPath("Assets/ArowMain/Editor/LocalFileDeliveryServer/MonoFileDeliveryServer.exe");

            KillRunningServer(ref serverPID); // 安全のために終了しておく。
            string args = string.Format("-Path \"{0}\" -ParentProcessId {1} -Port {2}", serverRootPath, Process.GetCurrentProcess().Id, port);

            UnityEngine.Debug.Log(" args: " + args);
            ProcessStartInfo startInfo = ExecuteInternalMono.GetProfileStartInfoForMono(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), "4.5", pathToAssetServer, args, true);

            startInfo.WorkingDirectory = serverRootPath;
            startInfo.UseShellExecute  = false;
            Process launchProcess = Process.Start(startInfo);

            if (launchProcess == null || launchProcess.HasExited == true || launchProcess.Id == 0)
            {
                //Unable to start process
                UnityEngine.Debug.Log(" Unable Start Server process");
                serverPID = 0;
                return(false);
            }
            else
            {
                //We seem to have launched, let's save the PID
                string urlKey    = kEditorPrefsLocalServerUrlKey;
                string serverUrl = GetServerURL(port);
                EditorPrefs.SetString(urlKey, serverUrl);
                UnityEngine.Debug.Log(" Start Server: " + serverUrl);
                launchProcess.EnableRaisingEvents = true;
                launchProcess.Exited += delegate(object sender, EventArgs eventArgs)
                {
                    UnityEngine.Debug.Log(string.Format("サーバが終了しました: {0}", serverRootPath));
                };
                serverPID = launchProcess.Id;
                return(true);
            }
        }
        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);
        }
Exemple #11
0
 private static string GetUnityReferenceProfileDirectory()
 {
     return(Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "UnityReferenceAssemblies", "unity-4.8-api"));
 }
Exemple #12
0
    // Copy of MonoCSharpCompiler.StartCompiler()
    // The only reason it exists is to call the new implementation
    // of GetCompilerPath(...) which is non-virtual unfortunately.
    protected override Program StartCompiler()
    {
        var arguments = new List <string>
        {
            "-debug",
            "-target:library",
            "-nowarn:0169",
            "-out:" + PrepareFileName(island._output),
            "-unsafe"
        };

        arguments.Add("-define:" + COMPILER_DEFINE);

        var unity5References = GetAdditionalReferences();

        if (unity5References != null)
        {
            foreach (string path in unity5References)
            {
                var text = Path.Combine(GetProfileDirectoryViaReflection(), path);
                if (File.Exists(text))
                {
                    arguments.Add("-r:" + PrepareFileName(text));
                }
            }
        }


        foreach (var define in island._defines.Distinct())
        {
            arguments.Add("-define:" + define);
        }

        foreach (var file in island._files)
        {
            arguments.Add(PrepareFileName(file));
        }

        foreach (string fileName in island._references)
        {
            arguments.Add("-r:" + PrepareFileName(fileName));
        }

        if (!island._development_player && (!buildingForEditor() || !EditorPrefs.GetBool("AllowAttachedDebuggingOfEditor", true)))
        {
            arguments.Add("-optimize+");
        }
        else
        {
            arguments.Add("-optimize-");
        }

        var universalCompilerPath = GetUniversalCompilerPath();

        if (universalCompilerPath != null)
        {
            // use universal compiler.
            arguments.Add("-define:__UNITY_PROCESSID__" + System.Diagnostics.Process.GetCurrentProcess().Id);

            // this function should be run because it adds an item to arguments
            //var compilerPath = GetCompilerPath(arguments);

            var rspFileName = "Assets/mcs.rsp";
            if (File.Exists(rspFileName))
            {
                arguments.Add("@" + rspFileName);
            }
            //else
            //{
            //	var defaultCompilerName = Path.GetFileNameWithoutExtension(compilerPath);
            //	rspFileName = "Assets/" + defaultCompilerName + ".rsp";
            //	if (File.Exists(rspFileName))
            //		arguments.Add("@" + rspFileName);
            //}


            // Replaced following line to use newer mono runtime for compiler
            // var program = StartCompiler(island._target, universalCompilerPath, arguments);
            // Side effect: API updater is disabled

            // Disabled API updater
            Program StartCompilerLocal(BuildTarget target, string compiler, List <string> arguments_)
            {
                AddCustomResponseFileIfPresent(arguments, Path.GetFileNameWithoutExtension(compiler) + ".rsp");
                var responseFile = CommandLineFormatter.GenerateResponseFile(arguments_);

                var p = new Program(CreateOSDependentStartInfo(
                                        isWindows: Application.platform == RuntimePlatform.WindowsEditor,
                                        processPath: compiler,
                                        processArguments: " @" + responseFile,
                                        unityEditorDataDir: MonoInstallationFinder.GetFrameWorksFolder()
                                        ));

                p.Start();
                return(p);
            }

            var program = StartCompilerLocal(island._target, universalCompilerPath, arguments);

            if (!CompilationFlags.checkIfBuildCompiles)
            {
                return(program);
            }

            var compiledDllName = island._output.Split('/').Last();
            if (compiledDllName != "Assembly-CSharp.dll")
            {
                return(program);
            }

            program.WaitForExit();
            if (program.ExitCode != 0)
            {
                return(program);
            }

            // message contents are used in CI script, so this shouldnt be changed
            Debug.Log("Scripts successfully compile in Build mode");
            // CI script expects to find log from above if process was killed
            // sometimes process.Kill() happens faster than Debug.Log() logs our message
            // sleeping the thread ensures that message was logged before we kill the process
            Thread.Sleep(5000);

            Process.GetCurrentProcess().Kill();
            throw new Exception("unreachable code");
        }
        else
        {
            // fallback to the default compiler.
            Debug.LogWarning($"Universal C# compiler not found in project directory. Use the default compiler");
            return(base.StartCompiler());
        }
    }
Exemple #13
0
    private static string GetProfileDirectory(string profile, string monoInstallation)
    {
        string monoInstallation2 = MonoInstallationFinder.GetMonoInstallation(monoInstallation);

        return(Path.Combine(monoInstallation2, Path.Combine("lib", Path.Combine("mono", profile))));
    }
        protected override Program StartCompiler()
        {
            var arguments = new List <string>
            {
                "-debug",
                "-target:library",
                "-nowarn:0169",
                "-langversion:" + ((EditorApplication.scriptingRuntimeVersion == ScriptingRuntimeVersion.Latest) ? "6" : "4"),
                "-out:" + PrepareFileName(m_Island._output),
                "-nostdlib",
            };

            if (m_Island._allowUnsafeCode)
            {
                arguments.Add("-unsafe");
            }

            if (!m_Island._development_player && !m_Island._editor)
            {
                arguments.Add("-optimize");
            }

            foreach (string dll in m_Island._references)
            {
                arguments.Add("-r:" + PrepareFileName(dll));
            }
            foreach (string define in m_Island._defines.Distinct())
            {
                arguments.Add("-define:" + define);
            }

            var pathMappings = new List <string>(m_Island._files.Length);

            foreach (string source in m_Island._files)
            {
                var preparedFileName = PrepareFileName(source);
                if (preparedFileName != source)
                {
                    pathMappings.Add(preparedFileName + " => " + source);
                }

                arguments.Add(preparedFileName);
            }

            var responseFiles = m_Island._responseFiles?.ToDictionary(Path.GetFileName) ?? new Dictionary <string, string>();
            KeyValuePair <string, string> obsoleteResponseFile = responseFiles
                                                                 .SingleOrDefault(x => CompilerSpecificResponseFiles.MonoCSharpCompilerObsolete.Contains(x.Key));

            if (!string.IsNullOrEmpty(obsoleteResponseFile.Key))
            {
                if (m_Island._api_compatibility_level == ApiCompatibilityLevel.NET_2_0_Subset)
                {
                    Debug.LogWarning($"Using obsolete custom response file '{obsoleteResponseFile.Key}'. Please use '{ResponseFilename}' instead.");
                }
                else
                {
                    responseFiles.Remove(obsoleteResponseFile.Key);
                }
            }

            foreach (var responseFile in responseFiles)
            {
                AddResponseFileToArguments(arguments, responseFile.Value);
            }

            return(StartCompiler(
                       m_Island._target,
                       GetCompilerPath(),
                       arguments,
                       BuildPipeline.CompatibilityProfileToClassLibFolder(m_Island._api_compatibility_level),
                       false,
                       MonoInstallationFinder.GetMonoInstallation(MonoInstallationFinder.MonoBleedingEdgeInstallation),
                       pathMappings
                       ));
        }
 private static string AssemblySearchPathArgument()
 {
     return(" -s \"" + (Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Managed") + ",+" + Path.Combine(EditorApplication.applicationContentsPath, "UnityExtensions/Unity") + ",+" + Application.dataPath) + "\"");
 }
Exemple #16
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();
            }
        }
 private static string GetUnityEditorManagedPath()
 {
     return(Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Managed"));
 }
        public static void Generate()
        {
            string pathToProtogen = "Assets/JUFrame/ProtoBuf/Editor/ProtoGen/protogen.exe";

#if UNITY_2017_1_OR_NEWER
            string monoProfile = "4.5";
#elif UNITY_5_5_OR_NEWER
            string monoProfile = "v4.0.30319";
#else
            string monoProfile = "4.0";
#endif
            pathToProtogen = pathToProtogen.Replace("Assets", Application.dataPath);
            UnityEngine.Debug.LogError(pathToProtogen);
            var args = string.Format("-i:{0} -o:{1}", Application.dataPath.Replace("Assets", "test.proto"), Application.dataPath.Replace("Assets", "test.cs"));
            UnityEngine.Debug.LogError(args);
            ProcessStartInfo startInfo = ExecuteInternalMono.GetProfileStartInfoForMono(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), monoProfile, pathToProtogen, args, true);

            startInfo.WorkingDirectory = "Assets/JUFrame/ProtoBuf/Editor/ProtoGen/".Replace("Assets", Application.dataPath);
            startInfo.UseShellExecute  = false;

            Process launchProcess = Process.Start(startInfo);

            /*
             * if (launchProcess == null || launchProcess.HasExited == true || launchProcess.Id == 0)
             * {
             *  //Unable to start process
             *  UnityEngine.Debug.LogError("Unable Start AssetBundleServer process");
             *  instance.m_args = "Not running.";
             *  instance.m_launchedSetting = null;
             * }
             * else
             * {
             *  UnityEngine.Debug.LogFormat("Local Server started with arg:{0}", args);
             *  //We seem to have launched, let's save the PID
             *  instance.m_ServerPID = launchProcess.Id;
             *  instance.m_args = args;
             *  instance.m_launchedSetting = serverSetting;
             * }
             */
        }