Skip to content

Commit 669232f

Browse files
authored
Move commit distance computation into a separate bash script. (dotnet#16712)
The script does the same thing, except: * It doesn't use 'bc', but instead bash's intrinsic math support: '$((1+2))' - because when we execute in bash on Windows, 'bc' might not be available. * It's easier to debug. This fixes a problem when we need to compute these values on Windows in CI.
1 parent 380cb06 commit 669232f

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

Make.config

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,7 @@ NUGET_VERSION_STABLE_COMMIT_DISTANCE_START=0
2020

2121
-include $(TOP)/Make.config.inc
2222
$(TOP)/Make.config.inc: $(TOP)/Make.config $(TOP)/mk/mono.mk
23-
@rm -f $@
24-
@printf "IOS_COMMIT_DISTANCE:=$(shell LANG=C; export LANG && git --git-dir $(TOP)/.git log `git --git-dir $(TOP)/.git blame -- ./Make.versions HEAD | grep IOS_PACKAGE_VERSION= | sed 's/ .*//' `..HEAD --oneline | wc -l | sed 's/ //g')\n" >> $@
25-
@printf "MAC_COMMIT_DISTANCE:=$(shell LANG=C; export LANG && git --git-dir $(TOP)/.git log `git --git-dir $(TOP)/.git blame -- ./Make.versions HEAD | grep MAC_PACKAGE_VERSION= | sed 's/ .*//' `..HEAD --oneline | wc -l | sed 's/ //g')\n" >> $@
26-
@#
27-
@printf "IOS_NUGET_COMMIT_DISTANCE:=$(shell LANG=C; export LANG; git --git-dir $(TOP)/.git log `git --git-dir $(TOP)/.git blame -- ./Make.versions HEAD | grep IOS_NUGET_OS_VERSION= | sed 's/ .*//' `..HEAD --oneline | wc -l | sed -e 's/ //g' -e "s/^/$(NUGET_VERSION_COMMIT_DISTANCE_START)+/" | bc)\\n" >> $@
28-
@printf "TVOS_NUGET_COMMIT_DISTANCE:=$(shell LANG=C; export LANG; git --git-dir $(TOP)/.git log `git --git-dir $(TOP)/.git blame -- ./Make.versions HEAD | grep TVOS_NUGET_OS_VERSION= | sed 's/ .*//' `..HEAD --oneline | wc -l | sed -e 's/ //g' -e "s/^/$(NUGET_VERSION_COMMIT_DISTANCE_START)+/" | bc)\\n" >> $@
29-
@printf "WATCHOS_NUGET_COMMIT_DISTANCE:=$(shell LANG=C; export LANG; git --git-dir $(TOP)/.git log `git --git-dir $(TOP)/.git blame -- ./Make.versions HEAD | grep WATCHOS_NUGET_OS_VERSION= | sed 's/ .*//' `..HEAD --oneline | wc -l | sed -e 's/ //g' -e "s/^/$(NUGET_VERSION_COMMIT_DISTANCE_START)+/" | bc)\\n" >> $@
30-
@printf "MACOS_NUGET_COMMIT_DISTANCE:=$(shell LANG=C; export LANG; git --git-dir $(TOP)/.git log `git --git-dir $(TOP)/.git blame -- ./Make.versions HEAD | grep MACOS_NUGET_OS_VERSION= | sed 's/ .*//' `..HEAD --oneline | wc -l | sed -e 's/ //g' -e "s/^/$(NUGET_VERSION_COMMIT_DISTANCE_START)+/" | bc)\\n" >> $@
31-
@printf "MACCATALYST_NUGET_COMMIT_DISTANCE:=$(shell LANG=C; export LANG; git --git-dir $(TOP)/.git log `git --git-dir $(TOP)/.git blame -- ./Make.versions HEAD | grep MACCATALYST_NUGET_OS_VERSION= | sed 's/ .*//' `..HEAD --oneline | wc -l | sed -e 's/ //g' -e "s/^/$(NUGET_VERSION_COMMIT_DISTANCE_START)+/" | bc)\\n" >> $@
32-
@printf "NUGET_STABLE_COMMIT_DISTANCE:=$(shell LANG=C; export LANG; git --git-dir $(TOP)/.git log `git --git-dir $(TOP)/.git blame -L '/^[#[:blank:]]*NUGET_RELEASE_BRANCH=/,+1' -- ./Make.config HEAD | sed 's/ .*//' `..HEAD --oneline | wc -l | sed -e 's/ //g' -e "s/^/$(NUGET_VERSION_STABLE_COMMIT_DISTANCE_START)+/" | bc)\\n" >> $@
33-
@#
34-
@if which ccache > /dev/null 2>&1; then printf "ENABLE_CCACHE=1\nexport CCACHE_BASEDIR=$(abspath $(TOP)/..)\n" >> $@; echo "Found ccache on the system, enabling it"; fi
35-
@if test -d $(TOP)/../maccore; then printf "ENABLE_XAMARIN=1\n" >> $@; echo "Detected the maccore repository, automatically enabled the Xamarin build"; fi
23+
$(Q) cd $(TOP) && ALL_DOTNET_PLATFORMS="$(ALL_DOTNET_PLATFORMS)" ./create-make-config.sh
3624

3725
include $(TOP)/Make.versions
3826

create-make-config.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash -eu
2+
3+
set -o pipefail
4+
IFS=$'\n\t '
5+
6+
OUTPUT=Make.config.inc
7+
OUTPUT_FILE=Make.config.inc.tmp
8+
9+
rm -f "$OUTPUT_FILE" "$OUTPUT"
10+
11+
LANG=C
12+
export LANG
13+
14+
# Support for hardcoding a commit distance start offset.
15+
NUGET_VERSION_COMMIT_DISTANCE_START=0
16+
NUGET_VERSION_STABLE_COMMIT_DISTANCE_START=0
17+
18+
# Compute commit distances
19+
printf "IOS_COMMIT_DISTANCE:=$(git log $(git blame -- ./Make.versions HEAD | grep IOS_PACKAGE_VERSION= | sed 's/ .*//' )..HEAD --oneline | wc -l | sed 's/ //g')\n" >> "$OUTPUT_FILE"
20+
printf "MAC_COMMIT_DISTANCE:=$(git log $(git blame -- ./Make.versions HEAD | grep MAC_PACKAGE_VERSION= | sed 's/ .*//' )..HEAD --oneline | wc -l | sed 's/ //g')\n" >> "$OUTPUT_FILE"
21+
22+
for platform in $ALL_DOTNET_PLATFORMS; do
23+
PLATFORM=$(echo "$platform" | tr '[:lower:]' '[:upper:]')
24+
COMMIT=$(git blame -- ./Make.versions HEAD | grep "${PLATFORM}_NUGET_OS_VERSION=" | sed 's/ .*//')
25+
COMMIT_DISTANCE=$(git log "$COMMIT..HEAD" --oneline | wc -l | sed -e 's/ //g')
26+
TOTAL_DISTANCE=$((NUGET_VERSION_COMMIT_DISTANCE_START+COMMIT_DISTANCE))
27+
printf "${PLATFORM}_NUGET_COMMIT_DISTANCE:=$TOTAL_DISTANCE\\n" >> "$OUTPUT_FILE"
28+
done
29+
30+
STABLE_COMMIT=$(git blame -L '/^[#[:blank:]]*NUGET_RELEASE_BRANCH=/,+1' -- ./Make.config HEAD | sed 's/ .*//')
31+
STABLE_COMMIT_DISTANCE=$(git log "$STABLE_COMMIT..HEAD" --oneline | wc -l | sed -e 's/ //g')
32+
STABLE_TOTAL_DISTANCE=$((STABLE_COMMIT_DISTANCE+NUGET_VERSION_STABLE_COMMIT_DISTANCE_START))
33+
34+
printf "NUGET_STABLE_COMMIT_DISTANCE:=$STABLE_TOTAL_DISTANCE\\n" >> "$OUTPUT_FILE"
35+
36+
# Detect ccache
37+
if which ccache > /dev/null 2>&1; then
38+
printf "ENABLE_CCACHE=1\n" >> "$OUTPUT_FILE"
39+
printf "export CCACHE_BASEDIR=$(cd .. && pwd)\n" >> "$OUTPUT_FILE"
40+
echo "Found ccache on the system, enabling it"
41+
fi
42+
43+
# Detect maccore / xamarin
44+
if test -d ../maccore; then
45+
printf "ENABLE_XAMARIN=1\n" >> "$OUTPUT_FILE"
46+
echo "Detected the maccore repository, automatically enabled the Xamarin build"
47+
fi
48+
49+
mv "$OUTPUT_FILE" "$OUTPUT"

0 commit comments

Comments
 (0)