From 72025bb43080dbafe4e4f7ac9652db6355dc0f96 Mon Sep 17 00:00:00 2001 From: Dwayne Bent Date: Mon, 15 Feb 2016 16:06:47 -0500 Subject: [PATCH] Use Cake for build --- .gitignore | 4 ++ Core/Meta.cs.in | 70 ++++++++++++++++++++++++++++++++ build | 60 ++++++++++++++++++++++++++++ build.cake | 104 ++++++++++++++++++++++++++++++++++++++++++++++++ build.ps1 | 51 ++++++++++++++++++++++++ build.sh | 62 ----------------------------- packages.config | 4 ++ 7 files changed, 293 insertions(+), 62 deletions(-) create mode 100644 Core/Meta.cs.in create mode 100755 build create mode 100644 build.cake create mode 100644 build.ps1 delete mode 100755 build.sh create mode 100644 packages.config diff --git a/.gitignore b/.gitignore index 3840cfad32..5ed7946d0a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +.build/ +tools/ +Core/Meta.cs build/ packages/ CKAN/*/bin @@ -15,6 +18,7 @@ ks2ckan.exe netkan.exe *.exe.config *.exe.mdb +*.pdb .*.swp .fatten.out *.resources diff --git a/Core/Meta.cs.in b/Core/Meta.cs.in new file mode 100644 index 0000000000..26a4da002a --- /dev/null +++ b/Core/Meta.cs.in @@ -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%>; + + /// + /// 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)" + /// + public static string Version() + { + string version = BuildVersion(); + + #if (STABLE) + version += " (stable)"; + #else + version += " (beta)"; + #endif + + return version; + } + + /// + /// Returns only the build info, with no decorations, or "development" if + /// unknown. + /// + public static string BuildVersion() + { + return BUILD_VERSION ?? Development; + } + + /// + /// Returns just our release number (eg: 1.0.3), or null for a dev build. + /// + 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); + } + + /// + /// Returns true if this is a 'stable' build, false otherwise. + /// + public static bool IsStable() + { + #if (STABLE) + return true; + #else + return false; + #endif + } + } +} diff --git a/build b/build new file mode 100755 index 0000000000..2eb7ab8b12 --- /dev/null +++ b/build @@ -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*\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 $? + diff --git a/build.cake b/build.cake new file mode 100644 index 0000000000..30e1347841 --- /dev/null +++ b/build.cake @@ -0,0 +1,104 @@ +#tool nuget:?package=ILRepack&version=2.0.10 + +using System.Text.RegularExpressions; + +var target = Argument("target", "Build"); +var configuration = Argument("configuration", "Debug"); +var solution = Argument("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 { MakeAbsolute(File("GUI/assets/ckan.ico")).FullPath }; + + if (IsStable()) + { + settings.Properties["DefineConstants"] = new List { "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 { 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 { 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 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 output; + if (StartProcess("git", processSettings, out output) == 0) + return output.Single(); + else + return null; +} diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000000..818a391300 --- /dev/null +++ b/build.ps1 @@ -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 diff --git a/build.sh b/build.sh deleted file mode 100755 index 25ee22788d..0000000000 --- a/build.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash - -xbuild /verbosity:minimal CKAN.sln - -#prove -NUNIT_BINARY="" - -check_nunit () { - # Extract the CLR version of nunit-console. - NUNIT_TEXT=$($1 -help) - NUNIT_VERSION=$(echo "$NUNIT_TEXT" | awk '$1 ~ /CLR/ {print substr($3,1,1)}') - - if [ $NUNIT_VERSION -eq 4 ] - then - NUNIT_BINARY=$1 - fi - - echo "Found $1 with CLR version $NUNIT_VERSION." -} - - -# Find a suitable version of nunit. -echo "Checking if nunit-console is available..." -command -v "nunit-console" >/dev/null 2>&1 && check_nunit "nunit-console" - -echo "Checking if nunit-console4 is available..." -command -v "nunit-console4" >/dev/null 2>&1 && check_nunit "nunit-console4" - -# If we found a suitable nunit binary, continue with the testing. -if [ "$NUNIT_BINARY" != "" ] -then - command $NUNIT_BINARY --exclude=FlakyNetwork Tests/bin/Debug/CKAN.Tests.dll -else - echo "Could not find a suitable version of nunit-console to run the tests. Skipping test execution." -fi - -mono Core/packages/ILRepack.1.25.0/tools/ILRepack.exe \ - /target:exe \ - /out:ckan.exe \ - Cmdline/bin/Debug/CmdLine.exe \ - Cmdline/bin/Debug/CKAN-GUI.exe \ - Cmdline/bin/Debug/ChinhDo.Transactions.dll \ - Cmdline/bin/Debug/CKAN.dll \ - Cmdline/bin/Debug/CommandLine.dll \ - Cmdline/bin/Debug/ICSharpCode.SharpZipLib.dll \ - Cmdline/bin/Debug/log4net.dll \ - Cmdline/bin/Debug/Newtonsoft.Json.dll \ - Cmdline/bin/Debug/INIFileParser.dll \ - Cmdline/bin/Debug/CurlSharp.dll - -mono Core/packages/ILRepack.1.25.0/tools/ILRepack.exe \ - /target:exe \ - /out:netkan.exe \ - Netkan/bin/Debug/NetKAN.exe \ - Cmdline/bin/Debug/ChinhDo.Transactions.dll \ - Cmdline/bin/Debug/CKAN.dll \ - Cmdline/bin/Debug/CommandLine.dll \ - Cmdline/bin/Debug/ICSharpCode.SharpZipLib.dll \ - Cmdline/bin/Debug/log4net.dll \ - Cmdline/bin/Debug/Newtonsoft.Json.dll \ - Cmdline/bin/Debug/INIFileParser.dll \ - Cmdline/bin/Debug/CurlSharp.dll diff --git a/packages.config b/packages.config new file mode 100644 index 0000000000..defb8b4f6a --- /dev/null +++ b/packages.config @@ -0,0 +1,4 @@ + + + +