Esempio n. 1
0
        protected override async Task <bool> Execute(Context context)
        {
            var dotnetPath = context.Properties.GetRequiredValue(KnownProperties.DotNetPreviewPath);

            dotnetPath = dotnetPath.TrimEnd(new char [] { Path.DirectorySeparatorChar });
            var dotnetTool               = Path.Combine(dotnetPath, "dotnet");
            var dotnetPreviewVersion     = context.Properties.GetRequiredValue(KnownProperties.MicrosoftDotnetSdkInternalPackageVersion);
            var dotnetTestRuntimeVersion = Configurables.Defaults.DotNetTestRuntimeVersion;

            // Delete any custom Microsoft.Android packs that may have been installed by test runs. Other ref/runtime packs will be ignored.
            var packsPath = Path.Combine(dotnetPath, "packs");

            if (Directory.Exists(packsPath))
            {
                foreach (var packToRemove in Directory.EnumerateDirectories(packsPath))
                {
                    var info = new DirectoryInfo(packToRemove);
                    if (info.Name.IndexOf("Android", StringComparison.OrdinalIgnoreCase) != -1)
                    {
                        Log.StatusLine($"Removing Android pack: {packToRemove}");
                        Utilities.DeleteDirectory(packToRemove);
                    }
                }
            }

            // Delete Workload manifests, such as sdk-manifests/6.0.100/Microsoft.NET.Sdk.Android
            var sdkManifestsPath = Path.Combine(dotnetPath, "sdk-manifests");

            if (Directory.Exists(sdkManifestsPath))
            {
                foreach (var versionBand in Directory.EnumerateDirectories(sdkManifestsPath))
                {
                    foreach (var workloadManifestDirectory in Directory.EnumerateDirectories(versionBand))
                    {
                        var info = new DirectoryInfo(workloadManifestDirectory);
                        if (info.Name.IndexOf("Android", StringComparison.OrdinalIgnoreCase) != -1)
                        {
                            Log.StatusLine($"Removing Android manifest directory: {workloadManifestDirectory}");
                            Utilities.DeleteDirectory(workloadManifestDirectory);
                        }
                    }
                }
            }

            // Delete any unnecessary SDKs if they exist.
            var sdkPath = Path.Combine(dotnetPath, "sdk");

            if (Directory.Exists(sdkPath))
            {
                foreach (var sdkToRemove in Directory.EnumerateDirectories(sdkPath).Where(s => new DirectoryInfo(s).Name != dotnetPreviewVersion))
                {
                    Log.StatusLine($"Removing out of date SDK: {sdkToRemove}");
                    Utilities.DeleteDirectory(sdkToRemove);
                }
            }

            // Delete Android template-packs
            var templatePacksPath = Path.Combine(dotnetPath, "template-packs");

            if (Directory.Exists(templatePacksPath))
            {
                foreach (var templateToRemove in Directory.EnumerateFiles(templatePacksPath))
                {
                    var name = Path.GetFileName(templateToRemove);
                    if (name.IndexOf("Android", StringComparison.OrdinalIgnoreCase) != -1)
                    {
                        Log.StatusLine($"Removing Android template: {templateToRemove}");
                        Utilities.DeleteFile(templateToRemove);
                    }
                }
            }

            if (File.Exists(dotnetTool))
            {
                if (!TestDotNetSdk(dotnetTool))
                {
                    Log.WarningLine($"Attempt to run `dotnet --version` failed, reinstalling the SDK.");
                    Utilities.DeleteDirectory(dotnetPath);
                }
            }

            if (!await InstallDotNetAsync(context, dotnetPath, dotnetPreviewVersion))
            {
                Log.ErrorLine($"Installation of dotnet SDK {dotnetPreviewVersion} failed.");
                return(false);
            }

            if (!await InstallDotNetAsync(context, dotnetPath, dotnetTestRuntimeVersion, runtimeOnly: true))
            {
                Log.ErrorLine($"Installation of dotnet runtime {dotnetTestRuntimeVersion} failed.");
                return(false);
            }

            // Install runtime packs associated with the SDK previously installed.
            var packageDownloadProj = Path.Combine(BuildPaths.XamarinAndroidSourceRoot, "build-tools", "xaprepare", "xaprepare", "package-download.proj");
            var logPath             = Path.Combine(Configurables.Paths.BuildBinDir, $"msbuild-{context.BuildTimeStamp}-download-runtime-packs.binlog");

            if (!Utilities.RunCommand(dotnetTool, new string [] { "restore", ProcessRunner.QuoteArgument(packageDownloadProj), ProcessRunner.QuoteArgument($"-bl:{logPath}") }))
            {
                Log.ErrorLine($"dotnet restore {packageDownloadProj} failed.");
                return(false);
            }

            // Copy the WorkloadManifest.* files from the latest Microsoft.NET.Workload.Mono.ToolChain listed in package-download.proj
            var destination = Path.Combine(dotnetPath, "sdk-manifests",
                                           context.Properties.GetRequiredValue(KnownProperties.DotNetPreviewVersionBand),
                                           "microsoft.net.workload.mono.toolchain"
                                           );

            foreach (var file in Directory.GetFiles(Configurables.Paths.MicrosoftNETWorkloadMonoToolChainDir, "WorkloadManifest.*"))
            {
                Utilities.CopyFileToDir(file, destination);
            }

            // Install the microsoft-net-runtime-android workload
            if (!Utilities.RunCommand(dotnetTool, BuildPaths.XamarinAndroidSourceRoot, ignoreEmptyArguments: false, new [] { "workload", "install", "microsoft-net-runtime-android", "--skip-manifest-update", "--verbosity", "diag" }))
            {
                Log.ErrorLine($"dotnet workload install failed.");
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        protected override async Task <bool> Execute(Context context)
        {
            var dotnetPath = context.Properties.GetRequiredValue(KnownProperties.DotNetPreviewPath);

            dotnetPath = dotnetPath.TrimEnd(new char [] { Path.DirectorySeparatorChar });
            var dotnetTool               = Path.Combine(dotnetPath, "dotnet");
            var dotnetPreviewVersion     = context.Properties.GetRequiredValue(KnownProperties.MicrosoftDotnetSdkInternalPackageVersion);
            var dotnetTestRuntimeVersion = Configurables.Defaults.DotNetTestRuntimeVersion;

            // Delete any custom Microsoft.Android packs that may have been installed by test runs. Other ref/runtime packs will be ignored.
            var packsPath = Path.Combine(dotnetPath, "packs");

            if (Directory.Exists(packsPath))
            {
                foreach (var packToRemove in Directory.EnumerateDirectories(packsPath).Where(p => new DirectoryInfo(p).Name.Contains("Android")))
                {
                    Log.StatusLine($"Removing Android pack: {packToRemove}");
                    Utilities.DeleteDirectory(packToRemove);
                }
            }

            // Delete any unnecessary SDKs if they exist.
            var sdkPath = Path.Combine(dotnetPath, "sdk");

            if (Directory.Exists(sdkPath))
            {
                foreach (var sdkToRemove in Directory.EnumerateDirectories(sdkPath).Where(s => new DirectoryInfo(s).Name != dotnetPreviewVersion))
                {
                    Log.StatusLine($"Removing out of date SDK: {sdkToRemove}");
                    Utilities.DeleteDirectory(sdkToRemove);
                }
            }

            if (File.Exists(dotnetTool))
            {
                if (!TestDotNetSdk(dotnetTool))
                {
                    Log.WarningLine($"Attempt to run `dotnet --version` failed, reinstalling the SDK.");
                    Utilities.DeleteDirectory(dotnetPath);
                }
            }

            if (!await InstallDotNetAsync(context, dotnetPath, dotnetPreviewVersion))
            {
                Log.ErrorLine($"Installation of dotnet SDK {dotnetPreviewVersion} failed.");
                return(false);
            }

            if (!await InstallDotNetAsync(context, dotnetPath, dotnetTestRuntimeVersion, runtimeOnly: true))
            {
                Log.ErrorLine($"Installation of dotnet runtime {dotnetTestRuntimeVersion} failed.");
                return(false);
            }

            // Install runtime packs associated with the SDK previously installed.
            var packageDownloadProj = Path.Combine(BuildPaths.XamarinAndroidSourceRoot, "build-tools", "xaprepare", "xaprepare", "package-download.proj");
            var logPath             = Path.Combine(Configurables.Paths.BuildBinDir, $"msbuild-{context.BuildTimeStamp}-download-runtime-packs.binlog");

            return(Utilities.RunCommand(dotnetTool, new string [] { "restore", $"-p:DotNetRuntimePacksVersion={context.BundledPreviewRuntimePackVersion}",
                                                                    ProcessRunner.QuoteArgument(packageDownloadProj), ProcessRunner.QuoteArgument($"-bl:{logPath}") }));
        }
Esempio n. 3
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();
            }
        }
        protected override async Task <bool> Execute(Context context)
        {
            var dotnetPath = context.Properties.GetRequiredValue(KnownProperties.DotNetPreviewPath);

            dotnetPath = dotnetPath.TrimEnd(new char [] { Path.DirectorySeparatorChar });
            var dotnetTool               = Path.Combine(dotnetPath, "dotnet");
            var dotnetPreviewVersion     = context.Properties.GetRequiredValue(KnownProperties.MicrosoftDotnetSdkInternalPackageVersion);
            var dotnetTestRuntimeVersion = Configurables.Defaults.DotNetTestRuntimeVersion;

            // Always delete the ~/android-toolchain/dotnet/ directory
            Utilities.DeleteDirectory(dotnetPath);

            if (!await InstallDotNetAsync(context, dotnetPath, dotnetPreviewVersion))
            {
                Log.ErrorLine($"Installation of dotnet SDK {dotnetPreviewVersion} failed.");
                return(false);
            }

            if (!await InstallDotNetAsync(context, dotnetPath, dotnetTestRuntimeVersion, runtimeOnly: true))
            {
                Log.ErrorLine($"Installation of dotnet runtime {dotnetTestRuntimeVersion} failed.");
                return(false);
            }

            // Install runtime packs associated with the SDK previously installed.
            var packageDownloadProj = Path.Combine(BuildPaths.XamarinAndroidSourceRoot, "build-tools", "xaprepare", "xaprepare", "package-download.proj");
            var logPath             = Path.Combine(Configurables.Paths.BuildBinDir, $"msbuild-{context.BuildTimeStamp}-download-runtime-packs.binlog");

            if (!Utilities.RunCommand(dotnetTool, new string [] { "restore", ProcessRunner.QuoteArgument(packageDownloadProj), ProcessRunner.QuoteArgument($"-bl:{logPath}") }))
            {
                Log.ErrorLine($"dotnet restore {packageDownloadProj} failed.");
                return(false);
            }

            // Copy the WorkloadManifest.* files from the latest Microsoft.NET.Workload.Mono.ToolChain listed in package-download.proj
            var destination = Path.Combine(dotnetPath, "sdk-manifests",
                                           context.Properties.GetRequiredValue(KnownProperties.DotNetPreviewVersionBand),
                                           "microsoft.net.workload.mono.toolchain"
                                           );

            foreach (var file in Directory.GetFiles(Configurables.Paths.MicrosoftNETWorkloadMonoToolChainDir, "WorkloadManifest.*"))
            {
                Utilities.CopyFileToDir(file, destination);
            }

            return(true);
        }
Esempio n. 5
0
 void SetStandardArguments(string?workingDirectory, bool haveChangeDirArg, bool haveConcurrency, ProcessRunner runner)
 {
     SetStandardArguments(workingDirectory, haveChangeDirArg, haveConcurrency, arg => runner.AddArgument(arg));
 }