Speedup build

This commit is contained in:
Pavel Krymets 2016-04-20 16:50:11 -07:00
parent 88ffa548ba
commit c3984443cd
3 changed files with 118 additions and 78 deletions

View file

@ -87,18 +87,21 @@ namespace Microsoft.DotNet.Cli.Build
{ {
string currentRid = GetRuntimeId(); string currentRid = GetRuntimeId();
var buildVersion = c.BuildContext.Get<BuildVersion>("BuildVersion"); var buildVersion = c.BuildContext.Get<BuildVersion>("BuildVersion");
PrepareDummyRuntimeNuGetPackage(
DotNetCli.Stage0,
buildVersion.HostNuGetPackageVersion,
Dirs.CorehostDummyPackages);
foreach (var hostPackageId in HostPackages) foreach (var hostPackageId in HostPackages)
{ {
foreach (var rid in HostPackageSupportedRids) foreach (var rid in HostPackageSupportedRids)
{ {
if (! rid.Equals(currentRid)) if (!rid.Equals(currentRid))
{ {
CreateDummyRuntimeNuGetPackage( CreateDummyRuntimeNuGetPackage(
DotNetCli.Stage0, DotNetCli.Stage0,
hostPackageId, hostPackageId,
rid, rid,
buildVersion.HostNuGetPackageVersion, buildVersion.HostNuGetPackageVersion,
Dirs.CorehostDummyPackages); Dirs.CorehostDummyPackages);
} }
} }
@ -354,17 +357,14 @@ namespace Microsoft.DotNet.Cli.Build
return c.Success(); return c.Success();
} }
private static void CreateDummyRuntimeNuGetPackage(DotNetCli dotnet, string basePackageId, string rid, string version, string outputDir)
{
var packageId = $"runtime.{rid}.{basePackageId}";
private static void PrepareDummyRuntimeNuGetPackage(DotNetCli dotnet, string version, string outputDir)
{
var projectJson = new StringBuilder(); var projectJson = new StringBuilder();
projectJson.Append("{"); projectJson.Append("{");
projectJson.Append($" \"version\": \"{version}\",");
projectJson.Append($" \"name\": \"{packageId}\",");
projectJson.Append(" \"dependencies\": { \"NETStandard.Library\": \"1.5.0-rc2-24008\" },"); projectJson.Append(" \"dependencies\": { \"NETStandard.Library\": \"1.5.0-rc2-24008\" },");
projectJson.Append(" \"frameworks\": { \"netcoreapp1.0\": { \"imports\": [\"netstandard1.5\", \"dnxcore50\"] } },"); projectJson.Append(" \"frameworks\": { \"netcoreapp1.0\": { \"imports\": [\"netstandard1.5\", \"dnxcore50\"] } },");
projectJson.Append($" \"runtimes\": {{ \"{rid}\": {{ }} }},"); projectJson.Append(" \"runtimes\": { \"win7-x64\": { } },");
projectJson.Append("}"); projectJson.Append("}");
var programCs = "using System; namespace ConsoleApplication { public class Program { public static void Main(string[] args) { Console.WriteLine(\"Hello World!\"); } } }"; var programCs = "using System; namespace ConsoleApplication { public class Program { public static void Main(string[] args) { Console.WriteLine(\"Hello World!\"); } } }";
@ -384,11 +384,28 @@ namespace Microsoft.DotNet.Cli.Build
.WorkingDirectory(tempPjDirectory) .WorkingDirectory(tempPjDirectory)
.Execute() .Execute()
.EnsureSuccessful(); .EnsureSuccessful();
dotnet.Build(tempPjFile, "--runtime", "win7-x64")
dotnet.Build(tempPjFile, "--runtime", rid)
.WorkingDirectory(tempPjDirectory) .WorkingDirectory(tempPjDirectory)
.Execute() .Execute()
.EnsureSuccessful(); .EnsureSuccessful();
}
private static void CreateDummyRuntimeNuGetPackage(DotNetCli dotnet, string basePackageId, string rid, string version, string outputDir)
{
var packageId = $"runtime.{rid}.{basePackageId}";
var projectJson = new StringBuilder();
projectJson.Append("{");
projectJson.Append($" \"version\": \"{version}\",");
projectJson.Append($" \"name\": \"{packageId}\",");
projectJson.Append(" \"dependencies\": { \"NETStandard.Library\": \"1.5.0-rc2-24008\" },");
projectJson.Append(" \"frameworks\": { \"netcoreapp1.0\": { \"imports\": [\"netstandard1.5\", \"dnxcore50\"] } },");
projectJson.Append("}");
var tempPjDirectory = Path.Combine(Dirs.Intermediate, "dummyNuGetPackageIntermediate");
var tempPjFile = Path.Combine(tempPjDirectory, "project.json");
File.WriteAllText(tempPjFile, projectJson.ToString());
dotnet.Pack( dotnet.Pack(
tempPjFile, "--no-build", tempPjFile, "--no-build",

View file

@ -13,6 +13,17 @@ namespace Microsoft.DotNet.Cli.Build
{ {
public static class TestPackageProjects public static class TestPackageProjects
{ {
public class TestPackageProject
{
public string Name { get; set; }
public bool IsTool { get; set; }
public string Path { get; set; }
public bool IsApplicable { get; set; }
public string VersionSuffix { get; set; }
public bool Clean { get; set; }
public string[] Frameworks { get; set; }
}
private static string s_testPackageBuildVersionSuffix = "<buildversion>"; private static string s_testPackageBuildVersionSuffix = "<buildversion>";
public static string TestPackageBuildVersionSuffix public static string TestPackageBuildVersionSuffix
@ -23,160 +34,177 @@ namespace Microsoft.DotNet.Cli.Build
} }
} }
public static readonly dynamic[] Projects = new[] public static readonly TestPackageProject[] Projects = new[]
{ {
new new TestPackageProject()
{ {
Name = "PackageWithFakeNativeDep", Name = "PackageWithFakeNativeDep",
IsTool = false, IsTool = false,
Path = "TestAssets/TestPackages/PackageWithFakeNativeDep", Path = "TestAssets/TestPackages/PackageWithFakeNativeDep",
IsApplicable = new Func<bool>(() => true), IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix, VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = true Clean = true,
Frameworks = new [] { "net45" }
}, },
new new TestPackageProject()
{ {
Name = "dotnet-dependency-context-test", Name = "dotnet-dependency-context-test",
IsTool = true, IsTool = true,
Path = "TestAssets/TestPackages/dotnet-dependency-context-test", Path = "TestAssets/TestPackages/dotnet-dependency-context-test",
IsApplicable = new Func<bool>(() => true), IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix, VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = true Clean = true,
Frameworks = new [] { "netcoreapp1.0" }
}, },
new new TestPackageProject()
{ {
Name = "dotnet-dependency-tool-invoker", Name = "dotnet-dependency-tool-invoker",
IsTool = true, IsTool = true,
Path = "TestAssets/TestPackages/dotnet-dependency-tool-invoker", Path = "TestAssets/TestPackages/dotnet-dependency-tool-invoker",
IsApplicable = new Func<bool>(() => CurrentPlatform.IsWindows), IsApplicable = CurrentPlatform.IsWindows,
VersionSuffix = s_testPackageBuildVersionSuffix, VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = true Clean = true,
Frameworks = new [] { "netcoreapp1.0" }
}, },
new new TestPackageProject()
{ {
Name = "dotnet-desktop-and-portable", Name = "dotnet-desktop-and-portable",
IsTool = true, IsTool = true,
Path = "TestAssets/TestPackages/dotnet-desktop-and-portable", Path = "TestAssets/TestPackages/dotnet-desktop-and-portable",
IsApplicable = new Func<bool>(() => CurrentPlatform.IsWindows), IsApplicable = CurrentPlatform.IsWindows,
VersionSuffix = s_testPackageBuildVersionSuffix, VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = true Clean = true,
Frameworks = new [] { "net451", "netcoreapp1.0" }
}, },
new new TestPackageProject()
{ {
Name = "dotnet-hello", Name = "dotnet-hello",
IsTool = true, IsTool = true,
Path = "TestAssets/TestPackages/dotnet-hello/v1/dotnet-hello", Path = "TestAssets/TestPackages/dotnet-hello/v1/dotnet-hello",
IsApplicable = new Func<bool>(() => true), IsApplicable =true,
VersionSuffix = string.Empty, VersionSuffix = string.Empty,
Clean = true Clean = true,
Frameworks = new [] { "netcoreapp1.0" }
}, },
new new TestPackageProject()
{ {
Name = "dotnet-hello", Name = "dotnet-hello",
IsTool = true, IsTool = true,
Path = "TestAssets/TestPackages/dotnet-hello/v2/dotnet-hello", Path = "TestAssets/TestPackages/dotnet-hello/v2/dotnet-hello",
IsApplicable = new Func<bool>(() => true), IsApplicable = true,
VersionSuffix = string.Empty, VersionSuffix = string.Empty,
Clean = true Clean = true,
Frameworks = new [] { "netcoreapp1.0" }
}, },
new new TestPackageProject()
{ {
Name = "dotnet-portable", Name = "dotnet-portable",
IsTool = true, IsTool = true,
Path = "TestAssets/TestPackages/dotnet-portable", Path = "TestAssets/TestPackages/dotnet-portable",
IsApplicable = new Func<bool>(() => true), IsApplicable = true,
VersionSuffix = string.Empty, VersionSuffix = string.Empty,
Clean = true Clean = true,
Frameworks = new [] { "netcoreapp1.0" }
}, },
new new TestPackageProject()
{ {
Name = "Microsoft.DotNet.Cli.Utils", Name = "Microsoft.DotNet.Cli.Utils",
IsTool = true, IsTool = true,
Path = "src/Microsoft.DotNet.Cli.Utils", Path = "src/Microsoft.DotNet.Cli.Utils",
IsApplicable = new Func<bool>(() => true), IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix, VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false Clean = false,
Frameworks = new [] { "net451", "netstandard1.5" }
}, },
new new TestPackageProject()
{ {
Name = "Microsoft.DotNet.ProjectModel", Name = "Microsoft.DotNet.ProjectModel",
IsTool = true, IsTool = true,
Path = "src/Microsoft.DotNet.ProjectModel", Path = "src/Microsoft.DotNet.ProjectModel",
IsApplicable = new Func<bool>(() => true), IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix, VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false Clean = false,
Frameworks = new [] { "net451", "netstandard1.5" }
}, },
new new TestPackageProject()
{ {
Name = "Microsoft.DotNet.ProjectModel.Loader", Name = "Microsoft.DotNet.ProjectModel.Loader",
IsTool = true, IsTool = true,
Path = "src/Microsoft.DotNet.ProjectModel.Loader", Path = "src/Microsoft.DotNet.ProjectModel.Loader",
IsApplicable = new Func<bool>(() => true), IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix, VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false Clean = false,
Frameworks = new [] { "netstandard1.5" }
}, },
new new TestPackageProject()
{ {
Name = "Microsoft.DotNet.ProjectModel.Workspaces", Name = "Microsoft.DotNet.ProjectModel.Workspaces",
IsTool = true, IsTool = true,
Path = "src/Microsoft.DotNet.ProjectModel.Workspaces", Path = "src/Microsoft.DotNet.ProjectModel.Workspaces",
IsApplicable = new Func<bool>(() => true), IsApplicable =true,
VersionSuffix = s_testPackageBuildVersionSuffix, VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false Clean = false,
Frameworks = new [] { "netstandard1.5" }
}, },
new new TestPackageProject()
{ {
Name = "Microsoft.DotNet.InternalAbstractions", Name = "Microsoft.DotNet.InternalAbstractions",
IsTool = true, IsTool = true,
Path = "src/Microsoft.DotNet.InternalAbstractions", Path = "src/Microsoft.DotNet.InternalAbstractions",
IsApplicable = new Func<bool>(() => true), IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix, VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false Clean = false,
Frameworks = new [] { "net451", "netstandard1.3" }
}, },
new new TestPackageProject()
{ {
Name = "Microsoft.Extensions.DependencyModel", Name = "Microsoft.Extensions.DependencyModel",
IsTool = true, IsTool = true,
Path = "src/Microsoft.Extensions.DependencyModel", Path = "src/Microsoft.Extensions.DependencyModel",
IsApplicable = new Func<bool>(() => true), IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix, VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false Clean = false,
Frameworks = new [] { "net451", "netstandard1.5" }
}, },
new new TestPackageProject()
{ {
Name = "Microsoft.Extensions.Testing.Abstractions", Name = "Microsoft.Extensions.Testing.Abstractions",
IsTool = true, IsTool = true,
Path = "src/Microsoft.Extensions.Testing.Abstractions", Path = "src/Microsoft.Extensions.Testing.Abstractions",
IsApplicable = new Func<bool>(() => true), IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix, VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false Clean = false,
Frameworks = new [] { "net451", "netstandard1.5" }
}, },
new new TestPackageProject()
{ {
Name = "Microsoft.DotNet.Compiler.Common", Name = "Microsoft.DotNet.Compiler.Common",
IsTool = true, IsTool = true,
Path = "src/Microsoft.DotNet.Compiler.Common", Path = "src/Microsoft.DotNet.Compiler.Common",
IsApplicable = new Func<bool>(() => true), IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix, VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false Clean = false,
Frameworks = new [] { "netstandard1.5" }
}, },
new new TestPackageProject()
{ {
Name = "Microsoft.DotNet.Files", Name = "Microsoft.DotNet.Files",
IsTool = true, IsTool = true,
Path = "src/Microsoft.DotNet.Files", Path = "src/Microsoft.DotNet.Files",
IsApplicable = new Func<bool>(() => true), IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix, VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false Clean = false,
Frameworks = new [] { "netstandard1.5" }
}, },
new new TestPackageProject()
{ {
Name = "dotnet-compile-fsc", Name = "dotnet-compile-fsc",
IsTool = true, IsTool = true,
Path = "src/dotnet-compile-fsc", Path = "src/dotnet-compile-fsc",
IsApplicable = new Func<bool>(() => true), IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix, VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = true Clean = true,
Frameworks = new [] { "netcoreapp1.0" }
} }
}; };
} }

View file

@ -149,7 +149,7 @@ namespace Microsoft.DotNet.Cli.Build
Rmdir(Dirs.TestPackages); Rmdir(Dirs.TestPackages);
Mkdirp(Dirs.TestPackages); Mkdirp(Dirs.TestPackages);
foreach (var testPackageProject in TestPackageProjects.Projects.Where(p => p.IsApplicable())) foreach (var testPackageProject in TestPackageProjects.Projects.Where(p => p.IsApplicable))
{ {
var relativePath = testPackageProject.Path; var relativePath = testPackageProject.Path;
@ -162,17 +162,11 @@ namespace Microsoft.DotNet.Cli.Build
var fullPath = Path.Combine(c.BuildContext.BuildDirectory, relativePath.Replace('/', Path.DirectorySeparatorChar)); var fullPath = Path.Combine(c.BuildContext.BuildDirectory, relativePath.Replace('/', Path.DirectorySeparatorChar));
c.Info($"Packing: {fullPath}"); c.Info($"Packing: {fullPath}");
// build and ignore failure, so net451 fail on non-windows doesn't crash the build var packageBuildFrameworks = testPackageProject.Frameworks.ToList();
var packageBuildFrameworks = new List<string>()
{
"netstandard1.5",
"netstandard1.3",
"netcoreapp1.0"
};
if (CurrentPlatform.IsWindows) if (!CurrentPlatform.IsWindows)
{ {
packageBuildFrameworks.Add("net451"); packageBuildFrameworks.RemoveAll(f => f.StartsWith("net4"));
} }
foreach (var packageBuildFramework in packageBuildFrameworks) foreach (var packageBuildFramework in packageBuildFrameworks)
@ -185,8 +179,9 @@ namespace Microsoft.DotNet.Cli.Build
buildArgs.Add(fullPath); buildArgs.Add(fullPath);
Mkdirp(Dirs.TestPackagesBuild); Mkdirp(Dirs.TestPackagesBuild);
var packBuildResult = DotNetCli.Stage1.Build(buildArgs.ToArray()) dotnet.Build(buildArgs.ToArray())
.Execute(); .Execute()
.EnsureSuccessful();
} }
var projectJson = Path.Combine(fullPath, "project.json"); var projectJson = Path.Combine(fullPath, "project.json");
@ -225,7 +220,7 @@ namespace Microsoft.DotNet.Cli.Build
[Target] [Target]
public static BuildTargetResult CleanTestPackages(BuildTargetContext c) public static BuildTargetResult CleanTestPackages(BuildTargetContext c)
{ {
foreach (var packageProject in TestPackageProjects.Projects.Where(p => p.IsApplicable() && p.Clean)) foreach (var packageProject in TestPackageProjects.Projects.Where(p => p.IsApplicable && p.Clean))
{ {
Rmdir(Path.Combine(Dirs.NuGetPackages, packageProject.Name)); Rmdir(Path.Combine(Dirs.NuGetPackages, packageProject.Name));
if(packageProject.IsTool) if(packageProject.IsTool)