CompileTargets moved to MSBuild

CompileTargets moved to MSBuild. Still need to work on input/outputs, refactoring of targets, specially around CompileStage and moving some of the tasks back to msbuild instead of C# code.
This commit is contained in:
Livar Cunha 2016-06-29 14:10:55 -07:00
parent 231abe264c
commit 76728be4cb
12 changed files with 489 additions and 409 deletions

View file

@ -15,6 +15,11 @@
<NoRunArg Condition=" '$(OS)' == 'Windows_NT' ">-NoRun</NoRunArg>
<NoRunArg Condition=" '$(OS)' != 'Windows_NT' ">--norun</NoRunArg>
<CR>%0D</CR>
<LF>%0A</LF>
<NewLine Condition=" '$(OSName)' == 'win' ">$(LF)</NewLine>
<NewLine Condition=" '$(OSName)' != 'win' ">$(CR)$(LF)</NewLine>
<CLITargets Condition=" '$(CLITargets)' == '' ">Prepare;Compile;Test;Package;Publish</CLITargets>
<CLIBuildFileName>$(MSBuildThisFileDirectory)/build_projects/dotnet-cli-build/bin/dotnet-cli-build</CLIBuildFileName>
<CLIBuildDll>$(CLIBuildFileName).dll</CLIBuildDll>
@ -49,12 +54,12 @@
<Target DependsOnTargets="$(CLITargets)" Name="BuildTheWholeCli"></Target>
<UsingTask TaskName="CompileTargets" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="PrepareTargets" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="TestTargets" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="PublishTargets" AssemblyFile="$(CLIBuildDll)" />
<Target DependsOnTargets="BuildDotnetCliBuildFramework" Name="Compile">
<CompileTargets />
<Target DependsOnTargets="BuildDotnetCliBuildFramework" Name="Prepare">
<PrepareTargets />
</Target>
<Target DependsOnTargets="BuildDotnetCliBuildFramework" Name="Test">
@ -66,5 +71,6 @@
</Target>
<Import Project="build/Microsoft.DotNet.Cli.Prepare.targets" />
<Import Project="build/Microsoft.DotNet.Cli.Compile.targets" />
<Import Project="build/Microsoft.DotNet.Cli.Package.targets" />
</Project>

View file

@ -0,0 +1,189 @@
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="compile/Microsoft.DotNet.Cli.Archive.targets" />
<UsingTask TaskName="FixModeFlags" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="ChangeEntryPointLibraryName" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="RemoveAssetFromDepsPackages" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="CleanPublishOutput" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="SharedFrameworkNameVersionPath" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="CrossgenDirectory" AssemblyFile="$(CLIBuildDll)" />
<Target Name="Compile" DependsOnTargets="BuildDotnetCliBuildFramework;
CompileStage1;
CompileStage2">
</Target>
<Target Name="CompileStage1"
DependsOnTargets="Init;
SetupStage1;
CompileStage;
AfterCompileStage">
</Target>
<Target Name="SetupStage1">
<PropertyGroup>
<StageDirectory>$(Stage1Directory)</StageDirectory>
<StageSymbolsDirectory>$(Stage1SymbolsDirectory)</StageSymbolsDirectory>
<DotnetExe>$(Stage0Path)/dotnet.exe</DotnetExe>
</PropertyGroup>
</Target>
<Target Name="CompileStage2"
DependsOnTargets="Init;
SetupStage2;
CompileStage;
AfterCompileStage;
BuildProjectsForNuGetPackages;
GenerateNuGetPackagesArchive">
</Target>
<Target Name="SetupStage2">
<PropertyGroup>
<StageDirectory>$(Stage2Directory)</StageDirectory>
<StageSymbolsDirectory>$(Stage2SymbolsDirectory)</StageSymbolsDirectory>
<DotnetExe>$(DotnetStage1)</DotnetExe>
</PropertyGroup>
</Target>
<Target Name="CompileStage"
DependsOnTargets="BeforeCompileStage">
<PropertyGroup>
<SdkOutputDirectory>$(StageDirectory)/sdk/$(NugetVersion)</SdkOutputDirectory>
<BinaryToCorehostifyRelDir>runtimes/any/native</BinaryToCorehostifyRelDir>
<BinaryToCorehostifyOutDir>$(SdkOutputDirectory)/$(BinaryToCorehostifyRelDir)</BinaryToCorehostifyOutDir>
<MSBuildTargetsDirectory>$(SdkOutputDirectory)/runtimes/any/native</MSBuildTargetsDirectory>
</PropertyGroup>
<ItemGroup>
<SharedFramework Include="$(IntermediateDirectory)/sharedFrameworkPublish/**/*.*" />
<BinariesToRemove Include="csc" />
<BinariesToRemove Include="vbc" />
<MSBuildTargetsToCopy Include="$(MSBuildTargetsDirectory)/**/*.targets" />
<MSBuildTargetsToCopy Include="$(MSBuildTargetsDirectory)/**/*.Targets" />
<MSBuildTargetsToCopy Include="$(MSBuildTargetsDirectory)/**/*.props" />
<MSBuildTargetsToCopy Include="$(MSBuildTargetsDirectory)/**/*.overridetasks" />
<MSBuildTargetsToCopy Include="$(MSBuildTargetsDirectory)/**/*.tasks" />
</ItemGroup>
<!-- CopySharedFramework -->
<Copy SourceFiles="@(SharedFramework)"
DestinationFiles="@(SharedFramework->'$(StageDirectory)\%(RecursiveDir)%(Filename)%(Extension)')" />
<!-- Publish DotNet -->
<Exec Command="$(DotnetExe) publish
--native-subdirectory
--output $(SdkOutputDirectory)
--configuration $(Configuration)
--version-suffix $(CommitCount)
$(SrcDirectory)/dotnet" />
<!-- Corehostify Binaries -->
<FixModeFlags Dir="$(SdkOutputDirectory)" />
<Exec Command="$(DotnetExe) publish
--output $(SdkOutputDirectory)
--framework netcoreapp1.0
$(SrcDirectory)/compilers" />
<Copy SourceFiles="$(BinaryToCorehostifyOutDir)/csc.exe"
DestinationFiles="$(SdkOutputDirectory)/csc.dll" />
<Move SourceFiles="$(BinaryToCorehostifyOutDir)/csc.exe"
DestinationFiles="$(SdkOutputDirectory)/csc.exe" />
<Copy SourceFiles="$(SdkOutputDirectory)/compilers.deps.json"
DestinationFiles="$(SdkOutputDirectory)/csc.deps.json" />
<Copy SourceFiles="$(SdkOutputDirectory)/compilers.runtimeconfig.json"
DestinationFiles="$(SdkOutputDirectory)/csc.runtimeconfig.json" />
<ChangeEntryPointLibraryName
DepsFile="$(SdkOutputDirectory)/csc.deps.json"
NewName="csc.deps.json" />
<RemoveAssetFromDepsPackages DepsFile="$(BinaryToCorehostifyRelDir)/csc.deps.json"
SectionName="runtimeTargets"
AssetPath="$(BinaryToCorehostifyRelDir)/%(BinariesToRemove.Identity).exe" />
<RemoveAssetFromDepsPackages DepsFile="$(SdkOutputDirectory)/dotnet.deps.json"
SectionName="runtimeTargets"
AssetPath="$(BinaryToCorehostifyRelDir)/%(BinariesToRemove.Identity).exe" />
<!-- cleanup compilers project output we don't need -->
<CleanPublishOutput Path="$(SdkOutputDirectory)"
Name="compilers"
DeleteRuntimeConfigJson="true"
DeleteDepsJson="true" />
<!-- Copy Host to SDK Directory -->
<Copy SourceFiles="$(SharedFrameworkNameVersionPath)/$(DotnetHostBaseName)"
DestinationFiles="$(SdkOutputDirectory)/corehost$(ExeSuffix)" />
<Copy SourceFiles="$(SharedFrameworkNameVersionPath)/$(DotnetHostFxrBaseName)"
DestinationFiles="$(SdkOutputDirectory)/$(DotnetHostFxrBaseName)" />
<Copy SourceFiles="$(SharedFrameworkNameVersionPath)/$(HostPolicyBaseName)"
DestinationFiles="$(SdkOutputDirectory)/$(HostPolicyBaseName)" />
<CrossgenDirectory SharedFrameworkNameVersionPath="$(SharedFrameworkNameVersionPath)"
SdkOutputDirectory="$(SdkOutputDirectory)" />
<!-- Generate .version file -->
<WriteLinesToFile File="$(SdkOutputDirectory)/.version"
Lines="$(CommitHash)$(NewLine)$(NugetVersion)$(NewLine)"
Overwrite="true" />
<Copy SourceFiles="@(MSBuildTargetsToCopy)"
DestinationFiles="@(MSBuildTargetsToCopy->'$(SdkOutputDirectory)\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
<Target Name="BeforeCompileStage">
<PropertyGroup>
<SrcDirectory>$(RepoRoot)/src</SrcDirectory>
<ExeSuffix Condition=" '$(OSName)' == 'win' ">.exe</ExeSuffix>
<ExeSuffix Condition=" '$(OSName)' != 'win' "></ExeSuffix>
<DynamicLibPrefix Condition=" '$(OSName)' == 'win' "></DynamicLibPrefix>
<DynamicLibPrefix Condition=" '$(OSName)' != 'win' ">lib</DynamicLibPrefix>
<DynamicLibSuffix Condition=" '$(OSName)' == 'win' ">.dll</DynamicLibSuffix>
<DynamicLibSuffix Condition=" '$(OSName)' == 'osx' ">.dylib</DynamicLibSuffix>
<DynamicLibSuffix Condition=" '$(DynamicLibSuffix)' == '' ">.so</DynamicLibSuffix>
<DotnetHostBaseName>dotnet$(ExeSuffix)</DotnetHostBaseName>
<DotnetHostFxrBaseName>$(DynamicLibPrefix)hostfxr$(DynamicLibSuffix)</DotnetHostFxrBaseName>
<HostPolicyBaseName>$(DynamicLibPrefix)hostpolicy$(DynamicLibSuffix)</HostPolicyBaseName>
</PropertyGroup>
<ItemGroup>
<BinObj Include="$(SrcDirectory)/**/bin/**/*" />
<BinObj Include="$(SrcDirectory)/**/obj/**/*" />
</ItemGroup>
<SharedFrameworkNameVersionPath RootOutputDirectory="$(StageDirectory)">
<Output TaskParameter="OutputSharedFrameworkNameVersionPath" PropertyName="SharedFrameworkNameVersionPath" />
</SharedFrameworkNameVersionPath>
<Delete Files="@(BinObj)" />
<RemoveDir Directories="$(StageDirectory)" />
<MakeDir Directories="$(StageDirectory)"/>
</Target>
<Target Name="AfterCompileStage">
<ItemGroup>
<FilesToClean Include="$(StageDirectory)/sdk/**/vbc.exe" />
<FilesToCopy Include="$(StageDirectory)/**/*.*" />
<PdbsToClean Include="$(StageDirectory)/sdk/**/*.pdb" />
</ItemGroup>
<Delete Files="@(FilesToClean)" />
<Copy SourceFiles="@(FilesToCopy)"
DestinationFiles="@(FilesToCopy->'$(StageSymbolsDirectory)\%(RecursiveDir)%(Filename)%(Extension)')" />
<Delete Files="@(PdbsToClean)" />
</Target>
</Project>

View file

@ -29,7 +29,14 @@
<DotNetPath>$(Stage0Path)</DotNetPath>
<BaseOutputDirectory>$(RepoRoot)/artifacts/$(Rid)</BaseOutputDirectory>
<OutputDirectory>$(BaseOutputDirectory)/stage2/</OutputDirectory>
<ToolsOutputDirectory>$(BaseOutputDirectory)/tools</ToolsOutputDirectory>
<Stage1Directory>$(BaseOutputDirectory)/stage1</Stage1Directory>
<Stage1SymbolsDirectory>$(BaseOutputDirectory)/stage1symbols</Stage1SymbolsDirectory>
<DotnetStage1>$(Stage1Directory)/dotnet.exe</DotnetStage1>
<Stage2Directory>$(BaseOutputDirectory)/stage2</Stage2Directory>
<Stage2SymbolsDirectory>$(BaseOutputDirectory)/stage2symbols</Stage2SymbolsDirectory>
<DotnetStage2>$(Stage2Directory)/dotnet.exe</DotnetStage2>
<OutputDirectory>$(Stage2Directory)</OutputDirectory>
<Stage2CompilationDirectory>$(BaseOutputDirectory)/stage2compilation</Stage2CompilationDirectory>
<IntermediateDirectory>$(BaseOutputDirectory)/intermediate</IntermediateDirectory>
<PackagesDirectory>$(BaseOutputDirectory)/packages</PackagesDirectory>

View file

@ -0,0 +1,43 @@
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="GenerateNuGetPackagesArchive"
DependsOnTargets="RestoreNuGetPackagesArchive;
CompressNuGetPackagesArchive"
Inputs="$(Stage2Directory)/sdk/**/dotnet.dll"
Outputs="$(FinalArchive)">
<Message Text="Generating NuGet Packages Archive" />
</Target>
<Target Name="RestoreNuGetPackagesArchive"
DependsOnTargets="SetupNuGetPackagesArchiveInputsOutputs">
<RemoveDir Directories="$(NuGetPackagesArchiveProject);$(NuGetPackagesArchiveFolder)" />
<MakeDir Directories="$(NuGetPackagesArchiveProject);$(NuGetPackagesArchiveFolder)"/>
<Exec Command="$(DotnetStage2) new" WorkingDirectory="$(NuGetPackagesArchiveProject)" />
<Exec Command="$(DotnetStage2) restore --packages $(NuGetPackagesArchiveFolder)"
WorkingDirectory="$(NuGetPackagesArchiveProject)" />
</Target>
<Target Name="CompressNuGetPackagesArchive"
DependsOnTargets="SetupNuGetPackagesArchiveInputsOutputs">
<Delete Files="$(IntermediateArchive);$(IntermediateArchive).zip" />
<Message Text="Publishing Archiver" />
<Exec Command="$(DotnetStage2) publish --output $(ToolsOutputDirectory) --configuration $(Configuration)"
WorkingDirectory="$(RepoRoot)/tools/Archiver" />
<Exec Command="$(ArchiverExe) -a $(IntermediateArchive) $(NuGetPackagesArchiveFolder)" />
<Copy SourceFiles="$(IntermediateArchive)" DestinationFiles="$(FinalArchive)" />
</Target>
<Target Name="SetupNuGetPackagesArchiveInputsOutputs"
DependsOnTargets="Init">
<PropertyGroup>
<NuGetPackagesArchiveProject>$(IntermediateDirectory)/NuGetPackagesArchiveProject</NuGetPackagesArchiveProject>
<NuGetPackagesArchiveFolder>$(IntermediateDirectory)/NuGetPackagesArchiveFolder</NuGetPackagesArchiveFolder>
<ArchiverExe>$(ToolsOutputDirectory)/Archiver</ArchiverExe>
<IntermediateArchive>$(IntermediateDirectory)/nuGetPackagesArchive.lzma</IntermediateArchive>
<FinalArchive>$(Stage2Directory)/nuGetPackagesArchive.lzma</FinalArchive>
</PropertyGroup>
</Target>
</Project>

View file

@ -66,4 +66,15 @@
--configuration $(Configuration)
--version-suffix $(NupkgVersionSuffix)" />
</Target>
<Target Name="BuildProjectsForNuGetPackages"
DependsOnTargets="Init"
Condition=" '$(OS)' == 'Windows_NT' ">
<MakeDir Directories="$(PackagingBuildBasePath)" />
<Exec Command="$(DotnetStage2) build
--build-base-path $(PackagingBuildBasePath)
--configuration $(Configuration)
%(ProjectsToPack.Identity)" />
</Target>
</Project>

View file

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Net.Http;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
namespace Microsoft.DotNet.Cli.Build
{
public class ChangeEntryPointLibraryName : Task
{
public string DepsFile { get; set; }
public string NewName { get; set; }
public override bool Execute()
{
PublishMutationUtilties.ChangeEntryPointLibraryName(DepsFile, NewName);
return true;
}
}
}

View file

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Net.Http;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
namespace Microsoft.DotNet.Cli.Build
{
public class CleanPublishOutput : Task
{
public string Path { get; set; }
public string Name { get; set; }
public bool DeleteRuntimeConfigJson { get; set; }
public bool DeleteDepsJson { get; set; }
public override bool Execute()
{
PublishMutationUtilties.CleanPublishOutput(Path, Name, DeleteRuntimeConfigJson, DeleteDepsJson);
return true;
}
}
}

View file

@ -1,402 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
using static Microsoft.DotNet.Cli.Build.FS;
namespace Microsoft.DotNet.Cli.Build
{
public class CompileTargets : Task
{
public static readonly bool IsWinx86 = CurrentPlatform.IsWindows && CurrentArchitecture.Isx86;
public static readonly string[] BinariesForCoreHost = new[]
{
"csc"
};
public static readonly string[] ProjectsToPublish = new[]
{
"dotnet"
};
public static readonly string[] FilesToClean = new[]
{
"vbc.exe"
};
public static string HostPackagePlatformRid => HostPackageSupportedRids[
(RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
? $"win7-{RuntimeEnvironment.RuntimeArchitecture}"
: RuntimeEnvironment.GetRuntimeIdentifier()];
public static readonly Dictionary<string, string> HostPackageSupportedRids = new Dictionary<string, string>()
{
// Key: Current platform RID. Value: The actual publishable (non-dummy) package name produced by the build system for this RID.
{ "win7-x64", "win7-x64" },
{ "win7-x86", "win7-x86" },
{ "osx.10.10-x64", "osx.10.10-x64" },
{ "osx.10.11-x64", "osx.10.10-x64" },
{ "ubuntu.14.04-x64", "ubuntu.14.04-x64" },
{ "ubuntu.16.04-x64", "ubuntu.16.04-x64" },
{ "centos.7-x64", "rhel.7-x64" },
{ "rhel.7-x64", "rhel.7-x64" },
{ "rhel.7.2-x64", "rhel.7-x64" },
{ "debian.8-x64", "debian.8-x64" },
{ "fedora.23-x64", "fedora.23-x64" },
{ "opensuse.13.2-x64", "opensuse.13.2-x64" }
};
public const string SharedFrameworkName = "Microsoft.NETCore.App";
public static Crossgen CrossgenUtil = new Crossgen(DependencyVersions.CoreCLRVersion, DependencyVersions.JitVersion);
public override bool Execute()
{
BuildContext context = new BuildSetup("MSBuild").UseAllTargetsFromAssembly<CompileTargets>().CreateBuildContext();
BuildTargetContext c = new BuildTargetContext(context, null, null);
return Compile(c).Success;
}
[Target]
public static BuildTargetResult Compile(BuildTargetContext c)
{
PrepareTargets.Init(c);
CompileStage1(c);
CompileStage2(c);
return c.Success();
}
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;
}
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);
var result = CompileCliSdk(c,
dotnet: DotNetCli.Stage1,
rootOutputDirectory: Dirs.Stage2,
generateNugetPackagesArchive: true);
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();
}
private static void CleanOutputDir(string directory)
{
foreach (var file in FilesToClean)
{
FS.RmFilesInDirRecursive(directory, file);
}
}
private static void RemovePdbsFromDir(string directory)
{
FS.RmFilesInDirRecursive(directory, "*.pdb");
}
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.Move(Path.Combine(binaryToCorehostifyOutDir, $"{binaryToCorehostify}.exe"), Path.Combine(sdkOutputDirectory, $"{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);
RemoveAssetFromDepsPackages(
Path.Combine(sdkOutputDirectory, "dotnet.deps.json"), "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);
}
CopyMSBuildTargetsToSDKRoot(sdkOutputDirectory);
return c.Success();
}
private static void CopyMSBuildTargetsToSDKRoot(string sdkOutputDirectory)
{
var msbuildTargetsDirectory = Path.Combine(sdkOutputDirectory, "runtimes", "any", "native");
var filesToCopy = new List<string>();
filesToCopy.AddRange(Directory.EnumerateFiles(msbuildTargetsDirectory, "*.targets", SearchOption.AllDirectories));
filesToCopy.AddRange(Directory.EnumerateFiles(msbuildTargetsDirectory, "*.Targets", SearchOption.AllDirectories));
filesToCopy.AddRange(Directory.EnumerateFiles(msbuildTargetsDirectory, "*.props", SearchOption.AllDirectories));
filesToCopy.AddRange(Directory.EnumerateFiles(msbuildTargetsDirectory, "*.overridetasks", SearchOption.AllDirectories));
filesToCopy.AddRange(Directory.EnumerateFiles(msbuildTargetsDirectory, "*.tasks", SearchOption.AllDirectories));
foreach (var fileFullPath in filesToCopy)
{
var fileRelativePath = fileFullPath.Substring(msbuildTargetsDirectory.Length + 1);
var destinationFilePath = Path.Combine(sdkOutputDirectory, fileRelativePath);
File.Copy(fileFullPath, destinationFilePath, true);
}
}
private static void GenerateNuGetPackagesArchive(
BuildTargetContext c,
DotNetCli dotnet,
string sdkOutputDirectory)
{
var nuGetPackagesArchiveProject = Path.Combine(Dirs.Intermediate, "NuGetPackagesArchiveProject");
var nuGetPackagesArchiveFolder = Path.Combine(Dirs.Intermediate, "nuGetPackagesArchiveFolder");
RestoreNuGetPackagesArchive(dotnet, nuGetPackagesArchiveProject, nuGetPackagesArchiveFolder);
CompressNuGetPackagesArchive(c, dotnet, nuGetPackagesArchiveFolder, sdkOutputDirectory);
}
private static void RestoreNuGetPackagesArchive(
DotNetCli dotnet,
string nuGetPackagesArchiveProject,
string nuGetPackagesArchiveFolder)
{
Rmdir(nuGetPackagesArchiveProject);
Mkdirp(nuGetPackagesArchiveProject);
Rmdir(nuGetPackagesArchiveFolder);
Mkdirp(nuGetPackagesArchiveFolder);
dotnet.New()
.WorkingDirectory(nuGetPackagesArchiveProject)
.Execute()
.EnsureSuccessful();
dotnet.Restore("--packages", nuGetPackagesArchiveFolder)
.WorkingDirectory(nuGetPackagesArchiveProject)
.Execute()
.EnsureSuccessful();
}
private static void CompressNuGetPackagesArchive(
BuildTargetContext c,
DotNetCli dotnet,
string nuGetPackagesArchiveFolder,
string sdkOutputDirectory)
{
var configuration = c.BuildContext.Get<string>("Configuration");
var archiverExe = Path.Combine(Dirs.Output, "tools", $"Archiver{Constants.ExeSuffix}");
var intermediateArchive = Path.Combine(Dirs.Intermediate, "nuGetPackagesArchive.lzma");
var finalArchive = Path.Combine(sdkOutputDirectory, "nuGetPackagesArchive.lzma");
Rm(intermediateArchive);
Rm($"{intermediateArchive}.zip");
c.Info("Publishing Archiver");
dotnet.Publish("--output", Path.Combine(Dirs.Output, "tools"), "--configuration", configuration)
.WorkingDirectory(Path.Combine(Dirs.RepoRoot, "tools", "Archiver"))
.Execute()
.EnsureSuccessful();
Cmd(archiverExe,
"-a", intermediateArchive,
nuGetPackagesArchiveFolder)
.Execute();
File.Copy(intermediateArchive, finalArchive);
}
private static void RemoveAssetFromDepsPackages(string depsFile, string sectionName, string assetPath)
{
JToken deps;
using (var file = File.OpenText(depsFile))
using (JsonTextReader reader = new JsonTextReader(file))
{
deps = JObject.ReadFrom(reader);
}
foreach (JProperty target in deps["targets"])
{
foreach (JProperty pv in target.Value.Children<JProperty>())
{
var section = pv.Value[sectionName];
if (section != null)
{
foreach (JProperty relPath in section)
{
if (assetPath.Equals(relPath.Name))
{
relPath.Remove();
break;
}
}
}
}
}
using (var file = File.CreateText(depsFile))
using (var writer = new JsonTextWriter(file) { Formatting = Formatting.Indented })
{
deps.WriteTo(writer);
}
}
private static void CopySharedFramework(string sharedFrameworkPublish, string rootOutputDirectory)
{
CopyRecursive(sharedFrameworkPublish, rootOutputDirectory);
}
}
}

View file

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Net.Http;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
namespace Microsoft.DotNet.Cli.Build
{
public class CrossgenDirectory : Task
{
private static Crossgen CrossgenUtil = new Crossgen(DependencyVersions.CoreCLRVersion, DependencyVersions.JitVersion);
public string SharedFrameworkNameVersionPath { get; set; }
public string SdkOutputDirectory { get; set; }
public override bool Execute()
{
CrossgenUtil.CrossgenDirectory(SharedFrameworkNameVersionPath, SdkOutputDirectory);
return true;
}
}
}

View file

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Net.Http;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
namespace Microsoft.DotNet.Cli.Build
{
public class FixModeFlags : Task
{
public string Dir { get; set; }
public override bool Execute()
{
FS.FixModeFlags(Dir);
return true;
}
}
}

View file

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Net.Http;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
namespace Microsoft.DotNet.Cli.Build
{
public class RemoveAssetFromDepsPackages : Task
{
public string DepsFile { get; set; }
public string SectionName { get; set; }
public string AssetPath { get; set; }
public override bool Execute()
{
DoRemoveAssetFromDepsPackages(DepsFile, SectionName, AssetPath);
return true;
}
private static void DoRemoveAssetFromDepsPackages(string depsFile, string sectionName, string assetPath)
{
JToken deps;
using (var file = File.OpenText(depsFile))
using (JsonTextReader reader = new JsonTextReader(file))
{
deps = JObject.ReadFrom(reader);
}
foreach (JProperty target in deps["targets"])
{
foreach (JProperty pv in target.Value.Children<JProperty>())
{
var section = pv.Value[sectionName];
if (section != null)
{
foreach (JProperty relPath in section)
{
if (assetPath.Equals(relPath.Name))
{
relPath.Remove();
break;
}
}
}
}
}
using (var file = File.CreateText(depsFile))
using (var writer = new JsonTextWriter(file) { Formatting = Formatting.Indented })
{
deps.WriteTo(writer);
}
}
}
}

View file

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Net.Http;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
namespace Microsoft.DotNet.Cli.Build
{
public class SharedFrameworkNameVersionPath : Task
{
public string RootOutputDirectory { get; set; }
[Output]
public string OutputSharedFrameworkNameVersionPath { get; set; }
public override bool Execute()
{
var sharedFrameworkNugetVersion = CliDependencyVersions.SharedFrameworkVersion;
OutputSharedFrameworkNameVersionPath = SharedFrameworkPublisher.GetSharedFrameworkPublishPath(
RootOutputDirectory,
sharedFrameworkNugetVersion);
return true;
}
}
}