|
1 | 1 | #!/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 | | - |
14 | 2 | # Copyright The Mbed TLS Contributors |
15 | 3 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
16 | 4 |
|
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. |
35 | 13 |
|
36 | 14 |
|
37 | | -#### .gitignore processing #### |
| 15 | +set -eu |
38 | 16 |
|
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 |
45 | 24 | 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 '' "$@" |
49 | 26 | fi |
50 | | -done |
51 | | - |
52 | | - |
53 | | - |
54 | | -#### Build scripts #### |
| 27 | +} |
55 | 28 |
|
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 |
63 | 35 |
|
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