Skip to content

Commit

Permalink
Merge pull request #71 from neutmute/build
Browse files Browse the repository at this point in the history
command line build scripts
  • Loading branch information
raspberry-sharp authored Oct 26, 2016
2 parents 58f84db + 68ae10c commit dc05b64
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
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"

0 comments on commit dc05b64

Please sign in to comment.