Skip to content

Commit

Permalink
Use Cake for build
Browse files Browse the repository at this point in the history
  • Loading branch information
dbent committed Mar 13, 2016
1 parent 282530e commit 72025bb
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 62 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.build/
tools/
Core/Meta.cs
build/
packages/
CKAN/*/bin
Expand All @@ -15,6 +18,7 @@ ks2ckan.exe
netkan.exe
*.exe.config
*.exe.mdb
*.pdb
.*.swp
.fatten.out
*.resources
Expand Down
70 changes: 70 additions & 0 deletions Core/Meta.cs.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System.Text.RegularExpressions;

namespace CKAN
{
public static class Meta
{
public readonly static string Development = "development";

// Do *not* change the following line, BUILD_VERSION is
// replaced by our build system with our actual version.

private readonly static string BUILD_VERSION = <%version%>;

/// <summary>
/// Returns the version of the CKAN.dll used, complete with git info
/// and other decorations as filled in by our build system.
/// Eg: v1.3.5-12-g055d7c3 (beta) or "development (unstable)"
/// </summary>
public static string Version()
{
string version = BuildVersion();

#if (STABLE)
version += " (stable)";
#else
version += " (beta)";
#endif

return version;
}

/// <summary>
/// Returns only the build info, with no decorations, or "development" if
/// unknown.
/// </summary>
public static string BuildVersion()
{
return BUILD_VERSION ?? Development;
}

/// <summary>
/// Returns just our release number (eg: 1.0.3), or null for a dev build.
/// </summary>
public static Version ReleaseNumber()
{
string build_version = BuildVersion();

if (build_version == Development)
{
return null;
}

string short_version = Regex.Match(build_version, @"^(.*)-\d+-.*$").Result("$1");

return new Version(short_version);
}

/// <summary>
/// Returns true if this is a 'stable' build, false otherwise.
/// </summary>
public static bool IsStable()
{
#if (STABLE)
return true;
#else
return false;
#endif
}
}
}
60 changes: 60 additions & 0 deletions build
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh
set -e

arg0=""
remainingArgs=""

if [ $# -gt 0 ]; then
arg0="$1"
fi

if [ $# -gt 1 ]; then
for i in $(seq 2 $#); do
remainingArgs+="${!i} "
done
fi

nugetVersion="3.3.0"
useExperimental=false
rootDir=$(dirname $0)
buildDir="$rootDir/.build"
toolsDir="$buildDir/tools"
packagesDir="$buildDir/lib/nuget"
nugetExe="$toolsDir/nuget/$nugetVersion/NuGet.exe"
packagesConfigFile="$rootDir/packages.config"
cakeVersion="$(sed -nE "s|\s*<package\s+id=\"Cake\"\s+version=\"(.+)\"\s*/>\s*|\1|p" $packagesConfigFile)"
cakeExe="$packagesDir/Cake.$cakeVersion/Cake.exe"

nugetDir="$(dirname $nugetExe)"
if [ ! -d "$nugetDir" ]; then
mkdir -p "$nugetDir"
fi

if [ ! -f "$nugetExe" ]; then
curl -L "https://dist.nuget.org/win-x86-commandline/v${nugetVersion}/nuget.exe" --output "$nugetExe"
fi

mono "$nugetExe" install "$packagesConfigFile" -OutputDirectory "$packagesDir"

cakeArgs=""

if [ -n "$arg0" ]; then
case $arg0 in
-*)
cakeArgs+="$arg0 "
;;
*)
cakeArgs+="--target=$arg0 "
;;
esac
fi

if $useExperimental; then
cakeArgs+="--experimental "
fi

echo "CAKE: mono $cakeExe $cakeArgs $remainingArgs"

mono "$cakeExe" $cakeArgs $remainingArgs
exit $?

104 changes: 104 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#tool nuget:?package=ILRepack&version=2.0.10

using System.Text.RegularExpressions;

var target = Argument<string>("target", "Build");
var configuration = Argument<string>("configuration", "Debug");
var solution = Argument<string>("solution", "CKAN.sln");

Task("BuildDotNet")
.Does(() =>
{
var version = GetGitVersion();
var metaFileContents = TransformTextFile("Core/Meta.cs.in")
.WithToken("version", version == null ? "null" : string.Format(@"""{0}""", version))
.ToString();
System.IO.File.WriteAllText("Core/Meta.cs", metaFileContents);
DotNetBuild(solution, settings =>
{
settings.Properties["win32icon"] = new List<string> { MakeAbsolute(File("GUI/assets/ckan.ico")).FullPath };
if (IsStable())
{
settings.Properties["DefineConstants"] = new List<string> { "STABLE" };
}
});
});

Task("BuildCkan")
.IsDependentOn("BuildDotNet")
.Does(() =>
{
var assemblyPaths = GetFiles(string.Format("Cmdline/bin/{0}/*.dll", configuration));
assemblyPaths.Add(string.Format("Cmdline/bin/{0}/CKAN-GUI.exe", configuration));
ILRepack("ckan.exe", string.Format("Cmdline/bin/{0}/CmdLine.exe", configuration), assemblyPaths,
new ILRepackSettings
{
Libs = new List<FilePath> { string.Format("Cmdline/bin/{0}", configuration) },
// TODO: Cannot use the "TargetPlaform"
// Must wait until https://github.com/cake-build/cake/pull/692 is released.
ArgumentCustomization = builder => {
builder.Append("/targetplatform:v4");
return builder;
}
}
);
});

Task("BuildNetkan")
.IsDependentOn("BuildDotNet")
.Does(() =>
{
ILRepack("netkan.exe", string.Format("Netkan/bin/{0}/NetKAN.exe", configuration), GetFiles(string.Format("Netkan/bin/{0}/*.dll", configuration)),
new ILRepackSettings
{
Libs = new List<FilePath> { string.Format("Netkan/bin/{0}", configuration) }
}
);
});

Task("Build")
.IsDependentOn("BuildCkan")
.IsDependentOn("BuildNetkan")
.Does(() => {});

RunTarget(target);

private bool IsStable()
{
var processSettings = new ProcessSettings
{
Arguments = "rev-parse --abbrev-ref HEAD",
RedirectStandardOutput = true
};

IEnumerable<string> output;
if (StartProcess("git", processSettings, out output) == 0)
{
var branch = output.Single();
return Regex.IsMatch(branch, @"(\b|_)stable(\b|_)") || Regex.IsMatch(branch, @"v\d+\.\d*[02468]$");
}
else
{
return false;
}
}

private string GetGitVersion()
{
var processSettings = new ProcessSettings
{
Arguments = "describe --tags --long",
RedirectStandardOutput = true
};

IEnumerable<string> output;
if (StartProcess("git", processSettings, out output) == 0)
return output.Single();
else
return null;
}
51 changes: 51 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Param (
[Parameter(Position = 0)]
[string]$Arg0,

[Parameter(ValueFromRemainingArguments = $true)]
[Object[]]$RemainingArgs
)

# Globals
$NugetVersion = "3.3.0"
$UseExperimental = $false
$RootDir = "${PSScriptRoot}"
$BuildDir = "${RootDir}/.build"
$ToolsDir = "${BuildDir}/tools"
$PackagesDir = "${BuildDir}/lib/nuget"
$NugetExe = "${ToolsDir}/nuget/${NugetVersion}/NuGet.exe"
$PackagesConfigFile = "${RootDir}/packages.config"
$CakeVersion = (Select-Xml -Xml ([xml](Get-Content $PackagesConfigFile)) -XPath "//package[@id='Cake'][1]/@version").Node.Value
$CakeExe = "${PackagesDir}/Cake.${CakeVersion}/Cake.exe"

# Download NuGet
$nugetDir = Split-Path $NugetExe -Parent
if (!(Test-Path $nugetDir)) {
mkdir $nugetDir > $null
}

if (!(Test-Path $NugetExe)) {
(New-Object System.Net.WebClient).DownloadFile("https://dist.nuget.org/win-x86-commandline/v${NugetVersion}/nuget.exe", $NugetExe)
}

# Install build packages
iex "${NugetExe} install `"${PackagesConfigFile}`" -OutputDirectory `"${PackagesDir}`""

# Build args
$cakeArgs = @()

if ($Arg0) {
if ($Arg0[0] -eq "-") {
$cakeArgs += "${Arg0}"
} else {
$cakeArgs += "--target=${Arg0}"
}
}

if ($UseExperimental) {
$cakeArgs += "--experimental"
}

# Run Cake
iex "${CakeExe} ${cakeArgs} ${RemainingArgs}"
exit $LASTEXITCODE
62 changes: 0 additions & 62 deletions build.sh

This file was deleted.

4 changes: 4 additions & 0 deletions 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.9.0" />
</packages>

0 comments on commit 72025bb

Please sign in to comment.