public void PublishSharedFramework(string outputRootDirectory, string commitHash, DotNetCli dotnetCli, string hostFxrVersion)
        {
            dotnetCli.Restore(
                "--verbosity", "verbose",
                "--disable-parallel",
                "--infer-runtimes",
                "--fallbacksource", _corehostPackageSource)
            .WorkingDirectory(_sharedFrameworkSourceRoot)
            .Execute()
            .EnsureSuccessful();

            // We publish to a sub folder of the PublishRoot so tools like heat and zip can generate folder structures easier.
            string sharedFrameworkNameAndVersionRoot = GetSharedFrameworkPublishPath(outputRootDirectory, _sharedFrameworkNugetVersion);

            if (Directory.Exists(sharedFrameworkNameAndVersionRoot))
            {
                Utils.DeleteDirectory(sharedFrameworkNameAndVersionRoot);
            }

            dotnetCli.Publish(
                "--output", sharedFrameworkNameAndVersionRoot,
                "-r", _sharedFrameworkRid,
                _sharedFrameworkSourceRoot)
            .Execute()
            .EnsureSuccessful();

            // Clean up artifacts that dotnet-publish generates which we don't need
            PublishMutationUtilties.CleanPublishOutput(
                sharedFrameworkNameAndVersionRoot,
                "framework",
                deleteRuntimeConfigJson: true,
                deleteDepsJson: false,
                deleteAppHost: true);

            // Rename the .deps file
            var destinationDeps = Path.Combine(sharedFrameworkNameAndVersionRoot, $"{s_sharedFrameworkName}.deps.json");

            File.Move(Path.Combine(sharedFrameworkNameAndVersionRoot, "framework.deps.json"), destinationDeps);
            PublishMutationUtilties.ChangeEntryPointLibraryName(destinationDeps, null);

            // Generate RID fallback graph
            GenerateRuntimeGraph(dotnetCli, destinationDeps);

            CopyHostArtifactsToSharedFramework(sharedFrameworkNameAndVersionRoot, hostFxrVersion);

            _crossgenUtil.CrossgenDirectory(sharedFrameworkNameAndVersionRoot, sharedFrameworkNameAndVersionRoot);

            // Generate .version file for sharedfx
            var version = _sharedFrameworkNugetVersion;
            var content = $@"{commitHash}{Environment.NewLine}{version}{Environment.NewLine}";

            File.WriteAllText(Path.Combine(sharedFrameworkNameAndVersionRoot, ".version"), content);

            return;
        }
        public void PublishSharedFramework(string outputRootDirectory, string commitHash, DotNetCli dotnetCli, string hostFxrVersion)
        {
            dotnetCli.Restore(
                "--verbosity", "verbose",
                "--disable-parallel",
                "--infer-runtimes",
                "--fallbacksource", _corehostPackageSource)
            .WorkingDirectory(_sharedFrameworkSourceRoot)
            .Execute()
            .EnsureSuccessful();

            // We publish to a sub folder of the PublishRoot so tools like heat and zip can generate folder structures easier.
            string sharedFrameworkNameAndVersionRoot = GetSharedFrameworkPublishPath(outputRootDirectory, _sharedFrameworkNugetVersion);

            if (Directory.Exists(sharedFrameworkNameAndVersionRoot))
            {
                Utils.DeleteDirectory(sharedFrameworkNameAndVersionRoot);
            }

            dotnetCli.Publish(
                "--output", sharedFrameworkNameAndVersionRoot,
                "-r", _sharedFrameworkRid,
                _sharedFrameworkSourceRoot)
            .Execute()
            .EnsureSuccessful();

            // Clean up artifacts that dotnet-publish generates which we don't need
            PublishMutationUtilties.CleanPublishOutput(
                sharedFrameworkNameAndVersionRoot,
                "framework",
                deleteRuntimeConfigJson: true,
                deleteDepsJson: false,
                deleteAppHost: true);

            // Rename the .deps file
            var destinationDeps = Path.Combine(sharedFrameworkNameAndVersionRoot, $"{s_sharedFrameworkName}.deps.json");

            File.Move(Path.Combine(sharedFrameworkNameAndVersionRoot, "framework.deps.json"), destinationDeps);
            PublishMutationUtilties.ChangeEntryPointLibraryName(destinationDeps, null);

            // Generate RID fallback graph
            GenerateRuntimeGraph(dotnetCli, destinationDeps);

            CopyHostArtifactsToSharedFramework(sharedFrameworkNameAndVersionRoot, hostFxrVersion);

            _crossgenUtil.CrossgenDirectory(sharedFrameworkNameAndVersionRoot, sharedFrameworkNameAndVersionRoot);

            // Generate .version file for sharedfx
            var version = _sharedFrameworkNugetVersion;
            var content = $@"{commitHash}{Environment.NewLine}{version}{Environment.NewLine}";

            File.WriteAllText(Path.Combine(sharedFrameworkNameAndVersionRoot, ".version"), content);

            // Populate symbols publish folder
            string sharedFrameworkNameAndVersionWithSymbolsRoot = $"{outputRootDirectory}.symbols";

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

            // Copy symbols to publish folder
            List <string> pdbFiles      = new List <string>();
            string        symbolsRoot   = Path.Combine(_repoRoot, "pkg", "bin", "symbols");
            string        libPdbPath    = GetNetCoreAppRuntimeLibSymbolsPath(symbolsRoot, _sharedFrameworkRid, _sharedFrameworkTarget);
            string        nativePdbPath = GetNetCoreAppRuntimeNativeSymbolsPath(symbolsRoot, _sharedFrameworkRid);
            string        toolsPdbPath  = GetNetCoreAppToolsSymbolsPath(symbolsRoot);

            if (Directory.Exists(libPdbPath))
            {
                pdbFiles.AddRange(Directory.GetFiles(libPdbPath));
            }
            if (Directory.Exists(nativePdbPath))
            {
                pdbFiles.AddRange(Directory.GetFiles(nativePdbPath));
            }
            if (Directory.Exists(toolsPdbPath))
            {
                pdbFiles.AddRange(Directory.GetFiles(toolsPdbPath));
            }
            foreach (string pdbFile in pdbFiles)
            {
                string destinationPath = Path.Combine(sharedFrameworkNameAndVersionWithSymbolsRoot, Path.GetFileName(pdbFile));
                if (!File.Exists(destinationPath))
                {
                    File.Copy(pdbFile, destinationPath);
                }
            }

            return;
        }
Esempio n. 3
0
        private static BuildTargetResult CompileCliSdk(BuildTargetContext c, DotNetCli dotnet, string rootOutputDirectory)
        {
            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",
                           "netstandard1.5")
            .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    = DependencyVersions.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);

            return(c.Success());
        }
        public override bool Execute()
        {
            PublishMutationUtilties.ChangeEntryPointLibraryName(DepsFile, NewName);

            return(true);
        }