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

Build the sln file instead of individual project files #159

Merged
merged 2 commits into from
Feb 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 38 additions & 14 deletions build/KoreBuild.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#requires -version 4

param([parameter(ValueFromRemainingArguments=$true)][string[]] $allparams)

function exec($cmd) {
$cmdName = [IO.Path]::GetFileName($cmd)
Write-Host -ForegroundColor Cyan "> $cmdName $args"
& $cmd @args
$exitCode = $LASTEXITCODE
if($exitCode -ne 0) {
throw "'$cmdName $args' failed with exit code: $exitCode"
}
}

$repoFolder = $env:REPO_FOLDER
if (!$repoFolder) {
throw "REPO_FOLDER is not set"
Expand Down Expand Up @@ -83,21 +95,33 @@ if (!($env:Path.Split(';') -icontains $dotnetLocalInstallFolder))
$sharedPath = (Join-Path (Split-Path ((get-command dotnet.exe).Path) -Parent) "shared");
(Get-ChildItem $sharedPath -Recurse *dotnet.exe) | %{ $_.FullName } | Remove-Item;

if (!(Test-Path "$koreBuildFolder\Sake"))
{
$toolsProject = "$koreBuildFolder\tools.proj"
&dotnet restore "$toolsProject" --packages "$PSScriptRoot" -v Minimal
# We still nuget because dotnet doesn't have support for pushing packages
Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/v3.5.0-beta2/NuGet.exe" -OutFile "$koreBuildFolder/nuget.exe"
}
# We still nuget because dotnet doesn't have support for pushing packages
# TODO remove. dotnet nuget push now exists
Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/v4.0.0-rc4/NuGet.exe" -OutFile "$koreBuildFolder/nuget.exe"

$env:KOREBUILD_FOLDER=$koreBuildFolder
$makeFileProj = "$koreBuildFolder/makefile.proj"
exec dotnet restore "$makeFileProj"

$msbuildArtifactsDir = "$repoFolder/artifacts/msbuild"
$msbuildLogFilePath = "$msbuildArtifactsDir/msbuild.log"
$msBuildResponseFile = "$msbuildArtifactsDir/msbuild.rsp"

$msBuildArguments = @"
/nologo
/m
"$makeFileProj"
/p:RepositoryRoot="$repoFolder/"
/fl
/flp:LogFile="$msbuildLogFilePath";Verbosity=diagnostic;Encoding=UTF-8
/p:SakeTargets=$($allparams -replace ' ',':')
"@

$makeFilePath = "makefile.shade"
if (!(Test-Path $makeFilePath))

if (!(Test-Path $msbuildArtifactsDir))
{
$makeFilePath = "$koreBuildFolder\shade\makefile.shade"
mkdir $msbuildArtifactsDir | Out-Null
}
$msBuildArguments | Out-File -Encoding ASCII -FilePath $msBuildResponseFile

Write-Host "Using makefile: $makeFilePath"

$env:KOREBUILD_FOLDER=$koreBuildFolder
&"$koreBuildFolder\Sake\0.2.2\tools\Sake.exe" -I $koreBuildFolder\shade -f $makeFilePath @args
exec dotnet build `@"$msBuildResponseFile"
71 changes: 54 additions & 17 deletions build/KoreBuild.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
#!/usr/bin/env bash

# Colors
GREEN="\033[1;32m"
CYAN="\033[0;36m"
RESET="\033[0m"
RED="\033[0;31m"

# functions

__exec() {
local cmd=$1
shift

local cmdname=$(basename $cmd)
echo -e "${CYAN}> $cmdname $@${RESET}"
$cmd "$@"

local exitCode=$?
if [ $exitCode -ne 0 ]; then
echo -e "${RED}'$cmdname $@' failed with exit code $exitCode${RESET}" 1>&2
exit $exitCode
fi
}

targets=""
repoFolder=""
while [[ $# > 0 ]]; do
Expand All @@ -9,7 +32,11 @@ while [[ $# > 0 ]]; do
repoFolder=$1
;;
*)
targets+=" $1"
if [ -z "$targets" ]; then
targets="$1"
else
targets+=":$1"
fi
;;
esac
shift
Expand Down Expand Up @@ -92,28 +119,38 @@ if [ "$(uname)" == "Darwin" ]; then
fi

netfxversion='4.6.1'
netFrameworkFolder=$repoFolder/$koreBuildFolder/netframeworkreferenceassemblies
netFrameworkContentDir=$netFrameworkFolder/$netfxversion/content
sakeFolder=$koreBuildFolder/sake
if [ ! -d $sakeFolder ]; then
toolsProject="$koreBuildFolder/tools.proj"
dotnet restore "$toolsProject" --packages $scriptRoot -v Minimal "/p:NetFxVersion=$netfxversion"
# Rename the project after restore because we don't want it to be restore afterwards
mv "$toolsProject" "$toolsProject.norestore"
if [ "$NUGET_PACKAGES" == "" ]; then
NUGET_PACKAGES="$HOME/.nuget/packages"
fi

export ReferenceAssemblyRoot=$netFrameworkContentDir
export ReferenceAssemblyRoot=$NUGET_PACKAGES/netframeworkreferenceassemblies/$netfxversion/content

nugetPath="$koreBuildFolder/nuget.exe"
if [ ! -f $nugetPath ]; then
nugetUrl="https://dist.nuget.org/win-x86-commandline/v3.5.0-beta2/NuGet.exe"
nugetUrl="https://dist.nuget.org/win-x86-commandline/v4.0.0-rc4/NuGet.exe"
wget -O $nugetPath $nugetUrl 2>/dev/null || curl -o $nugetPath --location $nugetUrl 2>/dev/null
fi

makeFile="makefile.shade"
if [ ! -e $makeFile ]; then
makeFile="$koreBuildFolder/shade/makefile.shade"
export KOREBUILD_FOLDER="$koreBuildFolder"
makeFileProj="$koreBuildFolder/makefile.proj"

__exec dotnet restore "$makeFileProj" "/p:NetFxVersion=$netfxversion"

msbuildArtifactsDir="$repoFolder/artifacts/msbuild"
msbuildResponseFile="$msbuildArtifactsDir/msbuild.rsp"
msbuildLogFile="$msbuildArtifactsDir/msbuild.log"

if [ ! -f $msbuildArtifactsDir ]; then
mkdir -p $msbuildArtifactsDir
fi

export KOREBUILD_FOLDER="$koreBuildFolder"
mono $sakeFolder/0.2.2/tools/Sake.exe -I $koreBuildFolder/shade -f $makeFile $targets
cat > $msbuildResponseFile <<ENDMSBUILDARGS
/nologo
/m
"$makeFileProj"
/p:RepositoryRoot="$repoFolder/"
/fl
/flp:LogFile="$msbuildLogFile";Verbosity=diagnostic;Encoding=UTF-8
/p:SakeTargets=$targets
ENDMSBUILDARGS

__exec dotnet msbuild @"$msbuildResponseFile"
2 changes: 1 addition & 1 deletion build/cli.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0-rc4-004757
1.0.0-rc4-004771
4 changes: 0 additions & 4 deletions build/contentFiles/cs/any/AssemblyInfo.Serviceable.cs

This file was deleted.

37 changes: 37 additions & 0 deletions build/makefile.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project>
<PropertyGroup>
<Configuration Condition="'$(Configuration)'==''">Debug</Configuration>
<LifecycleType>Legacy</LifecycleType>
<!-- TFM used only for the purpose of restoring build tools. It does not affect the TFM of projects -->
<TargetFramework>netcoreapp1.0</TargetFramework>
<SakeVersion>0.2.2</SakeVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NETFrameworkReferenceAssemblies" Version="$(NetFxVersion)" Condition="'$(NetFxVersion)'!=''" />
<PackageReference Include="NuGetPackageVerifier" Version="1.0.2-*"/>
<PackageReference Include="Sake" Version="$(SakeVersion)" />
</ItemGroup>

<Import Project="$(MSBuildThisFileDirectory)\targets\common.props" />

<ItemGroup>
<Solutions Include="$(RepositoryRoot)\*.sln" />
</ItemGroup>

<!-- import Microsoft.Common targets which will import NuGet-->
<Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" />

<!-- undo some special Microsoft.Common properties since this isn't a normal project -->
<PropertyGroup>
<_InvalidConfigurationWarn>false</_InvalidConfigurationWarn>
<_InvalidConfigurationError>false</_InvalidConfigurationError>
</PropertyGroup>

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

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

<Import Project="$(RepositoryRoot)build\repo.targets" Condition="Exists('$(RepositoryRoot)build\repo.targets')" />
</Project>
10 changes: 0 additions & 10 deletions build/restore.proj

This file was deleted.

93 changes: 24 additions & 69 deletions build/shade/_k-standard-goals.shade
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ use-ci-loggers
default BASE_DIR='${Directory.GetCurrentDirectory()}'
default TARGET_DIR='${Path.Combine(BASE_DIR, "artifacts")}'
default BUILD_DIR='${Path.Combine(TARGET_DIR, "build")}'
default TEST_DIR='${Path.Combine(TARGET_DIR, "test")}'
default Configuration='${E("Configuration")}'
default PACKAGELIST_JSON_FILENAME = 'NuGetPackageVerifier.json'
default SRC_PROJECT_GLOB = "src/*/*.csproj"
default TEST_PROJECT_GLOB = "test/*/*.csproj"
default SAMPLES_PROJECT_GLOB = "samples/*/*.csproj"

@{
if (string.IsNullOrEmpty(E("BuildNumber")))
Expand All @@ -32,12 +28,22 @@ 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/makefile.proj") + "\""
+ " \"/p:LifecycleType=Standard;Configuration=" + E("Configuration") + "\""
+ " " + arguments);
}
}

#--for-ci
@{
Configuration = "Release";
E("Configuration", Configuration);

E("KOREBUILD_VERIFY_NUPKGS", "1");
}

#restore-npm-modules
Expand Down Expand Up @@ -76,15 +82,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 All @@ -94,12 +95,16 @@ default SAMPLES_PROJECT_GLOB = "samples/*/*.csproj"
var directory = new DirectoryInfo(TARGET_DIR);
directory.Attributes &= ~FileAttributes.ReadOnly;

foreach (var info in directory.GetFileSystemInfos("*", SearchOption.AllDirectories))
foreach (var subDirectory in directory.GetDirectories().Where(d => d.Name != "msbuild"))
{
info.Attributes &= ~FileAttributes.ReadOnly;
subDirectory.Attributes &= ~FileAttributes.ReadOnly;
subDirectory.Delete(true);
}

directory.Delete(true);
foreach (var file in directory.EnumerateFiles())
{
file.Delete();
}
}
}

Expand All @@ -110,57 +115,15 @@ default SAMPLES_PROJECT_GLOB = "samples/*/*.csproj"

#build-compile target='compile'
@{
var projectGlobs = new List<string>();
List<string> srcProjects = null;

if (Directory.Exists("src"))
{
Directory.CreateDirectory(TARGET_DIR);
srcProjects = Files.Include(SRC_PROJECT_GLOB).ToList();
projectGlobs.AddRange(srcProjects);
}

if (!BuildSrcOnly && Directory.Exists("test"))
{
projectGlobs.AddRange(Files.Include(TEST_PROJECT_GLOB).ToList());
}

if (!BuildSrcOnly && Directory.Exists("samples"))
{
projectGlobs.AddRange(Files.Include(SAMPLES_PROJECT_GLOB).ToList());
}

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

#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:Package");
}

#native-compile target='compile' if='!IsLinux && Directory.Exists(Path.Combine(BASE_DIR, "src"))'
Expand Down Expand Up @@ -206,15 +169,7 @@ default SAMPLES_PROJECT_GLOB = "samples/*/*.csproj"

#nuget-verify target='package' description='Verify if all the packages are generated properly'
@{
if (Directory.Exists("src") && File.Exists(PACKAGELIST_JSON_FILENAME))
{
var verifierDirectory = Directory.EnumerateDirectories(Path.Combine(KoreBuildFolderPath, "nugetpackageverifier")).First();
Dotnet(
string.Format("\"{0}\" \"{1}\" \"{2}\"",
Path.Combine(verifierDirectory, "NuGetPackageVerifier.dll"),
BUILD_DIR.TrimEnd(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }),
Path.Combine(BASE_DIR, PACKAGELIST_JSON_FILENAME)));
}
MSBuild("/t:VerifyPackages");
}

#nuget-install target='install' description='Install NuGet packages to local repo'
Expand Down
7 changes: 7 additions & 0 deletions build/targets/common.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<PropertyGroup>
<RepositoryRoot Condition="'$(RepositoryRoot)'==''">$(MSBuildThisFileDirectory)..\..\</RepositoryRoot>
<ArtifactsDir>$(RepositoryRoot)artifacts\</ArtifactsDir>
<BuildDir>$(ArtifactsDir)build\</BuildDir>
</PropertyGroup>
</Project>
Loading