diff --git a/build.ps1 b/build.ps1 index c56584b6..0b70945d 100644 --- a/build.ps1 +++ b/build.ps1 @@ -46,7 +46,7 @@ Param( [Alias("WhatIf", "Noop")] [switch]$DryRun, [switch]$SkipToolPackageRestore, - [Parameter(Position = 0, Mandatory = $false, ValueFromRemainingArguments = $true)] + [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] [string[]]$ScriptArgs ) @@ -63,32 +63,37 @@ try { if (-not $IsCoreCLR) { [System.Net.ServicePointManager]::SecurityProtocol = 3072 -bor 768 -bor 192 -bor 48 } -} -catch { + } catch { Write-Output 'Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to upgrade to .NET Framework 4.5+ and PowerShell v3' -} + } [Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null -function MD5HashFile([string] $filePath) { - if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf)) { +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 { + try + { $md5 = [System.Security.Cryptography.MD5]::Create() $file = [System.IO.File]::OpenRead($filePath) return [System.BitConverter]::ToString($md5.ComputeHash($file)) } - finally { - if ($null -ne $file) { + finally + { + if ($file -ne $null) + { $file.Dispose() } } } -function GetProxyEnabledWebClient { +function GetProxyEnabledWebClient +{ $wc = New-Object System.Net.WebClient $proxy = [System.Net.WebRequest]::GetSystemWebProxy() $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials @@ -98,7 +103,7 @@ function GetProxyEnabledWebClient { Write-Host "Preparing to run build script..." -if (!$PSScriptRoot) { +if(!$PSScriptRoot){ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent } @@ -125,8 +130,7 @@ if (!(Test-Path $PACKAGES_CONFIG)) { try { $wc = GetProxyEnabledWebClient $wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) - } - catch { + } catch { Throw "Could not download packages.config." } } @@ -135,8 +139,8 @@ if (!(Test-Path $PACKAGES_CONFIG)) { if (!(Test-Path $NUGET_EXE)) { Write-Verbose -Message "Trying to find nuget.exe in PATH..." $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) } - $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select-Object -First 1 - if ($null -ne $NUGET_EXE_IN_PATH -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { + $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 } @@ -148,8 +152,7 @@ if (!(Test-Path $NUGET_EXE)) { try { $wc = GetProxyEnabledWebClient $wc.DownloadFile($NUGET_URL, $NUGET_EXE) - } - catch { + } catch { Throw "Could not download NuGet.exe." } } @@ -158,33 +161,33 @@ if (!(Test-Path $NUGET_EXE)) { $env:NUGET_EXE = $NUGET_EXE $env:NUGET_EXE_INVOCATION = if ($IsLinux -or $IsMacOS) { "mono `"$NUGET_EXE`"" -} -else { +} else { "`"$NUGET_EXE`"" } # Restore tools from NuGet? -if (-Not $SkipToolPackageRestore.IsPresent) { +if(-Not $SkipToolPackageRestore.IsPresent) { Push-Location Set-Location $TOOLS_DIR # 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 ))) { + if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or + ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) { Write-Verbose -Message "Missing or changed package.config hash..." - Get-ChildItem -Exclude packages.config, nuget.exe, Cake.Bakery | + Get-ChildItem -Exclude packages.config,nuget.exe,Cake.Bakery | Remove-Item -Recurse } Write-Verbose -Message "Restoring tools from NuGet..." - + $NuGetOutput = Invoke-Expression "& $env:NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" if ($LASTEXITCODE -ne 0) { Throw "An error occurred while restoring NuGet tools." } - else { + else + { $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII" } Write-Verbose -Message ($NuGetOutput | Out-String) @@ -233,8 +236,7 @@ if (!(Test-Path $CAKE_EXE)) { $CAKE_EXE_INVOCATION = if ($IsLinux -or $IsMacOS) { "mono `"$CAKE_EXE`"" -} -else { +} else { "`"$CAKE_EXE`"" } diff --git a/build.sh b/build.sh index 1f3df0d9..7fc4599a 100644 --- a/build.sh +++ b/build.sh @@ -7,7 +7,7 @@ ########################################################################## # Define directories. -SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) TOOLS_DIR=$SCRIPT_DIR/tools ADDINS_DIR=$TOOLS_DIR/Addins MODULES_DIR=$TOOLS_DIR/Modules @@ -33,23 +33,16 @@ CAKE_ARGUMENTS=() # Parse arguments. for i in "$@"; do case $1 in - -s | --script) - SCRIPT="$2" - shift - ;; - --) - shift - CAKE_ARGUMENTS+=("$@") - break - ;; - *) CAKE_ARGUMENTS+=("$1") ;; + -s|--script) SCRIPT="$2"; shift ;; + --) shift; CAKE_ARGUMENTS+=("$@"); break ;; + *) CAKE_ARGUMENTS+=("$1") ;; esac shift done # Make sure the tools folder exist. if [ ! -d "$TOOLS_DIR" ]; then - mkdir "$TOOLS_DIR" + mkdir "$TOOLS_DIR" fi # Make sure that packages.config exist. @@ -74,7 +67,7 @@ fi # Restore tools from NuGet. pushd "$TOOLS_DIR" >/dev/null -if [ ! -f "$PACKAGES_CONFIG_MD5" ] || [ "$(cat "$PACKAGES_CONFIG_MD5" | sed 's/\r$//')" != "$($MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }')" ]; then +if [ ! -f "$PACKAGES_CONFIG_MD5" ] || [ "$( cat "$PACKAGES_CONFIG_MD5" | sed 's/\r$//' )" != "$( $MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' )" ]; then find . -type d ! -name . ! -name 'Cake.Bakery' | xargs rm -rf fi @@ -84,7 +77,7 @@ if [ $? -ne 0 ]; then exit 1 fi -$MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' >|"$PACKAGES_CONFIG_MD5" +$MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' >| "$PACKAGES_CONFIG_MD5" popd >/dev/null