public static void UpdateScripts(string responseFile, string sourceExtension, string pathMappingsFilePath) { if (!APIUpdaterManager.WaitForVCSServerConnection(true)) { return; } var tempOutputPath = "Library/Temp/ScriptUpdater/" + new System.Random().Next() + "/"; try { RunUpdatingProgram( "ScriptUpdater.exe", sourceExtension + " " + CommandLineFormatter.PrepareFileName(MonoInstallationFinder.GetFrameWorksFolder()) + " " + tempOutputPath + " " + APIUpdaterManager.ConfigurationSourcesFilter + " " + pathMappingsFilePath + " " + responseFile, tempOutputPath); } catch (Exception ex) when(!(ex is StackOverflowException) && !(ex is ExecutionEngineException)) { Debug.LogError("[API Updater] ScriptUpdater threw an exception. Check the following message in the log."); Debug.LogException(ex); APIUpdaterManager.ReportExpectedUpdateFailure(); } }
private Program StartCompilerImpl(List <string> arguments, string argsPrefix, bool msBuildCompiler) { foreach (string reference in this._island._references) { arguments.Add("/reference:" + ScriptCompilerBase.PrepareFileName(reference)); } foreach (string str in ((IEnumerable <string>) this._island._defines).Distinct <string>()) { arguments.Add("/define:" + str); } foreach (string file in this._island._files) { arguments.Add(ScriptCompilerBase.PrepareFileName(file).Replace('/', '\\')); } string path = !msBuildCompiler?Path.Combine(MicrosoftCSharpCompiler.WindowsDirectory, "Microsoft.NET\\Framework\\v4.0.30319\\Csc.exe") : Path.Combine(MicrosoftCSharpCompiler.ProgramFilesDirectory, "MSBuild\\14.0\\Bin\\csc.exe"); if (!File.Exists(path)) { throw new Exception("'" + path + "' not found, either .NET 4.5 is not installed or your OS is not Windows 8/8.1."); } this.AddCustomResponseFileIfPresent(arguments, "csc.rsp"); string responseFile = CommandLineFormatter.GenerateResponseFile((IEnumerable <string>)arguments); Program program = new Program(new ProcessStartInfo() { Arguments = argsPrefix + "@" + responseFile, FileName = path, CreateNoWindow = true }); program.Start(); return(program); }
public static string PrepareFileName(string input) { if (Application.platform == RuntimePlatform.OSXEditor) { return(CommandLineFormatter.EscapeCharsQuote(input)); } return(CommandLineFormatter.EscapeCharsWindows(input)); }
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); }
public static string ArgumentsForScriptUpdater(string sourceExtension, string tempOutputPath, string pathMappingsFilePath, string responseFile) { return(sourceExtension + " " + CommandLineFormatter.PrepareFileName(MonoInstallationFinder.GetFrameWorksFolder()) + " " + CommandLineFormatter.PrepareFileName(tempOutputPath) + " \"" + APIUpdaterManager.ConfigurationSourcesFilter + "\" " // Quote the filter (regex) to avoid issues when passing through command line arg.) + CommandLineFormatter.PrepareFileName(pathMappingsFilePath) + " " + responseFile); // Response file is always relative and without spaces, no need to quote. }
public static void UpdateScripts(string responseFile, string sourceExtension, string[] sourceFiles) { if (!APIUpdaterManager.WaitForVCSServerConnection(true)) { return; } var pathMappingsFilePath = Path.GetTempFileName(); var filePathMappings = new List <string>(sourceFiles.Length); foreach (var source in sourceFiles) { var f = CommandLineFormatter.PrepareFileName(source); f = Paths.UnifyDirectorySeparator(f); if (f != source) { filePathMappings.Add(f + " => " + source); } } File.WriteAllLines(pathMappingsFilePath, filePathMappings.ToArray()); var tempOutputPath = "Library/Temp/ScriptUpdater/" + new System.Random().Next() + "/"; try { RunUpdatingProgram( "ScriptUpdater.exe", sourceExtension + " " + CommandLineFormatter.PrepareFileName(MonoInstallationFinder.GetFrameWorksFolder()) + " " + tempOutputPath + " \"" // Quote the filer (regex) to avoid issues when passing through command line arg. + APIUpdaterManager.ConfigurationSourcesFilter + "\" " + pathMappingsFilePath + " " + responseFile, tempOutputPath); } #pragma warning disable CS0618 // Type or member is obsolete catch (Exception ex) when(!(ex is StackOverflowException) && !(ex is ExecutionEngineException)) #pragma warning restore CS0618 // Type or member is obsolete { Debug.LogError("[API Updater] ScriptUpdater threw an exception. Check the following message in the log."); Debug.LogException(ex); APIUpdaterManager.ReportExpectedUpdateFailure(); } }
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); }
private Program StartCompilerImpl(List <string> arguments, string argsPrefix, bool msBuildCompiler) { string str4; foreach (string str in this._island._references) { arguments.Add("/reference:" + ScriptCompilerBase.PrepareFileName(str)); } IEnumerator <string> enumerator = this._island._defines.Distinct <string>().GetEnumerator(); try { while (enumerator.MoveNext()) { arguments.Add("/define:" + enumerator.Current); } } finally { if (enumerator == null) { } enumerator.Dispose(); } foreach (string str3 in this._island._files) { arguments.Add(ScriptCompilerBase.PrepareFileName(str3).Replace('/', '\\')); } if (msBuildCompiler) { str4 = Path.Combine(ProgramFilesDirectory, @"MSBuild\14.0\Bin\csc.exe"); } else { str4 = Path.Combine(WindowsDirectory, @"Microsoft.NET\Framework\v4.0.30319\Csc.exe"); } if (!File.Exists(str4)) { throw new Exception("'" + str4 + "' not found, either .NET 4.5 is not installed or your OS is not Windows 8/8.1."); } base.AddCustomResponseFileIfPresent(arguments, "csc.rsp"); string str5 = CommandLineFormatter.GenerateResponseFile(arguments); ProcessStartInfo si = new ProcessStartInfo { Arguments = argsPrefix + "@" + str5, FileName = str4, CreateNoWindow = true }; Program program = new Program(si); 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); }
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); }
public static string PrepareFileName(string input) { input = FileUtil.ResolveSymlinks(input); string result; if (Application.platform == RuntimePlatform.WindowsEditor) { result = CommandLineFormatter.EscapeCharsWindows(input); } else { result = CommandLineFormatter.EscapeCharsQuote(input); } return(result); }
public static void UpdateScripts(string responseFile, string sourceExtension, string[] sourceFiles) { bool anyFileInAssetsFolder = false; var pathMappingsFilePath = Path.GetTempFileName(); var filePathMappings = new List <string>(sourceFiles.Length); foreach (var source in sourceFiles) { anyFileInAssetsFolder |= (source.IndexOf("Assets/", StringComparison.OrdinalIgnoreCase) != -1); var f = CommandLineFormatter.PrepareFileName(source); if (f != source) // assume path represents a virtual path and needs to be mapped. { f = Paths.UnifyDirectorySeparator(f); filePathMappings.Add(f + " => " + source); } } // Only try to connect to VCS if there are files under VCS that need to be updated if (anyFileInAssetsFolder && !APIUpdaterManager.WaitForVCSServerConnection(true)) { return; } File.WriteAllLines(pathMappingsFilePath, filePathMappings.ToArray()); var tempOutputPath = "Library/Temp/ScriptUpdater/" + new System.Random().Next() + "/"; try { var arguments = ArgumentsForScriptUpdater( sourceExtension, tempOutputPath, pathMappingsFilePath, responseFile); RunUpdatingProgram("ScriptUpdater.exe", arguments, tempOutputPath, anyFileInAssetsFolder); } #pragma warning disable CS0618 // Type or member is obsolete catch (Exception ex) when(!(ex is StackOverflowException) && !(ex is ExecutionEngineException)) #pragma warning restore CS0618 // Type or member is obsolete { Debug.LogError("[API Updater] ScriptUpdater threw an exception. Check the following message in the log."); Debug.LogException(ex); APIUpdaterManager.ReportExpectedUpdateFailure(); } }
public static void UpdateScripts(string responseFile, string sourceExtension) { if (ScriptUpdatingManager.WaitForVCSServerConnection(true)) { string text = (!Provider.enabled) ? "." : "Temp/ScriptUpdater/"; APIUpdaterHelper.RunUpdatingProgram("ScriptUpdater.exe", string.Concat(new string[] { sourceExtension, " ", CommandLineFormatter.PrepareFileName(MonoInstallationFinder.GetFrameWorksFolder()), " ", text, " ", responseFile })); } }
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); } foreach (string source in _island._files) { arguments.Add(PrepareFileName(source).Replace('/', '\\')); } var coreRun = Paths.Combine(EditorApplication.applicationContentsPath, "Tools", "Roslyn", "CoreRun.exe").Replace('/', '\\'); var csc = Paths.Combine(EditorApplication.applicationContentsPath, "Tools", "Roslyn", "csc.exe").Replace('/', '\\'); if (!File.Exists(coreRun)) { ThrowCompilerNotFoundException(coreRun); } if (!File.Exists(csc)) { ThrowCompilerNotFoundException(csc); } AddCustomResponseFileIfPresent(arguments, "csc.rsp"); var responseFile = CommandLineFormatter.GenerateResponseFile(arguments); RunAPIUpdaterIfRequired(responseFile); var psi = new ProcessStartInfo() { Arguments = "\"" + csc + "\" " + argsPrefix + "@" + responseFile, FileName = coreRun, CreateNoWindow = true }; var program = new Program(psi); program.Start(); return(program); }
private Program StartCompilerImpl(List <string> arguments, string argsPrefix, bool msBuildCompiler) { string[] references = this._island._references; for (int i = 0; i < references.Length; i++) { string fileName = references[i]; arguments.Add("/reference:" + ScriptCompilerBase.PrepareFileName(fileName)); } foreach (string current in this._island._defines.Distinct <string>()) { arguments.Add("/define:" + current); } string[] files = this._island._files; for (int j = 0; j < files.Length; j++) { string fileName2 = files[j]; arguments.Add(ScriptCompilerBase.PrepareFileName(fileName2).Replace('/', '\\')); } string text; if (msBuildCompiler) { text = Path.Combine(MicrosoftCSharpCompiler.ProgramFilesDirectory, "MSBuild\\14.0\\Bin\\csc.exe"); } else { text = Path.Combine(MicrosoftCSharpCompiler.WindowsDirectory, "Microsoft.NET\\Framework\\v4.0.30319\\Csc.exe"); } if (!File.Exists(text)) { throw new Exception("'" + text + "' not found, either .NET 4.5 is not installed or your OS is not Windows 8/8.1."); } base.AddCustomResponseFileIfPresent(arguments, "csc.rsp"); string str = CommandLineFormatter.GenerateResponseFile(arguments); ProcessStartInfo si = new ProcessStartInfo { Arguments = argsPrefix + "@" + str, FileName = text, CreateNoWindow = true }; Program program = new Program(si); program.Start(); return(program); }
public static void UpdateScripts(string responseFile, string sourceExtension) { if (!ScriptUpdatingManager.WaitForVCSServerConnection(true)) { return; } var outputPath = Provider.enabled ? tempOutputPath : "."; RunUpdatingProgram( "ScriptUpdater.exe", sourceExtension + " " + CommandLineFormatter.PrepareFileName(MonoInstallationFinder.GetFrameWorksFolder()) + " " + outputPath + " " + responseFile); }
protected static string PrepareFileName(string fileName) { return(CommandLineFormatter.PrepareFileName(fileName)); }
private Program StartCompilerImpl(List <string> arguments, string argsPrefix) { string[] references = this._island._references; for (int i = 0; i < references.Length; i++) { string fileName = references[i]; arguments.Add("/reference:" + ScriptCompilerBase.PrepareFileName(fileName)); } foreach (string current in this._island._defines.Distinct <string>()) { arguments.Add("/define:" + current); } string[] files = this._island._files; for (int j = 0; j < files.Length; j++) { string fileName2 = files[j]; arguments.Add(ScriptCompilerBase.PrepareFileName(fileName2).Replace('/', '\\')); } string text = Paths.Combine(new string[] { EditorApplication.applicationContentsPath, "Tools", "Roslyn", "CoreRun.exe" }).Replace('/', '\\'); string text2 = Paths.Combine(new string[] { EditorApplication.applicationContentsPath, "Tools", "Roslyn", "csc.exe" }).Replace('/', '\\'); if (!File.Exists(text)) { MicrosoftCSharpCompiler.ThrowCompilerNotFoundException(text); } if (!File.Exists(text2)) { MicrosoftCSharpCompiler.ThrowCompilerNotFoundException(text2); } base.AddCustomResponseFileIfPresent(arguments, "csc.rsp"); string text3 = CommandLineFormatter.GenerateResponseFile(arguments); ProcessStartInfo si = new ProcessStartInfo { Arguments = string.Concat(new string[] { "\"", text2, "\" ", argsPrefix, "@", text3 }), FileName = text, CreateNoWindow = true }; Program program = new Program(si); program.Start(); return(program); }
protected static string PrepareFileName(string fileName) => CommandLineFormatter.PrepareFileName(fileName);
internal static string GenerateResponseFile(ScriptAssembly assembly, string tempBuildDirectory) { var assemblyOutputPath = PrepareFileName(AssetPath.Combine(tempBuildDirectory, assembly.Filename)); var arguments = new List <string> { "/target:library", "/nowarn:0169", "/out:" + assemblyOutputPath }; if (assembly.CompilerOptions.AllowUnsafeCode) { arguments.Add("/unsafe"); } if (assembly.CompilerOptions.UseDeterministicCompilation) { arguments.Add("/deterministic"); } arguments.Add("/debug:portable"); if (assembly.CompilerOptions.CodeOptimization == CodeOptimization.Release) { arguments.Add("/optimize+"); } else { arguments.Add("/optimize-"); } FillCompilerOptions(arguments, assembly.BuildTarget); string[] scriptAssemblyReferences = new string[assembly.ScriptAssemblyReferences.Length]; for (var index = 0; index < assembly.ScriptAssemblyReferences.Length; index++) { var reference = assembly.ScriptAssemblyReferences[index]; scriptAssemblyReferences[index] = "/reference:" + PrepareFileName(AssetPath.Combine(assembly.OutputDirectory, reference.Filename)); } Array.Sort(scriptAssemblyReferences, StringComparer.Ordinal); arguments.AddRange(scriptAssemblyReferences); Array.Sort(assembly.References, StringComparer.Ordinal); foreach (var reference in assembly.References) { arguments.Add("/reference:" + PrepareFileName(reference)); } var defines = assembly.Defines.Distinct().ToArray(); Array.Sort(defines, StringComparer.Ordinal); foreach (var define in defines) { arguments.Add("/define:" + define); } Array.Sort(assembly.Files, StringComparer.Ordinal); foreach (var source in assembly.Files) { var f = PrepareFileName(source); f = Paths.UnifyDirectorySeparator(f); arguments.Add(f); } var responseFileProvider = assembly.Language?.CreateResponseFileProvider(); var responseFilesList = responseFileProvider?.Get(assembly.OriginPath) ?? new List <string>(); HashSet <string> responseFiles = new HashSet <string>(responseFilesList); string obsoleteResponseFile = responseFiles.SingleOrDefault( x => CompilerSpecificResponseFiles.MicrosoftCSharpCompilerObsolete.Contains(AssetPath.GetFileName(x))); if (!string.IsNullOrEmpty(obsoleteResponseFile)) { Debug.LogWarning($"Using obsolete custom response file '{AssetPath.GetFileName(obsoleteResponseFile)}'. Please use '{CompilerSpecificResponseFiles.MicrosoftCSharpCompiler}' instead."); } foreach (var file in responseFiles) { AddResponseFileToArguments(arguments, file, assembly.CompilerOptions.ApiCompatibilityLevel); } var responseFile = CommandLineFormatter.GenerateResponseFile(arguments); return(responseFile); }
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); } }
protected string GenerateResponseFile(List <string> arguments) { this._responseFile = CommandLineFormatter.GenerateResponseFile(arguments); return(this._responseFile); }
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); } }
public static void UpdateScripts(string responseFile, string sourceExtension) { if (!ScriptUpdatingManager.WaitForVCSServerConnection(true)) { return; } string str = !Provider.enabled ? "." : "Temp/ScriptUpdater/"; APIUpdaterHelper.RunUpdatingProgram("ScriptUpdater.exe", sourceExtension + " " + CommandLineFormatter.PrepareFileName(MonoInstallationFinder.GetFrameWorksFolder()) + " " + str + " " + responseFile); }
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); f = Paths.UnifyDirectorySeparator(f); arguments.Add(f); if (f != source) { filePathMappings.Add(f + " => " + source); } } var csc = Paths.Combine(EditorApplication.applicationContentsPath, "Tools", "RoslynScripts", "unity_csc"); if (Application.platform == RuntimePlatform.WindowsEditor) { csc += ".bat"; } else { csc += ".sh"; } csc = Paths.UnifyDirectorySeparator(csc); if (!File.Exists(csc)) { ThrowCompilerNotFoundException(csc); } 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)) { Debug.LogWarning($"Using obsolete custom response file '{obsoleteResponseFile.Key}'. Please use '{CompilerSpecificResponseFiles.MicrosoftCSharpCompiler}' instead."); } foreach (var file in responseFiles) { AddResponseFileToArguments(arguments, file.Value); } var responseFile = CommandLineFormatter.GenerateResponseFile(arguments); RunAPIUpdaterIfRequired(responseFile, filePathMappings); var psi = new ProcessStartInfo() { Arguments = argsPrefix + "@" + responseFile, FileName = csc, CreateNoWindow = true }; var program = new Program(psi); program.Start(); return(program); }
internal static string GenerateResponseFile(ScriptAssembly assembly, EditorScriptCompilationOptions options, string tempBuildDirectory) { bool buildingForEditor = (options & EditorScriptCompilationOptions.BuildingForEditor) == EditorScriptCompilationOptions.BuildingForEditor; bool developmentBuild = (options & EditorScriptCompilationOptions.BuildingDevelopmentBuild) == EditorScriptCompilationOptions.BuildingDevelopmentBuild; var assemblyOutputPath = PrepareFileName(AssetPath.Combine(tempBuildDirectory, assembly.Filename)); var arguments = new List <string> { "/target:library", "/nowarn:0169", "/out:" + assemblyOutputPath }; if (assembly.CompilerOptions.AllowUnsafeCode) { arguments.Add("/unsafe"); } arguments.Add("/debug:portable"); var disableOptimizations = developmentBuild || (buildingForEditor && EditorPrefs.GetBool("AllowAttachedDebuggingOfEditor", true)); if (!disableOptimizations) { arguments.Add("/optimize+"); } else { arguments.Add("/optimize-"); } FillCompilerOptions(arguments, buildingForEditor, assembly.BuildTarget); foreach (var reference in assembly.ScriptAssemblyReferences) { arguments.Add("/reference:" + PrepareFileName(AssetPath.Combine(assembly.OutputDirectory, reference.Filename))); } foreach (var reference in assembly.References) { arguments.Add("/reference:" + PrepareFileName(reference)); } foreach (var define in assembly.Defines.Distinct()) { arguments.Add("/define:" + define); } foreach (var source in assembly.Files) { var f = PrepareFileName(source); f = Paths.UnifyDirectorySeparator(f); arguments.Add(f); } var responseFileProvider = assembly.Language?.CreateResponseFileProvider(); var responseFilesList = responseFileProvider?.Get(assembly.OriginPath) ?? new List <string>(); HashSet <string> responseFiles = new HashSet <string>(responseFilesList); string obsoleteResponseFile = responseFiles.SingleOrDefault( x => CompilerSpecificResponseFiles.MicrosoftCSharpCompilerObsolete.Contains(AssetPath.GetFileName(x))); if (!string.IsNullOrEmpty(obsoleteResponseFile)) { Debug.LogWarning($"Using obsolete custom response file '{AssetPath.GetFileName(obsoleteResponseFile)}'. Please use '{CompilerSpecificResponseFiles.MicrosoftCSharpCompiler}' instead."); } foreach (var file in responseFiles) { AddResponseFileToArguments(arguments, file, assembly.CompilerOptions.ApiCompatibilityLevel); } var responseFile = CommandLineFormatter.GenerateResponseFile(arguments); return(responseFile); }