Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 4854ad7

Browse files
committed
Sync init-tools scripts with what is in source-build
1 parent 6c45610 commit 4854ad7

File tree

2 files changed

+58
-58
lines changed

2 files changed

+58
-58
lines changed

init-tools.cmd

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if [%1]==[force] (
2121

2222
:: If semaphore exists do nothing
2323
if exist "%BUILD_TOOLS_SEMAPHORE%" (
24-
echo %__MsgPrefix%Tools are already initialized.
24+
echo Tools are already initialized.
2525
goto :EOF
2626
)
2727

@@ -37,6 +37,7 @@ if exist "%DotNetBuildToolsDir%" (
3737
)
3838

3939
echo Done initializing tools.
40+
if NOT exist "%BUILD_TOOLS_SEMAPHORE_DIR%" mkdir "%BUILD_TOOLS_SEMAPHORE_DIR%"
4041
echo Using tools from '%DotNetBuildToolsDir%'. > "%BUILD_TOOLS_SEMAPHORE%"
4142
exit /b 0
4243
)
@@ -46,26 +47,26 @@ echo Running %0 > "%INIT_TOOLS_LOG%"
4647
set /p DOTNET_VERSION=< "%~dp0DotnetCLIVersion.txt"
4748
if exist "%DOTNET_CMD%" goto :afterdotnetrestore
4849

49-
echo %__MsgPrefix%Installing dotnet cli...
50+
echo Installing dotnet cli...
5051
if NOT exist "%DOTNET_PATH%" mkdir "%DOTNET_PATH%"
5152
set DOTNET_ZIP_NAME=dotnet-sdk-%DOTNET_VERSION%-win-x64.zip
5253
set DOTNET_REMOTE_PATH=https://dotnetcli.azureedge.net/dotnet/Sdk/%DOTNET_VERSION%/%DOTNET_ZIP_NAME%
5354
set DOTNET_LOCAL_PATH=%DOTNET_PATH%%DOTNET_ZIP_NAME%
54-
echo %__MsgPrefix%Installing '%DOTNET_REMOTE_PATH%' to '%DOTNET_LOCAL_PATH%' >> "%INIT_TOOLS_LOG%"
55-
powershell -NoProfile -ExecutionPolicy unrestricted -Command "$retryCount = 0; $success = $false; do { try { (New-Object Net.WebClient).DownloadFile('%DOTNET_REMOTE_PATH%', '%DOTNET_LOCAL_PATH%'); $success = $true; } catch { if ($retryCount -ge 6) { throw; } else { $retryCount++; Start-Sleep -Seconds (5 * $retryCount); } } } while ($success -eq $false); Add-Type -Assembly 'System.IO.Compression.FileSystem' -ErrorVariable AddTypeErrors; if ($AddTypeErrors.Count -eq 0) { [System.IO.Compression.ZipFile]::ExtractToDirectory('%DOTNET_LOCAL_PATH%', '%DOTNET_PATH%') } else { (New-Object -com shell.application).namespace('%DOTNET_PATH%').CopyHere((new-object -com shell.application).namespace('%DOTNET_LOCAL_PATH%').Items(),16) }" >> "%INIT_TOOLS_LOG%"
55+
echo Installing '%DOTNET_REMOTE_PATH%' to '%DOTNET_LOCAL_PATH%' >> "%INIT_TOOLS_LOG%"
56+
powershell -NoProfile -ExecutionPolicy unrestricted -Command "$retryCount = 0; $success = $false; $proxyCredentialsRequired = $false; do { try { $wc = New-Object Net.WebClient; if ($proxyCredentialsRequired) { [Net.WebRequest]::DefaultWebProxy.Credentials = [Net.CredentialCache]::DefaultNetworkCredentials; } $wc.DownloadFile('%DOTNET_REMOTE_PATH%', '%DOTNET_LOCAL_PATH%'); $success = $true; } catch { if ($retryCount -ge 6) { throw; } else { $we = $_.Exception.InnerException -as [Net.WebException]; $proxyCredentialsRequired = ($we -ne $null -and ([Net.HttpWebResponse]$we.Response).StatusCode -eq [Net.HttpStatusCode]::ProxyAuthenticationRequired); Start-Sleep -Seconds (5 * $retryCount); $retryCount++; } } } while ($success -eq $false); Add-Type -Assembly 'System.IO.Compression.FileSystem' -ErrorVariable AddTypeErrors; if ($AddTypeErrors.Count -eq 0) { [System.IO.Compression.ZipFile]::ExtractToDirectory('%DOTNET_LOCAL_PATH%', '%DOTNET_PATH%') } else { (New-Object -com shell.application).namespace('%DOTNET_PATH%').CopyHere((new-object -com shell.application).namespace('%DOTNET_LOCAL_PATH%').Items(),16) }" >> "%INIT_TOOLS_LOG%"
5657
if NOT exist "%DOTNET_LOCAL_PATH%" (
57-
echo %__MsgPrefix%ERROR: Could not install dotnet cli correctly. 1>&2
58+
echo ERROR: Could not install dotnet cli correctly. 1>&2
5859
goto :error
5960
)
6061

6162
:afterdotnetrestore
6263

6364
if exist "%BUILD_TOOLS_PATH%" goto :afterbuildtoolsrestore
64-
echo %__MsgPrefix%Restoring BuildTools version %BUILDTOOLS_VERSION%...
65-
echo %__MsgPrefix%Running: "%DOTNET_CMD%" restore "%INIT_TOOLS_RESTORE_PROJECT%" --no-cache --packages %PACKAGES_DIR% --source "%BUILDTOOLS_SOURCE%" /p:BuildToolsPackageVersion=%BUILDTOOLS_VERSION% /p:ToolsDir=%TOOLRUNTIME_DIR% >> "%INIT_TOOLS_LOG%"
65+
echo Restoring BuildTools version %BUILDTOOLS_VERSION%...
66+
echo Running: "%DOTNET_CMD%" restore "%INIT_TOOLS_RESTORE_PROJECT%" --no-cache --packages %PACKAGES_DIR% --source "%BUILDTOOLS_SOURCE%" /p:BuildToolsPackageVersion=%BUILDTOOLS_VERSION% /p:ToolsDir=%TOOLRUNTIME_DIR% >> "%INIT_TOOLS_LOG%"
6667
call "%DOTNET_CMD%" restore "%INIT_TOOLS_RESTORE_PROJECT%" --no-cache --packages %PACKAGES_DIR% --source "%BUILDTOOLS_SOURCE%" /p:BuildToolsPackageVersion=%BUILDTOOLS_VERSION% /p:ToolsDir=%TOOLRUNTIME_DIR% >> "%INIT_TOOLS_LOG%"
6768
if NOT exist "%BUILD_TOOLS_PATH%init-tools.cmd" (
68-
%__MsgPrefix%echo ERROR: Could not restore build tools correctly. 1>&2
69+
echo ERROR: Could not restore build tools correctly. 1>&2
6970
goto :error
7071
)
7172

@@ -74,8 +75,8 @@ if NOT exist "%BUILD_TOOLS_PATH%init-tools.cmd" (
7475
:: Ask init-tools to also restore ILAsm
7576
set /p ILASMCOMPILER_VERSION=< "%~dp0ILAsmVersion.txt"
7677

77-
echo %__MsgPrefix%Initializing BuildTools...
78-
echo %__MsgPrefix%Running: "%BUILD_TOOLS_PATH%init-tools.cmd" "%~dp0" "%DOTNET_CMD%" "%TOOLRUNTIME_DIR%" >> "%INIT_TOOLS_LOG%"
78+
echo Initializing BuildTools...
79+
echo Running: "%BUILD_TOOLS_PATH%init-tools.cmd" "%~dp0" "%DOTNET_CMD%" "%TOOLRUNTIME_DIR%" >> "%INIT_TOOLS_LOG%"
7980
call "%BUILD_TOOLS_PATH%init-tools.cmd" "%~dp0" "%DOTNET_CMD%" "%TOOLRUNTIME_DIR%" >> "%INIT_TOOLS_LOG%"
8081
set INIT_TOOLS_ERRORLEVEL=%ERRORLEVEL%
8182
if not [%INIT_TOOLS_ERRORLEVEL%]==[0] (
@@ -84,14 +85,12 @@ if not [%INIT_TOOLS_ERRORLEVEL%]==[0] (
8485
)
8586

8687
:: Create semaphore file
87-
echo %__MsgPrefix%Done initializing tools.
88-
if NOT exist "%BUILD_TOOLS_SEMAPHORE_DIR%" (
89-
mkdir "%BUILD_TOOLS_SEMAPHORE_DIR%"
90-
)
91-
echo %__MsgPrefix%Init-Tools.cmd completed for BuildTools Version: %BUILDTOOLS_VERSION% > "%BUILD_TOOLS_SEMAPHORE%"
88+
echo Done initializing tools.
89+
if NOT exist "%BUILD_TOOLS_SEMAPHORE_DIR%" mkdir "%BUILD_TOOLS_SEMAPHORE_DIR%"
90+
echo Init-Tools.cmd completed for BuildTools Version: %BUILDTOOLS_VERSION% > "%BUILD_TOOLS_SEMAPHORE%"
9291
exit /b 0
9392

9493
:error
95-
echo %__MsgPrefix%Please check the detailed log that follows. 1>&2
94+
echo Please check the detailed log that follows. 1>&2
9695
type "%INIT_TOOLS_LOG%" 1>&2
9796
exit /b 1

init-tools.sh

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
#!/usr/bin/env bash
22

33
__scriptpath=$(cd "$(dirname "$0")"; pwd -P)
4-
__init_tools_log=$__scriptpath/init-tools.log
5-
__PACKAGES_DIR=$__scriptpath/packages
6-
__TOOLRUNTIME_DIR=$__scriptpath/Tools
7-
__DOTNET_PATH=$__TOOLRUNTIME_DIR/dotnetcli
8-
__DOTNET_CMD=$__DOTNET_PATH/dotnet
9-
if [ -z "$__BUILDTOOLS_SOURCE" ]; then __BUILDTOOLS_SOURCE=https://dotnet.myget.org/F/dotnet-buildtools/api/v3/index.json; fi
4+
__init_tools_log="$__scriptpath/init-tools.log"
5+
__PACKAGES_DIR="$__scriptpath/packages"
6+
__TOOLRUNTIME_DIR="$__scriptpath/Tools"
7+
__DOTNET_PATH="$__TOOLRUNTIME_DIR/dotnetcli"
8+
__DOTNET_CMD="$__DOTNET_PATH/dotnet"
9+
if [ -z "${__BUILDTOOLS_SOURCE:-}" ]; then __BUILDTOOLS_SOURCE=https://dotnet.myget.org/F/dotnet-buildtools/api/v3/index.json; fi
1010
export __BUILDTOOLS_USE_CSPROJ=true
11-
__BUILD_TOOLS_PACKAGE_VERSION=$(cat $__scriptpath/BuildToolsVersion.txt)
12-
__DOTNET_TOOLS_VERSION=$(cat $__scriptpath/DotnetCLIVersion.txt)
13-
__ILASM_VERSION=$(cat $__scriptpath/ILAsmVersion.txt)
14-
__BUILD_TOOLS_PATH=$__PACKAGES_DIR/microsoft.dotnet.buildtools/$__BUILD_TOOLS_PACKAGE_VERSION/lib
15-
__INIT_TOOLS_RESTORE_PROJECT=$__scriptpath/init-tools.msbuild
16-
__BUILD_TOOLS_SEMAPHORE=$__TOOLRUNTIME_DIR/$__BUILD_TOOLS_PACKAGE_VERSION/init-tools.complete
17-
18-
if [ -e $__BUILD_TOOLS_SEMAPHORE ]; then
11+
__BUILD_TOOLS_PACKAGE_VERSION=$(cat "$__scriptpath/BuildToolsVersion.txt" | sed 's/\r$//') # remove CR if mounted repo on Windows drive
12+
__DOTNET_TOOLS_VERSION=$(cat "$__scriptpath/DotnetCLIVersion.txt" | sed 's/\r$//') # remove CR if mounted repo on Windows drive
13+
__ILASM_VERSION=$(cat "$__scriptpath/ILAsmVersion.txt" | sed 's/\r$//') # remove CR if mounted repo on Windows drive
14+
__BUILD_TOOLS_PATH="$__PACKAGES_DIR/microsoft.dotnet.buildtools/$__BUILD_TOOLS_PACKAGE_VERSION/lib"
15+
__INIT_TOOLS_RESTORE_PROJECT="$__scriptpath/init-tools.msbuild"
16+
__BUILD_TOOLS_SEMAPHORE="$__TOOLRUNTIME_DIR/$__BUILD_TOOLS_PACKAGE_VERSION/init-tools.complete"
17+
18+
if [ -e "$__BUILD_TOOLS_SEMAPHORE" ]; then
1919
echo "Tools are already initialized"
2020
return #return instead of exit because this script is inlined in other scripts which we don't want to exit
2121
fi
2222

23-
if [ -e $__TOOLRUNTIME_DIR ]; then rm -rf -- $__TOOLRUNTIME_DIR; fi
23+
if [ -e "$__TOOLRUNTIME_DIR" ]; then rm -rf -- "$__TOOLRUNTIME_DIR"; fi
2424

25-
if [ -d "$DotNetBuildToolsDir" ]; then
25+
if [ -d "${DotNetBuildToolsDir:-}" ]; then
2626
echo "Using tools from '$DotNetBuildToolsDir'."
2727
ln -s "$DotNetBuildToolsDir" "$__TOOLRUNTIME_DIR"
2828

@@ -32,11 +32,11 @@ if [ -d "$DotNetBuildToolsDir" ]; then
3232
fi
3333

3434
echo "Done initializing tools."
35-
mkdir -p "$(dirname "$__BUILD_TOOLS_SEMAPHORE")" && touch $__BUILD_TOOLS_SEMAPHORE
35+
mkdir -p "$(dirname "$__BUILD_TOOLS_SEMAPHORE")" && touch "$__BUILD_TOOLS_SEMAPHORE"
3636
return #return instead of exit because this script is inlined in other scripts which we don't want to exit
3737
fi
3838

39-
echo "Running: $__scriptpath/init-tools.sh" > $__init_tools_log
39+
echo "Running: $__scriptpath/init-tools.sh" > "$__init_tools_log"
4040

4141
display_error_message()
4242
{
@@ -48,15 +48,15 @@ display_error_message()
4848
execute_with_retry() {
4949
local count=0
5050
local retries=${retries:-5}
51-
local waitFactor=${waitFactor:-6}
51+
local waitFactor=${waitFactor:-6}
5252
until "$@"; do
5353
local exit=$?
5454
count=$(( $count + 1 ))
5555
if [ $count -lt $retries ]; then
5656
local wait=$(( waitFactor ** (( count - 1 )) ))
5757
echo "Retry $count/$retries exited $exit, retrying in $wait seconds..."
5858
sleep $wait
59-
else
59+
else
6060
say_err "Retry $count/$retries exited $exit, no more retries left."
6161
return $exit
6262
fi
@@ -65,8 +65,8 @@ execute_with_retry() {
6565
return 0
6666
}
6767

68-
if [ ! -e $__DOTNET_PATH ]; then
69-
if [ -z "$__DOTNET_PKG" ]; then
68+
if [ ! -e "$__DOTNET_PATH" ]; then
69+
if [ -z "${__DOTNET_PKG:-}" ]; then
7070
if [ "$(uname -m | grep "i[3456]86")" = "i686" ]; then
7171
echo "Warning: build not supported on 32 bit Unix"
7272
fi
@@ -96,12 +96,12 @@ if [ ! -e $__DOTNET_PATH ]; then
9696
if [[ $ID == "alpine" ]]; then
9797
# remove the last version digit
9898
VERSION_ID=${VERSION_ID%.*}
99-
__PKG_RID=alpine.$VERSION_ID
99+
__PKG_RID=alpine.$VERSION_ID
100100
fi
101101
elif [ -e /etc/redhat-release ]; then
102102
redhatRelease=$(</etc/redhat-release)
103103
if [[ $redhatRelease == "CentOS release 6."* || $redhatRelease == "Red Hat Enterprise Linux Server release 6."* ]]; then
104-
__PKG_RID=rhel.6
104+
__PKG_RID=rhel.6
105105
fi
106106
fi
107107

@@ -112,16 +112,17 @@ if [ ! -e $__DOTNET_PATH ]; then
112112
OS=Linux
113113
__PKG_RID=linux
114114
;;
115-
esac
116-
__DOTNET_PKG=dotnet-sdk-${__DOTNET_TOOLS_VERSION}-$__PKG_RID-$__PKG_ARCH
115+
esac
116+
117+
__DOTNET_PKG=dotnet-sdk-${__DOTNET_TOOLS_VERSION}-$__PKG_RID-$__PKG_ARCH
117118
fi
118119
mkdir -p "$__DOTNET_PATH"
119120

120121
echo "Installing dotnet cli..."
121122
__DOTNET_LOCATION="https://dotnetcli.azureedge.net/dotnet/Sdk/${__DOTNET_TOOLS_VERSION}/${__DOTNET_PKG}.tar.gz"
122123

123124
install_dotnet_cli() {
124-
if [[ "$DotNetBootstrapCliTarPath" = "" ]]; then
125+
if [[ -z "${DotNetBootstrapCliTarPath-}" ]]; then
125126
echo "Installing '${__DOTNET_LOCATION}' to '$__DOTNET_PATH/dotnet.tar'"
126127
rm -rf -- "$__DOTNET_PATH/*"
127128
# curl has HTTPS CA trust-issues less often than wget, so lets try that first.
@@ -134,25 +135,25 @@ if [ ! -e $__DOTNET_PATH ]; then
134135
echo "Copying '$DotNetBootstrapCliTarPath' to '$__DOTNET_PATH/dotnet.tar'"
135136
cp $DotNetBootstrapCliTarPath $__DOTNET_PATH/dotnet.tar
136137
fi
137-
cd $__DOTNET_PATH
138-
tar -xf $__DOTNET_PATH/dotnet.tar
138+
cd "$__DOTNET_PATH"
139+
tar -xf "$__DOTNET_PATH/dotnet.tar"
139140
}
140141
execute_with_retry install_dotnet_cli >> "$__init_tools_log" 2>&1
141142

142-
cd $__scriptpath
143+
cd "$__scriptpath"
143144
fi
144145

145-
if [ ! -e $__BUILD_TOOLS_PATH ]; then
146+
if [ ! -e "$__BUILD_TOOLS_PATH" ]; then
146147
echo "Restoring BuildTools version $__BUILD_TOOLS_PACKAGE_VERSION..."
147-
echo "Running: $__DOTNET_CMD restore \"$__INIT_TOOLS_RESTORE_PROJECT\" --no-cache --packages $__PACKAGES_DIR --source $__BUILDTOOLS_SOURCE /p:BuildToolsPackageVersion=$__BUILD_TOOLS_PACKAGE_VERSION /p:ToolsDir=$__TOOLRUNTIME_DIR" >> $__init_tools_log
148-
$__DOTNET_CMD restore "$__INIT_TOOLS_RESTORE_PROJECT" --no-cache --packages $__PACKAGES_DIR --source $__BUILDTOOLS_SOURCE /p:BuildToolsPackageVersion=$__BUILD_TOOLS_PACKAGE_VERSION /p:ToolsDir=$__TOOLRUNTIME_DIR >> $__init_tools_log
148+
echo "Running: $__DOTNET_CMD restore \"$__INIT_TOOLS_RESTORE_PROJECT\" --no-cache --packages $__PACKAGES_DIR --source $__BUILDTOOLS_SOURCE /p:BuildToolsPackageVersion=$__BUILD_TOOLS_PACKAGE_VERSION /p:ToolsDir=$__TOOLRUNTIME_DIR" >> "$__init_tools_log"
149+
"$__DOTNET_CMD" restore "$__INIT_TOOLS_RESTORE_PROJECT" --no-cache --packages "$__PACKAGES_DIR" --source "$__BUILDTOOLS_SOURCE" /p:BuildToolsPackageVersion=$__BUILD_TOOLS_PACKAGE_VERSION /p:ToolsDir="$__TOOLRUNTIME_DIR" >> "$__init_tools_log"
149150
if [ ! -e "$__BUILD_TOOLS_PATH/init-tools.sh" ]; then
150151
echo "ERROR: Could not restore build tools correctly." 1>&2
151152
display_error_message
152153
fi
153154
fi
154155

155-
if [ -z "$__ILASM_RID" ]; then
156+
if [ -z "${__ILASM_RID-}" ]; then
156157
__ILASM_RID=$__PKG_RID-$__PKG_ARCH
157158
fi
158159

@@ -161,17 +162,17 @@ echo "Using RID $__ILASM_RID for BuildTools native tools"
161162
export ILASMCOMPILER_VERSION=$__ILASM_VERSION
162163
export NATIVE_TOOLS_RID=$__ILASM_RID
163164

164-
if [ ! "$DotNetBootstrapCliTarPath" = "" ]; then
165+
if [ -n "${DotNetBootstrapCliTarPath-}" ]; then
165166
# Assume ilasm is not in nuget yet when bootstrapping...
166167
unset ILASMCOMPILER_VERSION
167168
fi
168169

169170
echo "Initializing BuildTools..."
170-
echo "Running: $__BUILD_TOOLS_PATH/init-tools.sh $__scriptpath $__DOTNET_CMD $__TOOLRUNTIME_DIR $__PACKAGES_DIR" >> $__init_tools_log
171+
echo "Running: $__BUILD_TOOLS_PATH/init-tools.sh $__scriptpath $__DOTNET_CMD $__TOOLRUNTIME_DIR $__PACKAGES_DIR" >> "$__init_tools_log"
171172

172173
# Executables restored with .NET Core 2.0 do not have executable permission flags. https://github.com/NuGet/Home/issues/4424
173-
chmod +x $__BUILD_TOOLS_PATH/init-tools.sh
174-
$__BUILD_TOOLS_PATH/init-tools.sh $__scriptpath $__DOTNET_CMD $__TOOLRUNTIME_DIR $__PACKAGES_DIR >> $__init_tools_log
174+
chmod +x "$__BUILD_TOOLS_PATH/init-tools.sh"
175+
"$__BUILD_TOOLS_PATH/init-tools.sh" "$__scriptpath" "$__DOTNET_CMD" "$__TOOLRUNTIME_DIR" "$__PACKAGES_DIR" >> "$__init_tools_log"
175176
if [ "$?" != "0" ]; then
176177
echo "ERROR: An error occurred when trying to initialize the tools." 1>&2
177178
display_error_message
@@ -180,12 +181,12 @@ fi
180181

181182
echo "Making all .sh files executable under Tools."
182183
# Executables restored with .NET Core 2.0 do not have executable permission flags. https://github.com/NuGet/Home/issues/4424
183-
ls $__scriptpath/Tools/*.sh | xargs chmod +x
184-
ls $__scriptpath/Tools/scripts/docker/*.sh | xargs chmod +x
184+
ls "$__scriptpath/Tools/"*.sh | xargs chmod +x
185+
ls "$__scriptpath/Tools/scripts/docker/"*.sh | xargs chmod +x
185186

186-
Tools/crossgen.sh $__scriptpath/Tools
187+
"$__scriptpath/Tools/crossgen.sh" "$__scriptpath/Tools"
187188

188-
mkdir -p "$(dirname "$__BUILD_TOOLS_SEMAPHORE")" && touch $__BUILD_TOOLS_SEMAPHORE
189+
mkdir -p "$(dirname "$__BUILD_TOOLS_SEMAPHORE")" && touch "$__BUILD_TOOLS_SEMAPHORE"
189190

190191
echo "Done initializing tools."
191192

0 commit comments

Comments
 (0)