1
# This script looks for each archive file in a directory and extracts it into the target directory.
2
# For example, the file "$InputPath/bin.tar.gz" extracts to "$ExtractPath/bin.tar.gz.extracted/**".
3
# Uses the "tar" utility added to Windows 10 / Windows 2019 that supports tar.gz and zip.
5
# Full path to directory where archives are stored.
6
[Parameter(Mandatory=$true)][string] $InputPath,
7
# Full path to directory to extract archives into. May be the same as $InputPath.
8
[Parameter(Mandatory=$true)][string] $ExtractPath
11
$ErrorActionPreference = 'Stop'
12
Set-StrictMode -Version 2.0
14
$disableConfigureToolsetImport = $true
17
# `tools.ps1` checks $ci to perform some actions. Since the SDL
18
# scripts don't necessarily execute in the same agent that run the
19
# build.ps1/sh script this variable isn't automatically set.
21
. $PSScriptRoot\..\tools.ps1
26
# Find archive files for non-Windows and Windows builds.
28
Get-ChildItem (Join-Path $InputPath "*.tar.gz")
29
Get-ChildItem (Join-Path $InputPath "*.zip")
32
foreach ($targzFile in $archiveFiles) {
33
$jobs += Start-Job -ScriptBlock {
34
$file = $using:targzFile
35
$fileName = [System.IO.Path]::GetFileName($file)
36
$extractDir = Join-Path $using:ExtractPath "$fileName.extracted"
38
New-Item $extractDir -ItemType Directory -Force | Out-Null
40
Write-Host "Extracting '$file' to '$extractDir'..."
42
# Pipe errors to stdout to prevent PowerShell detecting them and quitting the job early.
43
# This type of quit skips the catch, so we wouldn't be able to tell which file triggered the
44
# error. Save output so it can be stored in the exception string along with context.
45
$output = tar -xf $file -C $extractDir 2>&1
46
# Handle NZEC manually rather than using Exit-IfNZEC: we are in a background job, so we
47
# don't have access to the outer scope.
48
if ($LASTEXITCODE -ne 0) {
49
throw "Error extracting '$file': non-zero exit code ($LASTEXITCODE). Output: '$output'"
52
Write-Host "Extracted to $extractDir"
56
Receive-Job $jobs -Wait
61
Write-PipelineTelemetryError -Force -Category 'Sdl' -Message $_