Skip to content

Commit 6522765

Browse files
committed
Update build scripts to most recent versions.
1 parent cbe5199 commit 6522765

File tree

10 files changed

+350
-137
lines changed

10 files changed

+350
-137
lines changed

eng/common/build.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Param(
2525
[switch] $prepareMachine,
2626
[string] $runtimeSourceFeed = '',
2727
[string] $runtimeSourceFeedKey = '',
28+
[switch] $excludePrereleaseVS,
2829
[switch] $help,
2930
[Parameter(ValueFromRemainingArguments=$true)][String[]]$properties
3031
)
@@ -65,6 +66,7 @@ function Print-Usage() {
6566
Write-Host " -prepareMachine Prepare machine for CI run, clean up processes after build"
6667
Write-Host " -warnAsError <value> Sets warnaserror msbuild parameter ('true' or 'false')"
6768
Write-Host " -msbuildEngine <value> Msbuild engine to use to run build ('dotnet', 'vs', or unspecified)."
69+
Write-Host " -excludePrereleaseVS Set to exclude build engines in prerelease versions of Visual Studio"
6870
Write-Host ""
6971

7072
Write-Host "Command line arguments not listed above are passed thru to msbuild."

eng/common/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ runtime_source_feed_key=''
8181

8282
properties=''
8383
while [[ $# > 0 ]]; do
84-
opt="$(echo "${1/#--/-}" | awk '{print tolower($0)}')"
84+
opt="$(echo "${1/#--/-}" | tr "[:upper:]" "[:lower:]")"
8585
case "$opt" in
8686
-help|-h)
8787
usage

eng/common/dotnet-install.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ runtime='dotnet'
1919
runtimeSourceFeed=''
2020
runtimeSourceFeedKey=''
2121
while [[ $# > 0 ]]; do
22-
opt="$(echo "$1" | awk '{print tolower($0)}')"
22+
opt="$(echo "$1" | tr "[:upper:]" "[:lower:]")"
2323
case "$opt" in
2424
-version|-v)
2525
shift
@@ -49,13 +49,8 @@ while [[ $# > 0 ]]; do
4949
shift
5050
done
5151

52-
# Use uname to determine what the CPU is.
53-
cpuname=$(uname -p)
54-
# Some Linux platforms report unknown for platform, but the arch for machine.
55-
if [[ "$cpuname" == "unknown" ]]; then
56-
cpuname=$(uname -m)
57-
fi
58-
52+
# Use uname to determine what the CPU is, see https://en.wikipedia.org/wiki/Uname#Examples
53+
cpuname=$(uname -m)
5954
case $cpuname in
6055
aarch64)
6156
buildarch=arm64

eng/common/init-tools-native.sh

Lines changed: 89 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ declare -A native_assets
1616
. $scriptroot/native/common-library.sh
1717

1818
while (($# > 0)); do
19-
lowerI="$(echo $1 | awk '{print tolower($0)}')"
19+
lowerI="$(echo $1 | tr "[:upper:]" "[:lower:]")"
2020
case $lowerI in
2121
--baseuri)
2222
base_uri=$2
@@ -76,24 +76,89 @@ while (($# > 0)); do
7676
done
7777

7878
function ReadGlobalJsonNativeTools {
79-
# Get the native-tools section from the global.json.
80-
local native_tools_section=$(cat $global_json_file | awk '/"native-tools"/,/}/')
81-
# Only extract the contents of the object.
82-
local native_tools_list=$(echo $native_tools_section | awk -F"[{}]" '{print $2}')
83-
native_tools_list=${native_tools_list//[\" ]/}
84-
native_tools_list=$( echo "$native_tools_list" | sed 's/\s//g' | sed 's/,/\n/g' )
85-
86-
local old_IFS=$IFS
87-
while read -r line; do
88-
# Lines are of the form: 'tool:version'
89-
IFS=:
90-
while read -r key value; do
91-
native_assets[$key]=$value
92-
done <<< "$line"
93-
done <<< "$native_tools_list"
94-
IFS=$old_IFS
95-
96-
return 0;
79+
# happy path: we have a proper JSON parsing tool `jq(1)` in PATH!
80+
if command -v jq &> /dev/null; then
81+
82+
# jq: read each key/value pair under "native-tools" entry and emit:
83+
# KEY="<entry-key>" VALUE="<entry-value>"
84+
# followed by a null byte.
85+
#
86+
# bash: read line with null byte delimeter and push to array (for later `eval`uation).
87+
88+
while IFS= read -rd '' line; do
89+
native_assets+=("$line")
90+
done < <(jq -r '. |
91+
select(has("native-tools")) |
92+
."native-tools" |
93+
keys[] as $k |
94+
@sh "KEY=\($k) VALUE=\(.[$k])\u0000"' "$global_json_file")
95+
96+
return
97+
fi
98+
99+
# Warning: falling back to manually parsing JSON, which is not recommended.
100+
101+
# Following routine matches the output and escaping logic of jq(1)'s @sh formatter used above.
102+
# It has been tested with several weird strings with escaped characters in entries (key and value)
103+
# and results were compared with the output of jq(1) in binary representation using xxd(1);
104+
# just before the assignment to 'native_assets' array (above and below).
105+
106+
# try to capture the section under "native-tools".
107+
if [[ ! "$(cat "$global_json_file")" =~ \"native-tools\"[[:space:]\:\{]*([^\}]+) ]]; then
108+
return
109+
fi
110+
111+
section="${BASH_REMATCH[1]}"
112+
113+
parseStarted=0
114+
possibleEnd=0
115+
escaping=0
116+
escaped=0
117+
isKey=1
118+
119+
for (( i=0; i<${#section}; i++ )); do
120+
char="${section:$i:1}"
121+
if ! ((parseStarted)) && [[ "$char" =~ [[:space:],:] ]]; then continue; fi
122+
123+
if ! ((escaping)) && [[ "$char" == "\\" ]]; then
124+
escaping=1
125+
elif ((escaping)) && ! ((escaped)); then
126+
escaped=1
127+
fi
128+
129+
if ! ((parseStarted)) && [[ "$char" == "\"" ]]; then
130+
parseStarted=1
131+
possibleEnd=0
132+
elif [[ "$char" == "'" ]]; then
133+
token="$token'\\\''"
134+
possibleEnd=0
135+
elif ((escaping)) || [[ "$char" != "\"" ]]; then
136+
token="$token$char"
137+
possibleEnd=1
138+
fi
139+
140+
if ((possibleEnd)) && ! ((escaping)) && [[ "$char" == "\"" ]]; then
141+
# Use printf to unescape token to match jq(1)'s @sh formatting rules.
142+
# do not use 'token="$(printf "$token")"' syntax, as $() eats the trailing linefeed.
143+
printf -v token "'$token'"
144+
145+
if ((isKey)); then
146+
KEY="$token"
147+
isKey=0
148+
else
149+
line="KEY=$KEY VALUE=$token"
150+
native_assets+=("$line")
151+
isKey=1
152+
fi
153+
154+
# reset for next token
155+
parseStarted=0
156+
token=
157+
elif ((escaping)) && ((escaped)); then
158+
escaping=0
159+
escaped=0
160+
fi
161+
done
97162
}
98163

99164
native_base_dir=$install_directory
@@ -111,14 +176,14 @@ if [[ ${#native_assets[@]} -eq 0 ]]; then
111176
exit 0;
112177
else
113178
native_installer_dir="$scriptroot/native"
114-
for tool in "${!native_assets[@]}"
115-
do
116-
tool_version=${native_assets[$tool]}
117-
installer_path="$native_installer_dir/install-$tool.sh"
179+
for index in "${!native_assets[@]}"; do
180+
eval "${native_assets["$index"]}"
181+
182+
installer_path="$native_installer_dir/install-$KEY.sh"
118183
installer_command="$installer_path"
119184
installer_command+=" --baseuri $base_uri"
120185
installer_command+=" --installpath $install_bin"
121-
installer_command+=" --version $tool_version"
186+
installer_command+=" --version $VALUE"
122187
echo $installer_command
123188

124189
if [[ $force = true ]]; then

eng/common/native/CommonLibrary.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function DownloadAndExtract {
4848
-Verbose:$Verbose
4949

5050
if ($DownloadStatus -Eq $False) {
51-
Write-Error "Download failed"
51+
Write-Error "Download failed from $Uri"
5252
return $False
5353
}
5454

eng/common/native/install-tool.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ try {
105105
Write-Error "There are multiple copies of $ToolName in $($ToolInstallDirectory): `n$(@($ToolFilePath | out-string))"
106106
exit 1
107107
} elseif (@($ToolFilePath).Length -Lt 1) {
108-
Write-Host "$ToolName was not found in $ToolFilePath."
108+
Write-Host "$ToolName was not found in $ToolInstallDirectory."
109109
exit 1
110110
}
111111

eng/common/pipeline-logging-functions.ps1

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ function Write-PipelineTelemetryError {
2929
[switch]$AsOutput,
3030
[switch]$Force)
3131

32-
$PSBoundParameters.Remove('Category') | Out-Null
32+
$PSBoundParameters.Remove('Category') | Out-Null
3333

34-
if($Force -Or ((Test-Path variable:ci) -And $ci)) {
35-
$Message = "(NETCORE_ENGINEERING_TELEMETRY=$Category) $Message"
36-
}
37-
$PSBoundParameters.Remove('Message') | Out-Null
38-
$PSBoundParameters.Add('Message', $Message)
39-
Write-PipelineTaskError @PSBoundParameters
34+
if ($Force -Or ((Test-Path variable:ci) -And $ci)) {
35+
$Message = "(NETCORE_ENGINEERING_TELEMETRY=$Category) $Message"
36+
}
37+
$PSBoundParameters.Remove('Message') | Out-Null
38+
$PSBoundParameters.Add('Message', $Message)
39+
Write-PipelineTaskError @PSBoundParameters
4040
}
4141

4242
# Specify "-Force" to force pipeline formatted output even if "$ci" is false or not set
@@ -55,8 +55,8 @@ function Write-PipelineTaskError {
5555
[switch]$Force
5656
)
5757

58-
if(!$Force -And (-Not (Test-Path variable:ci) -Or !$ci)) {
59-
if($Type -eq 'error') {
58+
if (!$Force -And (-Not (Test-Path variable:ci) -Or !$ci)) {
59+
if ($Type -eq 'error') {
6060
Write-Host $Message -ForegroundColor Red
6161
return
6262
}
@@ -66,47 +66,61 @@ function Write-PipelineTaskError {
6666
}
6767
}
6868

69-
if(($Type -ne 'error') -and ($Type -ne 'warning')) {
69+
if (($Type -ne 'error') -and ($Type -ne 'warning')) {
7070
Write-Host $Message
7171
return
7272
}
7373
$PSBoundParameters.Remove('Force') | Out-Null
74-
if(-not $PSBoundParameters.ContainsKey('Type')) {
74+
if (-not $PSBoundParameters.ContainsKey('Type')) {
7575
$PSBoundParameters.Add('Type', 'error')
7676
}
7777
Write-LogIssue @PSBoundParameters
78-
}
78+
}
7979

80-
function Write-PipelineSetVariable {
80+
function Write-PipelineSetVariable {
8181
[CmdletBinding()]
8282
param(
83-
[Parameter(Mandatory = $true)]
84-
[string]$Name,
85-
[string]$Value,
86-
[switch]$Secret,
87-
[switch]$AsOutput,
88-
[bool]$IsMultiJobVariable=$true)
89-
90-
if((Test-Path variable:ci) -And $ci) {
83+
[Parameter(Mandatory = $true)]
84+
[string]$Name,
85+
[string]$Value,
86+
[switch]$Secret,
87+
[switch]$AsOutput,
88+
[bool]$IsMultiJobVariable = $true)
89+
90+
if ((Test-Path variable:ci) -And $ci) {
9191
Write-LoggingCommand -Area 'task' -Event 'setvariable' -Data $Value -Properties @{
92-
'variable' = $Name
93-
'isSecret' = $Secret
94-
'isOutput' = $IsMultiJobVariable
92+
'variable' = $Name
93+
'isSecret' = $Secret
94+
'isOutput' = $IsMultiJobVariable
9595
} -AsOutput:$AsOutput
96-
}
97-
}
96+
}
97+
}
9898

99-
function Write-PipelinePrependPath {
99+
function Write-PipelinePrependPath {
100100
[CmdletBinding()]
101101
param(
102-
[Parameter(Mandatory=$true)]
103-
[string]$Path,
104-
[switch]$AsOutput)
102+
[Parameter(Mandatory = $true)]
103+
[string]$Path,
104+
[switch]$AsOutput)
105105

106-
if((Test-Path variable:ci) -And $ci) {
106+
if ((Test-Path variable:ci) -And $ci) {
107107
Write-LoggingCommand -Area 'task' -Event 'prependpath' -Data $Path -AsOutput:$AsOutput
108-
}
109-
}
108+
}
109+
}
110+
111+
function Write-PipelineSetResult {
112+
[CmdletBinding()]
113+
param(
114+
[ValidateSet("Succeeded", "SucceededWithIssues", "Failed", "Cancelled", "Skipped")]
115+
[Parameter(Mandatory = $true)]
116+
[string]$Result,
117+
[string]$Message)
118+
if ((Test-Path variable:ci) -And $ci) {
119+
Write-LoggingCommand -Area 'task' -Event 'complete' -Data $Message -Properties @{
120+
'result' = $Result
121+
}
122+
}
123+
}
110124

111125
<########################################
112126
# Private functions.
@@ -123,7 +137,8 @@ function Format-LoggingCommandData {
123137
foreach ($mapping in $script:loggingCommandEscapeMappings) {
124138
$Value = $Value.Replace($mapping.Token, $mapping.Replacement)
125139
}
126-
} else {
140+
}
141+
else {
127142
for ($i = $script:loggingCommandEscapeMappings.Length - 1 ; $i -ge 0 ; $i--) {
128143
$mapping = $script:loggingCommandEscapeMappings[$i]
129144
$Value = $Value.Replace($mapping.Replacement, $mapping.Token)
@@ -156,7 +171,8 @@ function Format-LoggingCommand {
156171
if ($first) {
157172
$null = $sb.Append(' ')
158173
$first = $false
159-
} else {
174+
}
175+
else {
160176
$null = $sb.Append(';')
161177
}
162178

@@ -193,7 +209,8 @@ function Write-LoggingCommand {
193209
$command = Format-LoggingCommand -Area $Area -Event $Event -Data $Data -Properties $Properties
194210
if ($AsOutput) {
195211
$command
196-
} else {
212+
}
213+
else {
197214
Write-Host $command
198215
}
199216
}
@@ -212,12 +229,12 @@ function Write-LogIssue {
212229
[switch]$AsOutput)
213230

214231
$command = Format-LoggingCommand -Area 'task' -Event 'logissue' -Data $Message -Properties @{
215-
'type' = $Type
216-
'code' = $ErrCode
217-
'sourcepath' = $SourcePath
218-
'linenumber' = $LineNumber
219-
'columnnumber' = $ColumnNumber
220-
}
232+
'type' = $Type
233+
'code' = $ErrCode
234+
'sourcepath' = $SourcePath
235+
'linenumber' = $LineNumber
236+
'columnnumber' = $ColumnNumber
237+
}
221238
if ($AsOutput) {
222239
return $command
223240
}
@@ -229,7 +246,8 @@ function Write-LogIssue {
229246
$foregroundColor = [System.ConsoleColor]::Red
230247
$backgroundColor = [System.ConsoleColor]::Black
231248
}
232-
} else {
249+
}
250+
else {
233251
$foregroundColor = $host.PrivateData.WarningForegroundColor
234252
$backgroundColor = $host.PrivateData.WarningBackgroundColor
235253
if ($foregroundColor -isnot [System.ConsoleColor] -or $backgroundColor -isnot [System.ConsoleColor]) {

0 commit comments

Comments
 (0)