forked from cloudfoundry/bsdtar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ps1
102 lines (87 loc) · 3.37 KB
/
install.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
$ErrorActionPreference = "Stop";
trap { $host.SetShouldExit(1) }
$ScriptPath = $MyInvocation.MyCommand.Path
$ScriptDirectory = Split-Path $ScriptPath -Parent
$ZlibDir = Join-Path $ScriptDirectory "zlib"
if (-Not (Test-Path $ZlibDir)) {
Write-Error "Missing zlib"
}
$LibarchiveDir = Join-Path $ScriptDirectory "libarchive"
if (-Not (Test-Path $LibarchiveDir)) {
Write-Error "Missing libarchive"
}
$LocalDir = Join-Path $ScriptDirectory "local"
if (Test-Path $LocalDir) {
Remove-Item -Path $LocalDir -Recurse -Force
}
New-Item -Path $LocalDir -ItemType directory
foreach ($name in @("bin", "lib", "include")) {
New-Item -Path (Join-Path $LocalDir $name) -ItemType directory
}
$LibDir = Join-Path $LocalDir "lib"
$IncludeDir = Join-Path $LocalDir "include"
Push-Location $ZlibDir
C:\\var\\vcap\\packages\\mingw64\\mingw64\\bin\\mingw32-make.exe -f win32/Makefile.gcc
if ($LASTEXITCODE -ne 0) {
Write-Error "non-zero exit code (mingw32-make.exe -f win32/Makefile.gcc): ${LASTEXITCODE}"
}
# Copy header files to include dir
foreach ($name in @("zconf.h", "zlib.h")) {
Copy-Item -Path $name -Destination (Join-Path $IncludeDir $name)
}
# Copy library and DLL files to lib dir
foreach ($name in @("libz.a", "libz.dll.a", "zlib1.dll")) {
Copy-Item -Path $name -Destination (Join-Path $LibDir $name)
}
# Copy zlib1.dll to zlib.dll
Copy-Item -Path "zlib1.dll" -Destination (Join-Path $LibDir "zlib.dll")
Copy-Item -Path (Join-Path "win32" "zlib.def") -Destination (Join-Path $LibDir "zlib.def")
Pop-Location
# Tests will be tee'd to this log file
$LogFile = Join-Path $ScriptDirectory "test-log.txt"
$BuildDir = Join-Path $ScriptDirectory "build-libarchive"
New-Item -Path $BuildDir -ItemType directory
Push-Location $BuildDir
# Configure
C:\var\vcap\packages\cmake\bin\cmake.exe -G "MinGW Makefiles" -DENABLE_CAT:BOOL="0" -DENABLE_BZip2:BOOL="0" -DENABLE_CNG:BOOL="0" -DENABLE_CPIO:BOOL="0" `
-DZLIB_INCLUDE_DIR:PATH="$IncludeDir" -DZLIB_LIBRARY_RELEASE:FILEPATH="$LibDir/libz.a" "$LibarchiveDir"
if ($LASTEXITCODE -ne 0) {
Write-Error "cmake: non-zero exit code: ${LASTEXITCODE}"
Exit $LASTEXITCODE
}
# Build
C:\\var\\vcap\\packages\\mingw64\\mingw64\\bin\\mingw32-make.exe -j 4
if ($LASTEXITCODE -ne 0) {
Write-Error "mingw32-make.exe: non-zero exit code: ${LASTEXITCODE}"
Exit $LASTEXITCODE
}
# Test
C:\\var\\vcap\\packages\\mingw64\\mingw64\\bin\\mingw32-make.exe -j 4 test | Tee-Object -FilePath $LogFile
Pop-Location
# We're able to pass every test. So we don't need this anymore
# Expected failures
# [hashtable]$expErrors = [ordered]@{
# "*libarchive_test_entry (Failed)*" = $false
# }
#
# foreach ($line in Get-Content -Path $LogFile) {
# foreach ($h in $expErrors.GetEnumerator()) {
# if ($line -like $h.Key) {
# $expErrors[$h.Key] = $true
# break
# }
# }
# }
#
# foreach ($h in $expErrors.GetEnumerator()) {
# if ($h.Value -eq $false) {
# $err = ("Tests failed: {0}" -f $h.Key)
# Write-Error $err
# }
# }
$bsdTar = [System.IO.Path]::Combine($BuildDir, "bin", "bsdtar.exe")
$tarball = ("tar-{0}.exe" -f ([int][double]::Parse((Get-Date -UFormat %s))))
$outputTar = [System.IO.Path]::Combine("tar-output", $tarball)
# Capture the output in Concourse
Move-Item $bsdTar $outputTar
Exit 0