private static BuildTargetResult CopyAppDeps(BuildTargetContext c, string outputDir) { var appDepOutputDir = Path.Combine(outputDir, "appdepsdk"); Rmdir(appDepOutputDir); Mkdirp(appDepOutputDir); // Find toolchain package string packageId; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { packageId = "toolchain.win7-x64.Microsoft.DotNet.AppDep"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { var osname = PlatformServices.Default.Runtime.OperatingSystem; if (string.Equals(osname, "ubuntu", StringComparison.OrdinalIgnoreCase)) { packageId = "toolchain.ubuntu.14.04-x64.Microsoft.DotNet.AppDep"; } else if (string.Equals(osname, "centos", StringComparison.OrdinalIgnoreCase)) { c.Warn("Native compilation is not yet working on CentOS"); return(c.Success()); } else { return(c.Failed($"Unknown Linux Distro: {osname}")); } } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { packageId = "toolchain.osx.10.10-x64.Microsoft.DotNet.AppDep"; } else { return(c.Failed("Unsupported OS Platform")); } var appDepPath = Path.Combine( Dirs.NuGetPackages, packageId, AppDepSdkVersion); CopyRecursive(appDepPath, appDepOutputDir, overwrite: true); return(c.Success()); }
public static BuildTargetResult CheckUbuntuCoreclrAndCoreFxDependencies(BuildTargetContext c) { var errorMessageBuilder = new StringBuilder(); var stage0 = DotNetCli.Stage0.BinPath; foreach (var package in PackageDependencies.UbuntuCoreclrAndCoreFxDependencies) { if (!AptDependencyUtility.PackageIsInstalled(package)) { errorMessageBuilder.Append($"Error: Coreclr package dependency {package} missing."); errorMessageBuilder.Append(Environment.NewLine); errorMessageBuilder.Append($"-> install with apt-get install {package}"); errorMessageBuilder.Append(Environment.NewLine); } } if (errorMessageBuilder.Length == 0) { return(c.Success()); } else { return(c.Failed(errorMessageBuilder.ToString())); } }
public static BuildTargetResult CheckUbuntuDebianPackageBuildDependencies(BuildTargetContext c) { var messageBuilder = new StringBuilder(); var aptDependencyUtility = new AptDependencyUtility(); foreach (var package in PackageDependencies.DebianPackageBuildDependencies) { if (!AptDependencyUtility.PackageIsInstalled(package)) { messageBuilder.Append($"Error: Debian package build dependency {package} missing."); messageBuilder.Append(Environment.NewLine); messageBuilder.Append($"-> install with apt-get install {package}"); messageBuilder.Append(Environment.NewLine); } } if (messageBuilder.Length == 0) { return(c.Success()); } else { return(c.Failed(messageBuilder.ToString())); } }
public static BuildTargetResult CheckPrereqCmakePresent(BuildTargetContext c) { try { Command.Create("cmake", "--version") .CaptureStdOut() .CaptureStdErr() .Execute(); } catch (Exception ex) { string message = $@"Error running cmake: {ex.Message} cmake is required to build the native host 'corehost'"; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { message += Environment.NewLine + "Download it from https://www.cmake.org"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { message += Environment.NewLine + "Ubuntu: 'sudo apt-get install cmake'"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { message += Environment.NewLine + "OS X w/Homebrew: 'brew install cmake'"; } return(c.Failed(message)); } return(c.Success()); }
public static BuildTargetResult TriggerDockerHubBuilds(BuildTargetContext c) { string dockerHubRepo = Environment.GetEnvironmentVariable("DOCKER_HUB_REPO"); string dockerHubTriggerToken = Environment.GetEnvironmentVariable("DOCKER_HUB_TRIGGER_TOKEN"); Uri baseDockerHubUri = new Uri("https://registry.hub.docker.com/u/"); Uri dockerHubTriggerUri; if (!Uri.TryCreate(baseDockerHubUri, $"{dockerHubRepo}/trigger/{dockerHubTriggerToken}/", out dockerHubTriggerUri)) { return(c.Failed("Invalid DOCKER_HUB_REPO and/or DOCKER_HUB_TRIGGER_TOKEN")); } c.Info($"Triggering automated DockerHub builds for {dockerHubRepo}"); using (HttpClient client = new HttpClient()) { StringContent requestContent = new StringContent("{\"build\": true}", Encoding.UTF8, "application/json"); try { HttpResponseMessage response = client.PostAsync(dockerHubTriggerUri, requestContent).Result; if (!response.IsSuccessStatusCode) { StringBuilder sb = new StringBuilder(); sb.AppendLine($"HTTP request to {dockerHubTriggerUri.ToString()} was unsuccessful."); sb.AppendLine($"Response status code: {response.StatusCode}. Reason phrase: {response.ReasonPhrase}."); sb.Append($"Respone content: {response.Content.ReadAsStringAsync().Result}"); return(c.Failed(sb.ToString())); } } catch (AggregateException e) { return(c.Failed($"HTTP request to {dockerHubTriggerUri.ToString()} failed. {e.ToString()}")); } } return(c.Success()); }
private static BuildTargetResult CopyAppDeps(BuildTargetContext c, string outputDir) { var appDepOutputDir = Path.Combine(outputDir, "appdepsdk"); Rmdir(appDepOutputDir); Mkdirp(appDepOutputDir); // Find toolchain package string packageId; if (CurrentPlatform.IsWindows) { if (CurrentArchitecture.Isx86) { // https://github.com/dotnet/cli/issues/1550 c.Warn("Native compilation is not yet working on Windows x86"); return(c.Success()); } packageId = "toolchain.win7-x64.Microsoft.DotNet.AppDep"; } else if (CurrentPlatform.IsUbuntu) { packageId = "toolchain.ubuntu.14.04-x64.Microsoft.DotNet.AppDep"; } else if (CurrentPlatform.IsCentOS || CurrentPlatform.IsRHEL || CurrentPlatform.IsDebian) { c.Warn($"Native compilation is not yet working on {CurrentPlatform.Current}"); return(c.Success()); } else if (CurrentPlatform.IsOSX) { packageId = "toolchain.osx.10.10-x64.Microsoft.DotNet.AppDep"; } else { return(c.Failed("Unsupported OS Platform")); } var appDepPath = Path.Combine( Dirs.NuGetPackages, packageId, AppDepSdkVersion); CopyRecursive(appDepPath, appDepOutputDir, overwrite: true); return(c.Success()); }
public static BuildTargetResult LocateStage0(BuildTargetContext c) { // We should have been run in the repo root, so locate the stage 0 relative to current directory var stage0 = DotNetCli.Stage0.BinPath; if (!Directory.Exists(stage0)) { return(c.Failed($"Stage 0 directory does not exist: {stage0}")); } // Identify the version var version = File.ReadAllLines(Path.Combine(stage0, "..", ".version")); c.Info($"Using Stage 0 Version: {version[1]}"); return(c.Success()); }
public static BuildTargetResult RunXUnitTests(BuildTargetContext c) { // Need to load up the VS Vars var dotnet = DotNetCli.Stage2; var vsvars = LoadVsVars(c); var configuration = c.BuildContext.Get <string>("Configuration"); // Copy the test projects var testProjectsDir = Path.Combine(Dirs.TestOutput, "TestProjects"); Rmdir(testProjectsDir); Mkdirp(testProjectsDir); CopyRecursive(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects"), testProjectsDir); // Run the tests and set the VS vars in the environment when running them var failingTests = new List <string>(); foreach (var project in TestProjects) { c.Info($"Running tests in: {project}"); var result = dotnet.Test("--configuration", configuration, "-xml", $"{project}-testResults.xml", "-notrait", "category=failing") .WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "test", project)) .Environment(vsvars) .EnvironmentVariable("PATH", $"{DotNetCli.Stage2.BinPath}{Path.PathSeparator}{Environment.GetEnvironmentVariable("PATH")}") .EnvironmentVariable("TEST_ARTIFACTS", Dirs.TestArtifacts) .Execute(); if (result.ExitCode != 0) { failingTests.Add(project); } } if (failingTests.Any()) { foreach (var project in failingTests) { c.Error($"{project} failed"); } return(c.Failed("Tests failed!")); } return(c.Success()); }
public static BuildTargetResult RunTests(BuildTargetContext c) { var dotnet = DotNetCli.Stage0; var configuration = c.BuildContext.Get <string>("Configuration"); var failingTests = RunDotnetTestOnTestProjects(c, dotnet, configuration); if (failingTests.Any()) { foreach (var project in failingTests) { c.Error($"{project} failed"); } return(c.Failed("Tests failed!")); } return(c.Success()); }
public static BuildTargetResult CheckCentOSCoreclrAndCoreFxDependencies(BuildTargetContext c) { var errorMessageBuilder = new StringBuilder(); foreach (var package in PackageDependencies.CentosCoreclrAndCoreFxDependencies) { if (!YumDependencyUtility.PackageIsInstalled(package)) { errorMessageBuilder.Append($"Error: Coreclr package dependency {package} missing."); errorMessageBuilder.Append(Environment.NewLine); errorMessageBuilder.Append($"-> install with yum install {package}"); errorMessageBuilder.Append(Environment.NewLine); } } if (errorMessageBuilder.Length == 0) { return(c.Success()); } else { return(c.Failed(errorMessageBuilder.ToString())); } }
public static BuildTargetResult LocateStage0(BuildTargetContext c) { // We should have been run in the repo root, so locate the stage 0 relative to current directory var stage0 = DotNetCli.Stage0.BinPath; if (!Directory.Exists(stage0)) { return(c.Failed($"Stage 0 directory does not exist: {stage0}")); } // Identify the version string versionFile = Directory.GetFiles(stage0, ".version", SearchOption.AllDirectories).FirstOrDefault(); if (string.IsNullOrEmpty(versionFile)) { throw new Exception($"'.version' file not found in '{stage0}' folder"); } var version = File.ReadAllLines(versionFile); c.Info($"Using Stage 0 Version: {version[1]}"); return(c.Success()); }
private static BuildTargetResult CompileCliSdk(BuildTargetContext c, DotNetCli dotnet, string outputDir) { var configuration = c.BuildContext.Get <string>("Configuration"); var buildVersion = c.BuildContext.Get <BuildVersion>("BuildVersion"); var srcDir = Path.Combine(c.BuildContext.BuildDirectory, "src"); outputDir = Path.Combine(outputDir, "sdk", buildVersion.NuGetVersion); FS.CleanBinObj(c, srcDir); Rmdir(outputDir); Mkdirp(outputDir); foreach (var project in ProjectsToPublish) { dotnet.Publish( "--native-subdirectory", "--output", outputDir, "--configuration", configuration, "--version-suffix", buildVersion.CommitCountString, Path.Combine(srcDir, project)) .Execute() .EnsureSuccessful(); } FixModeFlags(outputDir); string compilersProject = Path.Combine(Dirs.RepoRoot, "src", "compilers"); dotnet.Publish(compilersProject, "--output", outputDir, "--framework", "netstandard1.5") .Execute() .EnsureSuccessful(); var compilersDeps = Path.Combine(outputDir, "compilers.deps.json"); var compilersRuntimeConfig = Path.Combine(outputDir, "compilers.runtimeconfig.json"); File.Copy(Path.Combine(Dirs.CorehostLocked, DotnetHostBaseName), Path.Combine(outputDir, $"corehost{Constants.ExeSuffix}"), overwrite: true); File.Copy(Path.Combine(Dirs.CorehostLocked, $"{Constants.DynamicLibPrefix}hostfxr{Constants.DynamicLibSuffix}"), Path.Combine(outputDir, $"{Constants.DynamicLibPrefix}hostfxr{Constants.DynamicLibSuffix}"), overwrite: true); File.Copy(Path.Combine(Dirs.CorehostLatest, $"{Constants.DynamicLibPrefix}hostpolicy{Constants.DynamicLibSuffix}"), Path.Combine(outputDir, $"{Constants.DynamicLibPrefix}hostpolicy{Constants.DynamicLibSuffix}"), overwrite: true); var binaryToCorehostifyRelDir = Path.Combine("runtimes", "any", "native"); var binaryToCorehostifyOutDir = Path.Combine(outputDir, binaryToCorehostifyRelDir); // Corehostify binaries foreach (var binaryToCorehostify in BinariesForCoreHost) { try { // Yes, it is .exe even on Linux. This is the managed exe we're working with File.Copy(Path.Combine(binaryToCorehostifyOutDir, $"{binaryToCorehostify}.exe"), Path.Combine(outputDir, $"{binaryToCorehostify}.dll")); File.Delete(Path.Combine(binaryToCorehostifyOutDir, $"{binaryToCorehostify}.exe")); File.Copy(compilersDeps, Path.Combine(outputDir, binaryToCorehostify + ".deps.json")); File.Copy(compilersRuntimeConfig, Path.Combine(outputDir, binaryToCorehostify + ".runtimeconfig.json")); var binaryToCoreHostifyDeps = Path.Combine(outputDir, binaryToCorehostify + ".deps.json"); ChangeEntryPointLibraryName(binaryToCoreHostifyDeps, binaryToCorehostify); foreach (var binaryToRemove in new string[] { "csc", "vbc" }) { var assetPath = Path.Combine(binaryToCorehostifyRelDir, $"{binaryToRemove}.exe").Replace(Path.DirectorySeparatorChar, '/'); RemoveAssetFromDepsPackages(binaryToCoreHostifyDeps, "runtimeTargets", assetPath); } } catch (Exception ex) { return(c.Failed($"Failed to corehostify '{binaryToCorehostify}': {ex.ToString()}")); } } // cleanup compilers project output we don't need DeleteMainPublishOutput(outputDir, "compilers"); File.Delete(compilersDeps); File.Delete(compilersRuntimeConfig); CrossgenUtil.CrossgenDirectory(c, outputDir); // Generate .version file var version = buildVersion.NuGetVersion; var content = $@"{c.BuildContext["CommitHash"]}{Environment.NewLine}{version}{Environment.NewLine}"; File.WriteAllText(Path.Combine(outputDir, ".version"), content); return(c.Success()); }
private static BuildTargetResult CompileStage(BuildTargetContext c, DotNetCli dotnet, string outputDir) { Rmdir(outputDir); var configuration = c.BuildContext.Get <string>("Configuration"); var binDir = Path.Combine(outputDir, "bin"); var buildVesion = c.BuildContext.Get <BuildVersion>("BuildVersion"); Mkdirp(binDir); foreach (var project in ProjectsToPublish) { // TODO: Use the flag once we get a full build round tripped // --version-suffix buildVesion.VersionSuffix dotnet.Publish( "--native-subdirectory", "--output", binDir, "--configuration", configuration, Path.Combine(c.BuildContext.BuildDirectory, "src", project)) .Environment("DOTNET_BUILD_VERSION", buildVesion.VersionSuffix) .Execute() .EnsureSuccessful(); } FixModeFlags(outputDir); // Copy corehost File.Copy(Path.Combine(Dirs.Corehost, $"corehost{Constants.ExeSuffix}"), Path.Combine(binDir, $"corehost{Constants.ExeSuffix}"), overwrite: true); File.Copy(Path.Combine(Dirs.Corehost, $"{Constants.DynamicLibPrefix}hostpolicy{Constants.DynamicLibSuffix}"), Path.Combine(binDir, $"{Constants.DynamicLibPrefix}hostpolicy{Constants.DynamicLibSuffix}"), overwrite: true); // Corehostify binaries foreach (var binaryToCorehostify in BinariesForCoreHost) { try { // Yes, it is .exe even on Linux. This is the managed exe we're working with File.Copy(Path.Combine(binDir, $"{binaryToCorehostify}.exe"), Path.Combine(binDir, $"{binaryToCorehostify}.dll")); File.Delete(Path.Combine(binDir, $"{binaryToCorehostify}.exe")); File.Copy(Path.Combine(binDir, $"corehost{Constants.ExeSuffix}"), Path.Combine(binDir, binaryToCorehostify + Constants.ExeSuffix)); } catch (Exception ex) { return(c.Failed($"Failed to corehostify '{binaryToCorehostify}': {ex.ToString()}")); } } // dotnet.exe is from stage0. But we must be using the newly built corehost in stage1 File.Delete(Path.Combine(binDir, $"dotnet{Constants.ExeSuffix}")); File.Copy(Path.Combine(binDir, $"corehost{Constants.ExeSuffix}"), Path.Combine(binDir, $"dotnet{Constants.ExeSuffix}")); // Crossgen Roslyn var result = Crossgen(c, binDir); if (!result.Success) { return(result); } // Copy AppDeps result = CopyAppDeps(c, binDir); if (!result.Success) { return(result); } // Generate .version file var version = buildVesion.SimpleVersion; var content = $@"{c.BuildContext["CommitHash"]}{Environment.NewLine}{version}{Environment.NewLine}"; File.WriteAllText(Path.Combine(outputDir, ".version"), content); return(c.Success()); }
private static BuildTargetResult CompileCliSdk(BuildTargetContext c, DotNetCli dotnet, string outputDir) { var configuration = c.BuildContext.Get <string>("Configuration"); var buildVersion = c.BuildContext.Get <BuildVersion>("BuildVersion"); outputDir = Path.Combine(outputDir, "sdk", buildVersion.NuGetVersion); Rmdir(outputDir); Mkdirp(outputDir); foreach (var project in ProjectsToPublish) { // TODO: Use the flag once we get a full build round tripped // --version-suffix buildVesion.VersionSuffix dotnet.Publish( "--native-subdirectory", "--output", outputDir, "--configuration", configuration, Path.Combine(c.BuildContext.BuildDirectory, "src", project)) .Environment("DOTNET_BUILD_VERSION", buildVersion.VersionSuffix) .Execute() .EnsureSuccessful(); } FixModeFlags(outputDir); string compilersProject = Path.Combine(Dirs.RepoRoot, "src", "compilers"); dotnet.Publish(compilersProject, "--output", outputDir, "--framework", "netstandard1.5") .Execute() .EnsureSuccessful(); var compilersDeps = Path.Combine(outputDir, "compilers.deps.json"); var compilersRuntimeConfig = Path.Combine(outputDir, "compilers.runtimeconfig.json"); // Copy corehost File.Copy(Path.Combine(Dirs.Corehost, $"corehost{Constants.ExeSuffix}"), Path.Combine(outputDir, $"corehost{Constants.ExeSuffix}"), overwrite: true); File.Copy(Path.Combine(Dirs.Corehost, $"{Constants.DynamicLibPrefix}hostpolicy{Constants.DynamicLibSuffix}"), Path.Combine(outputDir, $"{Constants.DynamicLibPrefix}hostpolicy{Constants.DynamicLibSuffix}"), overwrite: true); File.Copy(Path.Combine(Dirs.Corehost, $"{Constants.DynamicLibPrefix}hostfxr{Constants.DynamicLibSuffix}"), Path.Combine(outputDir, $"{Constants.DynamicLibPrefix}hostfxr{Constants.DynamicLibSuffix}"), overwrite: true); var binaryToCorehostifyOutDir = Path.Combine(outputDir, "runtimes", "any", "native"); // Corehostify binaries foreach (var binaryToCorehostify in BinariesForCoreHost) { try { // Yes, it is .exe even on Linux. This is the managed exe we're working with File.Copy(Path.Combine(binaryToCorehostifyOutDir, $"{binaryToCorehostify}.exe"), Path.Combine(outputDir, $"{binaryToCorehostify}.dll")); File.Delete(Path.Combine(binaryToCorehostifyOutDir, $"{binaryToCorehostify}.exe")); File.Copy(compilersDeps, Path.Combine(outputDir, binaryToCorehostify + ".deps.json")); File.Copy(compilersRuntimeConfig, Path.Combine(outputDir, binaryToCorehostify + ".runtimeconfig.json")); } catch (Exception ex) { return(c.Failed($"Failed to corehostify '{binaryToCorehostify}': {ex.ToString()}")); } } // cleanup compilers project output we don't need DeleteMainPublishOutput(outputDir, "compilers"); File.Delete(compilersDeps); File.Delete(compilersRuntimeConfig); // Copy AppDeps var result = CopyAppDeps(c, outputDir); if (!result.Success) { return(result); } // Generate .version file var version = buildVersion.NuGetVersion; var content = $@"{c.BuildContext["CommitHash"]}{Environment.NewLine}{version}{Environment.NewLine}"; File.WriteAllText(Path.Combine(outputDir, ".version"), content); return(c.Success()); }
private static BuildTargetResult Crossgen(BuildTargetContext c, string outputDir) { // Check if we need to skip crossgen if (string.Equals(Environment.GetEnvironmentVariable("DOTNET_BUILD_SKIP_CROSSGEN"), "1")) { c.Warn("Skipping crossgen because DOTNET_BUILD_SKIP_CROSSGEN is set"); return(c.Success()); } // Find crossgen string packageId; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { packageId = "runtime.win7-x64.Microsoft.NETCore.Runtime.CoreCLR"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { var osname = PlatformServices.Default.Runtime.OperatingSystem; if (string.Equals(osname, "ubuntu", StringComparison.OrdinalIgnoreCase)) { packageId = "runtime.ubuntu.14.04-x64.Microsoft.NETCore.Runtime.CoreCLR"; } else if (string.Equals(osname, "centos", StringComparison.OrdinalIgnoreCase)) { // CentOS runtime is in the runtime.rhel.7-x64... package. packageId = "runtime.rhel.7-x64.Microsoft.NETCore.Runtime.CoreCLR"; } else { return(c.Failed($"Unknown Linux Distro: {osname}")); } } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { packageId = "runtime.osx.10.10-x64.Microsoft.NETCore.Runtime.CoreCLR"; } else { return(c.Failed("Unsupported OS Platform")); } var crossGenExePath = Path.Combine( Dirs.NuGetPackages, packageId, CoreCLRVersion, "tools", $"crossgen{Constants.ExeSuffix}"); // We have to copy crossgen next to mscorlib var crossgen = Path.Combine(outputDir, $"crossgen{Constants.ExeSuffix}"); File.Copy(crossGenExePath, crossgen, overwrite: true); Chmod(crossgen, "a+x"); // And if we have mscorlib.ni.dll, we need to rename it to mscorlib.dll if (File.Exists(Path.Combine(outputDir, "mscorlib.ni.dll"))) { File.Copy(Path.Combine(outputDir, "mscorlib.ni.dll"), Path.Combine(outputDir, "mscorlib.dll"), overwrite: true); } foreach (var assemblyToCrossgen in AssembliesToCrossGen) { c.Info($"Crossgenning {assemblyToCrossgen}"); ExecInSilent(outputDir, crossgen, "-nologo", "-platform_assemblies_paths", outputDir, assemblyToCrossgen); } c.Info("Crossgen complete"); // Check if csc/vbc.ni.exe exists, and overwrite the dll with it just in case if (File.Exists(Path.Combine(outputDir, "csc.ni.exe")) && !File.Exists(Path.Combine(outputDir, "csc.ni.dll"))) { File.Move(Path.Combine(outputDir, "csc.ni.exe"), Path.Combine(outputDir, "csc.ni.dll")); } if (File.Exists(Path.Combine(outputDir, "vbc.ni.exe")) && !File.Exists(Path.Combine(outputDir, "vbc.ni.dll"))) { File.Move(Path.Combine(outputDir, "vbc.ni.exe"), Path.Combine(outputDir, "vbc.ni.dll")); } return(c.Success()); }
public static BuildTargetResult CommitChanges(BuildTargetContext c) { CommandResult statusResult = Cmd("git", "status", "--porcelain") .CaptureStdOut() .Execute(); statusResult.EnsureSuccessful(); bool hasModifiedFiles = !string.IsNullOrWhiteSpace(statusResult.StdOut); bool hasUpdatedDependencies = c.GetDependencyInfos().Where(d => d.IsUpdated).Any(); if (hasModifiedFiles != hasUpdatedDependencies) { return(c.Failed($"'git status' does not match DependencyInfo information. Git has modified files: {hasModifiedFiles}. DependencyInfo is updated: {hasUpdatedDependencies}.")); } if (!hasUpdatedDependencies) { c.Warn("Dependencies are currently up to date"); return(c.Success()); } string userName = s_config.UserName; string email = s_config.Email; string commitMessage = GetCommitMessage(c); Cmd("git", "commit", "-a", "-m", commitMessage, "--author", $"{userName} <{email}>") .EnvironmentVariable("GIT_COMMITTER_NAME", userName) .EnvironmentVariable("GIT_COMMITTER_EMAIL", email) .Execute() .EnsureSuccessful(); string remoteUrl = $"github.com/{s_config.GitHubOriginOwner}/{s_config.GitHubProject}.git"; string remoteBranchName = $"UpdateDependencies{DateTime.UtcNow.ToString("yyyyMMddhhmmss")}"; string refSpec = $"HEAD:refs/heads/{remoteBranchName}"; string logMessage = $"git push https://{remoteUrl} {refSpec}"; BuildReporter.BeginSection("EXEC", logMessage); CommandResult pushResult = Cmd("git", "push", $"https://{userName}:{s_config.Password}@{remoteUrl}", refSpec) .QuietBuildReporter() // we don't want secrets showing up in our logs .CaptureStdErr() // git push will write to StdErr upon success, disable that .CaptureStdOut() .Execute(); var message = logMessage + $" exited with {pushResult.ExitCode}"; if (pushResult.ExitCode == 0) { BuildReporter.EndSection("EXEC", message.Green(), success: true); } else { BuildReporter.EndSection("EXEC", message.Red().Bold(), success: false); } pushResult.EnsureSuccessful(suppressOutput: true); c.SetRemoteBranchName(remoteBranchName); return(c.Success()); }
private static BuildTargetResult CompileCliSdk( BuildTargetContext c, DotNetCli dotnet, string rootOutputDirectory, bool generateNugetPackagesArchive = false) { var configuration = c.BuildContext.Get <string>("Configuration"); var buildVersion = c.BuildContext.Get <BuildVersion>("BuildVersion"); var srcDir = Path.Combine(c.BuildContext.BuildDirectory, "src"); var sdkOutputDirectory = Path.Combine(rootOutputDirectory, "sdk", buildVersion.NuGetVersion); CopySharedFramework(Dirs.SharedFrameworkPublish, rootOutputDirectory); FS.CleanBinObj(c, srcDir); Rmdir(sdkOutputDirectory); Mkdirp(sdkOutputDirectory); foreach (var project in ProjectsToPublish) { dotnet.Publish( "--native-subdirectory", "--output", sdkOutputDirectory, "--configuration", configuration, "--version-suffix", buildVersion.CommitCountString, Path.Combine(srcDir, project)) .Execute() .EnsureSuccessful(); } FixModeFlags(sdkOutputDirectory); string compilersProject = Path.Combine(Dirs.RepoRoot, "src", "compilers"); dotnet.Publish(compilersProject, "--output", sdkOutputDirectory, "--framework", "netcoreapp1.0") .Execute() .EnsureSuccessful(); var compilersDeps = Path.Combine(sdkOutputDirectory, "compilers.deps.json"); var compilersRuntimeConfig = Path.Combine(sdkOutputDirectory, "compilers.runtimeconfig.json"); var binaryToCorehostifyRelDir = Path.Combine("runtimes", "any", "native"); var binaryToCorehostifyOutDir = Path.Combine(sdkOutputDirectory, binaryToCorehostifyRelDir); // Corehostify binaries foreach (var binaryToCorehostify in BinariesForCoreHost) { try { // Yes, it is .exe even on Linux. This is the managed exe we're working with File.Copy(Path.Combine(binaryToCorehostifyOutDir, $"{binaryToCorehostify}.exe"), Path.Combine(sdkOutputDirectory, $"{binaryToCorehostify}.dll")); File.Delete(Path.Combine(binaryToCorehostifyOutDir, $"{binaryToCorehostify}.exe")); var binaryToCoreHostifyDeps = Path.Combine(sdkOutputDirectory, binaryToCorehostify + ".deps.json"); File.Copy(compilersDeps, Path.Combine(sdkOutputDirectory, binaryToCorehostify + ".deps.json")); File.Copy(compilersRuntimeConfig, Path.Combine(sdkOutputDirectory, binaryToCorehostify + ".runtimeconfig.json")); PublishMutationUtilties.ChangeEntryPointLibraryName(binaryToCoreHostifyDeps, binaryToCorehostify); foreach (var binaryToRemove in new string[] { "csc", "vbc" }) { var assetPath = Path.Combine(binaryToCorehostifyRelDir, $"{binaryToRemove}.exe").Replace(Path.DirectorySeparatorChar, '/'); RemoveAssetFromDepsPackages(binaryToCoreHostifyDeps, "runtimeTargets", assetPath); } } catch (Exception ex) { return(c.Failed($"Failed to corehostify '{binaryToCorehostify}': {ex.ToString()}")); } } // cleanup compilers project output we don't need PublishMutationUtilties.CleanPublishOutput( sdkOutputDirectory, "compilers", deleteRuntimeConfigJson: true, deleteDepsJson: true); // Crossgen SDK directory var sharedFrameworkNugetVersion = CliDependencyVersions.SharedFrameworkVersion; var sharedFrameworkNameVersionPath = SharedFrameworkPublisher.GetSharedFrameworkPublishPath( rootOutputDirectory, sharedFrameworkNugetVersion); // Copy Host to SDK Directory File.Copy( Path.Combine(sharedFrameworkNameVersionPath, HostArtifactNames.DotnetHostBaseName), Path.Combine(sdkOutputDirectory, $"corehost{Constants.ExeSuffix}"), overwrite: true); File.Copy( Path.Combine(sharedFrameworkNameVersionPath, HostArtifactNames.DotnetHostFxrBaseName), Path.Combine(sdkOutputDirectory, HostArtifactNames.DotnetHostFxrBaseName), overwrite: true); File.Copy( Path.Combine(sharedFrameworkNameVersionPath, HostArtifactNames.HostPolicyBaseName), Path.Combine(sdkOutputDirectory, HostArtifactNames.HostPolicyBaseName), overwrite: true); CrossgenUtil.CrossgenDirectory( sharedFrameworkNameVersionPath, sdkOutputDirectory); // Generate .version file var version = buildVersion.NuGetVersion; var content = $@"{c.BuildContext["CommitHash"]}{Environment.NewLine}{version}{Environment.NewLine}"; File.WriteAllText(Path.Combine(sdkOutputDirectory, ".version"), content); if (generateNugetPackagesArchive) { GenerateNuGetPackagesArchive(c, dotnet, sdkOutputDirectory); } return(c.Success()); }