Skip to content

Commit

Permalink
Update build script to use tools path environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
SharpeRAD committed Jul 23, 2016
1 parent 18e5f3b commit b0cffbf
Show file tree
Hide file tree
Showing 8 changed files with 331 additions and 103 deletions.
16 changes: 12 additions & 4 deletions .gitignore
Expand Up @@ -11,8 +11,7 @@ build/
tools/
test/tools/

# mstest test results
src/TestResults


## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
Expand Down Expand Up @@ -62,9 +61,18 @@ _ReSharper*
.*crunch*.local.xml
_NCrunch_*



# Visual Studio Directory
src/.vs/

# NuGet Packages Directory
src/packages
src/packages/

# mstest test results
src/TestResults/



# Windows
Thumbs.db

13 changes: 2 additions & 11 deletions build.cake
@@ -1,11 +1,10 @@
#addin "Cake.Slack"
#tool "xunit.runner.console"

//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////

var tools = Argument("tools", "./tools");

var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");

Expand Down Expand Up @@ -59,13 +58,7 @@ Setup(() =>
{
//Executed BEFORE the first task.
Information("Building version {0} of {1}.", semVersion, appName);
Information("Tools dir: {0}.", tools);
NuGetInstall("xunit.runner.console", new NuGetInstallSettings
{
ExcludeVersion = true,
OutputDirectory = tools
});
Information("Tools dir: {0}.", EnvironmentVariable("CAKE_PATHS_TOOLS"));
});

Teardown(() =>
Expand Down Expand Up @@ -155,8 +148,6 @@ Task("Run-Unit-Tests")
{
XUnit2("./src/**/bin/" + configuration + "/*.Tests.dll", new XUnit2Settings
{
ToolPath = tools + "/xunit.runner.console/tools/xunit.console.exe",
OutputDirectory = testResultsDir,
XmlReportV1 = true
});
Expand Down
169 changes: 129 additions & 40 deletions build.ps1
Expand Up @@ -21,49 +21,99 @@ Param(



[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
function MD5HashFile([string] $filePath)
{
if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf))
{
return $null
}

[System.IO.Stream] $file = $null;
[System.Security.Cryptography.MD5] $md5 = $null;
try
{
$md5 = [System.Security.Cryptography.MD5]::Create()
$file = [System.IO.File]::OpenRead($filePath)
return [System.BitConverter]::ToString($md5.ComputeHash($file))
}
finally
{
if ($file -ne $null)
{
$file.Dispose()
}
}
}



Write-Host "Preparing to run build script..."



# Script Location
if(!$PSScriptRoot)
{
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
}



# Find tools
if(($Tools.IsPresent) -and (Test-Path $Tools))
if($Tools)
{
# Parameter
Write-Host "Using tools parameter"
$TOOLS_DIR = $Tools
Write-Verbose -Message "Using tools parameter"
$TOOLS_DIR = Join-Path $PSScriptRoot $Tools
}
elseif (Test-Path "C:/Tools/Cake/Cake.exe")
{
# Shared location
Write-Host "Using shared tools"
Write-Verbose -Message "Using shared tools"
$TOOLS_DIR = "C:/Tools"
}
else
{
# Local path
Write-Host "Using local tools"
$PSScriptRoot = split-path -parent $MyInvocation.MyCommand.Definition
$TOOLS_DIR = Join-Path $PSScriptRoot "/tools"
Write-Verbose -Message "Using local tools"
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
}

if (!(Test-Path $TOOLS_DIR))
{
Write-Host "Creating tools directory"
New-Item $TOOLS_DIR -itemtype directory
}
# Make sure tools folder exists
if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR))
{
Write-Verbose -Message "Creating tools directory..."
New-Item -Path $TOOLS_DIR -Type directory | out-null
}





# Define Paths
$ADDINS_DIR = Join-Path $TOOLS_DIR "/Addins"
$MODULES_DIR = Join-Path $TOOLS_DIR "/Modules"

Write-Verbose -Message $ADDINS_DIR

$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"

$NUGET_URL = "https://nuget.org/nuget.exe"
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"

$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum"



# Save paths to environment for use in child processes
$ENV:TOOLS_DIR = $TOOLS_DIR
$ENV:NUGET_EXE = $NUGET_EXE

$ENV:CAKE_PATHS_TOOLS = $TOOLS_DIR
$ENV:CAKE_PATHS_ADDINS = $ADDINS_DIR
$ENV:CAKE_PATHS_MODULES =$MODULES_DIR



# Increase the default buffer size
Expand All @@ -82,10 +132,21 @@ $PSWindow.windowsize = $WindowSize



# Should we use experimental build of Roslyn?


# Should we use mono?
$UseMono = "";
if($Mono.IsPresent)
{
Write-Verbose -Message "Using the Mono based scripting engine."
$UseMono = "-mono"
}

# Should we use the new Roslyn?
$UseExperimental = "";
if($Experimental.IsPresent)
if($Experimental.IsPresent -and !($Mono.IsPresent))
{
Write-Verbose -Message "Using experimental version of Roslyn."
$UseExperimental = "-experimental"
}

Expand All @@ -96,62 +157,90 @@ if($WhatIf.IsPresent)
$UseDryRun = "-dryrun"
}

# Should we use mono?
$UseMono = "";
if($Mono.IsPresent)
{
$UseMono = "-mono"
}


# Make sure that packages.config exist.
if (!(Test-Path $PACKAGES_CONFIG))
{
Write-Verbose -Message "Downloading packages.config..."
try
{
(New-Object System.Net.WebClient).DownloadFile("http://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG)
}
catch
{
Throw "Could not download packages.config."
}
}

# Try download NuGet.exe if it does not exist.
# Try find NuGet.exe in path if not exists
if (!(Test-Path $NUGET_EXE))
{
Write-Host "Downloading Nuget"
(New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE)
Write-Verbose -Message "Trying to find nuget.exe in PATH..."
$existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_) }
$NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName))
{
Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
$NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
}
}

# Make sure NuGet exists where we expect it.
# Try download NuGet.exe if not exists
if (!(Test-Path $NUGET_EXE))
{
Throw "Could not find NuGet.exe"
Write-Verbose -Message "Downloading NuGet.exe..."
try
{
(New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE)
}
catch
{
Throw "Could not download NuGet.exe."
}
}



# Restore tools from NuGet
if (-Not $SkipToolPackageRestore.IsPresent)


# Restore tools from NuGet?
if(-Not $SkipToolPackageRestore.IsPresent)
{
Push-Location
Set-Location $TOOLS_DIR

if (Test-Path $PACKAGES_CONFIG)
{
# Restore tools from config
Invoke-Expression "$NUGET_EXE install -ExcludeVersion"
}
else
# Check for changes in packages.config and remove installed tools if true.
[string] $md5Hash = MD5HashFile($PACKAGES_CONFIG)
if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 )))
{
# Install just Cake if missing config
Invoke-Expression "$NUGET_EXE install Cake -ExcludeVersion"
Write-Verbose -Message "Missing or changed package.config hash..."
Remove-Item * -Recurse -Exclude packages.config,nuget.exe
}

Pop-Location
Write-Verbose -Message "Restoring tools from NuGet..."
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""

if ($LASTEXITCODE -ne 0)
{
exit $LASTEXITCODE
Throw "An error occured while restoring NuGet tools."
}
else
{
$md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII"
}
Write-Verbose -Message ($NuGetOutput | Out-String)
Pop-Location
}

# Make sure that Cake has been installed.
if (!(Test-Path $CAKE_EXE))
{
Throw "Could not find Cake.exe"
Throw "Could not find Cake.exe at $CAKE_EXE"
}



# Start Cake
Invoke-Expression "$CAKE_EXE `"$Script`" -tools=`"$TOOLS_DIR`" -target=`"$Target`" -configuration=`"$Configuration`" -custom=`"$Custom`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental"
Invoke-Expression "$CAKE_EXE `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -custom=`"$Custom`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental"
exit $LASTEXITCODE
2 changes: 1 addition & 1 deletion src/IIS/Manager/Base/BaseSiteManager.cs
Expand Up @@ -369,7 +369,7 @@ public bool Stop(string name)
/// <summary>
/// Adds a binding to a IIS site
/// </summary>
/// <param name="settings">The settings of the binding/param>
/// <param name="settings">The settings of the binding</param>
/// <returns>If the binding was added.</returns>
public bool AddBinding(BindingSettings settings)
{
Expand Down
8 changes: 4 additions & 4 deletions src/SolutionInfo.cs
Expand Up @@ -6,8 +6,8 @@
using System.Reflection;

[assembly: AssemblyProduct("Cake.IIS")]
[assembly: AssemblyVersion("0.1.4")]
[assembly: AssemblyFileVersion("0.1.4")]
[assembly: AssemblyInformationalVersion("0.1.4")]
[assembly: AssemblyCopyright("Copyright (c) Sergio Silveira, Phillip Sharpe 2015")]
[assembly: AssemblyVersion("0.1.5")]
[assembly: AssemblyFileVersion("0.1.5")]
[assembly: AssemblyInformationalVersion("0.1.5")]
[assembly: AssemblyCopyright("Copyright (c) 2015 - 2016 Sergio Silveira, Phillip Sharpe")]

4 changes: 2 additions & 2 deletions test/build.bat
@@ -1,3 +1,3 @@
@ECHO OFF
powershell -NoProfile -ExecutionPolicy Bypass -Command "& '.\build.ps1'"
PAUSE
powershell -NoProfile -ExecutionPolicy Bypass -Command "& '.\build.ps1' -Tools 'tools' -Verbosity 'Diagnostic'"
PAUSE
16 changes: 15 additions & 1 deletion test/build.cake
Expand Up @@ -11,6 +11,20 @@ var configuration = Argument("configuration", "Release");



///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////

Setup(context =>
{
//Executed BEFORE the first task.
Information("Tools dir: {0}.", EnvironmentVariable("CAKE_PATHS_TOOLS"));
});





///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -59,4 +73,4 @@ Task("Default")
// EXECUTION
///////////////////////////////////////////////////////////////////////////////

RunTarget(target);
RunTarget(target);

0 comments on commit b0cffbf

Please sign in to comment.