Skip to content

Commit e89f045

Browse files
authored
Merge pull request #1611 from omajid/test-sdk-diff
WIP: Add a test to compare two SDK and show file diff
2 parents 6686cd7 + 9da44d5 commit e89f045

File tree

3 files changed

+173
-4
lines changed

3 files changed

+173
-4
lines changed

scripts/compare-builds.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/bash
2+
3+
# Tests to compare 2 SDK builds - generally a Microsoft-built SDK and
4+
# a source-build SDK. This should help us find issues/surprises before
5+
# we ship out a source-built SDK.
6+
#
7+
# See --help for more details, including usage
8+
9+
set -euo pipefail
10+
IFS=$'\n\t'
11+
12+
# Filter out some directories that are special and source-build only:
13+
# - reference-packages/
14+
# - source-built-artifacts/
15+
paths_to_ignore_regex='\.\/reference-packages|\./source-built-artifacts'
16+
17+
function usage() {
18+
echo ""
19+
echo "usage: $0 SDK1_TARBALL SDK2_TARBALL"
20+
echo ""
21+
echo "Compare 2 SDK builds to spot differences and potential regressions or other bugs."
22+
}
23+
24+
function print_sdk_contents() {
25+
sdk=$1
26+
if [ -d "$sdk" ]; then
27+
pushd "$sdk" >/dev/null
28+
# We use two find invocation so we can add a / to the directories to match the file listing from tar
29+
(find . -type d -print | sed -e 's|$|/|'; find . '!' -type d -print) \
30+
| sort -u \
31+
| grep -v -E "$paths_to_ignore_regex"
32+
popd >/dev/null
33+
else
34+
if [[ "$sdk" =~ .*tar\.gz ]]; then
35+
tar tf "$sdk" | sort -u | grep -v -E "$paths_to_ignore_regex"
36+
else
37+
echo "error: Unknown file type ${sdk}"
38+
exit 1
39+
fi
40+
fi
41+
}
42+
43+
function cleanup() {
44+
if [ -d "$workdir" ]; then
45+
rm -rf "$workdir"
46+
fi
47+
}
48+
49+
positional_args=()
50+
while :; do
51+
if [ $# -le 0 ]; then
52+
break
53+
fi
54+
lowerI="$(echo "$1" | awk '{print tolower($0)}')"
55+
case $lowerI in
56+
"-?"|-h|--help)
57+
usage
58+
exit 0
59+
;;
60+
*)
61+
positional_args+=("$1")
62+
;;
63+
esac
64+
65+
shift
66+
done
67+
68+
sdk1=${positional_args[0]:-}
69+
if [[ -z ${sdk1} ]]; then
70+
echo "error: missing argument."
71+
usage
72+
exit 1
73+
fi
74+
sdk1=$(readlink -f "$sdk1")
75+
76+
sdk2=${positional_args[1]:-}
77+
if [[ -z ${sdk2} ]]; then
78+
echo "error: missing argument."
79+
usage
80+
exit 1
81+
fi
82+
sdk2=$(readlink -f "$sdk2")
83+
84+
workdir=$(mktemp -d)
85+
file1="${workdir}/sdk-at-$(echo "$sdk1" | sed -e 's|/|-|g')"
86+
file2="${workdir}/sdk-at-$(echo "$sdk2" | sed -e 's|/|-|g')"
87+
88+
print_sdk_contents "$sdk1" > "$file1"
89+
print_sdk_contents "$sdk2" > "$file2"
90+
91+
echo "--- $sdk1"
92+
echo "+++ $sdk2"
93+
94+
trap cleanup EXIT
95+
96+
# The files noare not part of any repository. We could use plain `diff` here,
97+
# but it's not available on some platforms.
98+
git diff --no-index "$file1" "$file2" | tail -n +3

scripts/fetch-microsoft-sdk.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
3+
# Download a .NET Core SDK published by Microsoft.
4+
#
5+
# See --help for more details, including usage
6+
7+
set -euo pipefail
8+
IFS=$'\n\t'
9+
10+
function usage() {
11+
echo ""
12+
echo "usage: $0 SDK_VERSION [output-location]"
13+
echo ""
14+
echo "Download a particular .NET Core SDK built by Microsoft based on exact version match."
15+
}
16+
17+
positional_args=()
18+
while :; do
19+
if [ $# -le 0 ]; then
20+
break
21+
fi
22+
lowerI="$(echo "$1" | awk '{print tolower($0)}')"
23+
case $lowerI in
24+
"-?"|-h|--help)
25+
usage
26+
exit 0
27+
;;
28+
*)
29+
positional_args+=("$1")
30+
;;
31+
esac
32+
33+
shift
34+
done
35+
36+
sdk_version=${positional_args[0]:-}
37+
if [[ -z ${sdk_version} ]]; then
38+
echo "error: missing argument."
39+
usage
40+
exit 1
41+
fi
42+
43+
output_location=${positional_args[1]:-dotnet-microsoft-built-sdk-${sdk_version}.tar.gz}
44+
45+
install_script_url=https://dot.net/v1/dotnet-install.sh
46+
install_script_dir=$(mktemp -d)
47+
install_script=${install_script_dir}/dotnet-install.sh
48+
49+
# Use curl if available, otherwise use wget
50+
if command -v curl > /dev/null; then
51+
curl "${install_script_url}" -sSL --retry 10 --create-dirs -o "${install_script}"
52+
else
53+
wget -q -O "${install_script}" "${install_script_url}"
54+
fi
55+
56+
chmod +x "${install_script}"
57+
url=$("${install_script_dir}/dotnet-install.sh" --dry-run --version "${sdk_version}" | grep https | sed -E 's|.*(https://.*tar.gz)$|\1|' | head -1)
58+
echo "${url}"
59+
60+
# Use curl if available, otherwise use wget
61+
if command -v curl > /dev/null; then
62+
curl "${url}" -sSL --retry 10 --create-dirs -o "${output_location}"
63+
else
64+
wget -q -O "${output_location}" "${url}"
65+
fi
66+
67+
rm "${install_script}"
68+
rmdir "${install_script_dir}"

smoke-test.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
set -euo pipefail
33

44
SCRIPT_ROOT="$(cd -P "$( dirname "$0" )" && pwd)"
5-
TARBALL_PREFIX=dotnet-sdk-
65
VERSION_PREFIX=3.1
76
# See https://github.com/dotnet/source-build/issues/579, this version
87
# needs to be compatible with the runtime produced from source-build
@@ -61,9 +60,9 @@ while :; do
6160
break
6261
fi
6362

64-
lowerI="$(echo $1 | awk '{print tolower($0)}')"
63+
lowerI="$(echo "$1" | awk '{print tolower($0)}')"
6564
case $lowerI in
66-
-?|-h|--help)
65+
"-?"|-h|--help)
6766
usage
6867
exit 0
6968
;;
@@ -363,7 +362,7 @@ export NUGET_PACKAGES="$restoredPackagesDir"
363362
SOURCE_BUILT_PKGS_PATH="$SCRIPT_ROOT/artifacts/obj/x64/$configuration/blob-feed/packages/"
364363
export DOTNET_ROOT="$dotnetDir"
365364
# OSX also requires DOTNET_ROOT to be on the PATH
366-
if [ `uname` == 'Darwin' ]; then
365+
if [ "$(uname)" == 'Darwin' ]; then
367366
export PATH="$dotnetDir:$PATH"
368367
fi
369368

@@ -404,4 +403,8 @@ if [ "$excludeOnlineTests" == "false" ]; then
404403
echo "ONLINE RESTORE SOURCE - ALL TESTS PASSED!"
405404
fi
406405

406+
fullSdkVersion="$($dotnetDir/dotnet --version)"
407+
"$SCRIPT_ROOT/scripts/fetch-microsoft-sdk.sh" "$fullSdkVersion" "microsoft-built-dotnet-sdk-${fullSdkVersion}.tar.gz"
408+
"$SCRIPT_ROOT/scripts/compare-builds.sh" "$dotnetDir" "microsoft-built-dotnet-sdk-${fullSdkVersion}.tar.gz" || true
409+
407410
echo "ALL TESTS PASSED!"

0 commit comments

Comments
 (0)