Merge pull request #8177 from gilles-peskine-arm/generated-files-off-in-release

Generated files off in release
This commit is contained in:
Gilles Peskine 2023-09-18 14:11:58 +00:00 committed by GitHub
commit bd50d5baec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 124 additions and 63 deletions

View file

@ -1,5 +1,16 @@
#!/bin/bash
#
print_usage()
{
cat <<EOF
Usage: $0 [OPTION]...
Prepare the source tree for a release.
Options:
-u Prepare for development (undo the release preparation)
EOF
}
# Copyright The Mbed TLS Contributors
# SPDX-License-Identifier: Apache-2.0
#
@ -14,52 +25,32 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Purpose
#
# For adapting gitignore files for releases so generated files can be included.
#
# Usage: gitignore_add_generated_files.sh [ -h | --help ] etc
#
set -eu
print_usage()
{
echo "Usage: $0"
echo -e " -h|--help\t\tPrint this help."
echo -e " -i|--ignore\t\tAdd generated files to the gitignores."
echo -e " -u|--unignore\t\tRemove generated files from the gitignores."
}
if [[ $# -eq 0 ]]; then
if [ $# -ne 0 ] && [ "$1" = "--help" ]; then
print_usage
exit 1
elif [[ $# -ge 2 ]]; then
echo "Too many arguments!"
exit 1
exit
fi
case "$1" in
-i | --ignore)
IGNORE=true
;;
-u | --uignore)
IGNORE=false
;;
-h | --help | "")
print_usage
exit 1
;;
*)
echo "Unknown argument: $1"
echo "run '$0 --help' for options"
exit 1
esac
unrelease= # if non-empty, we're in undo-release mode
while getopts u OPTLET; do
case $OPTLET in
u) unrelease=1;;
\?)
echo 1>&2 "$0: unknown option: -$OPTLET"
echo 1>&2 "Try '$0 --help' for more information."
exit 3;;
esac
done
#### .gitignore processing ####
GITIGNORES=$(find . -name ".gitignore")
for GITIGNORE in $GITIGNORES; do
if $IGNORE; then
if [ -n "$unrelease" ]; then
sed -i '/###START_COMMENTED_GENERATED_FILES###/,/###END_COMMENTED_GENERATED_FILES###/s/^# //' $GITIGNORE
sed -i 's/###START_COMMENTED_GENERATED_FILES###/###START_GENERATED_FILES###/' $GITIGNORE
sed -i 's/###END_COMMENTED_GENERATED_FILES###/###END_GENERATED_FILES###/' $GITIGNORE
@ -69,3 +60,23 @@ for GITIGNORE in $GITIGNORES; do
sed -i 's/###END_GENERATED_FILES###/###END_COMMENTED_GENERATED_FILES###/' $GITIGNORE
fi
done
#### Build scripts ####
# GEN_FILES defaults on (non-empty) in development, off (empty) in releases
if [ -n "$unrelease" ]; then
r=' yes'
else
r=''
fi
sed -i 's/^\(GEN_FILES[ ?:]*=\)\([^#]*\)/\1'"$r/" Makefile */Makefile
# GEN_FILES defaults on in development, off in releases
if [ -n "$unrelease" ]; then
r='ON'
else
r='OFF'
fi
sed -i '/[Oo][Ff][Ff] in development/! s/^\( *option *( *GEN_FILES *"[^"]*" *\)\([A-Za-z0-9][A-Za-z0-9]*\)/\1'"$r/" CMakeLists.txt