Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
        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();
            }
        }
        ProcessRunner GetBrewRunner(bool echoOutput, bool echoError, List <string> arguments)
        {
            ProcessRunner runner = CreateProcessRunner();

            if ((needSudo ?? false) && (needArch ?? false))
            {
                // So we run `sudo arch -arch x86_64 brew …`
                runner.AddArgument("arch");
            }

            if (needArch ?? false)
            {
                runner.AddArgument("-arch");
                runner.AddArgument("x86_64");
            }

            if ((needSudo ?? false) || (needArch ?? false))
            {
                runner.AddArgument(BrewPath);
            }

            AddArguments(runner, arguments);

            if (!echoOutput)
            {
                runner.EchoStandardOutputLevel = ProcessStandardStreamWrapper.LogLevel.Debug;
            }

            if (!echoError)
            {
                runner.EchoStandardErrorLevel = ProcessStandardStreamWrapper.LogLevel.Debug;
            }

            return(runner);
        }
Esempio n. 4
0
        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()));
        }
Esempio n. 5
0
        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);
            }
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        void AddStandardArguments(ProcessRunner runner)
        {
            // Disable progress indicator (doesn't appear to have any effect with some versions of 7z)
            runner.AddArgument("-bd");

            // Write standard messages to stdout
            runner.AddArgument("-bso1");

            // Write progress updates to stdout
            runner.AddArgument("-bsp1");

            // Write errors to stderr
            runner.AddArgument("-bse2");

            // Answer 'yes' to all questions
            runner.AddArgument("-y");
        }
Esempio n. 8
0
 void SetCommandArguments(ProcessRunner runner, string command, List <string>?commandArguments)
 {
     runner.AddArgument(command);
     if (commandArguments == null || commandArguments.Count == 0)
     {
         return;
     }
     AddArguments(runner, commandArguments);
 }
Esempio n. 9
0
        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();
            }
        }
Esempio n. 10
0
        ProcessRunner GetBrewRunner(bool echoOutput, bool echoError, params string[] parameters)
        {
            ProcessRunner runner = CreateProcessRunner();

            if (needSudo.HasValue && needSudo.Value)
            {
                runner.AddArgument(BrewPath);
            }

            AddArguments(runner, parameters);

            if (!echoOutput)
            {
                runner.EchoStandardOutputLevel = ProcessStandardStreamWrapper.LogLevel.Debug;
            }

            if (!echoError)
            {
                runner.EchoStandardErrorLevel = ProcessStandardStreamWrapper.LogLevel.Debug;
            }

            return(runner);
        }
Esempio n. 11
0
        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();
            }
        }
Esempio n. 12
0
 void SetStandardArguments(string?workingDirectory, bool haveChangeDirArg, bool haveConcurrency, ProcessRunner runner)
 {
     SetStandardArguments(workingDirectory, haveChangeDirArg, haveConcurrency, arg => runner.AddArgument(arg));
 }