/
CombineOutputBinaries.psm1
73 lines (63 loc) · 2.42 KB
/
CombineOutputBinaries.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Set-StrictMode -Version latest
$ErrorActionPreference = "Stop"
[String]$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
Import-Module "$ScriptDir\Helper.psm1"
Import-Module "$ScriptDir\Configuration.psm1"
# -------------------------------------------------------------------------------------------------------------------------------------
function CombineOutputBinaries
{
Param
(
[Parameter()][string] $SolutionPath = $global:SolutionPath,
[Parameter()][switch] $PauseOnError
)
Try
{
$SolutionDirectoryPath = Split-Path -Path "$SolutionPath"
$OutputPath = "$SolutionDirectoryPath\_build\.out"
$OutputBinariesBasePath = "$SolutionDirectoryPath\_build\.combined"
# clear old combined output folder if it exists
Remove-Item -Recurse -Path "$OutputBinariesBasePath" -ErrorAction Ignore
# consider all projects under '_build'
Write-Host -ForegroundColor "Green" "Combine output binaries into base path '$OutputBinariesBasePath' for all projects..."
foreach ($Project in Get-ChildItem -Path "$OutputPath" -Directory -Force -ErrorAction SilentlyContinue)
{
Push-Location "$OutputPath\$($Project.Name)"
foreach ($BinaryPath in Get-ChildItem -Recurse -Force -Attributes !Directory | Resolve-Path -Relative)
{
$OutputBinaryPath = [IO.Path]::GetFullPath([IO.Path]::Combine($OutputBinariesBasePath, $BinaryPath))
if (Test-Path "$OutputBinaryPath" -PathType Leaf)
{
# binary exist --> compare if existing binary is the same
if ((Get-FileHash $BinaryPath).Hash -ne (Get-FileHash $OutputBinaryPath).Hash)
{
# files are not the same --> throw exception
throw "Found binary incompatibility for '$BinaryPath' in project '$($Project.Name)'..."
}
Write-Host "EXISTS: Project: $($Project.Name), File: $BinaryPath"
}
else
{
# binary does not exist --> copy and continue with next one
$OutputDirectory = [IO.Path]::GetDirectoryName("$OutputBinaryPath")
if (!(Test-Path "$OutputDirectory" -PathType Container))
{
New-Item -Force -Path "$OutputDirectory" -ItemType "directory" | out-null
}
Copy-Item -Path "$BinaryPath" -Destination "$OutputBinaryPath"
Write-Host "COPIED: Project: $($Project.Name), File: $BinaryPath"
}
}
Pop-Location
}
}
Catch [Exception]
{
# tell the caller it has all gone wrong
echo $_.Exception|format-list -force
if ($PauseOnError) {
Read-Host "Press ANY key..."
}
exit(-1)
}
}