예제 #1
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));
        }
예제 #2
0
        public static Process PrepareMonoProcessBleedingEdge(string workDir)
        {
            Process process = new Process();
            string  text    = (Application.platform != RuntimePlatform.WindowsEditor) ? "mono" : "mono.exe";

            process.StartInfo.FileName = Paths.Combine(new string[]
            {
                MonoInstallationFinder.GetMonoBleedingEdgeInstallation(),
                "bin",
                text
            });
            process.StartInfo.EnvironmentVariables["_WAPI_PROCESS_HANDLE_OFFSET"] = "5";
            string profile = BuildPipeline.CompatibilityProfileToClassLibFolder(ApiCompatibilityLevel.NET_4_6);

            process.StartInfo.EnvironmentVariables["MONO_PATH"] = MonoInstallationFinder.GetProfileDirectory(profile);
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.WorkingDirectory       = workDir;
            return(process);
        }
예제 #3
0
        public static Process PrepareMonoProcessBleedingEdge(string workDir)
        {
            var process = new Process();

            var executableName = Application.platform == RuntimePlatform.WindowsEditor ? "mono.exe" : "mono";

            process.StartInfo.FileName = Paths.Combine(MonoInstallationFinder.GetMonoBleedingEdgeInstallation(), "bin", executableName);

            // ;; TODO fix this hack for strange process handle duplication problem inside mono
            process.StartInfo.EnvironmentVariables["_WAPI_PROCESS_HANDLE_OFFSET"] = "5";

            // We run the stripper on .NET 4.6 profile
            var monoProfile = BuildPipeline.CompatibilityProfileToClassLibFolder(ApiCompatibilityLevel.NET_4_6);

            process.StartInfo.EnvironmentVariables["MONO_PATH"] = MonoInstallationFinder.GetProfileDirectory(monoProfile);
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.CreateNoWindow         = true;

            process.StartInfo.WorkingDirectory = workDir;

            return(process);
        }
    private static void RunCoverter(string converterPath)
    {
        var option = EditorUtility.DisplayDialogComplex(
            Title,
            "Run the conversion tool (this process may take several minutes) ?\r\n\r\n" +
            "Make sure you have a backup of your project before continuing.", "Convert", "Convert (verbose logging)", "Cancel");

        if (option == 2)
        {
            Debug.Log("User choose to not allow converter to run.");
            return;
        }

        var startInfo = new ProcessStartInfo
        {
            CreateNoWindow         = true,
            RedirectStandardError  = true,
            RedirectStandardOutput = true,
            WorkingDirectory       = Application.dataPath + "/..",
            UseShellExecute        = false
        };

        var monoExecutableExtension = Application.platform == RuntimePlatform.WindowsEditor ? ".exe" : "";

        startInfo.Arguments = converterPath + " " + ComputeConverterCommandLineArguments(option == 1);
        startInfo.FileName  = Path.Combine(MonoInstallationFinder.GetMonoBleedingEdgeInstallation(), "bin/mono" + monoExecutableExtension);

        Console.WriteLine("--------- UnityScript2CSharp Arguments\r\n\r\n{0}\n\r---------", startInfo.Arguments);

        using (var p = Process.Start(startInfo))
        {
            var sw = new Stopwatch();
            sw.Start();

            var sleepTime = 100;                     // ms
            var value     = 0.0f;
            var increment = 0.5f / unityScriptCount; // Assumes that each script will take 2 x seepTime
            while (!p.HasExited && sw.ElapsedMilliseconds < 60000)
            {
                if (EditorUtility.DisplayCancelableProgressBar("Runing", "converting from UnityScript -> C#", value))
                {
                    p.Kill();
                    return;
                }

                value += increment;

                Thread.Sleep(sleepTime);
            }

            EditorUtility.ClearProgressBar();

            if (!p.HasExited)
            {
                EditorUtility.DisplayDialog(Title, "Conversion process taking to long. Killing process.", "Ok");
                p.Kill();
            }
            else
            {
                ShowConversionResultsInConsole(p.ExitCode);
                AssetDatabase.Refresh();
            }
        }
    }
        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));
        }
예제 #6
0
        private Program StartCompilerImpl(List <string> arguments, string argsPrefix)
        {
            foreach (string dll in m_Island._references)
            {
                arguments.Add("/reference:" + PrepareFileName(dll));
            }

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

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

            foreach (var source in m_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);

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

            if (!string.IsNullOrEmpty(obsoleteResponseFile.Key))
            {
                if (!IsBuildingForDotNetScriptingBackend(buildTargetGroup, m_Island._editor))
                {
                    Debug.LogWarning($"Using obsolete custom response file '{obsoleteResponseFile.Key}'. Please use '{CompilerSpecificResponseFiles.MicrosoftCSharpCompiler}' instead.");
                }
                else
                {
                    responseFiles.Remove(obsoleteResponseFile.Key);
                }
            }

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

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