Merge pull request #1408 from dotnet/davidfowl/build-cleanup

More build and project clean up
This commit is contained in:
David Fowler 2016-02-15 13:41:32 -08:00
commit c9cf2585a0
15 changed files with 160 additions and 173 deletions

View file

@ -33,6 +33,8 @@ namespace Microsoft.DotNet.Cli.Build.Framework
_maxTargetLen = targets.Values.Select(t => t.Name.Length).Max(); _maxTargetLen = targets.Values.Select(t => t.Name.Length).Max();
} }
public T Get<T>(string name) => (T)this[name];
public BuildTargetResult RunTarget(string name) => RunTarget(name, force: false); public BuildTargetResult RunTarget(string name) => RunTarget(name, force: false);
public BuildTargetResult RunTarget(string name, bool force) public BuildTargetResult RunTarget(string name, bool force)

View file

@ -1,9 +1,9 @@
using Microsoft.DotNet.Cli.Build.Framework; using System;
using Microsoft.Extensions.PlatformAbstractions;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.Extensions.PlatformAbstractions;
using static Microsoft.DotNet.Cli.Build.FS; using static Microsoft.DotNet.Cli.Build.FS;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
@ -63,7 +63,7 @@ namespace Microsoft.DotNet.Cli.Build
Rmdir(cmakeOut); Rmdir(cmakeOut);
Mkdirp(cmakeOut); Mkdirp(cmakeOut);
var configuration = (string)c.BuildContext["Configuration"]; var configuration = c.BuildContext.Get<string>("Configuration");
// Run the build // Run the build
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@ -120,13 +120,14 @@ namespace Microsoft.DotNet.Cli.Build
[Target] [Target]
public static BuildTargetResult CompileStage2(BuildTargetContext c) public static BuildTargetResult CompileStage2(BuildTargetContext c)
{ {
var configuration = (string)c.BuildContext["Configuration"]; var configuration = c.BuildContext.Get<string>("Configuration");
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "src")); CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "src"));
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "test")); CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "test"));
var result = CompileStage(c, var result = CompileStage(c,
dotnet: DotNetCli.Stage1, dotnet: DotNetCli.Stage1,
outputDir: Dirs.Stage2); outputDir: Dirs.Stage2);
if (!result.Success) if (!result.Success)
{ {
return result; return result;
@ -158,9 +159,7 @@ namespace Microsoft.DotNet.Cli.Build
{ {
Rmdir(outputDir); Rmdir(outputDir);
dotnet.SetDotNetHome(); var configuration = c.BuildContext.Get<string>("Configuration");
var configuration = (string)c.BuildContext["Configuration"];
var binDir = Path.Combine(outputDir, "bin"); var binDir = Path.Combine(outputDir, "bin");
var runtimeOutputDir = Path.Combine(outputDir, "runtime", "coreclr"); var runtimeOutputDir = Path.Combine(outputDir, "runtime", "coreclr");
@ -240,7 +239,7 @@ namespace Microsoft.DotNet.Cli.Build
} }
// Generate .version file // Generate .version file
var version = ((BuildVersion)c.BuildContext["BuildVersion"]).SimpleVersion; var version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
var content = $@"{c.BuildContext["CommitHash"]}{Environment.NewLine}{version}{Environment.NewLine}"; var content = $@"{c.BuildContext["CommitHash"]}{Environment.NewLine}{version}{Environment.NewLine}";
File.WriteAllText(Path.Combine(outputDir, ".version"), content); File.WriteAllText(Path.Combine(outputDir, ".version"), content);

View file

@ -29,6 +29,7 @@ namespace Microsoft.DotNet.Cli.Build
{ {
configEnv = "Debug"; configEnv = "Debug";
} }
c.BuildContext["Configuration"] = configEnv; c.BuildContext["Configuration"] = configEnv;
c.Info($"Building {c.BuildContext["Configuration"]} to: {Dirs.Output}"); c.Info($"Building {c.BuildContext["Configuration"]} to: {Dirs.Output}");

View file

@ -1,9 +1,9 @@
using Microsoft.DotNet.Cli.Build.Framework; using System;
using Microsoft.Extensions.PlatformAbstractions;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.Extensions.PlatformAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
@ -19,7 +19,7 @@ namespace Microsoft.DotNet.Cli.Build
// Set up the environment variables previously defined by common.sh/ps1 // Set up the environment variables previously defined by common.sh/ps1
// This is overkill, but I want to cover all the variables used in all OSes (including where some have the same names) // This is overkill, but I want to cover all the variables used in all OSes (including where some have the same names)
var buildVersion = (BuildVersion)c.BuildContext["BuildVersion"]; var buildVersion = c.BuildContext.Get<BuildVersion>("BuildVersion");
var env = new Dictionary<string, string>() var env = new Dictionary<string, string>()
{ {
{ "RID", PlatformServices.Default.Runtime.GetRuntimeIdentifier() }, { "RID", PlatformServices.Default.Runtime.GetRuntimeIdentifier() },

View file

@ -1,13 +1,13 @@
using Microsoft.DotNet.Cli.Build.Framework; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework;
using static Microsoft.DotNet.Cli.Build.FS; using static Microsoft.DotNet.Cli.Build.FS;
using static Microsoft.DotNet.Cli.Build.Utils;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
using static Microsoft.DotNet.Cli.Build.Utils;
namespace Microsoft.DotNet.Cli.Build namespace Microsoft.DotNet.Cli.Build
{ {
@ -65,7 +65,7 @@ namespace Microsoft.DotNet.Cli.Build
foreach (var relativePath in TestPackageProjects) foreach (var relativePath in TestPackageProjects)
{ {
var fullPath = Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestPackages", relativePath.Replace('/', Path.DirectorySeparatorChar)); var fullPath = Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestPackages", relativePath.Replace('/', Path.DirectorySeparatorChar));
c.Info("Packing: {fullPath}"); c.Info($"Packing: {fullPath}");
dotnet.Pack("--output", Dirs.TestPackages) dotnet.Pack("--output", Dirs.TestPackages)
.WorkingDirectory(fullPath) .WorkingDirectory(fullPath)
.Execute() .Execute()
@ -95,7 +95,7 @@ namespace Microsoft.DotNet.Cli.Build
var dotnet = DotNetCli.Stage2; var dotnet = DotNetCli.Stage2;
foreach (var testProject in TestProjects) foreach (var testProject in TestProjects)
{ {
c.Info("Building tests: {project}"); c.Info($"Building tests: {testProject}");
dotnet.Build() dotnet.Build()
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "test", testProject)) .WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "test", testProject))
.Execute() .Execute()
@ -180,7 +180,7 @@ namespace Microsoft.DotNet.Cli.Build
[Target] [Target]
public static BuildTargetResult ValidateDependencies(BuildTargetContext c) public static BuildTargetResult ValidateDependencies(BuildTargetContext c)
{ {
var configuration = (string)c.BuildContext["Configuration"]; var configuration = c.BuildContext.Get<string>("Configuration");
var dotnet = DotNetCli.Stage2; var dotnet = DotNetCli.Stage2;
c.Info("Publishing MultiProjectValidator"); c.Info("Publishing MultiProjectValidator");

View file

@ -20,11 +20,6 @@ namespace Microsoft.DotNet.Cli.Build
BinPath = binPath; BinPath = binPath;
} }
public void SetDotNetHome()
{
Environment.SetEnvironmentVariable("DOTNET_HOME", Path.GetDirectoryName(BinPath));
}
public Command Exec(string command, params string[] args) public Command Exec(string command, params string[] args)
{ {
return Command.Create(Path.Combine(BinPath, $"dotnet{Constants.ExeSuffix}"), Enumerable.Concat(new[] { command }, args)); return Command.Create(Path.Combine(BinPath, $"dotnet{Constants.ExeSuffix}"), Enumerable.Concat(new[] { command }, args));

View file

@ -9,13 +9,18 @@
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-16537" "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-16537"
}, },
"frameworks": { "frameworks": {
"net451": {}, "net451": {
"frameworkAssemblies": {
"System.Runtime": {
"type": "build"
}
}
},
"dnxcore50": { "dnxcore50": {
"imports": "portable-net45+win8", "imports": "portable-net45+win8",
"dependencies": { "dependencies": {
"NETStandard.Library": "1.0.0-rc2-23811" "NETStandard.Library": "1.0.0-rc2-23811"
} }
} }
}, }
"scripts": {}
} }

View file

@ -1,23 +1,20 @@
{ {
"version": "1.0.0-*", "version": "1.0.0-*",
"compilationOptions": { "compilationOptions": {
"keyFile": "../../tools/Key.snk" "keyFile": "../../tools/Key.snk"
}, },
"dependencies": { "dependencies": {
"NETStandard.Library": "1.0.0-rc2-23811", "NETStandard.Library": "1.0.0-rc2-23811",
"System.CommandLine": "0.1.0-e160119-1", "System.CommandLine": "0.1.0-e160119-1",
"Microsoft.CodeAnalysis.CSharp": "1.2.0-beta1-20160202-02", "Microsoft.CodeAnalysis.CSharp": "1.2.0-beta1-20160202-02",
"Microsoft.DotNet.ProjectModel": "1.0.0-*", "Microsoft.DotNet.ProjectModel": "1.0.0-*",
"Microsoft.DotNet.Cli.Utils": "1.0.0-*", "Microsoft.DotNet.Cli.Utils": "1.0.0-*",
"Microsoft.DotNet.Files": {"version": "1.0.0-*", "target": "project"} "Microsoft.DotNet.Files": "1.0.0-*"
}, },
"frameworks": { "frameworks": {
"dnxcore50": { "dnxcore50": {
"imports": "portable-net45+win8" "imports": "portable-net45+win8"
} }
}, },
"scripts": { "scripts": {}
}
} }

View file

@ -7,25 +7,14 @@
"dependencies": { "dependencies": {
"NETStandard.Library": "1.0.0-rc2-23811", "NETStandard.Library": "1.0.0-rc2-23811",
"System.Linq.Expressions": "4.0.11-rc2-23811", "System.Linq.Expressions": "4.0.11-rc2-23811",
"Microsoft.Extensions.FileSystemGlobbing": "1.0.0-rc2-15996", "Microsoft.Extensions.FileSystemGlobbing": "1.0.0-rc2-15996",
"Microsoft.DotNet.Cli.Utils": "1.0.0-*",
"Microsoft.DotNet.Cli.Utils": { "Microsoft.DotNet.ProjectModel": "1.0.0-*"
"type": "build",
"version": "1.0.0-*"
}, },
"Microsoft.DotNet.ProjectModel": {
"type": "build",
"version": "1.0.0-*"
}
},
"frameworks": { "frameworks": {
"dnxcore50": { "dnxcore50": {
"imports": "portable-net45+win8" "imports": "portable-net45+win8"
} }
}, },
"scripts": { "scripts": {}
}
} }

View file

@ -6,7 +6,6 @@
"description": "Types to model a .NET Project", "description": "Types to model a .NET Project",
"dependencies": { "dependencies": {
"System.Reflection.Metadata": "1.2.0-rc3-23811", "System.Reflection.Metadata": "1.2.0-rc3-23811",
"NuGet.Packaging": "3.4.0-beta-583", "NuGet.Packaging": "3.4.0-beta-583",
"Microsoft.Extensions.FileSystemGlobbing": "1.0.0-rc2-15996", "Microsoft.Extensions.FileSystemGlobbing": "1.0.0-rc2-15996",
"Microsoft.Extensions.JsonParser.Sources": { "Microsoft.Extensions.JsonParser.Sources": {
@ -17,15 +16,20 @@
"type": "build", "type": "build",
"version": "1.0.0-rc2-16054" "version": "1.0.0-rc2-16054"
}, },
"Microsoft.Extensions.DependencyModel": { "Microsoft.Extensions.DependencyModel": "1.0.0-*"
"type": "build",
"version": "1.0.0-*"
}
}, },
"frameworks": { "frameworks": {
"net451": { "net451": {
"frameworkAssemblies": { "frameworkAssemblies": {
"System.IO": "" "System.Runtime": {
"type": "build"
},
"System.Collections": {
"type": "build"
},
"System.IO": {
"type": "build"
}
} }
}, },
"dnxcore50": { "dnxcore50": {
@ -39,7 +43,5 @@
"System.Xml.XDocument": "4.0.11-rc2-23811" "System.Xml.XDocument": "4.0.11-rc2-23811"
} }
} }
},
"scripts": {
} }
} }

View file

@ -3,11 +3,9 @@
"compilationOptions": { "compilationOptions": {
"emitEntryPoint": true "emitEntryPoint": true
}, },
"dependencies": { "dependencies": {
"NETStandard.Library": "1.0.0-rc2-23811" "NETStandard.Library": "1.0.0-rc2-23811"
}, },
"frameworks": { "frameworks": {
"dnxcore50": { "dnxcore50": {
"imports": "portable-net45+win8" "imports": "portable-net45+win8"

View file

@ -37,6 +37,5 @@
} }
} }
}, },
"scripts": { "scripts": {}
}
} }