public async Task <bool> Extract(string archivePath, string outputDirectory, List <string> extraArguments = null) { if (String.IsNullOrEmpty(archivePath)) { throw new ArgumentException("must not be null or empty", nameof(archivePath)); } if (String.IsNullOrEmpty(outputDirectory)) { throw new ArgumentException("must not be null or empty", nameof(outputDirectory)); } ProcessRunner runner = CreateProcessRunner("x"); AddStandardArguments(runner); AddArguments(runner, extraArguments); runner.AddQuotedArgument($"-o{outputDirectory}"); runner.AddQuotedArgument(archivePath); try { Log.StatusLine($"Archive path: {archivePath}", ConsoleColor.White); return(await RunTool( () => { using (TextWriter outputSink = SetupOutputSink(runner, $"7zip-extract.{Path.GetFileName (archivePath)}", "extracting archive")) { runner.WorkingDirectory = Path.GetDirectoryName(archivePath); StartTwiddler(); return runner.Run(); } } )); } finally { StopTwiddler(); } }
async Task <bool> DoZip(string outputArchivePath, string workingDirectory, List <string> inputFiles, string archiveFormat, uint compressionLevel) { if (String.IsNullOrEmpty(outputArchivePath)) { throw new ArgumentException("must not be null or empty", nameof(outputArchivePath)); } if (String.IsNullOrEmpty(workingDirectory)) { throw new ArgumentException("must not be null or empty", nameof(workingDirectory)); } if (inputFiles == null) { throw new ArgumentNullException(nameof(inputFiles)); } var files = inputFiles.Where(f => !String.IsNullOrEmpty(f)).ToList(); if (files.Count == 0) { throw new ArgumentException("must not be an empty list", nameof(inputFiles)); } ProcessRunner runner = CreateProcessRunner("a"); AddStandardArguments(runner); runner.AddArgument($"-t{archiveFormat}"); runner.AddArgument($"-mx={compressionLevel}"); // maximum compression (range: 0-9) runner.AddQuotedArgument(outputArchivePath); string responseFilePath = Path.GetTempFileName(); File.WriteAllLines(responseFilePath, files); runner.AddQuotedArgument($"@{responseFilePath}"); try { Log.StatusLine($"Archive path: {outputArchivePath}", ConsoleColor.White); return(await RunTool( () => { using (TextWriter outputSink = SetupOutputSink(runner, $"7zip-create-{archiveFormat}.{Path.GetFileName (outputArchivePath)}", $"creating {archiveFormat} archive")) { runner.WorkingDirectory = workingDirectory; StartTwiddler(); return runner.Run(); } } )); } finally { StopTwiddler(); Utilities.DeleteFileSilent(responseFilePath); } }
public async Task <bool> Restore(string solutionFilePath) { if (String.IsNullOrEmpty(solutionFilePath)) { throw new ArgumentException("must not be null or empty", nameof(solutionFilePath)); } if (!File.Exists(solutionFilePath)) { throw new InvalidOperationException($"Solution file '{solutionFilePath}' does not exist"); } ProcessRunner runner = CreateProcessRunner("restore"); runner.AddArgument("-Verbosity").AddArgument("detailed"); runner.AddArgument("-NonInteractive"); runner.AddArgument("-ForceEnglishOutput"); runner.AddQuotedArgument(solutionFilePath); try { return(await RunTool(() => { using (TextWriter outputSink = SetupOutputSink(runner, $"nuget-restore.{Path.GetFileName (solutionFilePath)}", "restoring NuGet packages")) { Log.StatusLine($"Solution file: {Utilities.GetRelativePath (BuildPaths.XamarinAndroidSourceRoot, solutionFilePath)}", ConsoleColor.White); runner.WorkingDirectory = Path.GetDirectoryName(solutionFilePath); StartTwiddler(); return runner.Run(); } } )); } finally { StopTwiddler(); } }
public async Task <bool> Extract(string fullArchivePath, string destinationDirectory) { if (String.IsNullOrEmpty(fullArchivePath)) { throw new ArgumentException("must not be null or empty", nameof(fullArchivePath)); } if (String.IsNullOrEmpty(destinationDirectory)) { throw new ArgumentException("must not be null or empty", nameof(destinationDirectory)); } ProcessRunner runner = CreateProcessRunner(); runner.AddArgument("-x"); runner.AddArgument("-f"); runner.AddQuotedArgument(fullArchivePath); try { Log.StatusLine($"Archive path: {fullArchivePath}"); return(await RunTool( () => { using (TextWriter outputSink = SetupOutputSink(runner, $"tar-extract-archive.{Path.GetFileName (fullArchivePath)}", "extracting archive")) { StartTwiddler(); runner.WorkingDirectory = destinationDirectory; return runner.Run(); } } )); } finally { StopTwiddler(); } }
public async Task <bool> VerifyArchive(string archivePath) { if (String.IsNullOrEmpty(archivePath)) { throw new ArgumentException("must not be null or empty", nameof(archivePath)); } ProcessRunner runner = CreateProcessRunner("t"); AddStandardArguments(runner); runner.AddQuotedArgument(archivePath); try { Log.StatusLine($"Archive path: {archivePath}"); return(await RunTool( () => { using (TextWriter outputSink = SetupOutputSink(runner, $"7zip-verify-archive.{Path.GetFileName (archivePath)}", "verifying archive integrity")) { StartTwiddler(); return runner.Run(); } } )); } finally { StopTwiddler(); } }
protected virtual ProcessRunner CreateProcessRunner(params string[] initialParams) { string managedRunner = Context.OS.GetManagedProgramRunner(FullToolPath); if (managedRunner != null) { managedRunner = Context.OS.Which(managedRunner); } var runner = new ProcessRunner(managedRunner ?? FullToolPath, initialParams) { ProcessTimeout = ProcessTimeout, EchoCmdAndArguments = EchoCmdAndArguments, EchoStandardError = EchoStandardError, EchoStandardOutput = EchoStandardOutput, }; if (Context.Instance.OS.EnvironmentVariables != null) { foreach (var kvp in Context.Instance.OS.EnvironmentVariables) { runner.Environment [kvp.Key] = kvp.Value; } } if (managedRunner != null) { runner.AddQuotedArgument(FullToolPath); } return(runner); }
public async Task <bool> Run(string projectPath, string logTag, List <string> arguments = null, string binlogName = null, string workingDirectory = null) { if (String.IsNullOrEmpty(logTag)) { throw new ArgumentException("must not be null or empty", nameof(logTag)); } if (String.IsNullOrEmpty(workingDirectory)) { workingDirectory = BuildPaths.XamarinAndroidSourceRoot; } ProcessRunner runner = CreateProcessRunner(); AddArguments(runner, StandardArguments); if (!String.IsNullOrEmpty(binlogName)) { string logPath = Utilities.GetRelativePath(workingDirectory, Path.Combine(Configurables.Paths.BuildBinDir, $"msbuild-{Context.BuildTimeStamp}-{binlogName}.binlog")); runner.AddArgument("/v:normal"); runner.AddQuotedArgument($"/bl:{logPath}"); } AddArguments(runner, arguments); runner.AddQuotedArgument(Utilities.GetRelativePath(workingDirectory, projectPath)); string message = GetLogMessage(runner); Log.Info(message, CommandMessageColor); Log.StatusLine(); try { return(await RunTool( () => { using (var outputSink = (OutputSink)SetupOutputSink(runner, $"msbuild.{logTag}")) { runner.WorkingDirectory = workingDirectory; StartTwiddler(); return runner.Run(); } } )); } finally { StopTwiddler(); } }
public async Task <bool> ReSign(string snkPath, string assemblyPath, string logTag, string workingDirectory = null) { if (String.IsNullOrEmpty(snkPath)) { throw new ArgumentException("must not be null or empty", nameof(snkPath)); } if (String.IsNullOrEmpty(assemblyPath)) { throw new ArgumentException("must not be null or empty", nameof(assemblyPath)); } if (String.IsNullOrEmpty(logTag)) { throw new ArgumentException("must not be null or empty", nameof(logTag)); } if (String.IsNullOrEmpty(workingDirectory)) { workingDirectory = BuildPaths.XamarinAndroidSourceRoot; } ProcessRunner runner = CreateProcessRunner(); runner.AddQuotedArgument("-R"); runner.AddQuotedArgument(Utilities.GetRelativePath(workingDirectory, assemblyPath)); runner.AddQuotedArgument(Utilities.GetRelativePath(workingDirectory, snkPath)); string message = GetLogMessage(runner); Log.Info(message, CommandMessageColor); Log.StatusLine(); return(await RunTool( () => { using (var outputSink = (OutputSink)SetupOutputSink(runner, $"sn.{logTag}")) { runner.WorkingDirectory = workingDirectory; return runner.Run(); } } )); }
public override async Task <bool> Install() { Context context = Context.Instance; if (!context.AutoProvisionUsesSudo) { Log.ErrorLine("Installation of macOS packages requires sudo to be enabled (pass `--auto-provision-uses-sudo=yes` to the bootstrapper)"); return(false); } if (PackageUrl == null) { Log.ErrorLine($"{Name} is not installed but no URL is provided to download it from. Please make sure to install it before continuing"); return(false); } (bool success, ulong size) = await Utilities.GetDownloadSize(PackageUrl); if (!success) { Log.ErrorLine($"Failed to get download size of {PackageUrl}"); return(false); } DownloadStatus downloadStatus = Utilities.SetupDownloadStatus(context, size, context.InteractiveSession); Log.StatusLine($" {context.Characters.Link} {PackageUrl}", ConsoleColor.White); string localPath = Path.Combine(context.Properties.GetRequiredValue(KnownProperties.AndroidToolchainCacheDirectory), Path.GetFileName(PackageUrl.LocalPath)); success = await Utilities.Download(PackageUrl, localPath, downloadStatus); if (!success) { Log.ErrorLine($"Failed to download {PackageUrl}"); return(false); } var runner = new ProcessRunner("sudo") { EchoStandardError = true, EchoStandardOutput = true, ProcessTimeout = TimeSpan.FromMinutes(10) }; runner.AddArgument("/usr/sbin/installer"); runner.AddArgument("-verbose"); runner.AddArgument("-pkg"); runner.AddQuotedArgument(localPath); runner.AddArgument("-target"); runner.AddArgument("/"); return(await Task.Run(() => runner.Run())); }
public async Task <bool> Run(string logTag, string?workingDirectory = null, List <string>?arguments = null) { if (String.IsNullOrEmpty(logTag)) { throw new ArgumentException("must not be null or empty", nameof(logTag)); } bool haveChangeDirArg = false; bool haveConcurrency = false; ProcessRunner runner = CreateProcessRunner(); if (arguments != null && arguments.Count > 0) { foreach (string a in arguments) { string arg = a.Trim(); if (String.IsNullOrEmpty(arg)) { continue; } if (arg.StartsWith("-C", StringComparison.Ordinal) || arg.StartsWith("--directory", StringComparison.Ordinal)) { haveChangeDirArg = true; } if (arg.StartsWith("-j", StringComparison.Ordinal)) { haveConcurrency = true; } runner.AddQuotedArgument(arg); } } SetStandardArguments(workingDirectory, haveChangeDirArg, haveConcurrency, runner); string message = GetLogMessage(runner); Log.Info(message, CommandMessageColor); Log.StatusLine(); try { return(await RunTool( () => { using (var outputSink = (OutputSink)SetupOutputSink(runner, $"make.{logTag}")) { StartTwiddler(); runner.WorkingDirectory = workingDirectory; return runner.Run(); } } )); } finally { StopTwiddler(); } }
void SetGitArguments(ProcessRunner runner, string workingDirectory, List <string> gitArguments) { foreach (string arg in standardGlobalOptions) { runner.AddArgument(arg); } if (!String.IsNullOrEmpty(workingDirectory)) { runner.AddArgument("-C"); runner.AddQuotedArgument(workingDirectory); } AddArguments(runner, gitArguments); }
protected void AddArguments(ProcessRunner runner, IEnumerable <string> arguments) { if (arguments == null) { return; } foreach (string a in arguments) { string arg = a?.Trim(); if (String.IsNullOrEmpty(arg)) { continue; } runner.AddQuotedArgument(arg); } }
public async Task <bool> Run(string logTag, string workingDirectory, List <string>?arguments = null) { if (String.IsNullOrEmpty(logTag)) { throw new ArgumentException("must not be null or empty", nameof(logTag)); } if (String.IsNullOrEmpty(workingDirectory)) { throw new ArgumentException("must not be null or empty", nameof(workingDirectory)); } ProcessRunner runner = CreateProcessRunner(); AddArguments(runner, arguments); bool haveConcurrency = false; bool haveChangeDir = false; if (arguments != null) { foreach (string a in arguments) { if (String.IsNullOrEmpty(a)) { continue; } if (a.StartsWith("-j", StringComparison.Ordinal)) { haveConcurrency = true; } if (a.StartsWith("-C", StringComparison.Ordinal)) { haveChangeDir = true; } } } if (!haveChangeDir) { runner.AddQuotedArgument($"-C{workingDirectory}"); } if (!haveConcurrency && Context.MakeConcurrency > 1) { runner.AddArgument($"-j{Context.MakeConcurrency}"); } try { return(await RunTool(() => { using (var outputSink = (OutputSink)SetupOutputSink(runner, $"ninja.{logTag}")) { outputSink.Runner = runner; runner.WorkingDirectory = workingDirectory; StartTwiddler(); return runner.Run(); } })); } finally { StopTwiddler(); } }