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

Commit 35903bc

Browse files
committed
Sync init-tools scripts with what is in source-build
1 parent 8130620 commit 35903bc

File tree

2 files changed

+45
-45
lines changed

2 files changed

+45
-45
lines changed

init-tools.cmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ if exist "%BUILD_TOOLS_SEMAPHORE%" (
2727

2828
if exist "%TOOLRUNTIME_DIR%" rmdir /S /Q "%TOOLRUNTIME_DIR%"
2929

30-
if NOT exist "%BUILD_TOOLS_SEMAPHORE_DIR%" mkdir "%BUILD_TOOLS_SEMAPHORE_DIR%"
31-
3230
if exist "%DotNetBuildToolsDir%" (
3331
echo Using tools from '%DotNetBuildToolsDir%'.
3432
mklink /j "%TOOLRUNTIME_DIR%" "%DotNetBuildToolsDir%"
@@ -39,6 +37,7 @@ if exist "%DotNetBuildToolsDir%" (
3937
)
4038

4139
echo Done initializing tools.
40+
if NOT exist "%BUILD_TOOLS_SEMAPHORE_DIR%" mkdir "%BUILD_TOOLS_SEMAPHORE_DIR%"
4241
echo Using tools from '%DotNetBuildToolsDir%'. > "%BUILD_TOOLS_SEMAPHORE%"
4342
exit /b 0
4443
)
@@ -64,8 +63,8 @@ if NOT exist "%DOTNET_LOCAL_PATH%" (
6463

6564
if exist "%BUILD_TOOLS_PATH%" goto :afterbuildtoolsrestore
6665
echo Restoring BuildTools version %BUILDTOOLS_VERSION%...
67-
echo Running: "%DOTNET_CMD%" restore "%INIT_TOOLS_RESTORE_PROJECT%" --no-cache --packages %PACKAGES_DIR% --source "%BUILDTOOLS_SOURCE%" /p:BuildToolsPackageVersion=%BUILDTOOLS_VERSION% >> "%INIT_TOOLS_LOG%"
68-
call "%DOTNET_CMD%" restore "%INIT_TOOLS_RESTORE_PROJECT%" --no-cache --packages %PACKAGES_DIR% --source "%BUILDTOOLS_SOURCE%" /p:BuildToolsPackageVersion=%BUILDTOOLS_VERSION% >> "%INIT_TOOLS_LOG%"
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%"
67+
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%"
6968
if NOT exist "%BUILD_TOOLS_PATH%init-tools.cmd" (
7069
echo ERROR: Could not restore build tools correctly. 1>&2
7170
goto :error
@@ -87,6 +86,7 @@ if not [%INIT_TOOLS_ERRORLEVEL%]==[0] (
8786

8887
:: Create semaphore file
8988
echo Done initializing tools.
89+
if NOT exist "%BUILD_TOOLS_SEMAPHORE_DIR%" mkdir "%BUILD_TOOLS_SEMAPHORE_DIR%"
9090
echo Init-Tools.cmd completed for BuildTools Version: %BUILDTOOLS_VERSION% > "%BUILD_TOOLS_SEMAPHORE%"
9191
exit /b 0
9292

init-tools.sh

Lines changed: 41 additions & 41 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 | 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/tools-local/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
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/tools-local/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
{
@@ -65,13 +65,13 @@ 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
7373

74-
__PKG_ARCH=x64
74+
__PKG_ARCH=x64
7575

7676
OSName=$(uname -s)
7777
case $OSName in
@@ -88,7 +88,7 @@ if [ ! -e $__DOTNET_PATH ]; then
8888
;;
8989

9090
Linux)
91-
__PKG_RID=linux
91+
__PKG_RID=linux
9292
OS=Linux
9393

9494
if [ -e /etc/os-release ]; then
@@ -108,21 +108,21 @@ if [ ! -e $__DOTNET_PATH ]; then
108108
;;
109109

110110
*)
111-
echo "Unsupported OS '$OSName' detected. Downloading linux-$__PKG_ARCH tools."
111+
echo "Unsupported OS '$OSName' detected. Downloading linux-$__PKG_ARCH tools."
112112
OS=Linux
113113
__PKG_RID=linux
114114
;;
115-
esac
115+
esac
116116

117-
__DOTNET_PKG=dotnet-sdk-${__DOTNET_TOOLS_VERSION}-$__PKG_RID-$__PKG_ARCH
117+
__DOTNET_PKG=dotnet-sdk-${__DOTNET_TOOLS_VERSION}-$__PKG_RID-$__PKG_ARCH
118118
fi
119119
mkdir -p "$__DOTNET_PATH"
120120

121121
echo "Installing dotnet cli..."
122122
__DOTNET_LOCATION="https://dotnetcli.azureedge.net/dotnet/Sdk/${__DOTNET_TOOLS_VERSION}/${__DOTNET_PKG}.tar.gz"
123123

124124
install_dotnet_cli() {
125-
if [[ "$DotNetBootstrapCliTarPath" = "" ]]; then
125+
if [[ -z "${DotNetBootstrapCliTarPath-}" ]]; then
126126
echo "Installing '${__DOTNET_LOCATION}' to '$__DOTNET_PATH/dotnet.tar'"
127127
rm -rf -- "$__DOTNET_PATH/*"
128128
# curl has HTTPS CA trust-issues less often than wget, so lets try that first.
@@ -135,25 +135,25 @@ if [ ! -e $__DOTNET_PATH ]; then
135135
echo "Copying '$DotNetBootstrapCliTarPath' to '$__DOTNET_PATH/dotnet.tar'"
136136
cp $DotNetBootstrapCliTarPath $__DOTNET_PATH/dotnet.tar
137137
fi
138-
cd $__DOTNET_PATH
139-
tar -xf $__DOTNET_PATH/dotnet.tar
138+
cd "$__DOTNET_PATH"
139+
tar -xf "$__DOTNET_PATH/dotnet.tar"
140140
}
141141
execute_with_retry install_dotnet_cli >> "$__init_tools_log" 2>&1
142142

143-
cd $__scriptpath
143+
cd "$__scriptpath"
144144
fi
145145

146-
if [ ! -e $__BUILD_TOOLS_PATH ]; then
146+
if [ ! -e "$__BUILD_TOOLS_PATH" ]; then
147147
echo "Restoring BuildTools version $__BUILD_TOOLS_PACKAGE_VERSION..."
148-
echo "Running: $__DOTNET_CMD restore \"$__INIT_TOOLS_RESTORE_PROJECT\" --no-cache --packages $__PACKAGES_DIR --source $__BUILDTOOLS_SOURCE /p:BuildToolsPackageVersion=$__BUILD_TOOLS_PACKAGE_VERSION" >> $__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 >> $__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"
150150
if [ ! -e "$__BUILD_TOOLS_PATH/init-tools.sh" ]; then
151151
echo "ERROR: Could not restore build tools correctly." 1>&2
152152
display_error_message
153153
fi
154154
fi
155155

156-
if [ -z "$__ILASM_RID" ]; then
156+
if [ -z "${__ILASM_RID-}" ]; then
157157
__ILASM_RID=$__PKG_RID-$__PKG_ARCH
158158
fi
159159

@@ -162,17 +162,17 @@ echo "Using RID $__ILASM_RID for BuildTools native tools"
162162
export ILASMCOMPILER_VERSION=$__ILASM_VERSION
163163
export NATIVE_TOOLS_RID=$__ILASM_RID
164164

165-
if [ ! "$DotNetBootstrapCliTarPath" = "" ]; then
165+
if [ -n "${DotNetBootstrapCliTarPath-}" ]; then
166166
# Assume ilasm is not in nuget yet when bootstrapping...
167167
unset ILASMCOMPILER_VERSION
168168
fi
169169

170170
echo "Initializing BuildTools..."
171-
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"
172172

173173
# Executables restored with .NET Core 2.0 do not have executable permission flags. https://github.com/NuGet/Home/issues/4424
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
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"
176176
if [ "$?" != "0" ]; then
177177
echo "ERROR: An error occurred when trying to initialize the tools." 1>&2
178178
display_error_message
@@ -181,12 +181,12 @@ fi
181181

182182
echo "Making all .sh files executable under Tools."
183183
# Executables restored with .NET Core 2.0 do not have executable permission flags. https://github.com/NuGet/Home/issues/4424
184-
ls $__scriptpath/Tools/*.sh | xargs chmod +x
185-
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
186186

187-
Tools/crossgen.sh $__scriptpath/Tools
187+
"$__scriptpath/Tools/crossgen.sh" "$__scriptpath/Tools"
188188

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

191191
echo "Done initializing tools."
192192

0 commit comments

Comments
 (0)