Skip to content

Commit f219a38

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 - copy into repo from wherever it's found - add lots of `Write-Host` debugging nit: clean up / comment on VS Code warnings about build.ps1
1 parent 3c65c03 commit f219a38

File tree

5 files changed

+114
-11
lines changed

5 files changed

+114
-11
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: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
$finalCommand = "$repoRoot\.tools\tar.exe"
27+
28+
Write-Host "Windows version and other information, because who knows"
29+
cmd.exe /c ver
30+
systeminfo.exe
31+
32+
Write-Host "Processor Architecture: $env:PROCESSOR_ARCHITECTURE"
33+
Write-Host "Dumping environment"
34+
Get-ChildItem env:\
35+
36+
Write-Host "Checking $env:SystemRoot\System32\tar.exe"
37+
Get-ChildItem "$env:SystemRoot\System32\ta*.exe"
38+
if (Test-Path "$env:SystemRoot\System32\tar.exe") {
39+
Write-Host "Found $env:SystemRoot\System32\tar.exe"
40+
$tarCommand = "$env:SystemRoot\System32\tar.exe"
41+
}
42+
elseif (Test-Path "$env:ProgramFiles\Git\usr\bin\tar.exe") {
43+
$tarCommand = "$env:ProgramFiles\Git\usr\bin\tar.exe"
44+
}
45+
elseif (Test-Path "${env:ProgramFiles(x86)}\Git\usr\bin\tar.exe") {
46+
$tarCommand = "${env:ProgramFiles(x86)}\Git\usr\bin\tar.exe"
47+
}
48+
elseif (Test-Path "$env:AGENT_HOMEDIRECTORY\externals\git\usr\bin\tar.exe") {
49+
$tarCommand = "$env:AGENT_HOMEDIRECTORY\externals\git\usr\bin\tar.exe"
50+
}
51+
elseif ((Test-Path $tarCommand) -And (-Not $Force)) {
52+
Write-Verbose "Repo-local Git installation and $tarCommand already exist, skipping Git install."
53+
}
54+
else {
55+
if (-not $GitVersion) {
56+
$globalJson = Get-Content "$repoRoot\global.json" | ConvertFrom-Json
57+
$GitVersion = $globalJson.tools.Git
58+
}
59+
60+
$Uri = "https://netcorenativeassets.blob.core.windows.net/resource-packages/external/windows/git/Git-${GitVersion}-64-bit.zip"
61+
62+
Import-Module -Name (Join-Path $PSScriptRoot "..\common\native\CommonLibrary.psm1" -Resolve)
63+
$InstallStatus = CommonLibrary\DownloadAndExtract -Uri $Uri -InstallDirectory "$installDir\" -Force:$Force -Verbose
64+
65+
if ($InstallStatus -Eq $False) {
66+
Write-Error "Installation failed"
67+
exit 1
68+
}
69+
}
70+
71+
Copy-Item "$tarCommand" "$finalCommand" -Verbose
72+
Write-Host "Tar now available at '$finalCommand'"
73+
74+
if ($tarCommand -like '*\Git\*') {
75+
$null >.\.tools\tar.fromGit
76+
}

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: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,34 @@ 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="Exists('$(RepoRoot).tools\tar.exe')">$(RepoRoot).tools\tar.exe</_TarCommand>
174+
<_TarCommand Condition="'$(_TarCommand)' == ''">tar</_TarCommand>
175+
176+
<!-- For the tar packed with git, transform e.g. "C:\root\AspNetCore\File.tar.gz" to "/C/root/AspNetCore/File.tar.gz". -->
177+
<_TarArchiveOutputPath>$(TarArchiveOutputPath)</_TarArchiveOutputPath>
178+
<_TarArchiveOutputPath
179+
Condition="Exists('$(repoRoot)\.tools\tar.fromGit')">/$(TarArchiveOutputPath.Replace('\','/').Replace(':',''))</_TarArchiveOutputPath>
180+
</PropertyGroup>
181+
172182
<ZipDirectory
173183
SourceDirectory="$(TargetingPackLayoutRoot)"
174184
DestinationFile="$(ZipArchiveOutputPath)"
175185
Overwrite="true" />
186+
176187
<!-- Requires Windows 10 version 1803 or newer -->
177-
<Exec
178-
Command="tar -czf $(TarArchiveOutputPath) ."
179-
WorkingDirectory="$(TargetingPackLayoutRoot)" />
188+
<Message Importance="High" Text="Processor Architecture: $(PROCESSOR_ARCHITECTURE)"
189+
Condition="'$(OS)' == 'Windows_NT'" />
190+
<Message Importance="High" Text="Tar Command: $(_TarCommand) -czf $(_TarArchiveOutputPath) ."
191+
Condition="'$(OS)' == 'Windows_NT'" />
192+
<Exec Command="$(_TarCommand) -czf $(_TarArchiveOutputPath) ."
193+
WorkingDirectory="$(TargetingPackLayoutRoot)"
194+
Condition="'$(OS)' == 'Windows_NT'" />
195+
196+
<Exec Command="tar -czf $(_TarArchiveOutputPath) ."
197+
WorkingDirectory="$(TargetingPackLayoutRoot)"
198+
Condition="'$(OS)' != 'Windows_NT'" />
199+
180200
<Message Importance="High" Text="$(MSBuildProjectName) -> $(TarArchiveOutputPath)" />
181201
</Target>
182202

0 commit comments

Comments
 (0)