Skip to content

Commit

Permalink
Merge pull request #6 from codeConcussion/master
Browse files Browse the repository at this point in the history
Upgrade to psake 4.7.0
  • Loading branch information
qetza authored Dec 7, 2017
2 parents d9d2dd7 + d493c62 commit 343c4fe
Show file tree
Hide file tree
Showing 34 changed files with 1,960 additions and 797 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qetza.psake-vsts",
"version": "0.1.0",
"version": "0.2.0",
"description": "Build task for VS Team Services that can run psake build scripts.",
"author": "Guillaume Rouchon",
"license": "MIT",
Expand Down
9 changes: 9 additions & 0 deletions task/ps_modules/psake/private/CleanupEnvironment.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function CleanupEnvironment {
if ($psake.context.Count -gt 0) {
$currentContext = $psake.context.Peek()
$env:path = $currentContext.originalEnvPath
Set-Location $currentContext.originalDirectory
$global:ErrorActionPreference = $currentContext.originalErrorActionPreference
[void] $psake.context.Pop()
}
}
164 changes: 164 additions & 0 deletions task/ps_modules/psake/private/ConfigureBuildEnvironment.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@

function ConfigureBuildEnvironment {
if (!(Get-Variable -Name IsWindows -ErrorAction SilentlyContinue) -or $IsWindows) {
$framework = $psake.context.peek().config.framework
if ($framework -cmatch '^((?:\d+\.\d+)(?:\.\d+){0,1})(x86|x64){0,1}$') {
$versionPart = $matches[1]
$bitnessPart = $matches[2]
}
else {
throw ($msgs.error_invalid_framework -f $framework)
}
$versions = $null
$buildToolsVersions = $null
switch ($versionPart) {
'1.0' {
$versions = @('v1.0.3705')
}
'1.1' {
$versions = @('v1.1.4322')
}
'1.1.0' {
$versions = @()
}
'2.0' {
$versions = @('v2.0.50727')
}
'2.0.0' {
$versions = @()
}
'3.0' {
$versions = @('v2.0.50727')
}
'3.5' {
$versions = @('v3.5', 'v2.0.50727')
}
'4.0' {
$versions = @('v4.0.30319')
}
{($_ -eq '4.5') -or ($_ -eq '4.5.1') -or ($_ -eq '4.5.2')} {
$versions = @('v4.0.30319')
$buildToolsVersions = @('15.0', '14.0', '12.0')
}
{($_ -eq '4.6') -or ($_ -eq '4.6.1') -or ($_ -eq '4.6.2')} {
$versions = @('v4.0.30319')
$buildToolsVersions = @('15.0', '14.0')
}
{($_ -eq '4.7') -or ($_ -eq '4.7.1')} {
$versions = @('v4.0.30319')
$buildToolsVersions = @('15.0')
}

default {
throw ($msgs.error_unknown_framework -f $versionPart, $framework)
}
}

$bitness = 'Framework'
if ($versionPart -ne '1.0' -and $versionPart -ne '1.1') {
switch ($bitnessPart) {
'x86' {
$bitness = 'Framework'
$buildToolsKey = 'MSBuildToolsPath32'
}
'x64' {
$bitness = 'Framework64'
$buildToolsKey = 'MSBuildToolsPath'
}
{ [string]::IsNullOrEmpty($_) } {
$ptrSize = [System.IntPtr]::Size
switch ($ptrSize) {
4 {
$bitness = 'Framework'
$buildToolsKey = 'MSBuildToolsPath32'
}
8 {
$bitness = 'Framework64'
$buildToolsKey = 'MSBuildToolsPath'
}
default {
throw ($msgs.error_unknown_pointersize -f $ptrSize)
}
}
}
default {
throw ($msgs.error_unknown_bitnesspart -f $bitnessPart, $framework)
}
}
}

$frameworkDirs = @()
if ($buildToolsVersions -ne $null) {
foreach($ver in $buildToolsVersions) {
if ($ver -eq "15.0") {
if ((Get-Module -Name VSSetup -ListAvailable) -eq $null) {
WriteColoredOutput ($msgs.warning_missing_vsssetup_module -f $ver) -foregroundcolor Yellow
continue
}

Import-Module VSSetup

# borrowed from nightroman https://github.com/nightroman/Invoke-Build
if ($vsInstances = Get-VSSetupInstance) {
$vs = @($vsInstances | Select-VSSetupInstance -Version '[15.0,16.0)' -Require Microsoft.Component.MSBuild)
if ($vs) {
if ($buildToolsKey -eq 'MSBuildToolsPath32') {
$frameworkDirs += Join-Path ($vs[0].InstallationPath) MSBuild\15.0\Bin
}
else {
$frameworkDirs += Join-Path ($vs[0].InstallationPath) MSBuild\15.0\Bin\amd64
}
}

$vs = @($vsInstances | Select-VSSetupInstance -Version '[15.0,16.0)' -Product Microsoft.VisualStudio.Product.BuildTools)
if ($vs) {
if ($buildToolsKey -eq 'MSBuildToolsPath32') {
$frameworkDirs += Join-Path ($vs[0].InstallationPath) MSBuild\15.0\Bin
}
else {
$frameworkDirs += Join-Path ($vs[0].InstallationPath) MSBuild\15.0\Bin\amd64
}
}
}
else {
if (!($root = ${env:ProgramFiles(x86)})) {$root = $env:ProgramFiles}
if (Test-Path -LiteralPath "$root\Microsoft Visual Studio\2017") {
if ($buildToolsKey -eq 'MSBuildToolsPath32') {
$rp = @(Resolve-Path "$root\Microsoft Visual Studio\2017\*\MSBuild\15.0\Bin" -ErrorAction SilentlyContinue)
}
else {
$rp = @(Resolve-Path "$root\Microsoft Visual Studio\2017\*\MSBuild\15.0\Bin\amd64" -ErrorAction SilentlyContinue)
}

if ($rp) {
$frameworkDirs += $rp[-1].ProviderPath
}
}
}
}
elseif (Test-Path "HKLM:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\$ver") {
$frameworkDirs += (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\$ver" -Name $buildToolsKey).$buildToolsKey
}
}
}

$frameworkDirs = $frameworkDirs + @($versions | ForEach-Object { "$env:windir\Microsoft.NET\$bitness\$_\" })
for ($i = 0; $i -lt $frameworkDirs.Count; $i++) {
$dir = $frameworkDirs[$i]
if ($dir -Match "\$\(Registry:HKEY_LOCAL_MACHINE(.*?)@(.*)\)") {
$key = "HKLM:" + $matches[1]
$name = $matches[2]
$dir = (Get-ItemProperty -Path $key -Name $name).$name
$frameworkDirs[$i] = $dir
}
}

$frameworkDirs | ForEach-Object { Assert (test-path $_ -pathType Container) ($msgs.error_no_framework_install_dir_found -f $_)}

$env:PATH = ($frameworkDirs -join ";") + ";$env:PATH"
}

# if any error occurs in a PS function then "stop" processing immediately
# this does not effect any external programs that return a non-zero exit code
$global:ErrorActionPreference = "Stop"
}
28 changes: 28 additions & 0 deletions task/ps_modules/psake/private/CreateConfigurationForNewContext.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function CreateConfigurationForNewContext {
param(
[string] $buildFile,
[string] $framework
)

$previousConfig = GetCurrentConfigurationOrDefault

$config = new-object psobject -property @{
buildFileName = $previousConfig.buildFileName;
framework = $previousConfig.framework;
taskNameFormat = $previousConfig.taskNameFormat;
verboseError = $previousConfig.verboseError;
coloredOutput = $previousConfig.coloredOutput;
modules = $previousConfig.modules;
moduleScope = $previousConfig.moduleScope;
}

if ($framework) {
$config.framework = $framework;
}

if ($buildFile) {
$config.buildFileName = $buildFile;
}

return $config
}
50 changes: 50 additions & 0 deletions task/ps_modules/psake/private/ExecuteInBuildFileScope.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
function ExecuteInBuildFileScope {
param([string]$buildFile, $module, [scriptblock]$sb)

# Execute the build file to set up the tasks and defaults
Assert (test-path $buildFile -pathType Leaf) ($msgs.error_build_file_not_found -f $buildFile)

$psake.build_script_file = get-item $buildFile
$psake.build_script_dir = $psake.build_script_file.DirectoryName
$psake.build_success = $false

$psake.context.push(@{
"taskSetupScriptBlock" = {};
"taskTearDownScriptBlock" = {};
"executedTasks" = new-object System.Collections.Stack;
"callStack" = new-object System.Collections.Stack;
"originalEnvPath" = $env:path;
"originalDirectory" = get-location;
"originalErrorActionPreference" = $global:ErrorActionPreference;
"tasks" = @{};
"aliases" = @{};
"properties" = @();
"includes" = new-object System.Collections.Queue;
"config" = CreateConfigurationForNewContext $buildFile $framework
})

LoadConfiguration $psake.build_script_dir

set-location $psake.build_script_dir

LoadModules

$frameworkOldValue = $framework
. $psake.build_script_file.FullName

$currentContext = $psake.context.Peek()

if ($framework -ne $frameworkOldValue) {
writecoloredoutput $msgs.warning_deprecated_framework_variable -foregroundcolor Yellow
$currentContext.config.framework = $framework
}

ConfigureBuildEnvironment

while ($currentContext.includes.Count -gt 0) {
$includeFilename = $currentContext.includes.Dequeue()
. $includeFilename
}

& $sb $currentContext $module
}
17 changes: 17 additions & 0 deletions task/ps_modules/psake/private/Get-DefaultBuildFile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Attempt to find the default build file given the config_default of
# buildFileName and legacyBuildFileName. If neither exist optionally
# return the buildFileName or $null
function Get-DefaultBuildFile {
param(
[boolean] $UseDefaultIfNoneExist = $true
)

if (test-path $psake.config_default.buildFileName -pathType Leaf) {
Write-Output $psake.config_default.buildFileName
} elseif (test-path $psake.config_default.legacyBuildFileName -pathType Leaf) {
Write-Warning "The default configuration file of default.ps1 is deprecated. Please use psakefile.ps1"
Write-Output $psake.config_default.legacyBuildFileName
} elseif ($UseDefaultIfNoneExist) {
Write-Output $psake.config_default.buildFileName
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function GetCurrentConfigurationOrDefault() {
if ($psake.context.count -gt 0) {
return $psake.context.peek().config
} else {
return $psake.config_default
}
}
15 changes: 15 additions & 0 deletions task/ps_modules/psake/private/GetTasksFromContext.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function GetTasksFromContext($currentContext) {

$docs = $currentContext.tasks.Keys | foreach-object {

$task = $currentContext.tasks.$_
new-object PSObject -property @{
Name = $task.Name;
Alias = $task.Alias;
Description = $task.Description;
DependsOn = $task.DependsOn;
}
}

return $docs
}
16 changes: 16 additions & 0 deletions task/ps_modules/psake/private/LoadConfiguration.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function LoadConfiguration {
param(
[string] $configdir = $PSScriptRoot
)

$psakeConfigFilePath = (join-path $configdir "psake-config.ps1")

if (test-path $psakeConfigFilePath -pathType Leaf) {
try {
$config = GetCurrentConfigurationOrDefault
. $psakeConfigFilePath
} catch {
throw "Error Loading Configuration from psake-config.ps1: " + $_
}
}
}
20 changes: 20 additions & 0 deletions task/ps_modules/psake/private/LoadModules.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function LoadModules {
$currentConfig = $psake.context.peek().config
if ($currentConfig.modules) {

$scope = $currentConfig.moduleScope

$global = [string]::Equals($scope, "global", [StringComparison]::CurrentCultureIgnoreCase)

$currentConfig.modules | foreach {
resolve-path $_ | foreach {
"Loading module: $_"
$module = import-module $_ -passthru -DisableNameChecking -global:$global
if (!$module) {
throw ($msgs.error_loading_module -f $_.Name)
}
}
}
""
}
}
Loading

0 comments on commit 343c4fe

Please sign in to comment.