Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
Move build-compile and build-pack targets to the MSBuild lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate McMaster committed Feb 3, 2017
1 parent 0e30b52 commit 7228b4e
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 82 deletions.
4 changes: 4 additions & 0 deletions build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ignore packages that are installed into this folder when KoreBuild is symlinked
sake/
nugetpackageverifier/
netframeworkreferenceassemblies/
96 changes: 27 additions & 69 deletions build/shade/_k-standard-goals.shade
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ default SAMPLES_PROJECT_GLOB = "samples/*/*.csproj"
}
}

functions
@{
// convenince method as we incrementally move to MSBuild standard lifecycle
void MSBuild(string arguments)
{
Dotnet("msbuild /nologo"
+ " \"" + Path.Combine(Directory.GetCurrentDirectory(), ".build/targets/makefile.proj") + "\""
+ " \"/p:LifecycleType=Standard;Configuration=" + E("Configuration") + "\""
+ " " + arguments);
}
}

#--for-ci
@{
Configuration = "Release";
Expand Down Expand Up @@ -80,15 +92,10 @@ default SAMPLES_PROJECT_GLOB = "samples/*/*.csproj"
-// Target order is important because clean-npm-modules may (re)create bin folder.
#deep-clean .clean-npm-modules .clean-bin-folder description='Clean folders that may cause problems for `git clean`.'

#repo-initialize target='initialize'
#repo-initialize target='initialize' if='!NoRestore'
use-volatile-feed
-//dotnet-restore if='!NoRestore'
@{
// workaround https://github.com/Microsoft/msbuild/issues/1587
if (!NoRestore)
{
Dotnet("msbuild \"" + Path.Combine(BASE_DIR, ".build/restore.proj") + "\"");
}
MSBuild("/t:Restore");
}

#target-dir-clean target='clean'
Expand Down Expand Up @@ -121,83 +128,34 @@ default SAMPLES_PROJECT_GLOB = "samples/*/*.csproj"
var projectGlobs = new List<string>();
List<string> srcProjects = null;

if (Directory.Exists("src"))
// TODO add commit hash generation to internal.aspnetcore.sdk
if (Directory.Exists("src") && AddAssemblyInfo)
{
Directory.CreateDirectory(TARGET_DIR);

string commitHash = null;
if (AddAssemblyInfo)
{
var commitHashFile = Path.Combine(TARGET_DIR, "commit");
GitCommand("rev-parse HEAD >> " + commitHashFile);
commitHash = File.ReadAllLines(commitHashFile)[0];
}
var commitHashFile = Path.Combine(TARGET_DIR, "commit");
GitCommand("rev-parse HEAD >> " + commitHashFile);
var commitHash = File.ReadAllLines(commitHashFile)[0];

srcProjects = Files.Include(SRC_PROJECT_GLOB).ToList();
srcProjects.ForEach(projectFile =>
{
if (AddAssemblyInfo)
{
// var projectText = File.ReadAllText(projectFile);
// var project = (JsonObject)Json.Deserialize(projectText);
// var isSharedProject = project.Keys.Contains("shared");
var isSharedProject = false;
// We don't want to embed the commit hash in it because
// the consumers would get that file
if (!isSharedProject)
{
Console.WriteLine("Embedding commit hash in assembly");
var projectFolder = Path.GetDirectoryName(projectFile);
var commitHashAttribute = String.Format("[assembly: System.Reflection.AssemblyMetadata(\"CommitHash\", \"{0}\")]", commitHash);

var buildInfoFile = Path.Combine(projectFolder, "BuildInfo.generated.cs");
File.WriteAllText(buildInfoFile, commitHashAttribute);
}
}
});
Console.WriteLine("Embedding commit hash in assembly");
var projectFolder = Path.GetDirectoryName(projectFile);
var commitHashAttribute = String.Format("[assembly: System.Reflection.AssemblyMetadata(\"CommitHash\", \"{0}\")]", commitHash);

projectGlobs.AddRange(srcProjects);
}
if (!BuildSrcOnly && Directory.Exists("test"))
{
projectGlobs.AddRange(Files.Include(TEST_PROJECT_GLOB).ToList());
}
if (!BuildSrcOnly && Directory.Exists("samples") && Directory.EnumerateFiles("samples", "*.csproj", SearchOption.AllDirectories).Any())
{
projectGlobs.AddRange(Files.Include(SAMPLES_PROJECT_GLOB).ToList());
var buildInfoFile = Path.Combine(projectFolder, "BuildInfo.generated.cs");
File.WriteAllText(buildInfoFile, commitHashAttribute);
});
}

if (projectGlobs.Any())
{
foreach (var project in projectGlobs)
{
DotnetBuild(project, Configuration, BuildFramework);
}
}
MSBuild("/t:Rebuild");
}

#run-api-check .build-compile target='compile' description='Checks the compiled assemblies against a baseline for potential breaking changes'
api-check

#build-pack .build-compile target='compile'
@{
if (Directory.Exists("src"))
{
Directory.CreateDirectory(BUILD_DIR);
var srcProjects = Files.Include(SRC_PROJECT_GLOB).ToList();
if (srcProjects != null && srcProjects.Count > 0)
{
srcProjects.ForEach(projectFile =>
{
DotnetPack(projectFile, BUILD_DIR, Configuration, E("KOREBUILD_DOTNET_PACK_OPTIONS") + " --no-build");
});

foreach (var nupkg in Files.Include(Path.Combine(BUILD_DIR, "*/" + Configuration + "/*.nupkg")))
{
File.Copy(nupkg, Path.Combine(BUILD_DIR, Path.GetFileName(nupkg)), true);
}
}
}
MSBuild("/t:Pack");
}

#native-compile target='compile' if='!IsLinux && Directory.Exists(Path.Combine(BASE_DIR, "src"))'
Expand Down
5 changes: 3 additions & 2 deletions build/targets/common.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<PropertyGroup>
<BuildDir>$(RepositoryRoot)\build</BuildDir>
<ArtifactsDir>$(BuildDir)\artifacts</ArtifactsDir>
<RepositoryRoot Condition="'$(RepositoryRoot)'==''">$(MSBuildThisFileDirectory)..\..\</RepositoryRoot>
<ArtifactsDir>$(RepositoryRoot)\artifacts</ArtifactsDir>
<BuildDir>$(ArtifactsDir)\build</BuildDir>
</PropertyGroup>
</Project>
6 changes: 5 additions & 1 deletion build/targets/legacy-lifecycle.targets
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,15 @@
<MakeFilePath>$(ShadeDirectory)makefile.shade</MakeFilePath>
<MakeFilePath Condition="!Exists('$(RepositoryRoot)makefile.shade')">$(RepositoryRoot)makefile.shade</MakeFilePath>

<!-- TODO test if 'file://' works on Windows -->
<MakeFilePath Condition="'$(OS)'=='Windows_NT'">$([MSBuild]::MakeRelative('$(RepositoryRoot)', '$(MakeFilePath)'))</MakeFilePath>
<MakeFilePath Condition="'$(OS)'!='Windows_NT'">$([MSBuild]::MakeRelative('file://$(RepositoryRoot)', 'file://$(MakeFilePath)'))</MakeFilePath>

<ShadeTarget Condition="'$(NoRestore)'=='true'">--no-restore $(ShadeTarget)</ShadeTarget>
<ShadeTarget Condition="'$(MakeQuiet)'=='true'">--quiet $(ShadeTarget)</ShadeTarget>
</PropertyGroup>

<Exec
<Exec
Command="$(SakeExecutable) -I $(KoreBuildDirectory)shade -f $(MakeFilePath) $(ShadeTarget)"
WorkingDirectory="$(RepositoryRoot)" />
</Target>
Expand Down
7 changes: 3 additions & 4 deletions build/targets/makefile.proj
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<Project DefaultTarget="Default">
<PropertyGroup>
<UseLegacyLifecycle Condition="'$(UseLegacyLifecycle)'==''">true</UseLegacyLifecycle>
<UseStandardLifecycle Condition="'$(UseLegacyLifecycle)'!='true' AND '$(UseStandardLifecycle)'==''">true</UseStandardLifecycle>
<LifecycleType Condition="'$(LifecycleType)'==''">Legacy</LifecycleType>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)\common.props" />
<Import Project="$(RepositoryRoot)build\repo.props" Condition="Exists('$(RepositoryRoot)build\repo.props')" />

<Import Project="$(MSBuildThisFileDirectory)\legacy-lifecycle.targets" Condition="'$(UseLegacyLifecycle)'=='true'" />
<Import Project="$(MSBuildThisFileDirectory)\standard-lifecycle.targets" Condition="'$(UseStandardLifecycle)'=='true'" />
<Import Project="$(MSBuildThisFileDirectory)\legacy-lifecycle.targets" Condition="'$(LifecycleType)'=='Legacy'" />
<Import Project="$(MSBuildThisFileDirectory)\standard-lifecycle.targets" Condition="'$(LifecycleType)'=='Standard'" />

<Import Project="$(RepositoryRoot)build\repo.targets" Condition="Exists('$(RepositoryRoot)build\repo.targets')" />
</Project>
48 changes: 42 additions & 6 deletions build/targets/standard-lifecycle.targets
Original file line number Diff line number Diff line change
@@ -1,17 +1,53 @@
<Project>
<Target Name="Default" DependsOnTargets="Build" />

<Target Name="Build" DependsOnTargets="Clean;Initialize;Compile;Test;Verify;Publish" />
<PropertyGroup>
<Configuration>Debug</Configuration>
</PropertyGroup>

<Target Name="Clean" />
<ItemGroup>
<SolutionsToBuild Include="$(RepositoryRoot)\*.sln" />
<ProjectsToPack Include="$(RepositoryRoot)\src\*\*.*proj" />
</ItemGroup>

<Target Name="Initialize" />
<!-- default targets -->

<Target Name="Compile" />
<Target Name="Default" DependsOnTargets="Clean;Restore;Rebuild;Pack;Test;Verify;Publish" />

<Target Name="Test" />
<Target Name="Clean">
<RemoveDir Directories="$(ArtifactsDir)" />
</Target>

<Target Name="Restore">
<MSBuild Targets="Restore"
Projects="@(SolutionsToBuild)"
Properties="Configuration=$(Configuration)" />
</Target>

<Target Name="Rebuild">
<MSBuild Targets="Rebuild"
Projects="@(SolutionsToBuild)"
Properties="Configuration=$(Configuration)" />
</Target>

<Target Name="Pack">
<!-- TODO consider using GeneratePackageOnBuild. Requires setting IsPackable=false on test and samples -->
<MSBuild Targets="Pack"
Projects="@(ProjectsToPack)"
Properties="Configuration=$(Configuration);PackageOutputPath=$(BuildDir)" />
</Target>

<Target Name="Test" />
<Target Name="Verify" />

<Target Name="Publish" />

<!-- convenience targets -->

<!-- build without cleaning -->
<Target Name="Build">
<MSBuild Targets="Build"
Projects="@(SolutionsToBuild)"
Properties="Configuration=$(Configuration)" />
</Target>

</Project>

0 comments on commit 7228b4e

Please sign in to comment.