示例#1
0
        public static BuildTargetResult CompileStage2(BuildTargetContext c)
        {
            var configuration = c.BuildContext.Get <string>("Configuration");

            CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "src"));

            if (Directory.Exists(Dirs.Stage2))
            {
                Utils.DeleteDirectory(Dirs.Stage2);
            }
            Directory.CreateDirectory(Dirs.Stage2);

            PublishSharedFramework(c, Dirs.Stage2, DotNetCli.Stage1);
            CopySharedHost(Dirs.Stage2);
            var result = CompileCliSdk(c,
                                       dotnet: DotNetCli.Stage1,
                                       outputDir: Dirs.Stage2);

            if (!result.Success)
            {
                return(result);
            }

            if (CurrentPlatform.IsWindows)
            {
                // build projects for nuget packages
                var packagingOutputDir = Path.Combine(Dirs.Stage2Compilation, "forPackaging");
                Mkdirp(packagingOutputDir);
                foreach (var project in PackageTargets.ProjectsToPack)
                {
                    // Just build them, we'll pack later
                    var packBuildResult = DotNetCli.Stage1.Build(
                        "--build-base-path",
                        packagingOutputDir,
                        "--configuration",
                        configuration,
                        Path.Combine(c.BuildContext.BuildDirectory, "src", project))
                                          .Execute();

                    packBuildResult.EnsureSuccessful();
                }
            }

            CleanOutputDir(Path.Combine(Dirs.Stage2, "sdk"));
            FS.CopyRecursive(Dirs.Stage2, Dirs.Stage2Symbols);

            RemovePdbsFromDir(Path.Combine(Dirs.Stage2, "sdk"));

            return(c.Success());
        }
示例#2
0
        private void CopyFilesToDebianLayout(
            DebianLayoutDirectories layoutDirectories,
            string debianConfigFile,
            string inputBinariesDirectory,
            string manpagesDirectory)
        {
            FS.CopyRecursive(inputBinariesDirectory, layoutDirectories.PackageRoot);

            if (manpagesDirectory != null)
            {
                FS.CopyRecursive(manpagesDirectory, layoutDirectories.Docs);
            }

            File.Copy(debianConfigFile,
                      Path.Combine(layoutDirectories.LayoutDirectory, s_debianConfigJsonFileName));
        }
示例#3
0
        public static BuildTargetResult RestoreLockedCoreHost(BuildTargetContext c)
        {
            var hostVersion          = c.BuildContext.Get <HostVersion>("HostVersion");
            var lockedHostFxrVersion = hostVersion.LockedHostFxrVersion;

            var currentRid = HostPackagePlatformRid;

            string projectJson     = $@"{{
  ""dependencies"": {{
      ""Microsoft.NETCore.DotNetHostResolver"" : ""{lockedHostFxrVersion}""
  }},
  ""frameworks"": {{
      ""netcoreapp1.0"": {{}}
  }},
  ""runtimes"": {{
      ""{currentRid}"": {{}}
  }}
}}";
            var    tempPjDirectory = Path.Combine(Dirs.Intermediate, "lockedHostTemp");

            FS.Rmdir(tempPjDirectory);
            Directory.CreateDirectory(tempPjDirectory);
            var tempPjFile = Path.Combine(tempPjDirectory, "project.json");

            File.WriteAllText(tempPjFile, projectJson);

            DotNetCli.Stage0.Restore("--verbosity", "verbose",
                                     "--fallbacksource", Dirs.CorehostLocalPackages,
                                     "--fallbacksource", Dirs.CorehostDummyPackages)
            .WorkingDirectory(tempPjDirectory)
            .Execute()
            .EnsureSuccessful();

            // Clean out before publishing locked binaries
            FS.Rmdir(Dirs.CorehostLocked);

            // Use specific RIDS for non-backward compatible platforms.
            (CurrentPlatform.IsWindows
                ? DotNetCli.Stage0.Publish("--output", Dirs.CorehostLocked, "--no-build")
                : DotNetCli.Stage0.Publish("--output", Dirs.CorehostLocked, "--no-build", "-r", currentRid))
            .WorkingDirectory(tempPjDirectory)
            .Execute()
            .EnsureSuccessful();

            return(c.Success());
        }
示例#4
0
        private void CopyFilesToDebianLayout(
            DebianLayoutDirectories layoutDirectories,
            string packageVersion,
            string debianConfigFile,
            string inputBinariesDirectory,
            string manpagesDirectory,
            bool versionManpages,
            IEnumerable <string> debianFiles)
        {
            FS.CopyRecursive(inputBinariesDirectory, layoutDirectories.PackageRoot);

            if (manpagesDirectory != null)
            {
                FS.CopyRecursive(manpagesDirectory, layoutDirectories.Docs);

                // Append version to all manpage files
                if (versionManpages)
                {
                    foreach (var file in Directory.EnumerateFiles(layoutDirectories.Docs, "*", SearchOption.AllDirectories))
                    {
                        var versionedFile = Path.Combine(
                            Path.GetDirectoryName(file),
                            $"{Path.GetFileNameWithoutExtension(file)}-{packageVersion}{Path.GetExtension(file)}");

                        if (File.Exists(versionedFile))
                        {
                            File.Delete(versionedFile);
                        }

                        File.Move(file, versionedFile);
                    }
                }
            }

            File.Copy(debianConfigFile,
                      Path.Combine(layoutDirectories.LayoutDirectory, s_debianConfigJsonFileName));

            if (debianFiles != null)
            {
                foreach (var debianFile in debianFiles)
                {
                    File.Copy(debianFile,
                              Path.Combine(layoutDirectories.DebianFiles, Path.GetFileName(debianFile)));
                }
            }
        }
示例#5
0
        public override bool Execute()
        {
            FS.Mkdirp(Path.GetDirectoryName(DestinationPath));

            if (File.Exists(DestinationPath) && !Overwrite)
            {
                return(true);
            }

            const string FileUriProtocol = "file://";

            if (Uri.StartsWith(FileUriProtocol, StringComparison.Ordinal))
            {
                var filePath = Uri.Substring(FileUriProtocol.Length);
                Log.LogMessage($"Copying '{filePath}' to '{DestinationPath}'");
                File.Copy(filePath, DestinationPath);
            }
            else
            {
                Log.LogMessage($"Downloading '{Uri}' to '{DestinationPath}'");

                using (var httpClient = new HttpClient())
                {
                    var getTask = httpClient.GetStreamAsync(Uri);

                    try
                    {
                        using (var outStream = File.Create(DestinationPath))
                        {
                            getTask.Result.CopyTo(outStream);
                        }
                    }
                    catch (Exception)
                    {
                        File.Delete(DestinationPath);
                        throw;
                    }
                }
            }

            return(true);
        }
示例#6
0
        public static BuildTargetResult GenerateNugetPackages(BuildTargetContext c)
        {
            var versionSuffix = c.BuildContext.Get <BuildVersion>("BuildVersion").VersionSuffix;
            var configuration = c.BuildContext.Get <string>("Configuration");

            var env    = GetCommonEnvVars(c);
            var dotnet = DotNetCli.Stage2;

            var packagingBuildBasePath = Path.Combine(Dirs.Stage2Compilation, "forPackaging");

            FS.Mkdirp(Dirs.PackagesIntermediate);
            FS.Mkdirp(Dirs.Packages);

            foreach (var projectName in ProjectsToPack)
            {
                var projectFile = Path.Combine(Dirs.RepoRoot, "src", projectName, "project.json");

                dotnet.Pack(
                    projectFile,
                    "--no-build",
                    "--build-base-path", packagingBuildBasePath,
                    "--output", Dirs.PackagesIntermediate,
                    "--configuration", configuration,
                    "--version-suffix", versionSuffix)
                .Execute()
                .EnsureSuccessful();
            }

            var packageFiles = Directory.EnumerateFiles(Dirs.PackagesIntermediate, "*.nupkg");

            foreach (var packageFile in packageFiles)
            {
                if (!packageFile.EndsWith(".symbols.nupkg"))
                {
                    var destinationPath = Path.Combine(Dirs.Packages, Path.GetFileName(packageFile));
                    File.Copy(packageFile, destinationPath, overwrite: true);
                }
            }

            return(c.Success());
        }
示例#7
0
        private void CreateAndRestoreToolConsumingProject()
        {
            if (Directory.Exists(_consumingProjectDirectory))
            {
                FS.Rmdir(_consumingProjectDirectory);
            }
            FS.Mkdirp(_consumingProjectDirectory);

            var projectJsonFile = Path.Combine(_consumingProjectDirectory, "project.json");

            File.WriteAllText(projectJsonFile, GetDotnetDebProjectJsonContents());

            Command restore = _dotnetDebToolPackageSource == null
                ? _dotnet.Restore()
                : _dotnet.Restore("-f", $"{_dotnetDebToolPackageSource}");

            restore
            .WorkingDirectory(Path.GetDirectoryName(projectJsonFile))
            .Execute()
            .EnsureSuccessful();
        }
示例#8
0
        public static BuildTargetResult CompileStage1(BuildTargetContext c)
        {
            CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "src"));

            if (Directory.Exists(Dirs.Stage1))
            {
                Utils.DeleteDirectory(Dirs.Stage1);
            }
            Directory.CreateDirectory(Dirs.Stage1);

            var result = CompileCliSdk(c,
                                       dotnet: DotNetCli.Stage0,
                                       rootOutputDirectory: Dirs.Stage1);

            CleanOutputDir(Path.Combine(Dirs.Stage1, "sdk"));
            FS.CopyRecursive(Dirs.Stage1, Dirs.Stage1Symbols);

            RemovePdbsFromDir(Path.Combine(Dirs.Stage1, "sdk"));

            return(result);
        }
示例#9
0
        public override bool Execute()
        {
            FS.Mkdirp(Path.GetDirectoryName(DestinationPath));

            if (File.Exists(DestinationPath) && !Overwrite)
            {
                return(true);
            }

            Log.LogMessage($"Downloading '{Uri}' to '{DestinationPath}'");

            using (var httpClient = new HttpClient())
            {
                var getTask = httpClient.GetStreamAsync(Uri);

                using (var outStream = File.Create(DestinationPath))
                {
                    getTask.Result.CopyTo(outStream);
                }
            }

            return(true);
        }
示例#10
0
        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());
        }
示例#11
0
 private static void RemovePdbsFromDir(string directory)
 {
     FS.RmFilesInDirRecursive(directory, "*.pdb");
 }
示例#12
0
 private static void CleanOutputDir(string directory)
 {
     FS.RmFilesInDirRecursive(directory, "vbc.exe");
     FS.RmFilesInDirRecursive(directory, "*.pdb");
 }
示例#13
0
        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());
        }