Skip to content

Commit 5dae448

Browse files
Merge pull request #10462 from minosgalanakis/bugfix/update_prepare_release
Update `prepare_release.sh`
2 parents 00d579e + a2cba40 commit 5dae448

File tree

1 file changed

+26
-59
lines changed

1 file changed

+26
-59
lines changed

scripts/prepare_release.sh

Lines changed: 26 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,37 @@
11
#!/bin/bash
2-
3-
print_usage()
4-
{
5-
cat <<EOF
6-
Usage: $0 [OPTION]...
7-
Prepare the source tree for a release.
8-
9-
Options:
10-
-u Prepare for development (undo the release preparation)
11-
EOF
12-
}
13-
142
# Copyright The Mbed TLS Contributors
153
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
164

17-
set -eu
18-
19-
if [ $# -ne 0 ] && [ "$1" = "--help" ]; then
20-
print_usage
21-
exit
22-
fi
23-
24-
unrelease= # if non-empty, we're in undo-release mode
25-
while getopts u OPTLET; do
26-
case $OPTLET in
27-
u) unrelease=1;;
28-
\?)
29-
echo 1>&2 "$0: unknown option: -$OPTLET"
30-
echo 1>&2 "Try '$0 --help' for more information."
31-
exit 3;;
32-
esac
33-
done
34-
5+
# prepare_release.sh — Prepare the source tree for a release.
6+
#
7+
# This script switches the repo into “release” mode:
8+
# - Updates all tracked `.gitignore` files to stop
9+
# ignoring the automatically-generated files.
10+
# - Sets the CMake option `GEN_FILES` to OFF to explicitely disable
11+
# recreating the automatically-generated files.
12+
#. - The script will recursively update the tf-psa-crypto files too.
3513

3614

37-
#### .gitignore processing ####
15+
set -eu
3816

39-
GITIGNORES=$(find . -name ".gitignore")
40-
for GITIGNORE in $GITIGNORES; do
41-
if [ -n "$unrelease" ]; then
42-
sed -i '/###START_COMMENTED_GENERATED_FILES###/,/###END_COMMENTED_GENERATED_FILES###/s/^#//' $GITIGNORE
43-
sed -i 's/###START_COMMENTED_GENERATED_FILES###/###START_GENERATED_FILES###/' $GITIGNORE
44-
sed -i 's/###END_COMMENTED_GENERATED_FILES###/###END_GENERATED_FILES###/' $GITIGNORE
17+
# Portable inline sed. Helper function that will automatically pre-pend
18+
# an empty string as the backup suffix (required by macOS sed).
19+
psed() {
20+
# macOS sed does not offer a version
21+
if sed --version >/dev/null 2>&1; then
22+
sed -i "$@"
23+
# macOS/BSD sed
4524
else
46-
sed -i '/###START_GENERATED_FILES###/,/###END_GENERATED_FILES###/s/^/#/' $GITIGNORE
47-
sed -i 's/###START_GENERATED_FILES###/###START_COMMENTED_GENERATED_FILES###/' $GITIGNORE
48-
sed -i 's/###END_GENERATED_FILES###/###END_COMMENTED_GENERATED_FILES###/' $GITIGNORE
25+
sed -i '' "$@"
4926
fi
50-
done
51-
52-
53-
54-
#### Build scripts ####
27+
}
5528

56-
# GEN_FILES defaults on (non-empty) in development, off (empty) in releases
57-
if [ -n "$unrelease" ]; then
58-
r=' yes'
59-
else
60-
r=''
61-
fi
62-
sed -i 's/^\(GEN_FILES[ ?:]*=\)\([^#]*\)/\1'"$r/" Makefile */Makefile
29+
#### .gitignore processing ####
30+
for GITIGNORE in $(git ls-files --recurse-submodules -- '*.gitignore'); do
31+
psed '/###START_GENERATED_FILES###/,/###END_GENERATED_FILES###/s/^/#/' "$GITIGNORE"
32+
psed 's/###START_GENERATED_FILES###/###START_COMMENTED_GENERATED_FILES###/' "$GITIGNORE"
33+
psed 's/###END_GENERATED_FILES###/###END_COMMENTED_GENERATED_FILES###/' "$GITIGNORE"
34+
done
6335

64-
# GEN_FILES defaults on in development, off in releases
65-
if [ -n "$unrelease" ]; then
66-
r='ON'
67-
else
68-
r='OFF'
69-
fi
70-
sed -i '/[Oo][Ff][Ff] in development/! s/^\( *option *( *GEN_FILES *"[^"]*" *\)\([A-Za-z0-9][A-Za-z0-9]*\)/\1'"$r/" CMakeLists.txt
36+
#### Build system ####
37+
psed '/[Oo][Ff][Ff] in development/! s/^\( *option *( *GEN_FILES *"[^"]*" *\)\([A-Za-z0-9][A-Za-z0-9]*\)/\1OFF/' CMakeLists.txt tf-psa-crypto/CMakeLists.txt

0 commit comments

Comments
 (0)