/
make.ps1
106 lines (84 loc) · 3.51 KB
/
make.ps1
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Copyright 2014, 2015 Sensics, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Compute settings
$OrigDir = $PWD
$ScriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition
Set-Location $ScriptPath
$Version = git describe --tags --always
$InstallBase = "install"
$BuildStem = "OSVR-Boxstarter-$Version"
# All files in the root directory ending in this will result in a self-extracting installer.
$ConfigBase = "sfxconfig.txt"
function Get-RepoFullPath ($RelativePath) {
Join-Path -ChildPath $RelativePath -Path $ScriptPath
}
$InstallDir = Get-RepoFullPath "$InstallBase\$BuildStem"
# Check for nuget
$nuget = Get-Command -ErrorAction Stop nuget
Write-Output "Building OSVR Boxstarter Packages, release $Version"
# Clean the build
function Clean {
Write-Output "Cleaning..."
$BadFiles = @(Get-ChildItem -Path (RepoFullPath "repo\*.nupkg") -Recurse)
$BadFiles += Get-RepoFullPath "repo\OSVR-CI-Environment\tools\slave.jar"
$BadFiles += Get-RepoFullPath "repo\OSVR-Jenkins-Updater\slave.jar"
$BadFiles += Get-RepoFullPath "$InstallBase"
foreach ($BadFile in $BadFiles) {
if (Test-Path $BadFile) {
Write-Output "Cleaning $BadFile"
Remove-Item $BadFile -Recurse
}
}
}
function Build-Packages {
Write-Output "Building Boxstarter packages..."
Import-Module Boxstarter.Chocolatey
Set-Location (Get-RepoFullPath "repo")
foreach ($nuspec in @(Get-ChildItem -path "$PWD\*.nuspec" -recurse)) {
Set-Location $nuspec.Directory.Parent.FullName
& $nuget pack (join-path $nuspec.Directory $nuspec.Name) -NoPackageAnalysis -NonInteractive
}
}
function Copy-Install {
Import-Module Boxstarter.Chocolatey
Write-Output "Copying Boxstarter to $InstallDir..."
mkdir -Path $InstallDir
Copy-Item $Boxstarter.BaseDir $InstallDir -Recurse
Copy-Item (Get-ChildItem -Path (RepoFullPath "repo\*.nupkg")) "$InstallDir\Boxstarter\BuildPackages" -Recurse
}
# Example: Create-7ZipSFX 7z920_extra\7zSD.sfx MySFXConfig.txt MyFiles.7z MyOutputFile.exe
function Create-7ZipSFX ($7zSFXModule, $SFXConfig, $7zFile, $Output) {
Get-Content "$7zSFXModule", "$SFXConfig", "$7zFile" -Encoding Byte -Read 512 | Set-Content "$Output" -Encoding Byte
}
function Build-SFX () {
# Get list of configs
Set-Location "$ScriptPath"
$Configs = Get-ChildItem "*$ConfigBase" | foreach-object {$_.name.Replace($ConfigBase, "")}
Write-Output "Compressing distribution..."
Set-Location "$InstallDir"
$SevenZip = "$ScriptPath\7z920_extra"
&"$SevenZip\7zr" -r a "..\$BuildStem.7z" "*"
Set-Location (Get-RepoFullPath "$InstallBase")
foreach ($Config in $Configs) {
Write-Output "Creating $Config self-extracting file"
Create-7ZipSFX "$SevenZip\7zSD.sfx" ("$ScriptPath\$Config" + "sfxconfig.txt") "$BuildStem.7z" "$BuildStem-$Config.exe"
}
}
Clean
Build-Packages
Copy-Install
Build-SFX
Write-Output "Done!"
#
Set-Location $OrigDir