Skip to content

Commit ec2fed0

Browse files
committed
Find or install Tar on CI
- work around dotnet/core-eng#7970 - install Git in repo if Tar can't be found in usual locations - use found or installed Tar in Microsoft.AspNetCore.App.Ref project - nit: clean up / comment on VS Code warnings about build.ps1
1 parent 3c65c03 commit ec2fed0

File tree

5 files changed

+90
-9
lines changed

5 files changed

+90
-9
lines changed

.azure/pipelines/jobs/default-build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ parameters:
5555
artifacts: []
5656
buildDirectory: ''
5757
buildScript: ''
58+
installTar: true
5859
installNodeJs: true
5960
installJdk: true
6061
timeoutInMinutes: 180
@@ -146,6 +147,9 @@ jobs:
146147
Write-Host "##vso[task.setvariable variable=SeleniumProcessTrackingFolder]$(BuildDirectory)\artifacts\tmp\selenium\"
147148
./eng/scripts/InstallGoogleChrome.ps1
148149
displayName: Install Chrome
150+
- ${{ if and(eq(parameters.installTar, 'true'), eq(parameters.agentOs, 'Windows')) }}:
151+
- powershell: ./eng/scripts/InstallTar.ps1
152+
displayName: Find or install Tar
149153

150154
- ${{ parameters.beforeBuild }}
151155

build.ps1

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ if (-not $foundJdk -and $RunBuild -and ($All -or $BuildJava) -and -not $NoBuildJ
307307
# Initialize global variables need to be set before the import of Arcade is imported
308308
$restore = $RunRestore
309309

310+
# Though VS Code may indicate $nodeReuse, $warnAsError and $msbuildEngine are unused, tools.ps1 uses them.
311+
310312
# Disable node reuse - Workaround perpetual issues in node reuse and custom task assemblies
311313
$nodeReuse = $false
312314
$env:MSBUILDDISABLENODEREUSE=1
@@ -328,10 +330,10 @@ if ($CI) {
328330
}
329331

330332
# tools.ps1 corrupts global state, so reset these values in case they carried over from a previous build
331-
rm variable:global:_BuildTool -ea Ignore
332-
rm variable:global:_DotNetInstallDir -ea Ignore
333-
rm variable:global:_ToolsetBuildProj -ea Ignore
334-
rm variable:global:_MSBuildExe -ea Ignore
333+
Remove-Item variable:global:_BuildTool -ea Ignore
334+
Remove-Item variable:global:_DotNetInstallDir -ea Ignore
335+
Remove-Item variable:global:_ToolsetBuildProj -ea Ignore
336+
Remove-Item variable:global:_MSBuildExe -ea Ignore
335337

336338
# Import Arcade
337339
. "$PSScriptRoot/eng/common/tools.ps1"
@@ -391,10 +393,10 @@ finally {
391393
}
392394

393395
# tools.ps1 corrupts global state, so reset these values so they don't carry between invocations of build.ps1
394-
rm variable:global:_BuildTool -ea Ignore
395-
rm variable:global:_DotNetInstallDir -ea Ignore
396-
rm variable:global:_ToolsetBuildProj -ea Ignore
397-
rm variable:global:_MSBuildExe -ea Ignore
396+
Remove-Item variable:global:_BuildTool -ea Ignore
397+
Remove-Item variable:global:_DotNetInstallDir -ea Ignore
398+
Remove-Item variable:global:_ToolsetBuildProj -ea Ignore
399+
Remove-Item variable:global:_MSBuildExe -ea Ignore
398400

399401
if ($DumpProcesses -or $ci) {
400402
Stop-Job -Name DumpProcesses

eng/scripts/InstallTar.ps1

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<#
2+
.SYNOPSIS
3+
Finds or installs the Tar command on this system.
4+
.DESCRIPTION
5+
This script searches for Tar on this system. If not found, downloads and extracts Git to use its tar.exe. Prefers
6+
global installation locations even if Git has been downloaded into this repo.
7+
.PARAMETER GitVersion
8+
The version of the Git to install. If not set, the default value is read from global.json.
9+
.PARAMETER Force
10+
Overwrite the existing installation if one exists in this repo and Tar isn't installed globally.
11+
#>
12+
param(
13+
[string]$GitVersion,
14+
[switch]$Force
15+
)
16+
17+
$ErrorActionPreference = 'Stop'
18+
$ProgressPreference = 'SilentlyContinue' # Workaround PowerShell/PowerShell#2138
19+
20+
Set-StrictMode -Version 1
21+
22+
# Find tar. If not found, install Git to get it.
23+
$repoRoot = (Join-Path $PSScriptRoot "..\.." -Resolve)
24+
$installDir = "$repoRoot\.tools\Git\win-x64\"
25+
$tarCommand = "$installDir\usr\bin\tar.exe"
26+
27+
if (Test-Path "$env:SystemRoot\System32\tar.exe") {
28+
$tarCommand = "$env:SystemRoot\System32\tar.exe"
29+
}
30+
elseif (Test-Path "$env:ProgramFiles\Git\usr\bin\tar.exe") {
31+
$tarCommand = "$env:ProgramFiles\Git\usr\bin\tar.exe"
32+
}
33+
elseif (Test-Path "${env:ProgramFiles(x86)}\Git\usr\bin\tar.exe") {
34+
$tarCommand = "${env:ProgramFiles(x86)}\Git\usr\bin\tar.exe"
35+
}
36+
elseif (Test-Path "$env:AGENT_HOMEDIRECTORY\externals\git\usr\bin\tar.exe") {
37+
$tarCommand = "$env:AGENT_HOMEDIRECTORY\externals\git\usr\bin\tar.exe"
38+
}
39+
elseif ((Test-Path $tarCommand) -And (-Not $Force)) {
40+
Write-Verbose "Repo-local Git installation and $tarCommand already exist, skipping Git install."
41+
}
42+
else {
43+
if (-not $GitVersion) {
44+
$globalJson = Get-Content "$repoRoot\global.json" | ConvertFrom-Json
45+
$GitVersion = $globalJson.tools.Git
46+
}
47+
48+
$Uri = "https://netcorenativeassets.blob.core.windows.net/resource-packages/external/windows/git/Git-${GitVersion}-64-bit.zip"
49+
50+
Import-Module -Name (Join-Path $PSScriptRoot "..\common\native\CommonLibrary.psm1" -Resolve)
51+
$InstallStatus = CommonLibrary\DownloadAndExtract -Uri $Uri -InstallDirectory "$installDir" -Force:$Force -Verbose
52+
53+
if ($InstallStatus -Eq $False) {
54+
Write-Error "Installation failed"
55+
exit 1
56+
}
57+
}
58+
59+
if ($env:TF_BUILD) {
60+
Write-Host "##vso[task.setvariable variable=TarCommand;]$tarCommand"
61+
}
62+
else {
63+
Write-Host "Tar now available at '$tarCommand'"
64+
}

global.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"$(MicrosoftNETCoreAppRuntimeVersion)"
1313
]
1414
},
15+
"Git": "2.22.0",
1516
"jdk": "11.0.3",
1617
"vs": {
1718
"version": "16.0",

src/Framework/ref/Microsoft.AspNetCore.App.Ref.csproj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,23 @@ This package is an internal implementation of the .NET Core SDK and is not meant
169169
Inputs="@(RefPackContent)"
170170
Outputs="$(ZipArchiveOutputPath);$(TarArchiveOutputPath)"
171171
Condition="'$(IsPackable)' == 'true'">
172+
<PropertyGroup>
173+
<TarCommand Condition="'$(TarCommand)' == ''">tar</TarCommand>
174+
175+
<!-- For the tar packed with git, transform e.g. "C:\root\AspNetCore\File.tar.gz" to "/C/root/AspNetCore/File.tar.gz". -->
176+
<_TarArchiveOutputPath>$(TarArchiveOutputPath)</_TarArchiveOutputPath>
177+
<_TarArchiveOutputPath
178+
Condition="$(TarCommand.Contains('\Git\'))">/$(TarArchiveOutputPath.Replace('\','/').Replace(':',''))</_TarArchiveOutputPath>
179+
</PropertyGroup>
180+
172181
<ZipDirectory
173182
SourceDirectory="$(TargetingPackLayoutRoot)"
174183
DestinationFile="$(ZipArchiveOutputPath)"
175184
Overwrite="true" />
185+
176186
<!-- Requires Windows 10 version 1803 or newer -->
177187
<Exec
178-
Command="tar -czf $(TarArchiveOutputPath) ."
188+
Command="$(TarCommand) -czf $(_TarArchiveOutputPath) ."
179189
WorkingDirectory="$(TargetingPackLayoutRoot)" />
180190
<Message Importance="High" Text="$(MSBuildProjectName) -> $(TarArchiveOutputPath)" />
181191
</Target>

0 commit comments

Comments
 (0)