private string Execute(string[] providers, params string[] args) { var providersSet = (providers != null && providers.Any()) ? new HashSet <string>(providers) : null; var assemblyLoadPaths = PlatformAssemblyLoadPath .Where(x => providersSet?.Contains(x.Key) ?? true) .Select(x => x.Value) .ToArray(); var environment = Environment .Where(x => providersSet?.Contains(x.Key) ?? true) .SelectMany(x => x.Value) .ToDictionary(x => x.Key, x => x.Value); var pramExecutable = Path.Combine(PlatformsPackagePath, "Editor/Unity.Build.Internals/pram~/pram.exe"); var platformAssembliesPaths = string.Join(" ", assemblyLoadPaths.Select(x => $"--assembly-load-path \"{x}\"")); // Override executable and assembly load paths if local repository is used if (LocalPramDevelopmentRepository != null) { pramExecutable = $"\"{Path.Combine(LocalPramDevelopmentRepository, "artifacts/PramDistribution/pram.exe")}\""; platformAssembliesPaths = ""; } var trace = Trace ? "--trace --very-verbose" : ""; #if UNITY_EDITOR_WIN var exe = ".exe"; #elif UNITY_EDITOR_OSX var exe = ""; #else var exe = ""; #endif var monoExe = $"{EditorApplication.applicationContentsPath}/MonoBleedingEdge/bin/mono{exe}"; var arguments = new List <string> { $"\"{pramExecutable}\"", trace, platformAssembliesPaths }; arguments.AddRange(args.Select(arg => $"\"{arg}\"")); var result = ShellProcess.Run(new ShellProcessArguments() { ThrowOnError = false, AnyOutputToErrorIsAnError = false, Executable = monoExe, Arguments = arguments.ToArray(), EnvironmentVariables = environment }); if (Trace) { Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, "{0}", result.ErrorOutput); } if (!result.Succeeded) { throw new Exception($"Failed {result.Command}\n{result.ErrorOutput}"); } return(result.FullOutput); }
public static ShellProcess Start(ShellProcessArguments args) { var startInfo = new ProcessStartInfo() { FileName = args.Executable, Arguments = string.Join(" ", args.Arguments), WorkingDirectory = args.WorkingDirectory?.FullName ?? new DirectoryInfo(".").FullName, RedirectStandardInput = true, RedirectStandardOutput = true, StandardOutputEncoding = Encoding.UTF8, RedirectStandardError = true, StandardErrorEncoding = Encoding.UTF8, CreateNoWindow = true, UseShellExecute = false }; if (args.EnvironmentVariables != null) { foreach (var pair in args.EnvironmentVariables) { startInfo.EnvironmentVariables[pair.Key] = pair.Value; } } var shellProcess = new ShellProcess(startInfo); shellProcess.Process.OutputDataReceived += (sender, data) => { shellProcess.TimeOfLastObservedOutput = DateTime.Now; args.OutputDataReceived?.Invoke(sender, data); }; shellProcess.Process.ErrorDataReceived += (sender, data) => { shellProcess.TimeOfLastObservedOutput = DateTime.Now; args.ErrorDataReceived?.Invoke(sender, data); }; shellProcess.Process.Start(); shellProcess.Process.BeginOutputReadLine(); shellProcess.Process.BeginErrorReadLine(); return(shellProcess); }