Merge pull request #437 from Microsoft/feature/new-cake

Feature/new cake
This commit is contained in:
Zander Chocron 2017-09-18 12:18:02 -07:00 коммит произвёл GitHub
Родитель b2b06f4732 1d947e6fba
Коммит cd78a87de8
10 изменённых файлов: 220 добавлений и 111 удалений

Просмотреть файл

@ -303,24 +303,24 @@ Task("Externals-Android")
Task("Externals-Ios")
.Does(() =>
{
CleanDirectory("./externals/ios");
CleanDirectory("./externals/ios");
// Download zip file containing MobileCenter frameworks
DownloadFile(IOS_URL, "./externals/ios/ios.zip");
Unzip("./externals/ios/ios.zip", "./externals/ios/");
// Download zip file containing MobileCenter frameworks
DownloadFile(IOS_URL, "./externals/ios/ios.zip");
Unzip("./externals/ios/ios.zip", "./externals/ios/");
// Copy the MobileCenter binaries directly from the frameworks and add the ".a" extension
var files = GetFiles("./externals/ios/*/iOS/*.framework/MobileCenter*");
foreach (var file in files)
{
MoveFile(file, "./externals/ios/" + file.GetFilename() + ".a");
}
// Copy the MobileCenter binaries directly from the frameworks and add the ".a" extension
var files = GetFiles("./externals/ios/*/iOS/*.framework/MobileCenter*");
foreach (var file in files)
{
MoveFile(file, "./externals/ios/" + file.GetFilename() + ".a");
}
// Copy Distribute resource bundle and copy it to the externals directory. There is no method in cake to get all subdirectories.
if(DirectoryExists("./externals/ios/MobileCenter-SDK-Apple/iOS/MobileCenterDistributeResources.bundle"))
{
MoveDirectory("./externals/ios/MobileCenter-SDK-Apple/iOS/MobileCenterDistributeResources.bundle", "./externals/ios/MobileCenterDistributeResources.bundle");
}
// Copy Distribute resource bundle and copy it to the externals directory. There is no method in cake to get all subdirectories.
if(DirectoryExists("./externals/ios/MobileCenter-SDK-Apple/iOS/MobileCenterDistributeResources.bundle"))
{
MoveDirectory("./externals/ios/MobileCenter-SDK-Apple/iOS/MobileCenterDistributeResources.bundle", "./externals/ios/MobileCenterDistributeResources.bundle");
}
}).OnError(HandleError);
// Create a common externals task depending on platform specific ones
@ -388,7 +388,6 @@ Task("PrepareNuspecsForVSTS").IsDependentOn("Version").Does(()=>
}
});
// Upload assemblies to Azure storage
Task("UploadAssemblies")
.IsDependentOn("PrepareAssemblies")
@ -536,7 +535,7 @@ Task("RemoveTemporaries").Does(()=>
var dirs = GetDirectories(TEMPORARY_PREFIX + "*");
foreach (var directory in dirs)
{
DeleteDirectory(directory, true);
DeleteDirectoryIfExists(directory.ToString());
}
DeleteFiles("./nuget/*.temp.nuspec");
});
@ -601,7 +600,7 @@ void DeleteDirectoryIfExists(string directoryName)
{
if (DirectoryExists(directoryName))
{
DeleteDirectory(directoryName, true);
DeleteDirectory(directoryName, new DeleteDirectorySettings { Force = true, Recursive = true });
}
}

160
build.ps1
Просмотреть файл

@ -4,17 +4,52 @@
# Feel free to change this file to fit your needs.
##########################################################################
<#
.SYNOPSIS
This is a Powershell script to bootstrap a Cake build.
.DESCRIPTION
This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
and execute your Cake build script with the parameters you provide.
.PARAMETER Script
The build script to execute.
.PARAMETER Target
The build script target to run.
.PARAMETER Configuration
The build configuration to use.
.PARAMETER Verbosity
Specifies the amount of information to be displayed.
.PARAMETER ShowDescription
Shows description about tasks.
.PARAMETER DryRun
Performs a dry run.
.PARAMETER Experimental
Uses the nightly builds of the Roslyn script engine.
.PARAMETER Mono
Uses the Mono Compiler rather than the Roslyn script engine.
.PARAMETER SkipToolPackageRestore
Skips restoring of packages.
.PARAMETER ScriptArgs
Remaining arguments are added here.
.LINK
https://cakebuild.net
#>
[CmdletBinding()]
Param(
[string]$Script = "build.cake",
[string]$Target = "Default",
[ValidateSet("Release", "Debug")]
[string]$Configuration = "Release",
[string]$Target,
[string]$Configuration,
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
[string]$Verbosity = "Diagnostic",
[string]$Verbosity,
[switch]$ShowDescription,
[Alias("WhatIf", "Noop")]
[switch]$DryRun,
[switch]$Experimental,
[Alias("DryRun","Noop")]
[switch]$WhatIf,
[switch]$Mono,
[switch]$SkipToolPackageRestore,
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
@ -46,6 +81,15 @@ function MD5HashFile([string] $filePath)
}
}
function GetProxyEnabledWebClient
{
$wc = New-Object System.Net.WebClient
$proxy = [System.Net.WebRequest]::GetSystemWebProxy()
$proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
$wc.Proxy = $proxy
return $wc
}
Write-Host "Preparing to run build script..."
if(!$PSScriptRoot){
@ -53,63 +97,49 @@ if(!$PSScriptRoot){
}
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
$ADDINS_DIR = Join-Path $TOOLS_DIR "Addins"
$MODULES_DIR = Join-Path $TOOLS_DIR "Modules"
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
#$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/v4.0.0/nuget.exe"
$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum"
# 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 -and !($Mono.IsPresent)) {
Write-Host -Message "Using experimental version of Roslyn."
$UseExperimental = "-experimental"
}
# Is this a dry run?
$UseDryRun = "";
if($WhatIf.IsPresent) {
$UseDryRun = "-dryrun"
}
$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config"
$MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config"
# Make sure tools folder exists
if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
Write-Host -Message "Creating tools directory..."
Write-Verbose -Message "Creating tools directory..."
New-Item -Path $TOOLS_DIR -Type directory | out-null
}
# Make sure that packages.config exist.
if (!(Test-Path $PACKAGES_CONFIG)) {
Write-Host -Message "Downloading packages.config..."
try { (New-Object System.Net.WebClient).DownloadFile("http://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch {
Write-Verbose -Message "Downloading packages.config..."
try {
$wc = GetProxyEnabledWebClient
$wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch {
Throw "Could not download packages.config."
}
}
# Try find NuGet.exe in path if not exists
if (!(Test-Path $NUGET_EXE)) {
Write-Host -Message "Trying to find nuget.exe in PATH..."
$existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_) }
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 -First 1
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) {
Write-Host -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
$NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
}
}
# Try download NuGet.exe if not exists
if (!(Test-Path $NUGET_EXE)) {
Write-Host -Message "Downloading NuGet.exe..."
Write-Verbose -Message "Downloading NuGet.exe..."
try {
(New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE)
$wc = GetProxyEnabledWebClient
$wc.DownloadFile($NUGET_URL, $NUGET_EXE)
} catch {
Throw "Could not download NuGet.exe."
}
@ -127,12 +157,12 @@ if(-Not $SkipToolPackageRestore.IsPresent) {
[string] $md5Hash = MD5HashFile($PACKAGES_CONFIG)
if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or
($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
Write-Host -Message "Missing or changed package.config hash..."
Write-Verbose -Message "Missing or changed package.config hash..."
Remove-Item * -Recurse -Exclude packages.config,nuget.exe
}
Write-Host -Message "Restoring tools from NuGet..."
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -source `"https://api.nuget.org/v3/index.json`" -OutputDirectory `"$TOOLS_DIR`""
Write-Verbose -Message "Restoring tools from NuGet..."
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""
if ($LASTEXITCODE -ne 0) {
Throw "An error occured while restoring NuGet tools."
@ -141,7 +171,42 @@ if(-Not $SkipToolPackageRestore.IsPresent) {
{
$md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII"
}
Write-Host -Message ($NuGetOutput | out-string)
Write-Verbose -Message ($NuGetOutput | out-string)
Pop-Location
}
# Restore addins from NuGet
if (Test-Path $ADDINS_PACKAGES_CONFIG) {
Push-Location
Set-Location $ADDINS_DIR
Write-Verbose -Message "Restoring addins from NuGet..."
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`""
if ($LASTEXITCODE -ne 0) {
Throw "An error occured while restoring NuGet addins."
}
Write-Verbose -Message ($NuGetOutput | out-string)
Pop-Location
}
# Restore modules from NuGet
if (Test-Path $MODULES_PACKAGES_CONFIG) {
Push-Location
Set-Location $MODULES_DIR
Write-Verbose -Message "Restoring modules from NuGet..."
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`""
if ($LASTEXITCODE -ne 0) {
Throw "An error occured while restoring NuGet modules."
}
Write-Verbose -Message ($NuGetOutput | out-string)
Pop-Location
}
@ -150,7 +215,20 @@ if (!(Test-Path $CAKE_EXE)) {
Throw "Could not find Cake.exe at $CAKE_EXE"
}
# Build Cake arguments
$cakeArguments = @("$Script");
if ($Target) { $cakeArguments += "-target=$Target" }
if ($Configuration) { $cakeArguments += "-configuration=$Configuration" }
if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" }
if ($ShowDescription) { $cakeArguments += "-showdescription" }
if ($DryRun) { $cakeArguments += "-dryrun" }
if ($Experimental) { $cakeArguments += "-experimental" }
if ($Mono) { $cakeArguments += "-mono" }
$cakeArguments += $ScriptArgs
# Start Cake
Write-Host "Running build script..."
Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs"
&$CAKE_EXE $cakeArguments --settings_skipverification=true
exit $LASTEXITCODE

107
build.sh
Просмотреть файл

@ -1,48 +1,54 @@
#!/bin/bash
###############################################################
# This is the Cake bootstrapper script that is responsible for
# downloading Cake and all specified tools from NuGet.
###############################################################
PATH=$PATH:/Library/Frameworks/Mono.framework/Versions/Current/Commands
#!/usr/bin/env bash
##########################################################################
# This is the Cake bootstrapper script for Linux and OS X.
# This file was downloaded from https://github.com/cake-build/resources
# Feel free to change this file to fit your needs.
##########################################################################
# Define directories.
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
TOOLS_DIR=$SCRIPT_DIR/tools
ADDINS_DIR=$TOOLS_DIR/Addins
MODULES_DIR=$TOOLS_DIR/Modules
NUGET_EXE=$TOOLS_DIR/nuget.exe
#XC_EXE=$TOOLS_DIR/xamarin-component.exe
CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe
PACKAGES_CONFIG=$TOOLS_DIR/packages.config
PACKAGES_CONFIG_MD5=$TOOLS_DIR/packages.config.md5sum
ADDINS_PACKAGES_CONFIG=$ADDINS_DIR/packages.config
MODULES_PACKAGES_CONFIG=$MODULES_DIR/packages.config
# Define md5sum or md5 depending on Linux/OSX
MD5_EXE=
if [[ "$(uname -s)" == "Darwin" ]]; then
MD5_EXE="md5 -r"
else
MD5_EXE="md5sum"
fi
# Define default arguments.
SCRIPT="build.cake"
TARGET="Default"
CONFIGURATION="Release"
VERBOSITY="diagnostic"
DRYRUN=false
SHOW_VERSION=false
EXTRA_ARGS=""
CAKE_ARGUMENTS=()
# Parse arguments.
for i in "$@"; do
case $1 in
-s|--script) SCRIPT="$2"; shift ;;
-t|--target) TARGET="$2"; shift ;;
-c|--configuration) CONFIGURATION="$2"; shift ;;
-v|--verbosity) VERBOSITY="$2"; shift ;;
-d|--dryrun) DRYRUN=true ;;
--version) SHOW_VERSION=true ;;
*) if [[ "$1" && "$2" ]];then EXTRA_ARGS+="$1=$2 "; fi; 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
if [ ! -d "$TOOLS_DIR" ]; then
mkdir "$TOOLS_DIR"
fi
# Make sure that packages.config exist.
if [ ! -f $TOOLS_DIR/packages.config ]; then
if [ ! -f "$TOOLS_DIR/packages.config" ]; then
echo "Downloading packages.config..."
curl -Lsfo $TOOLS_DIR/packages.config http://cakebuild.net/download/bootstrapper/packages
curl -Lsfo "$TOOLS_DIR/packages.config" https://cakebuild.net/download/bootstrapper/packages
if [ $? -ne 0 ]; then
echo "An error occured while downloading packages.config."
exit 1
@ -50,9 +56,9 @@ if [ ! -f $TOOLS_DIR/packages.config ]; then
fi
# Download NuGet if it does not exist.
if [ ! -f $NUGET_EXE ]; then
if [ ! -f "$NUGET_EXE" ]; then
echo "Downloading NuGet..."
curl -Lsfo $NUGET_EXE https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
if [ $? -ne 0 ]; then
echo "An error occured while downloading nuget.exe."
exit 1
@ -60,27 +66,52 @@ if [ ! -f $NUGET_EXE ]; then
fi
# Restore tools from NuGet.
pushd $TOOLS_DIR >/dev/null
mono $NUGET_EXE install -ExcludeVersion
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
find . -type d ! -name . | xargs rm -rf
fi
mono "$NUGET_EXE" install -ExcludeVersion
if [ $? -ne 0 ]; then
echo "Could not restore NuGet packages."
echo "Could not restore NuGet tools."
exit 1
fi
$MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' >| "$PACKAGES_CONFIG_MD5"
popd >/dev/null
# Restore addins from NuGet.
if [ -f "$ADDINS_PACKAGES_CONFIG" ]; then
pushd "$ADDINS_DIR" >/dev/null
mono "$NUGET_EXE" install -ExcludeVersion
if [ $? -ne 0 ]; then
echo "Could not restore NuGet addins."
exit 1
fi
popd >/dev/null
fi
# Restore modules from NuGet.
if [ -f "$MODULES_PACKAGES_CONFIG" ]; then
pushd "$MODULES_DIR" >/dev/null
mono "$NUGET_EXE" install -ExcludeVersion
if [ $? -ne 0 ]; then
echo "Could not restore NuGet modules."
exit 1
fi
popd >/dev/null
fi
# Make sure that Cake has been installed.
if [ ! -f $CAKE_EXE ]; then
if [ ! -f "$CAKE_EXE" ]; then
echo "Could not find Cake.exe at '$CAKE_EXE'."
exit 1
fi
# Start Cake
if $SHOW_VERSION; then
mono $CAKE_EXE -version
elif $DRYRUN; then
mono $CAKE_EXE $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET -dryrun $EXTRA_ARGS
else
mono $CAKE_EXE $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET $EXTRA_ARGS
fi
exit $?
exec mono "$CAKE_EXE" $SCRIPT "${CAKE_ARGUMENTS[@]}" --settings_skipverification=true

2
cake.config Normal file
Просмотреть файл

@ -0,0 +1,2 @@
[NuGet]
Source=https://api.nuget.org/v3/index.json

Просмотреть файл

@ -7,13 +7,13 @@ PLATFORM=""
# NOTE: For "--group", use '_' instead of spaces.
for i in "$@"; do
case $1 in
-m|--mandatory) MANDATORY="-Mandatory true" ;;
-e|--environment) ENVIRONMENT="-Environment $2"; shift ;;
-p|--platform) PLATFORM="-Platform $2"; shift ;;
-g|--group) GROUP="-Group $2"; shift ;;
-m|--mandatory) MANDATORY="-Mandatory=true" ;;
-e|--environment) ENVIRONMENT="-Environment=$2"; shift ;;
-p|--platform) PLATFORM="-Platform=$2"; shift ;;
-g|--group) GROUP="-Group=$2"; shift ;;
*) shift ;;
esac
shift
done
./build.sh -s test-tools.cake -t "ReleaseApplication" $GROUP $MANDATORY $PLATFORM $ENVIRONMENT
./build.sh -s test-tools.cake -t="ReleaseApplication" $GROUP $MANDATORY $PLATFORM $ENVIRONMENT

Просмотреть файл

@ -1,5 +1,5 @@
#!/bin/bash
# Note: Run this from within the root directory
./build.sh -t "MergeAssemblies" -StorageId $1
./build.sh -t="MergeAssemblies" -StorageId=$1

Просмотреть файл

@ -2,14 +2,13 @@
ENVIRONMENT=""
PLATFORM=""
# NOTE: For "--group", use '_' instead of spaces.
for i in "$@"; do
case $1 in
-e|--environment) ENVIRONMENT="-Environment $2"; shift ;;
-p|--platform) PLATFORM="-Platform $2"; shift ;;
-e|--environment) ENVIRONMENT="-Environment=$2"; shift ;;
-p|--platform) PLATFORM="-Platform=$2"; shift ;;
*) shift ;;
esac
shift
done
./build.sh -s test-tools.cake -t "SendPushNotification" $PLATFORM $ENVIRONMENT
./build.sh -s test-tools.cake -t="SendPushNotification" $PLATFORM $ENVIRONMENT

Просмотреть файл

@ -3,4 +3,4 @@
version=$1
./build.sh -s "version.cake" -t "StartNewVersion" -NewVersion "$version"
./build.sh -s "version.cake" -t="StartNewVersion" -NewVersion="$version"

Просмотреть файл

@ -3,5 +3,5 @@
version=$1
./build.sh -s "version.cake" -t "UpdateDemoVersion" -DemoVersion "$version"
./build.sh -s "version.cake" -t="UpdateDemoVersion" -DemoVersion="$version"

Просмотреть файл

@ -1,5 +1,5 @@
#!/bin/bash
# Note: Run this from within the root directory
./build.sh -t "UploadAssemblies" -StorageId $1
./build.sh -t="UploadAssemblies" -StorageId=$1