Skip to content

Commit 5d67b4d

Browse files
shmuelieCopilot
andcommitted
portable: extract common release helpers into release-common.sh
The portable and MSIX release scripts share significant logic: argument parsing, MSYSTEM/architecture detection, root directory setup, file list generation, gitconfig configuration, DLL copying, and PDB handling. Extract these into release-common.sh as a shared include with reusable functions (prepare_root, init_etc_gitconfig, generate_file_list, copy_dlls_to_libexec, unpack_pdbs), and refactor portable/release.sh to source it. No behavioral change to portable builds. Signed-off-by: Shmueli Englard <shmueli.yosef@englard.net> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0fff9f8 commit 5d67b4d

2 files changed

Lines changed: 181 additions & 139 deletions

File tree

portable/release.sh

Lines changed: 10 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -2,156 +2,27 @@
22

33
# Build the portable Git for Windows.
44

5-
die () {
6-
echo "$*" >&1
7-
exit 1
8-
}
9-
10-
output_directory="$HOME"
11-
include_pdbs=
12-
while test $# -gt 0
13-
do
14-
case "$1" in
15-
--output)
16-
shift
17-
output_directory="$1"
18-
;;
19-
--output=*)
20-
output_directory="${1#*=}"
21-
;;
22-
--include-pdbs)
23-
include_pdbs=t
24-
;;
25-
-*)
26-
die "Unknown option: $1"
27-
;;
28-
*)
29-
break
30-
esac
31-
shift
32-
done
33-
34-
test $# -gt 0 ||
35-
die "Usage: $0 [--output=<directory>] <version> [optional components]"
36-
37-
test -d "$output_directory" ||
38-
die "Directory inaccessible: '$output_directory'"
5+
. "$(dirname "$0")/../release-common.sh"
396

407
case "$MSYSTEM" in
41-
MINGW32)
42-
BITNESS=32
43-
ARCH=i686
44-
ARTIFACT_SUFFIX="32-bit"
45-
MD_ARG=128M
46-
MINGW_PREFIX=mingw-w64-i686-
47-
;;
48-
MINGW64)
49-
BITNESS=64
50-
ARCH=x86_64
51-
ARTIFACT_SUFFIX="64-bit"
52-
MD_ARG=256M
53-
MINGW_PREFIX=mingw-w64-x86_64-
54-
;;
55-
CLANGARM64)
56-
BITNESS=64
57-
ARCH=aarch64
58-
ARTIFACT_SUFFIX=arm64
59-
MD_ARG=256M
60-
MINGW_PREFIX=mingw-w64-clang-aarch64-
61-
;;
62-
*)
63-
die "Unhandled MSYSTEM: $MSYSTEM"
64-
;;
8+
MINGW32) ARTIFACT_SUFFIX="32-bit";;
9+
MINGW64) ARTIFACT_SUFFIX="64-bit";;
10+
CLANGARM64) ARTIFACT_SUFFIX=arm64;;
6511
esac
66-
MSYSTEM_LOWER=${MSYSTEM,,}
67-
VERSION=$1
68-
shift
12+
6913
TARGET="$output_directory"/PortableGit-"$VERSION"-"$ARTIFACT_SUFFIX".7z.exe
7014
OPTS7="-m0=lzma -mqs -mlc=8 -mx=9 -md=$MD_ARG -mfb=273 -ms=256M "
7115
TMPPACK=/tmp.7z
72-
SCRIPT_PATH="$(cd "$(dirname "$0")" && pwd)"
73-
74-
case "$SCRIPT_PATH" in
75-
*" "*)
76-
die "This script cannot handle spaces in $SCRIPT_PATH"
77-
;;
78-
esac
79-
80-
81-
# Generate a couple of files dynamically
82-
83-
cp "$SCRIPT_PATH/../LICENSE.txt" "$SCRIPT_PATH/root/" ||
84-
die "Could not copy license file"
85-
86-
mkdir -p "$SCRIPT_PATH/root/dev/mqueue" ||
87-
die "Could not make /dev/mqueue directory"
88-
89-
mkdir -p "$SCRIPT_PATH/root/dev/shm" ||
90-
die "Could not make /dev/shm/ directory"
9116

92-
mkdir -p "$SCRIPT_PATH/root/etc" ||
93-
die "Could not make etc/ directory"
94-
95-
mkdir -p "$SCRIPT_PATH/root/tmp" ||
96-
die "Could not make tmp/ directory"
97-
98-
mkdir -p "$SCRIPT_PATH/root/bin" ||
99-
die "Could not make bin/ directory"
100-
101-
cp /cmd/git.exe "$SCRIPT_PATH/root/bin/git.exe" &&
102-
cp /$MSYSTEM_LOWER/share/git/compat-bash.exe "$SCRIPT_PATH/root/bin/bash.exe" &&
103-
cp /$MSYSTEM_LOWER/share/git/compat-bash.exe "$SCRIPT_PATH/root/bin/sh.exe" ||
104-
die "Could not install bin/ redirectors"
17+
prepare_root
10518

10619
cp "$SCRIPT_PATH/../post-install.bat" "$SCRIPT_PATH/root/" ||
10720
die "Could not copy post-install script"
10821

109-
etc_gitconfig="$(git -c core.editor=echo config --system -e 2>/dev/null)" &&
110-
etc_gitconfig="$(cygpath -au "$etc_gitconfig")" &&
111-
etc_gitconfig="${etc_gitconfig#/}" ||
112-
die "Could not determine the path of the system config"
113-
114-
# Make a list of files to include
115-
LIST="$(ARCH=$ARCH ETC_GITCONFIG="$etc_gitconfig" \
116-
PACKAGE_VERSIONS_FILE="$SCRIPT_PATH"/root/etc/package-versions.txt \
117-
sh "$SCRIPT_PATH"/../make-file-list.sh "$@" |
118-
grep -v "^$etc_gitconfig$")" ||
119-
die "Could not generate file list"
120-
121-
mkdir -p "$SCRIPT_PATH/root/${etc_gitconfig%/*}" &&
122-
cp /"$etc_gitconfig" "$SCRIPT_PATH/root/$etc_gitconfig" &&
123-
git config -f "$SCRIPT_PATH/root/$etc_gitconfig" \
124-
credential.helper manager ||
125-
die "Could not configure Git-Credential-Manager as default"
126-
test 64 != $BITNESS ||
127-
git config -f "$SCRIPT_PATH/root/$etc_gitconfig" --unset pack.packSizeLimit
128-
git config -f "$SCRIPT_PATH/root/$etc_gitconfig" core.fscache true
129-
130-
case "$LIST" in
131-
*/git-credential-helper-selector.exe*)
132-
git config -f "$SCRIPT_PATH/root/$etc_gitconfig" \
133-
credential.helper helper-selector
134-
;;
135-
esac
136-
137-
git_core="$SCRIPT_PATH/root/$MSYSTEM_LOWER/libexec/git-core" &&
138-
rm -rf "$git_core" &&
139-
mkdir -p "$git_core" &&
140-
if test "$(stat -c %D /$MSYSTEM_LOWER/bin)" = "$(stat -c %D "$git_core")"
141-
then
142-
ln_or_cp=ln
143-
else
144-
ln_or_cp=cp
145-
fi &&
146-
$ln_or_cp $(echo "$LIST" | sed -n "s|^$MSYSTEM_LOWER/bin/[^/]*\.dll$|/&|p") "$git_core" ||
147-
die "Could not copy .dll files into libexec/git-core/"
148-
149-
test -z "$include_pdbs" || {
150-
find "$SCRIPT_PATH/root" -name \*.pdb -exec rm {} \; &&
151-
"$SCRIPT_PATH"/../please.sh bundle-pdbs \
152-
--arch=$ARCH --unpack="$SCRIPT_PATH"/root
153-
} ||
154-
die "Could not unpack .pdb files"
22+
init_etc_gitconfig
23+
generate_file_list "$@"
24+
copy_dlls_to_libexec
25+
unpack_pdbs
15526

15627
TITLE="$BITNESS-bit"
15728
test $ARCH == "aarch64" && TITLE="ARM64"

release-common.sh

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# Common helpers for release scripts.
2+
# Source this file; it consumes the shared command-line flags and
3+
# leaves the remaining positional parameters (optional components) in "$@".
4+
#
5+
# After sourcing, the following variables are set:
6+
# output_directory, include_pdbs, VERSION,
7+
# BITNESS, ARCH, MD_ARG, MINGW_PREFIX, MSYSTEM_LOWER, SCRIPT_PATH
8+
#
9+
# The following functions are available:
10+
# die, prepare_root, init_etc_gitconfig,
11+
# generate_file_list, copy_dlls_to_libexec, unpack_pdbs
12+
13+
die () {
14+
echo "$*" >&1
15+
exit 1
16+
}
17+
18+
output_directory="$HOME"
19+
include_pdbs=
20+
while test $# -gt 0
21+
do
22+
case "$1" in
23+
--output)
24+
shift
25+
output_directory="$1"
26+
;;
27+
--output=*)
28+
output_directory="${1#*=}"
29+
;;
30+
--include-pdbs)
31+
include_pdbs=t
32+
;;
33+
-*)
34+
die "Unknown option: $1"
35+
;;
36+
*)
37+
break
38+
esac
39+
shift
40+
done
41+
42+
test $# -gt 0 ||
43+
die "Usage: $0 [--output=<directory>] <version> [optional components]"
44+
45+
test -d "$output_directory" ||
46+
die "Directory inaccessible: '$output_directory'"
47+
48+
case "$MSYSTEM" in
49+
MINGW32)
50+
BITNESS=32
51+
ARCH=i686
52+
MD_ARG=128M
53+
MINGW_PREFIX=mingw-w64-i686-
54+
;;
55+
MINGW64)
56+
BITNESS=64
57+
ARCH=x86_64
58+
MD_ARG=256M
59+
MINGW_PREFIX=mingw-w64-x86_64-
60+
;;
61+
CLANGARM64)
62+
BITNESS=64
63+
ARCH=aarch64
64+
MD_ARG=256M
65+
MINGW_PREFIX=mingw-w64-clang-aarch64-
66+
;;
67+
*)
68+
die "Unhandled MSYSTEM: $MSYSTEM"
69+
;;
70+
esac
71+
MSYSTEM_LOWER=${MSYSTEM,,}
72+
VERSION=$1
73+
shift
74+
75+
SCRIPT_PATH="$(cd "$(dirname "$0")" && pwd)"
76+
77+
case "$SCRIPT_PATH" in
78+
*" "*)
79+
die "This script cannot handle spaces in $SCRIPT_PATH"
80+
;;
81+
esac
82+
83+
# Set up the root directory with common files and redirectors.
84+
prepare_root () {
85+
mkdir -p "$SCRIPT_PATH/root/" ||
86+
die "Could not make root"
87+
88+
cp "$SCRIPT_PATH/../LICENSE.txt" "$SCRIPT_PATH/root/" ||
89+
die "Could not copy license file"
90+
91+
mkdir -p "$SCRIPT_PATH/root/dev/mqueue" ||
92+
die "Could not make /dev/mqueue directory"
93+
94+
mkdir -p "$SCRIPT_PATH/root/dev/shm" ||
95+
die "Could not make /dev/shm/ directory"
96+
97+
mkdir -p "$SCRIPT_PATH/root/etc" ||
98+
die "Could not make etc/ directory"
99+
100+
mkdir -p "$SCRIPT_PATH/root/tmp" ||
101+
die "Could not make tmp/ directory"
102+
103+
mkdir -p "$SCRIPT_PATH/root/bin" ||
104+
die "Could not make bin/ directory"
105+
106+
cp /cmd/git.exe "$SCRIPT_PATH/root/bin/git.exe" &&
107+
cp /$MSYSTEM_LOWER/share/git/compat-bash.exe "$SCRIPT_PATH/root/bin/bash.exe" &&
108+
cp /$MSYSTEM_LOWER/share/git/compat-bash.exe "$SCRIPT_PATH/root/bin/sh.exe" ||
109+
die "Could not install bin/ redirectors"
110+
}
111+
112+
# Detect the system gitconfig path.
113+
# Sets: etc_gitconfig
114+
init_etc_gitconfig () {
115+
etc_gitconfig="$(git -c core.editor=echo config --system -e 2>/dev/null)" &&
116+
etc_gitconfig="$(cygpath -au "$etc_gitconfig")" &&
117+
etc_gitconfig="${etc_gitconfig#/}" ||
118+
die "Could not determine the path of the system config"
119+
}
120+
121+
# Generate the file list and configure the system gitconfig.
122+
# Pass any optional components as arguments.
123+
# Sets: LIST
124+
generate_file_list () {
125+
LIST="$(ARCH=$ARCH ETC_GITCONFIG="$etc_gitconfig" \
126+
PACKAGE_VERSIONS_FILE="$SCRIPT_PATH"/root/etc/package-versions.txt \
127+
sh "$SCRIPT_PATH"/../make-file-list.sh "$@" |
128+
grep -v "^$etc_gitconfig$")" ||
129+
die "Could not generate file list"
130+
131+
mkdir -p "$SCRIPT_PATH/root/${etc_gitconfig%/*}" &&
132+
cp /"$etc_gitconfig" "$SCRIPT_PATH/root/$etc_gitconfig" &&
133+
git config -f "$SCRIPT_PATH/root/$etc_gitconfig" \
134+
credential.helper manager ||
135+
die "Could not configure Git-Credential-Manager as default"
136+
test 64 != $BITNESS ||
137+
git config -f "$SCRIPT_PATH/root/$etc_gitconfig" --unset pack.packSizeLimit
138+
git config -f "$SCRIPT_PATH/root/$etc_gitconfig" core.fscache true
139+
140+
case "$LIST" in
141+
*/git-credential-helper-selector.exe*)
142+
git config -f "$SCRIPT_PATH/root/$etc_gitconfig" \
143+
credential.helper helper-selector
144+
;;
145+
esac
146+
}
147+
148+
# Copy DLL files into libexec/git-core for runtime.
149+
copy_dlls_to_libexec () {
150+
git_core="$SCRIPT_PATH/root/$MSYSTEM_LOWER/libexec/git-core" &&
151+
rm -rf "$git_core" &&
152+
mkdir -p "$git_core" &&
153+
if test "$(stat -c %D /$MSYSTEM_LOWER/bin)" = "$(stat -c %D "$git_core")"
154+
then
155+
ln_or_cp=ln
156+
else
157+
ln_or_cp=cp
158+
fi &&
159+
$ln_or_cp $(echo "$LIST" | sed -n "s|^$MSYSTEM_LOWER/bin/[^/]*\.dll$|/&|p") "$git_core" ||
160+
die "Could not copy .dll files into libexec/git-core/"
161+
}
162+
163+
# Unpack PDB files if --include-pdbs was given.
164+
unpack_pdbs () {
165+
test -z "$include_pdbs" || {
166+
find "$SCRIPT_PATH/root" -name \*.pdb -exec rm {} \; &&
167+
"$SCRIPT_PATH"/../please.sh bundle-pdbs \
168+
--arch=$ARCH --unpack="$SCRIPT_PATH"/root
169+
} ||
170+
die "Could not unpack .pdb files"
171+
}

0 commit comments

Comments
 (0)