From 070f107a6157f4721472519c48b92ea68d418c86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 18 Jun 2019 11:17:17 +0200 Subject: [PATCH] Add --check option to scripts/baremetal.sh Only effective together with --rom, makes two changes: - abort in case of build warnings - skip writing statistics The goal is to make sure we build cleanly in the configuration used for measuring code size, with all the compilers we use, both because we care about that configuration and those compilers, and because any warnings would cast a shadow on the code size measurements. Currently the build fails with armc5 due to a pre-existing warning in PK, this will be fixed in the next commit. The next commit will also add an all.sh component to make sure we have no regression in the future. (Which is the motivation for --check skipping statistics: an all.sh component should probably not leave files around.) While at it, fix two things: 1. The call to gcc --version was redundant with the echo line below 2. WARNING_CFLAGS shouldn't be overriden with armclang, as it would remove the -Wall -Wextra and any directory-specific warning (such as -Wdeclaration-after-statement in library). It's meant to be overriden only with compilers that don't accept the default value (namely armc5 here). --- scripts/baremetal.sh | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/scripts/baremetal.sh b/scripts/baremetal.sh index 86fac5687..88413252f 100755 --- a/scripts/baremetal.sh +++ b/scripts/baremetal.sh @@ -75,15 +75,20 @@ baremetal_build_gcc() echo "Create 32-bit library-only baremetal build (GCC, config: $BAREMETAL_CONFIG)" gcc_ver=$($GCC_CC --version | head -n 1 | sed -n 's/^.*\([0-9]\.[0-9]\.[0-9]\).*$/\1/p') - CFLAGS_BAREMETAL="-Os -mthumb -mcpu=cortex-m0plus" + CFLAGS_BAREMETAL="-Os -mthumb -mcpu=cortex-m0plus --std=c99" + if [ $check -ne 0 ]; then + CFLAGS_BAREMETAL="$CFLAGS_BAREMETAL -Werror" + fi CFLAGS="$CFLAGS_BAREMETAL $CFLAGS_CONFIG" - $GCC_CC --version - echo "GCC version: $gcc_ver" echo "Flags: $CFLAGS_BAREMETAL" make CC=$GCC_CC AR=$GCC_AR CFLAGS="$CFLAGS" lib -j > /dev/null + if [ $check -ne 0 ]; then + return + fi + ROM_OUT_FILE="rom_files__${date}__${NAME}__gcc_${gcc_ver}" ROM_OUT_SYMS="rom_syms__${date}__${NAME}__gcc_${gcc_ver}" echo "Generate file statistics..." @@ -108,10 +113,18 @@ baremetal_build_armc5() CFLAGS="$CFLAGS_BAREMETAL $CFLAGS_CONFIG" WARNING_CFLAGS="--strict --c99" + if [ $check -ne 0 ]; then + WARNING_CFLAGS="$WARNING_CFLAGS --diag_error=warning" + fi + echo "ARMC5 version: $armc5_ver" echo "Flags: $WARNING_CFLAGS $CFLAGS_BAREMETAL" make WARNING_CFLAGS="$WARNING_CFLAGS" CC=$ARMC5_CC AR=$ARMC5_AR CFLAGS="$CFLAGS" lib -j > /dev/null + if [ $check -ne 0 ]; then + return + fi + ROM_OUT_FILE="rom_files__${date}__${NAME}__armc5_${armc5_ver}" ROM_OUT_SYMS="rom_syms__${date}__${NAME}__armc5_${armc5_ver}" echo "Generate file statistics..." @@ -132,13 +145,19 @@ baremetal_build_armc6() echo "Create 32-bit library-only baremetal build (ARMC6, Config: $BAREMETAL_CONFIG)" armc6_ver=$($ARMC6_CC --version | sed -n 's/.*ARM Compiler \([^ ]*\)$/\1/p') - CFLAGS_BAREMETAL="-Os --target=arm-arm-none-eabi -mthumb -mcpu=cortex-m0plus" + CFLAGS_BAREMETAL="-Os --target=arm-arm-none-eabi -mthumb -mcpu=cortex-m0plus -xc --std=c99" + if [ $check -ne 0 ]; then + CFLAGS_BAREMETAL="$CFLAGS_BAREMETAL -Werror" + fi CFLAGS="$CFLAGS_BAREMETAL $CFLAGS_CONFIG" - WARNING_CFLAGS="-xc -std=c99" echo "ARMC6 version: $armc6_ver" - echo "Flags: $WARNING_CFLAGS $CFLAGS_BAREMETAL" - make WARNING_CFLAGS="$WARNING_CFLAGS" CC=$ARMC6_CC AR=$ARMC6_AR CFLAGS="$CFLAGS" lib -j > /dev/null + echo "Flags: $CFLAGS_BAREMETAL" + make CC=$ARMC6_CC AR=$ARMC6_AR CFLAGS="$CFLAGS" lib -j > /dev/null + + if [ $check -ne 0 ]; then + return + fi ROM_OUT_FILE="rom_files__${date}__${NAME}__armc6_${armc6_ver}" ROM_OUT_SYMS="rom_syms__${date}__${NAME}__armc6_${armc6_ver}" @@ -284,7 +303,7 @@ baremetal_ram_stack() { } show_usage() { - echo "Usage: $0 [--rom [--gcc] [--armc5] [--armc6]|--ram [--stack] [--heap]]" + echo "Usage: $0 [--rom [--check] [--gcc] [--armc5] [--armc6]|--ram [--stack] [--heap]]" } test_build=0 @@ -297,6 +316,8 @@ build_armc6=0 measure_heap=0 measure_stack=0 +check=0 + while [ $# -gt 0 ]; do case "$1" in --gcc) build_gcc=1;; @@ -306,6 +327,7 @@ while [ $# -gt 0 ]; do --rom) raw_build=1;; --heap) measure_heap=1;; --stack) measure_stack=1;; + --check) check=1;; -*) echo >&2 "Unknown option: $1" show_usage