public void Start() { var runner = Paths.Combine(EditorApplication.applicationContentsPath, "Tools", "ILPostProcessorRunner", "ILPostProcessorRunner.exe"); if (!File.Exists(runner)) { throw new Exception(string.Format($"'{runner}' not found. Is your Unity installation corrupted?")); } var assemblyPath = AssetPath.GetFullPath(AssetPath.Combine(tempOutputDirectory, Assembly.Filename)); var assemblyReferencesPaths = Assembly.GetAllReferences().ToArray(); var assemblyFolderPaths = ilPostProcessing.AssemblySearchPaths; var outputDirectory = AssetPath.GetFullPath(tempOutputDirectory); var postProcessorPaths = ilPostProcessing.PostProcessorAssemblyPaths; var arguments = new List <string> { $"-a \"{assemblyPath}\"", $"-f \"{string.Join(",", assemblyFolderPaths)}\"", $"-r \"{string.Join(",", assemblyReferencesPaths)}\"", $"-d \"{string.Join(",", Assembly.Defines)}\"", $"-p \"{string.Join(",", postProcessorPaths)}\"", $"-o \"{outputDirectory}\"", }; var responseFilePath = PrepareFileName(AssetPath.GetFullPath(CommandLineFormatter.GenerateResponseFile(arguments))); var args = $"@{responseFilePath}"; // Always run on Mono until all ILPostProcessors have been fixed // to run on NET Core. //if (NetCoreRunProgram.IsSupported()) //{ // process = new NetCoreRunProgram(runner, args, null); //} //else { process = new ManagedProgram(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), null, runner, args, false, null); } process.Start(); }
static string GenerateResponseFileEdited( ScriptAssembly assembly, EditorScriptCompilationOptions options, string tempBuildDirectory) { bool buildingForEditor = (options & EditorScriptCompilationOptions.BuildingForEditor) == EditorScriptCompilationOptions.BuildingForEditor; bool flag = (options & EditorScriptCompilationOptions.BuildingDevelopmentBuild) == EditorScriptCompilationOptions.BuildingDevelopmentBuild; List <string> arguments = new List <string>() { "-target:library", "-nowarn:0169", "-out:" + PrepareFileName(AssetPath.Combine(tempBuildDirectory, assembly.Filename)) }; // added arguments.Add("-define:__UNITY_PROCESSID__" + Process.GetCurrentProcess().Id); if (assembly.CompilerOptions.AllowUnsafeCode) { arguments.Add("-unsafe"); } arguments.Add("-debug:portable"); if (!flag && (!buildingForEditor || !EditorPrefs.GetBool("AllowAttachedDebuggingOfEditor", true))) { arguments.Add("-optimize+"); } else { arguments.Add("-optimize-"); } FillCompilerOptionsEdited(arguments, buildingForEditor, assembly.BuildTarget); foreach (ScriptAssembly assemblyReference in assembly.ScriptAssemblyReferences) { arguments.Add("-reference:" + ScriptCompilerBase.PrepareFileName(AssetPath.Combine(assembly.OutputDirectory, assemblyReference.Filename))); } foreach (string reference in assembly.References) { arguments.Add("-reference:" + ScriptCompilerBase.PrepareFileName(reference)); } foreach (string str in ((IEnumerable <string>)assembly.Defines).Distinct <string>()) { arguments.Add("-define:" + str); } foreach (string file in assembly.Files) { string str = Paths.UnifyDirectorySeparator(ScriptCompilerBase.PrepareFileName(file)); arguments.Add(str); } HashSet <string> source = new HashSet <string>((IEnumerable <string>)(assembly.Language?.CreateResponseFileProvider()?.Get(assembly.OriginPath) ?? new List <string>())); string path = source.SingleOrDefault <string>((Func <string, bool>)(x => ((IEnumerable <string>)CompilerSpecificResponseFiles.MicrosoftCSharpCompilerObsolete).Contains <string>(AssetPath.GetFileName(x)))); if (!string.IsNullOrEmpty(path)) { UnityEngine.Debug.LogWarning((object)("Using obsolete custom response file '" + AssetPath.GetFileName(path) + "'. Please use 'csc.rsp' instead.")); } // Assembly-CSharp has null OriginPath if (assembly.OriginPath?.StartsWith("Assets", StringComparison.Ordinal) ?? true) { // excludes unity packages var rspPath = "Assets/assets-csc.rsp"; if (File.Exists(rspPath)) { source.Add(rspPath); } } foreach (string responseFileName in source) { ScriptCompilerBase.AddResponseFileToArguments(arguments, responseFileName, assembly.CompilerOptions.ApiCompatibilityLevel); } return(CommandLineFormatter.GenerateResponseFile((IEnumerable <string>)arguments)); }
// 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()); } }