public override async Task <bool> Install()
        {
            var runner = new ProcessRunner("sudo", "apt-get", "-y", "-f", "-u", "install", PackageName)
            {
                EchoStandardOutput        = true,
                EchoStandardError         = true,
                ProcessTimeout            = TimeSpan.FromMinutes(30),
                StandardOutputEchoWrapper = new AptGetStandardStreamWrapper(),
            };

            bool failed = await Task.Run(() => !runner.Run());

            if (failed)
            {
                Log.Error($"Installation of {PackageName} timed out");
                failed = true;
            }

            if (runner.ExitCode != 0)
            {
                Log.Error($"Installation failed with error code {runner.ExitCode}");
                failed = true;
            }

            return(!failed);
        }
Esempio n. 2
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. 3
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();
            }
        }
#pragma warning disable CS1998
        public override async Task <bool> Install()
        {
            var runner = new ProcessRunner("sudo", "pacman", "-S", "--noconfirm", PackageName)
            {
                EchoStandardOutput = true,
                EchoStandardError  = true,
                ProcessTimeout     = TimeSpan.FromMinutes(30),
            };

            bool failed = await Task.Run(() => !runner.Run());

            if (failed)
            {
                Log.Error($"Installation of {PackageName} timed out");
                failed = true;
            }

            if (runner.ExitCode != 0)
            {
                Log.Error($"Installation failed with error code {runner.ExitCode}");
                failed = true;
            }

            return(!failed);
        }
Esempio n. 5
0
        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();
            }
        }
Esempio n. 6
0
        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();
            }
        }
Esempio n. 7
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. 8
0
        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();
            }
        }
Esempio n. 9
0
        protected override bool CheckWhetherInstalled()
        {
            var runner = new ProcessRunner("pacman", "-Q", "--", PackageName);

            if (!runner.Run())
            {
                Log.Error($"Check for package {PackageName} failed");
                return(false);
            }

            return(runner.ExitCode == 0);
        }
Esempio n. 10
0
        async Task <bool> RunBrew(bool echoOutput, bool echoError, params string[] parameters)
        {
            ProcessRunner runner  = GetBrewRunner(echoOutput, echoError, parameters);
            bool          success = await RunTool(() => runner.Run());

            if (!success)
            {
                var os = Context.Instance.OS as MacOS;
                os.HomebrewErrors = true;
            }

            return(success);
        }
Esempio n. 11
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. 12
0
        public static bool RunCommand(string command, string workingDirectory, bool echoStderr, bool ignoreEmptyArguments, params string[] arguments)
        {
            if (String.IsNullOrEmpty(command))
            {
                throw new ArgumentException("must not be null or empty", nameof(command));
            }

            var runner = new ProcessRunner(command, ignoreEmptyArguments, arguments)
            {
                EchoStandardError = echoStderr,
                WorkingDirectory  = workingDirectory,
            };

            return(runner.Run());
        }
Esempio n. 13
0
 async Task <bool> RunGit(ProcessRunner runner, string logTag)
 {
     try {
         return(await RunTool(
                    () => {
             using (var outputSink = (OutputSink)SetupOutputSink(runner)) {
                 StartTwiddler();
                 return runner.Run();
             }
         }
                    ));
     } finally {
         StopTwiddler();
     }
 }
Esempio n. 14
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. 15
0
        async Task <List <string> > RunForOutputAsync(ProcessRunner runner)
        {
            var  lines   = new List <string> ();
            bool success = await RunTool(
                () => {
                using (var outputSink = (OutputSink)SetupOutputSink(runner)) {
                    outputSink.LineCallback = (string line) => lines.Add(line);
                    return(runner.Run());
                }
            }
                );

            if (!success)
            {
                return(null);
            }

            return(lines);
        }
Esempio n. 16
0
        public static string GetStringFromStdout(ProcessRunner runner, bool throwOnErrors = false, bool trimTrailingWhitespace = true, bool quietErrors = false)
        {
            using (var sw = new StringWriter()) {
                runner.AddStandardOutputSink(sw);
                if (!runner.Run())
                {
                    LogError("did not exit cleanly");
                    return(null);
                }

                if (runner.ExitCode != 0)
                {
                    LogError($"failed with exit code {runner.ExitCode}");
                    return(null);
                }

                string ret = sw.ToString();
                if (trimTrailingWhitespace)
                {
                    return(ret.TrimEnd());
                }
                return(ret);
            }

            void LogError(string message)
            {
                string msg = $"{runner.FullCommandLine}: {message}";

                if (throwOnErrors)
                {
                    throw new InvalidOperationException(msg);
                }
                if (quietErrors)
                {
                    Log.DebugLine(msg);
                }
                else
                {
                    Log.ErrorLine(msg);
                }
            }
        }
Esempio n. 17
0
        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();
                }
            }
                       ));
        }
Esempio n. 18
0
 async Task <bool> RunGit(ProcessRunner runner, string logTag)
 {
     try {
         return(await RunTool(
                    () => {
             using (var outputSink = (OutputSink)SetupOutputSink(runner)) {
                 StartTwiddler();
                 return runner.Run();
             }
         }
                    ));
     } finally {
         StopTwiddler();
         if (runner.ExitCode != 0 && runner.StandardErrorEchoWrapper is GitProgressStderrWrapper wrapper)
         {
             foreach (string message in wrapper.Messages)
             {
                 Log.ErrorLine(message);
             }
         }
     }
 }
        protected override async Task <bool> Execute(Context context)
        {
            string xcrun = context.OS.Which("xcrun");

            var libs = new string[] {
                Path.Combine(Configurables.Paths.HostRuntimeDir, Configurables.Paths.UnstrippedLibMonoSgenName),
                Path.Combine(Configurables.Paths.HostRuntimeDir, Configurables.Paths.StrippedLibMonoSgenName),
            };

            bool result = true;

            Log.StatusLine("Changing id for:");
            foreach (string libPath in libs)
            {
                if (!Utilities.FileExists(libPath))
                {
                    Log.StatusLine("    not found", ConsoleColor.Magenta);
                    continue;
                }

                if (!ChangeID(libPath))
                {
                    Log.StatusLine("    failed", ConsoleColor.Magenta);
                    result = false;
                }
            }

            return(result);

            bool ChangeID(string path)
            {
                Log.DebugLine($"Changing dylib id for {path}");
                Log.StatusLine($"  {context.Characters.Bullet} {Utilities.GetRelativePath (BuildPaths.XamarinAndroidSourceRoot, path)}");
                var runner = new ProcessRunner(xcrun, "install_name_tool", "-id", "@loader_path/libmonosgen-2.0.dylib", path);

                return(runner.Run());
            }
        }
Esempio n. 20
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();
            }
        }