Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command line build scripts #71

Merged
merged 1 commit into from
Oct 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
powershell -f build.ps1 -configuration release
powershell -f build.ps1 -configuration debug
90 changes: 90 additions & 0 deletions build.common.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
$Script:UseWriteHost = $true

if(!$Global:ColorScheme) {
$Global:ColorScheme = @{
"Banner"=[ConsoleColor]::Cyan
"RuntimeName"=[ConsoleColor]::Yellow
"Help_Header"=[ConsoleColor]::Yellow
"Help_Switch"=[ConsoleColor]::Green
"Help_Argument"=[ConsoleColor]::Cyan
"Help_Optional"=[ConsoleColor]::Gray
"Help_Command"=[ConsoleColor]::DarkYellow
"Help_Executable"=[ConsoleColor]::DarkYellow
"ParameterName"=[ConsoleColor]::Cyan
"Warning" = [ConsoleColor]::Yellow
}
}

function _WriteOut {
param(
[Parameter(Mandatory=$false, Position=0, ValueFromPipeline=$true)][string]$msg,
[Parameter(Mandatory=$false)][ConsoleColor]$ForegroundColor,
[Parameter(Mandatory=$false)][ConsoleColor]$BackgroundColor,
[Parameter(Mandatory=$false)][switch]$NoNewLine)

if($__TestWriteTo) {
$cur = Get-Variable -Name $__TestWriteTo -ValueOnly -Scope Global -ErrorAction SilentlyContinue
$val = $cur + "$msg"
if(!$NoNewLine) {
$val += [Environment]::NewLine
}
Set-Variable -Name $__TestWriteTo -Value $val -Scope Global -Force
return
}

if(!$Script:UseWriteHost) {
if(!$msg) {
$msg = ""
}
if($NoNewLine) {
[Console]::Write($msg)
} else {
[Console]::WriteLine($msg)
}
}
else {
try {
if(!$ForegroundColor) {
$ForegroundColor = $host.UI.RawUI.ForegroundColor
}
if(!$BackgroundColor) {
$BackgroundColor = $host.UI.RawUI.BackgroundColor
}

Write-Host $msg -ForegroundColor:$ForegroundColor -BackgroundColor:$BackgroundColor -NoNewLine:$NoNewLine
} catch {
$Script:UseWriteHost = $false
_WriteOut $msg
}
}
}

function _WriteConfig{
param(
[Parameter(Mandatory=$true,Position=0)]$name,
[Parameter(Mandatory=$true,Position=1)]$value)

_WriteOut -NoNewline -ForegroundColor $Global:ColorScheme.ParameterName "${name}: "
_WriteOut "$value"

}

function _DownloadNuget{
param(
[Parameter(Mandatory=$true,Position=0)]$rootPath)

$sourceNugetExe = "http://nuget.org/nuget.exe"
$targetNugetExe = "$rootPath\nuget.exe"


if(!(Test-Path $targetNugetExe )){
_WriteOut "Downloading nuget to $targetNugetExe"
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
}
else{
# _WriteOut "nuget.exe is already present"
}

Set-Alias nuget $targetNugetExe -Scope Global

}
43 changes: 43 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
param(
[string]$configuration = "Release"
)

. ".\build.common.ps1"

$solutionName = "RaspberrySharp.IO"

function init {
# Initialization
$global:rootFolder = Split-Path -parent $script:MyInvocation.MyCommand.Path
$global:rootFolder = Join-Path $rootFolder .
$global:packagesFolder = Join-Path $rootFolder packages
$global:outputFolder = Join-Path $rootFolder _artifacts
$global:msbuild = "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"

_WriteOut -ForegroundColor $ColorScheme.Banner "-= $solutionName Build =-"
_WriteConfig "rootFolder" $rootFolder
}

function restorePackages{
_WriteOut -ForegroundColor $ColorScheme.Banner "nuget restore"

New-Item -Force -ItemType directory -Path $packagesFolder
_DownloadNuget $packagesFolder
nuget restore
}

function buildSolution{

_WriteOut -ForegroundColor $ColorScheme.Banner "Build Solution"
& $msbuild "$rootFolder\$solutionName.sln" /p:Configuration=$configuration

}


init

restorePackages

buildSolution

Write-Host "Build $configuration complete"