private static bool StartManagedProgram(string exe, string arguments, CompilerOutputParserBase parser, ref IEnumerable <CompilerMessage> compilerMessages)
    {
        bool result;

        using (ManagedProgram managedProgram = GendarmeValidationRule.ManagedProgramFor(exe, arguments))
        {
            managedProgram.LogProcessStartInfo();
            try
            {
                managedProgram.Start();
            }
            catch
            {
                throw new Exception("Could not start " + exe);
            }
            managedProgram.WaitForExit();
            if (managedProgram.ExitCode == 0)
            {
                result = true;
                return(result);
            }
            compilerMessages = parser.Parse(managedProgram.GetErrorOutput(), managedProgram.GetStandardOutput(), true);
        }
        result = false;
        return(result);
    }
示例#2
0
 internal static void RunManagedProgram(string exe, string args, string workingDirectory, CompilerOutputParserBase parser)
 {
     using (ManagedProgram managedProgram = new ManagedProgram(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), "4.0", exe, args))
     {
         managedProgram.GetProcessStartInfo().WorkingDirectory = workingDirectory;
         managedProgram.Start();
         managedProgram.WaitForExit();
         if (managedProgram.ExitCode != 0)
         {
             if (parser != null)
             {
                 string[] errorOutput    = managedProgram.GetErrorOutput();
                 string[] standardOutput = managedProgram.GetStandardOutput();
                 IEnumerable <CompilerMessage> enumerable = parser.Parse(errorOutput, standardOutput, true);
                 foreach (CompilerMessage current in enumerable)
                 {
                     Debug.LogPlayerBuildError(current.message, current.file, current.line, current.column);
                 }
             }
             Debug.LogError(string.Concat(new string[]
             {
                 "Failed running ",
                 exe,
                 " ",
                 args,
                 "\n\n",
                 managedProgram.GetAllOutput()
             }));
             throw new Exception(string.Format("{0} did not run properly!", exe));
         }
     }
 }
示例#3
0
        internal static void RunManagedProgram(string exe, string args, string workingDirectory, CompilerOutputParserBase parser, Action <ProcessStartInfo> setupStartInfo)
        {
            Program p;

            // Run on .NET if running on windows
            // It's twice as fast as Mono for IL2CPP.exe
            if (Application.platform == RuntimePlatform.WindowsEditor)
            {
                var startInfo = new ProcessStartInfo()
                {
                    Arguments      = args,
                    CreateNoWindow = true,
                    FileName       = exe
                };

                if (setupStartInfo != null)
                {
                    setupStartInfo(startInfo);
                }

                p = new Program(startInfo);
            }
            else
            {
                p = new ManagedProgram(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), null, exe, args, false, setupStartInfo);
            }

            RunProgram(p, exe, args, workingDirectory, parser);
        }
示例#4
0
        internal static void RunManagedProgram(string exe, string args, string workingDirectory, CompilerOutputParserBase parser, Action <ProcessStartInfo> setupStartInfo)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            Program program;

            if (Application.platform == RuntimePlatform.WindowsEditor)
            {
                ProcessStartInfo processStartInfo = new ProcessStartInfo
                {
                    Arguments      = args,
                    CreateNoWindow = true,
                    FileName       = exe
                };
                if (setupStartInfo != null)
                {
                    setupStartInfo(processStartInfo);
                }
                program = new Program(processStartInfo);
            }
            else
            {
                program = new ManagedProgram(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), null, exe, args, false, setupStartInfo);
            }
            using (program)
            {
                program.GetProcessStartInfo().WorkingDirectory = workingDirectory;
                program.Start();
                program.WaitForExit();
                stopwatch.Stop();
                Console.WriteLine("{0} exited after {1} ms.", exe, stopwatch.ElapsedMilliseconds);
                if (program.ExitCode != 0)
                {
                    if (parser != null)
                    {
                        string[] errorOutput    = program.GetErrorOutput();
                        string[] standardOutput = program.GetStandardOutput();
                        IEnumerable <CompilerMessage> enumerable = parser.Parse(errorOutput, standardOutput, true);
                        foreach (CompilerMessage current in enumerable)
                        {
                            UnityEngine.Debug.LogPlayerBuildError(current.message, current.file, current.line, current.column);
                        }
                    }
                    UnityEngine.Debug.LogError(string.Concat(new string[]
                    {
                        "Failed running ",
                        exe,
                        " ",
                        args,
                        "\n\n",
                        program.GetAllOutput()
                    }));
                    throw new Exception(string.Format("{0} did not run properly!", exe));
                }
            }
        }
 private static void RunUpdatingProgram(string executable, string arguments)
 {
   ManagedProgram program = new ManagedProgram(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), "4.5", EditorApplication.applicationContentsPath + "/Tools/ScriptUpdater/" + executable, arguments);
   program.LogProcessStartInfo();
   program.Start();
   program.WaitForExit();
   Console.WriteLine(string.Join(Environment.NewLine, program.GetStandardOutput()));
   APIUpdaterHelper.HandleUpdaterReturnValue(program);
 }
        protected ManagedProgram StartCompiler(BuildTarget target, string compiler, List <string> arguments, bool setMonoEnvironmentVariables, string monodistro)
        {
            string text = CommandLineFormatter.GenerateResponseFile(arguments);

            base.RunAPIUpdaterIfRequired(text);
            ManagedProgram managedProgram = new ManagedProgram(monodistro, BuildPipeline.CompatibilityProfileToClassLibFolder(this._island._api_compatibility_level), compiler, " @" + text, setMonoEnvironmentVariables, null);

            managedProgram.Start();
            return(managedProgram);
        }
 protected ManagedProgram StartCompiler(BuildTarget target, string compiler, List<string> arguments, bool setMonoEnvironmentVariables)
 {
   this.AddCustomResponseFileIfPresent(arguments, Path.GetFileNameWithoutExtension(compiler) + ".rsp");
   string responseFile = CommandLineFormatter.GenerateResponseFile((IEnumerable<string>) arguments);
   if (this.runUpdater)
     APIUpdaterHelper.UpdateScripts(responseFile, this._island.GetExtensionOfSourceFiles());
   ManagedProgram managedProgram = new ManagedProgram(MonoInstallationFinder.GetMonoInstallation(), this._island._classlib_profile, compiler, " @" + responseFile, setMonoEnvironmentVariables);
   managedProgram.Start();
   return managedProgram;
 }
示例#8
0
        private static void RunUpdatingProgram(string executable, string arguments)
        {
            ManagedProgram program = new ManagedProgram(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), "4.5", EditorApplication.applicationContentsPath + "/Tools/ScriptUpdater/" + executable, arguments);

            program.LogProcessStartInfo();
            program.Start();
            program.WaitForExit();
            Console.WriteLine(string.Join(Environment.NewLine, program.GetStandardOutput()));
            APIUpdaterHelper.HandleUpdaterReturnValue(program);
        }
示例#9
0
        internal static void RunManagedProgram(string exe, string args, string workingDirectory, CompilerOutputParserBase parser)
        {
            Program   program;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            if (Application.platform == RuntimePlatform.WindowsEditor)
            {
                ProcessStartInfo si = new ProcessStartInfo {
                    Arguments      = args,
                    CreateNoWindow = true,
                    FileName       = exe
                };
                program = new Program(si);
            }
            else
            {
                program = new ManagedProgram(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), "4.0", exe, args);
            }
            using (program)
            {
                program.GetProcessStartInfo().WorkingDirectory = workingDirectory;
                program.Start();
                program.WaitForExit();
                stopwatch.Stop();
                Console.WriteLine("{0} exited after {1} ms.", exe, stopwatch.ElapsedMilliseconds);
                if (program.ExitCode != 0)
                {
                    if (parser != null)
                    {
                        string[] errorOutput    = program.GetErrorOutput();
                        string[] standardOutput = program.GetStandardOutput();
                        IEnumerator <CompilerMessage> enumerator = parser.Parse(errorOutput, standardOutput, true).GetEnumerator();
                        try
                        {
                            while (enumerator.MoveNext())
                            {
                                CompilerMessage current = enumerator.Current;
                                Debug.LogPlayerBuildError(current.message, current.file, current.line, current.column);
                            }
                        }
                        finally
                        {
                            if (enumerator == null)
                            {
                            }
                            enumerator.Dispose();
                        }
                    }
                    Debug.LogError("Failed running " + exe + " " + args + "\n\n" + program.GetAllOutput());
                    throw new Exception(string.Format("{0} did not run properly!", exe));
                }
            }
        }
示例#10
0
        protected ManagedProgram StartCompiler(BuildTarget target, string compiler, List <string> arguments, string profileDirectory, bool setMonoEnvironmentVariables, string monodistro, IList <string> pathMappings = null)
        {
            var responseFile = CommandLineFormatter.GenerateResponseFile(arguments);

            RunAPIUpdaterIfRequired(responseFile, pathMappings);

            var program = new ManagedProgram(monodistro, profileDirectory, compiler, " @" + responseFile, setMonoEnvironmentVariables, null);

            program.Start();

            return(program);
        }
        protected ManagedProgram StartCompiler(BuildTarget target, string compiler, List <string> arguments, bool setMonoEnvironmentVariables, string monodistro)
        {
            string text = CommandLineFormatter.GenerateResponseFile(arguments);

            if (this.runUpdater)
            {
                APIUpdaterHelper.UpdateScripts(text, this._island.GetExtensionOfSourceFiles());
            }
            ManagedProgram managedProgram = new ManagedProgram(monodistro, this._island._classlib_profile, compiler, " @" + text, setMonoEnvironmentVariables, null);

            managedProgram.Start();
            return(managedProgram);
        }
示例#12
0
        static void RunUpdatingProgram(string executable, string arguments, string tempOutputPath)
        {
            var scriptUpdater = EditorApplication.applicationContentsPath + "/Tools/ScriptUpdater/" + executable;
            var program       = new ManagedProgram(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), null, scriptUpdater, arguments, false, null);

            program.LogProcessStartInfo();
            program.Start();
            program.WaitForExit();

            Console.WriteLine(string.Join(Environment.NewLine, program.GetStandardOutput()));

            HandleUpdaterReturnValue(program, tempOutputPath);
        }
        protected ManagedProgram StartCompiler(BuildTarget target, string compiler, List <string> arguments, bool setMonoEnvironmentVariables)
        {
            base.AddCustomResponseFileIfPresent(arguments, Path.GetFileNameWithoutExtension(compiler) + ".rsp");
            string responseFile = CommandLineFormatter.GenerateResponseFile(arguments);

            if (this.runUpdater)
            {
                UnityEditor.Scripting.Compilers.APIUpdaterHelper.UpdateScripts(responseFile, this._island.GetExtensionOfSourceFiles());
            }
            ManagedProgram program = new ManagedProgram(MonoInstallationFinder.GetMonoInstallation(), this._island._classlib_profile, compiler, " @" + responseFile, setMonoEnvironmentVariables);

            program.Start();
            return(program);
        }
 private static void HandleUpdaterReturnValue(ManagedProgram program)
 {
   if (program.ExitCode == 0)
   {
     APIUpdaterHelper.UpdateFilesInVCIfNeeded();
   }
   else
   {
     ScriptUpdatingManager.ReportExpectedUpdateFailure();
     if (program.ExitCode > 0)
       APIUpdaterHelper.ReportAPIUpdaterFailure((IEnumerable<string>) program.GetErrorOutput());
     else
       APIUpdaterHelper.ReportAPIUpdaterCrash((IEnumerable<string>) program.GetErrorOutput());
   }
 }
示例#15
0
        static void RunUpdatingProgram(string executable, string arguments, string tempOutputPath, bool anyFileInAssetsFolder)
        {
            var scriptUpdaterPath = EditorApplication.applicationContentsPath + "/Tools/ScriptUpdater/" + executable; // ManagedProgram will quote this path for us.

            using (var program = new ManagedProgram(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), null, scriptUpdaterPath, arguments, false, null))
            {
                program.LogProcessStartInfo();
                program.Start();
                program.WaitForExit();

                Console.WriteLine(string.Join(Environment.NewLine, program.GetStandardOutput()));

                HandleUpdaterReturnValue(program, tempOutputPath, anyFileInAssetsFolder);
            }
        }
        public Program ParseManagedProgram(ManagedProgram managedProgram)
        {
            int programStepsCount = GetProgramStepsCount(managedProgram);
            List <ProgramStepWithSourceMap> programSteps = new(programStepsCount);

            List <ManagedProgramStep> innerLoopStepsBuffer = new();
            bool intoInnerLoop = false;

            foreach (ManagedProgramStep managedStep in managedProgram.ManagedProgramSteps)
            {
                switch (managedStep.InnerLoopFlag)
                {
                case InnerLoopFlag.None:
                    if (!intoInnerLoop)
                    {
                        programSteps.Add(ParseNoneLoopStep(managedStep));
                    }
                    else
                    {
                        innerLoopStepsBuffer.Add(managedStep);
                    }
                    break;

                case InnerLoopFlag.On:
                    innerLoopStepsBuffer.Add(managedStep);
                    intoInnerLoop = true;
                    break;

                case InnerLoopFlag.Off:
                    innerLoopStepsBuffer.Add(managedStep);
                    programSteps.AddRange(ParseInnerLoopSteps(innerLoopStepsBuffer));
                    innerLoopStepsBuffer.Clear();
                    intoInnerLoop = false;
                    break;
                }
            }

            if (intoInnerLoop)
            {
                throw new ArgumentException("The program is invalid", nameof(managedProgram));
            }

            return(new Program
            {
                OuterLoopCount = managedProgram.OuterLoopCount,
                ProgramStepsWithSourceMap = programSteps
            });
        }
示例#17
0
 private static void HandleUpdaterReturnValue(ManagedProgram program)
 {
     if (program.ExitCode == 0)
     {
         APIUpdaterHelper.UpdateFilesInVCIfNeeded();
         return;
     }
     ScriptUpdatingManager.ReportExpectedUpdateFailure();
     if (program.ExitCode > 0)
     {
         APIUpdaterHelper.ReportAPIUpdaterFailure(program.GetErrorOutput());
     }
     else
     {
         APIUpdaterHelper.ReportAPIUpdaterCrash(program.GetErrorOutput());
     }
 }
		private static void RunUpdatingProgram(string executable, string arguments)
		{
			string executable2 = EditorApplication.applicationContentsPath + "/Tools/ScriptUpdater/" + executable;
			ManagedProgram managedProgram = new ManagedProgram(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), "4.5", executable2, arguments);
			managedProgram.LogProcessStartInfo();
			managedProgram.Start();
			managedProgram.WaitForExit();
			Console.WriteLine(string.Join(Environment.NewLine, managedProgram.GetStandardOutput()));
			if (managedProgram.ExitCode == 0)
			{
				APIUpdaterHelper.UpdateFilesInVCIfNeeded();
			}
			else
			{
				APIUpdaterHelper.ReportAPIUpdaterFailure(managedProgram.GetErrorOutput());
			}
		}
示例#19
0
 private void Create(string _path, int _port)
 {
     string str2;
     string executable = EmscriptenPaths.buildToolsDir + "/SimpleWebServer.exe";
     object[] objArray1 = new object[] { "\"", _path, "\" ", _port, " ", Process.GetCurrentProcess().Id };
     ManagedProgram program = new ManagedProgram(MonoInstallationFinder.GetMonoInstallation("Mono"), "2.0", executable, string.Concat(objArray1), null);
     program._process.Start();
     do
     {
         str2 = program._process.StandardOutput.ReadLine();
     }
     while ((str2 != null) && !str2.Contains("Starting web server"));
     this.path = _path;
     this.port = _port;
     this.pid = program._process.Id;
     this.time = program._process.StartTime.ToString();
     this.Save(true);
 }
示例#20
0
        private static void RunUpdatingProgram(string executable, string arguments)
        {
            string         executable2    = EditorApplication.applicationContentsPath + "/Tools/ScriptUpdater/" + executable;
            ManagedProgram managedProgram = new ManagedProgram(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), "4.5", executable2, arguments);

            managedProgram.LogProcessStartInfo();
            managedProgram.Start();
            managedProgram.WaitForExit();
            Console.WriteLine(string.Join(Environment.NewLine, managedProgram.GetStandardOutput()));
            if (managedProgram.ExitCode == 0)
            {
                APIUpdaterHelper.UpdateFilesInVCIfNeeded();
            }
            else
            {
                APIUpdaterHelper.ReportAPIUpdaterFailure(managedProgram.GetErrorOutput());
            }
        }
示例#21
0
        static void HandleUpdaterReturnValue(ManagedProgram program, string tempOutputPath)
        {
            if (program.ExitCode == 0)
            {
                Console.WriteLine(string.Join(Environment.NewLine, program.GetErrorOutput()));
                CopyUpdatedFiles(tempOutputPath);
                return;
            }

            APIUpdaterManager.ReportExpectedUpdateFailure();
            if (program.ExitCode > 0)
            {
                ReportAPIUpdaterFailure(program.GetErrorOutput());
            }
            else
            {
                ReportAPIUpdaterCrash(program.GetErrorOutput());
            }
        }
示例#22
0
        private static void HandleUpdaterReturnValue(ManagedProgram program)
        {
            if (program.ExitCode == 0)
            {
                Console.WriteLine(string.Join(Environment.NewLine, program.GetErrorOutput()));
                UpdateFilesInVCIfNeeded();
                return;
            }

            ScriptUpdatingManager.ReportExpectedUpdateFailure();
            if (program.ExitCode > 0)
            {
                ReportAPIUpdaterFailure(program.GetErrorOutput());
            }
            else
            {
                ReportAPIUpdaterCrash(program.GetErrorOutput());
            }
        }
        private int GetProgramStepsCount(ManagedProgram managedProgram)
        {
            int  count               = 0;
            int  innerLoopCount      = 0;
            int  innerLoopStepsCount = 0;
            bool intoInnerLoop       = false;

            foreach (ManagedProgramStep managedStep in managedProgram.ManagedProgramSteps)
            {
                switch (managedStep.InnerLoopFlag)
                {
                case InnerLoopFlag.None:
                    if (!intoInnerLoop)
                    {
                        ++count;
                    }
                    else
                    {
                        ++innerLoopStepsCount;
                    }
                    break;

                case InnerLoopFlag.On:
                    innerLoopCount = managedStep.InnerLoopCount;
                    ++innerLoopStepsCount;
                    intoInnerLoop = true;
                    break;

                case InnerLoopFlag.Off:
                    ++innerLoopStepsCount;
                    count              += (innerLoopCount * innerLoopStepsCount);
                    innerLoopCount      = 0;
                    innerLoopStepsCount = 0;
                    intoInnerLoop       = false;
                    break;
                }
            }
            return(count);
        }
示例#24
0
        public void ExecuteAsync(BuildPlayerDataGeneratorOptions options)
        {
            Program typeDbGeneratorProcess;
            var     arguments = OptionsToStringArgument(options);

            if (NetCoreRunProgram.IsSupported())
            {
                typeDbGeneratorProcess = new NetCoreRunProgram(buildDataGeneratorPath, arguments, null);
            }
            else
            {
                typeDbGeneratorProcess =
                    new ManagedProgram(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), null,
                                       buildDataGeneratorPath, arguments, false, null);
            }

            typeDbGeneratorProcess.Start((s, e) =>
            {
                ProcessExit(typeDbGeneratorProcess);
            });
            runningProcesses.Add(typeDbGeneratorProcess);
        }
示例#25
0
        public static void WeaveInto(string assemblyPath, string destPath, string unityEngine, string playerPackage)
        {
            string arguments = Weaver.CommandLineArgsFor(assemblyPath, destPath, unityEngine);

            using (ManagedProgram managedProgram = Weaver.SerializationWeaverProgramWith(arguments, playerPackage))
            {
                try
                {
                    managedProgram.Start();
                }
                catch
                {
                    managedProgram.LogProcessStartInfo();
                    throw new Exception("Could not start SerializationWeaver.exe");
                }
                managedProgram.WaitForExit();
                if (managedProgram.ExitCode != 0)
                {
                    throw new Exception("Failed running SerializationWeaver. output was: " + managedProgram.GetAllOutput());
                }
            }
        }
示例#26
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);
            }
        }
示例#28
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);
        }