Skip to content

Commit

Permalink
Initial Cake script
Browse files Browse the repository at this point in the history
  • Loading branch information
CharliePoole committed Dec 6, 2015
1 parent 130ceba commit 61fa1a3
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
213 changes: 213 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
@@ -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);
55 changes: 55 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -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
64 changes: 64 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions cake.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
tools\Cake\Cake.exe %*
2 changes: 2 additions & 0 deletions cakebuild.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
powershell ./build.ps1 %*
2 changes: 2 additions & 0 deletions nunit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tools/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cake" version="0.6.0" />
</packages>

0 comments on commit 61fa1a3

Please sign in to comment.