Skip to content

Commit de0f4f9

Browse files
committed
build finally working....MAGIC
1 parent 94ce022 commit de0f4f9

File tree

4 files changed

+375
-7
lines changed

4 files changed

+375
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
NAME ?= ocelot
22

33
build:
4-
dotnet tool restore --tool-manifest ./.config/dotnet-tools.json && dotnet cake --verbosity=diagnostic
4+
./build.sh
55

66
build_and_run_tests:
77
./build.sh --target=RunTests

build.cake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#tool "nuget:?package=GitVersion.CommandLine&version=5.5.1"
1+
#tool "nuget:?package=GitVersion.CommandLine&version=5.0.1"
22
#addin nuget:?package=Cake.Json
33
#addin nuget:?package=Newtonsoft.Json
44
#addin nuget:?package=System.Net.Http&version=4.3.4

build.ps1

Lines changed: 256 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,256 @@
1-
dotnet tool restore
2-
dotnet cake
1+
##########################################################################
2+
# This is the Cake bootstrapper script for PowerShell.
3+
# This file was downloaded from https://github.com/cake-build/resources
4+
# Feel free to change this file to fit your needs.
5+
##########################################################################
6+
7+
<#
8+
9+
.SYNOPSIS
10+
This is a Powershell script to bootstrap a Cake build.
11+
12+
.DESCRIPTION
13+
This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
14+
and execute your Cake build script with the parameters you provide.
15+
16+
.PARAMETER Script
17+
The build script to execute.
18+
.PARAMETER Target
19+
The build script target to run.
20+
.PARAMETER Configuration
21+
The build configuration to use.
22+
.PARAMETER Verbosity
23+
Specifies the amount of information to be displayed.
24+
.PARAMETER ShowDescription
25+
Shows description about tasks.
26+
.PARAMETER DryRun
27+
Performs a dry run.
28+
.PARAMETER SkipToolPackageRestore
29+
Skips restoring of packages.
30+
.PARAMETER ScriptArgs
31+
Remaining arguments are added here.
32+
33+
.LINK
34+
https://cakebuild.net
35+
36+
#>
37+
38+
[CmdletBinding()]
39+
Param(
40+
[string]$Script = "build.cake",
41+
[string]$Target,
42+
[string]$Configuration,
43+
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
44+
[string]$Verbosity,
45+
[switch]$ShowDescription,
46+
[Alias("WhatIf", "Noop")]
47+
[switch]$DryRun,
48+
[switch]$SkipToolPackageRestore,
49+
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
50+
[string[]]$ScriptArgs
51+
)
52+
53+
# Attempt to set highest encryption available for SecurityProtocol.
54+
# PowerShell will not set this by default (until maybe .NET 4.6.x). This
55+
# will typically produce a message for PowerShell v2 (just an info
56+
# message though)
57+
try {
58+
# Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192), finally SSL 3.0 (48)
59+
# Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won't
60+
# exist in .NET 4.0, even though they are addressable if .NET 4.5+ is
61+
# installed (.NET 4.5 is an in-place upgrade).
62+
# PowerShell Core already has support for TLS 1.2 so we can skip this if running in that.
63+
if (-not $IsCoreCLR) {
64+
[System.Net.ServicePointManager]::SecurityProtocol = 3072 -bor 768 -bor 192 -bor 48
65+
}
66+
} catch {
67+
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'
68+
}
69+
70+
[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
71+
function MD5HashFile([string] $filePath)
72+
{
73+
if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf))
74+
{
75+
return $null
76+
}
77+
78+
[System.IO.Stream] $file = $null;
79+
[System.Security.Cryptography.MD5] $md5 = $null;
80+
try
81+
{
82+
$md5 = [System.Security.Cryptography.MD5]::Create()
83+
$file = [System.IO.File]::OpenRead($filePath)
84+
return [System.BitConverter]::ToString($md5.ComputeHash($file))
85+
}
86+
finally
87+
{
88+
if ($file -ne $null)
89+
{
90+
$file.Dispose()
91+
}
92+
}
93+
}
94+
95+
function GetProxyEnabledWebClient
96+
{
97+
$wc = New-Object System.Net.WebClient
98+
$proxy = [System.Net.WebRequest]::GetSystemWebProxy()
99+
$proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
100+
$wc.Proxy = $proxy
101+
return $wc
102+
}
103+
104+
Write-Host "Preparing to run build script..."
105+
106+
if(!$PSScriptRoot){
107+
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
108+
}
109+
110+
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
111+
$ADDINS_DIR = Join-Path $TOOLS_DIR "Addins"
112+
$MODULES_DIR = Join-Path $TOOLS_DIR "Modules"
113+
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
114+
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
115+
$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
116+
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
117+
$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum"
118+
$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config"
119+
$MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config"
120+
121+
# Make sure tools folder exists
122+
if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
123+
Write-Verbose -Message "Creating tools directory..."
124+
New-Item -Path $TOOLS_DIR -Type Directory | Out-Null
125+
}
126+
127+
# Make sure that packages.config exist.
128+
if (!(Test-Path $PACKAGES_CONFIG)) {
129+
Write-Verbose -Message "Downloading packages.config..."
130+
try {
131+
$wc = GetProxyEnabledWebClient
132+
$wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG)
133+
} catch {
134+
Throw "Could not download packages.config."
135+
}
136+
}
137+
138+
# Try find NuGet.exe in path if not exists
139+
if (!(Test-Path $NUGET_EXE)) {
140+
Write-Verbose -Message "Trying to find nuget.exe in PATH..."
141+
$existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) }
142+
$NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1
143+
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) {
144+
Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
145+
$NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
146+
}
147+
}
148+
149+
# Try download NuGet.exe if not exists
150+
if (!(Test-Path $NUGET_EXE)) {
151+
Write-Verbose -Message "Downloading NuGet.exe..."
152+
try {
153+
$wc = GetProxyEnabledWebClient
154+
$wc.DownloadFile($NUGET_URL, $NUGET_EXE)
155+
} catch {
156+
Throw "Could not download NuGet.exe."
157+
}
158+
}
159+
160+
# Save nuget.exe path to environment to be available to child processed
161+
$env:NUGET_EXE = $NUGET_EXE
162+
$env:NUGET_EXE_INVOCATION = if ($IsLinux -or $IsMacOS) {
163+
"mono `"$NUGET_EXE`""
164+
} else {
165+
"`"$NUGET_EXE`""
166+
}
167+
168+
# Restore tools from NuGet?
169+
if(-Not $SkipToolPackageRestore.IsPresent) {
170+
Push-Location
171+
Set-Location $TOOLS_DIR
172+
173+
# Check for changes in packages.config and remove installed tools if true.
174+
[string] $md5Hash = MD5HashFile $PACKAGES_CONFIG
175+
if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or
176+
($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
177+
Write-Verbose -Message "Missing or changed package.config hash..."
178+
Get-ChildItem -Exclude packages.config,nuget.exe,Cake.Bakery |
179+
Remove-Item -Recurse -Force
180+
}
181+
182+
Write-Verbose -Message "Restoring tools from NuGet..."
183+
184+
$NuGetOutput = Invoke-Expression "& $env:NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""
185+
186+
if ($LASTEXITCODE -ne 0) {
187+
Throw "An error occurred while restoring NuGet tools."
188+
}
189+
else
190+
{
191+
$md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII"
192+
}
193+
Write-Verbose -Message ($NuGetOutput | Out-String)
194+
195+
Pop-Location
196+
}
197+
198+
# Restore addins from NuGet
199+
if (Test-Path $ADDINS_PACKAGES_CONFIG) {
200+
Push-Location
201+
Set-Location $ADDINS_DIR
202+
203+
Write-Verbose -Message "Restoring addins from NuGet..."
204+
$NuGetOutput = Invoke-Expression "& $env:NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`""
205+
206+
if ($LASTEXITCODE -ne 0) {
207+
Throw "An error occurred while restoring NuGet addins."
208+
}
209+
210+
Write-Verbose -Message ($NuGetOutput | Out-String)
211+
212+
Pop-Location
213+
}
214+
215+
# Restore modules from NuGet
216+
if (Test-Path $MODULES_PACKAGES_CONFIG) {
217+
Push-Location
218+
Set-Location $MODULES_DIR
219+
220+
Write-Verbose -Message "Restoring modules from NuGet..."
221+
$NuGetOutput = Invoke-Expression "& $env:NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`""
222+
223+
if ($LASTEXITCODE -ne 0) {
224+
Throw "An error occurred while restoring NuGet modules."
225+
}
226+
227+
Write-Verbose -Message ($NuGetOutput | Out-String)
228+
229+
Pop-Location
230+
}
231+
232+
# Make sure that Cake has been installed.
233+
if (!(Test-Path $CAKE_EXE)) {
234+
Throw "Could not find Cake.exe at $CAKE_EXE"
235+
}
236+
237+
$CAKE_EXE_INVOCATION = if ($IsLinux -or $IsMacOS) {
238+
"mono `"$CAKE_EXE`""
239+
} else {
240+
"`"$CAKE_EXE`""
241+
}
242+
243+
# Build an array (not a string) of Cake arguments to be joined later
244+
$cakeArguments = @()
245+
if ($Script) { $cakeArguments += "`"$Script`"" }
246+
if ($Target) { $cakeArguments += "-target=`"$Target`"" }
247+
if ($Configuration) { $cakeArguments += "-configuration=$Configuration" }
248+
if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" }
249+
if ($ShowDescription) { $cakeArguments += "-showdescription" }
250+
if ($DryRun) { $cakeArguments += "-dryrun" }
251+
$cakeArguments += $ScriptArgs
252+
253+
# Start Cake
254+
Write-Host "Running build script..."
255+
Invoke-Expression "& $CAKE_EXE_INVOCATION $($cakeArguments -join " ")"
256+
exit $LASTEXITCODE

build.sh

Lines changed: 117 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,117 @@
1-
# dotnet tool restore --tool-manifest ./.config/dotnet-tools.json
2-
# echo "tool installed?"
3-
# dotnet cake
1+
#!/usr/bin/env bash
2+
3+
##########################################################################
4+
# This is the Cake bootstrapper script for Linux and OS X.
5+
# This file was downloaded from https://github.com/cake-build/resources
6+
# Feel free to change this file to fit your needs.
7+
##########################################################################
8+
9+
# Define directories.
10+
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
11+
TOOLS_DIR=$SCRIPT_DIR/tools
12+
ADDINS_DIR=$TOOLS_DIR/Addins
13+
MODULES_DIR=$TOOLS_DIR/Modules
14+
NUGET_EXE=$TOOLS_DIR/nuget.exe
15+
CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe
16+
PACKAGES_CONFIG=$TOOLS_DIR/packages.config
17+
PACKAGES_CONFIG_MD5=$TOOLS_DIR/packages.config.md5sum
18+
ADDINS_PACKAGES_CONFIG=$ADDINS_DIR/packages.config
19+
MODULES_PACKAGES_CONFIG=$MODULES_DIR/packages.config
20+
21+
# Define md5sum or md5 depending on Linux/OSX
22+
MD5_EXE=
23+
if [[ "$(uname -s)" == "Darwin" ]]; then
24+
MD5_EXE="md5 -r"
25+
else
26+
MD5_EXE="md5sum"
27+
fi
28+
29+
# Define default arguments.
30+
SCRIPT="build.cake"
31+
CAKE_ARGUMENTS=()
32+
33+
# Parse arguments.
34+
for i in "$@"; do
35+
case $1 in
36+
-s|--script) SCRIPT="$2"; shift ;;
37+
--) shift; CAKE_ARGUMENTS+=("$@"); break ;;
38+
*) CAKE_ARGUMENTS+=("$1") ;;
39+
esac
40+
shift
41+
done
42+
43+
# Make sure the tools folder exist.
44+
if [ ! -d "$TOOLS_DIR" ]; then
45+
mkdir "$TOOLS_DIR"
46+
fi
47+
48+
# Make sure that packages.config exist.
49+
if [ ! -f "$TOOLS_DIR/packages.config" ]; then
50+
echo "Downloading packages.config..."
51+
curl -Lsfo "$TOOLS_DIR/packages.config" https://cakebuild.net/download/bootstrapper/packages
52+
if [ $? -ne 0 ]; then
53+
echo "An error occurred while downloading packages.config."
54+
exit 1
55+
fi
56+
fi
57+
58+
# Download NuGet if it does not exist.
59+
if [ ! -f "$NUGET_EXE" ]; then
60+
echo "Downloading NuGet..."
61+
curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
62+
if [ $? -ne 0 ]; then
63+
echo "An error occurred while downloading nuget.exe."
64+
exit 1
65+
fi
66+
fi
67+
68+
# Restore tools from NuGet.
69+
pushd "$TOOLS_DIR" >/dev/null
70+
if [ ! -f "$PACKAGES_CONFIG_MD5" ] || [ "$( cat "$PACKAGES_CONFIG_MD5" | sed 's/\r$//' )" != "$( $MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' )" ]; then
71+
find . -type d ! -name . ! -name 'Cake.Bakery' | xargs rm -rf
72+
fi
73+
74+
mono "$NUGET_EXE" install -ExcludeVersion
75+
if [ $? -ne 0 ]; then
76+
echo "Could not restore NuGet tools."
77+
exit 1
78+
fi
79+
80+
$MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' >| "$PACKAGES_CONFIG_MD5"
81+
82+
popd >/dev/null
83+
84+
# Restore addins from NuGet.
85+
if [ -f "$ADDINS_PACKAGES_CONFIG" ]; then
86+
pushd "$ADDINS_DIR" >/dev/null
87+
88+
mono "$NUGET_EXE" install -ExcludeVersion
89+
if [ $? -ne 0 ]; then
90+
echo "Could not restore NuGet addins."
91+
exit 1
92+
fi
93+
94+
popd >/dev/null
95+
fi
96+
97+
# Restore modules from NuGet.
98+
if [ -f "$MODULES_PACKAGES_CONFIG" ]; then
99+
pushd "$MODULES_DIR" >/dev/null
100+
101+
mono "$NUGET_EXE" install -ExcludeVersion
102+
if [ $? -ne 0 ]; then
103+
echo "Could not restore NuGet modules."
104+
exit 1
105+
fi
106+
107+
popd >/dev/null
108+
fi
109+
110+
# Make sure that Cake has been installed.
111+
if [ ! -f "$CAKE_EXE" ]; then
112+
echo "Could not find Cake.exe at '$CAKE_EXE'."
113+
exit 1
114+
fi
115+
116+
# Start Cake
117+
exec mono "$CAKE_EXE" $SCRIPT "${CAKE_ARGUMENTS[@]}"

0 commit comments

Comments
 (0)