From 61fa1a357c96f1ef7a3e6dea5b23cc92d9409b04 Mon Sep 17 00:00:00 2001 From: Charlie Poole Date: Sun, 22 Nov 2015 22:00:18 -0700 Subject: [PATCH] Initial Cake script --- .gitignore | 1 + build.cake | 213 ++++++++++++++++++++++++++++++++++++++++++ build.ps1 | 55 +++++++++++ build.sh | 64 +++++++++++++ cake.cmd | 2 + cakebuild.cmd | 2 + nunit.sln | 2 + tools/packages.config | 4 + 8 files changed, 343 insertions(+) create mode 100644 build.cake create mode 100644 build.ps1 create mode 100644 build.sh create mode 100644 cake.cmd create mode 100644 cakebuild.cmd create mode 100644 tools/packages.config diff --git a/.gitignore b/.gitignore index 964078fa7b..4d06b1503e 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ build/ [Bb]in/ [Oo]bj/ .vs/ +tools/Cake # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets !packages/*/build/ diff --git a/build.cake b/build.cake new file mode 100644 index 0000000000..e6f241c995 --- /dev/null +++ b/build.cake @@ -0,0 +1,213 @@ +////////////////////////////////////////////////////////////////////// +// ARGUMENTS +////////////////////////////////////////////////////////////////////// + +var target = Argument("target", "Default"); +var configuration = Argument("configuration", "Debug"); +var framework = Argument("framework", "net-4.5"); + +////////////////////////////////////////////////////////////////////// +// SUPPORTED FRAMEWORKS +////////////////////////////////////////////////////////////////////// + +string[] AllFrameworks = new string[] { + "net-4.5", "net-4.0", "net-2.0", "portable" }; + +////////////////////////////////////////////////////////////////////// +// PREPARATION +////////////////////////////////////////////////////////////////////// + +// Versioning +var packageVersion = "3.1.0"; + +// Directories +//var baseDir = Directory("."); +//var srcDir = Directory("./src"); +//var nugetDir = Directory("./nuget"); +//var toolsDir = Directory("./tools"); +//var libDir = Directory ("./lib"); +var binDir = Directory("./bin") + Directory(configuration); + +// Test Runners +var NUNIT3_CONSOLE = binDir + File("nunit3-console.exe"); +var PORTABLE_RUNNER = binDir + File("portable/nunit.portable.tests.exe"); + +// Test Assemblies +var FRAMEWORK_TESTS = "nunit.framework.tests.dll"; +var NUNITLITE_TESTS = "nunitlite.tests.exe"; +var ENGINE_TESTS = "nunit.engine.tests.dll"; +var ADDIN_TESTS = "addins/tests/addin-tests.dll"; +var V2_DRIVER_TESTS = "addins/v2-tests/nunit.v2.driver.tests.dll"; +var CONSOLE_TESTS = "nunit3-console.tests.dll"; + +/////////////////////////////////////////////////////////////////////////////// +// SETUP / TEARDOWN +/////////////////////////////////////////////////////////////////////////////// + +Setup(() => +{ + Information("Building version {0} of Nunit.", packageVersion); +}); + +////////////////////////////////////////////////////////////////////// +// TASKS +////////////////////////////////////////////////////////////////////// + +Task("Clean") + .Does(() => +{ + CleanDirectory(binDir); +}); + + +Task("Restore-NuGet-Packages") + .Does(() => +{ + NuGetRestore("./nunit.sln"); +}); + +Task("Build") + .IsDependentOn("Restore-NuGet-Packages") + .Does(() => +{ + if(IsRunningOnWindows()) + { + // Use MSBuild + MSBuild("./nunit.sln", new MSBuildSettings() + .SetConfiguration(configuration) + .SetPlatformTarget(PlatformTarget.MSIL) +// .WithProperty("TreatWarningsAsErrors", "true") + .SetVerbosity(Verbosity.Minimal) + .SetNodeReuse(false) + ); + } + else + { + // Use XBuild + XBuild("./nunit.sln", new XBuildSettings() + .SetConfiguration(configuration) + .WithTarget("AnyCPU") +// .WithProperty("TreatWarningsAsErrors", "true") + .SetVerbosity(Verbosity.Minimal) + ); + } +}); + +Task("TestAllFrameworks") + .IsDependentOn("Build") + .Does(() => + { + foreach(string runtime in AllFrameworks) + { + RunFrameworkTests(runtime); + RunNUnitLiteTests(runtime); + } + }); + +Task("TestFramework") + .IsDependentOn("Build") + .Does(() => + { + RunFrameworkTests(framework); + }); + +Task("TestNUnitLite") + .IsDependentOn("Build") + .Does(() => + { + RunNUnitLiteTests(framework); + }); + +Task("TestEngine") + .IsDependentOn("Build") + .Does(() => + { + RunTestWithConsoleRunner(ENGINE_TESTS); + }); + +Task("TestAddins") + .IsDependentOn("Build") + .Does(() => + { + RunTestWithConsoleRunner(ADDIN_TESTS); + }); + +Task("TestV2Driver") + .IsDependentOn("Build") + .Does(() => + { + RunTestWithConsoleRunner(V2_DRIVER_TESTS); + }); + +Task("TestConsole") + .IsDependentOn("Build") + .Does(() => + { + RunTestWithConsoleRunner(CONSOLE_TESTS); + }); + +////////////////////////////////////////////////////////////////////// +// HELPER METHODS +////////////////////////////////////////////////////////////////////// + +void RunExecutableTest(FilePath exePath) +{ + StartProcess(exePath, new ProcessSettings() + { + WorkingDirectory = binDir + }); +} + +void RunTestWithConsoleRunner(string testAssembly) +{ + StartProcess(NUNIT3_CONSOLE, new ProcessSettings() + { + Arguments = testAssembly, + WorkingDirectory = binDir + }); +} + +void RunNUnitLiteTests(string runtime) +{ + RunExecutableTest(binDir + File(runtime + "/" + NUNITLITE_TESTS)); +} + +void RunFrameworkTests(string runtime) +{ + if (runtime == "portable") + RunExecutableTest(PORTABLE_RUNNER); + else + RunTestWithConsoleRunner(runtime + "/" + FRAMEWORK_TESTS); +} + +////////////////////////////////////////////////////////////////////// +// TASK TARGETS +////////////////////////////////////////////////////////////////////// + +Task("Rebuild") + .IsDependentOn("Clean") + .IsDependentOn("Build"); + +Task("TestAll") + .IsDependentOn("TestAllFrameworks") + .IsDependentOn("TestEngine") + .IsDependentOn("TestAddins") + .IsDependentOn("TestV2Driver") + .IsDependentOn("TestConsole"); + +Task("Test") + .IsDependentOn("TestFramework") + .IsDependentOn("TestNUnitLite") + .IsDependentOn("TestEngine") + .IsDependentOn("TestAddins") + .IsDependentOn("TestV2Driver") + .IsDependentOn("TestConsole"); + +Task("Default") + .IsDependentOn("Build"); // Rebuild? + +////////////////////////////////////////////////////////////////////// +// EXECUTION +////////////////////////////////////////////////////////////////////// + +RunTarget(target); diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000000..519ad09eb9 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,55 @@ +Param( + [string]$Script = "build.cake", + [string]$Target = "Default", + [ValidateSet("Release", "Debug")] + [string]$Configuration = "Release", + [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] + [string]$Verbosity = "Verbose", + [switch]$Experimental, + [switch]$WhatIf +) + +$TOOLS_DIR = Join-Path $PSScriptRoot "tools" +$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" +$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" + +# Should we use experimental build of Roslyn? +$UseExperimental = ""; +if($Experimental.IsPresent) { + $UseExperimental = "-experimental" +} + +# Is this a dry run? +$UseDryRun = ""; +if($WhatIf.IsPresent) { + $UseDryRun = "-dryrun" +} + +# Try download NuGet.exe if do not exist. +if (!(Test-Path $NUGET_EXE)) { + Invoke-WebRequest -Uri http://nuget.org/nuget.exe -OutFile $NUGET_EXE +} + +# Make sure NuGet exists where we expect it. +if (!(Test-Path $NUGET_EXE)) { + Throw "Could not find NuGet.exe" +} + +# Restore tools from NuGet. +Push-Location +Set-Location $TOOLS_DIR +Invoke-Expression "$NUGET_EXE install -ExcludeVersion" +Pop-Location +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} + +# Make sure that Cake has been installed. +if (!(Test-Path $CAKE_EXE)) { + Throw "Could not find Cake.exe" +} + +# Start Cake +Invoke-Expression "$CAKE_EXE `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseDryRun $UseExperimental" +Write-Host +exit $LASTEXITCODE \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000000..e354c253dd --- /dev/null +++ b/build.sh @@ -0,0 +1,64 @@ +#!/bin/bash +############################################################### +# This is the Cake bootstrapper script that is responsible for +# downloading Cake and all specified tools from NuGet. +############################################################### + +# Define directories. +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +TOOLS_DIR=$SCRIPT_DIR/tools +NUGET_EXE=$TOOLS_DIR/nuget.exe +CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe + +# Define default arguments. +SCRIPT="build.cake" +TARGET="Default" +CONFIGURATION="Release" +VERBOSITY="verbose" +DRYRUN=false +SHOW_VERSION=false + +# Parse arguments. +for i in "$@"; do + case $1 in + -s|--script) SCRIPT="$2"; shift ;; + -t|--target) TARGET="$2"; shift ;; + -c|--configuration) CONFIGURATION="$2"; shift ;; + -v|--verbosity) VERBOSITY="$2"; shift ;; + -d|--dryrun) DRYRUN=true ;; + --version) SHOW_VERSION=true ;; + esac + shift +done + +# Download NuGet if it does not exist. +if [ ! -f $NUGET_EXE ]; then + echo "Downloading NuGet..." + curl -Lsfo $NUGET_EXE https://www.nuget.org/nuget.exe + if [ $? -ne 0 ]; then + echo "An error occured while downloading nuget.exe." + exit 1 + fi +fi + +# Restore tools from NuGet. +pushd $TOOLS_DIR >/dev/null +mono $NUGET_EXE install -ExcludeVersion +popd >/dev/null + +# Make sure that Cake has been installed. +if [ ! -f $CAKE_EXE ]; then + echo "Could not find Cake.exe." + exit 1 +fi + +# Start Cake +if $SHOW_VERSION; then + mono $CAKE_EXE -version +elif $DRYRUN; then + mono $CAKE_EXE $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET -dryrun + echo +else + mono $CAKE_EXE $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET + echo +fi diff --git a/cake.cmd b/cake.cmd new file mode 100644 index 0000000000..9ab12e33cd --- /dev/null +++ b/cake.cmd @@ -0,0 +1,2 @@ +@echo off +tools\Cake\Cake.exe %* diff --git a/cakebuild.cmd b/cakebuild.cmd new file mode 100644 index 0000000000..f58b06f2a4 --- /dev/null +++ b/cakebuild.cmd @@ -0,0 +1,2 @@ +@echo off +powershell ./build.ps1 %* diff --git a/nunit.sln b/nunit.sln index 6745e5ae59..235e1aa2d6 100644 --- a/nunit.sln +++ b/nunit.sln @@ -49,6 +49,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .travis.yml = .travis.yml appveyor.ps1 = appveyor.ps1 appveyor.yml = appveyor.yml + build.cake = build.cake BUILDING.txt = BUILDING.txt CHANGES.txt = CHANGES.txt CONTRIBUTING.md = CONTRIBUTING.md @@ -66,6 +67,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget", "nuget", "{A972031D nuget\install.ps1 = nuget\install.ps1 nuget\nunit.console.nuspec = nuget\nunit.console.nuspec nuget\nunit.nuspec = nuget\nunit.nuspec + nuget\nunit.runners.nuspec = nuget\nunit.runners.nuspec nuget\nunitlite.nuspec = nuget\nunitlite.nuspec nuget\nunitliteSL.nuspec = nuget\nunitliteSL.nuspec nuget\nunitSL.nuspec = nuget\nunitSL.nuspec diff --git a/tools/packages.config b/tools/packages.config new file mode 100644 index 0000000000..b8481a92ea --- /dev/null +++ b/tools/packages.config @@ -0,0 +1,4 @@ + + + +