Skip to content

Conversation

cladmi
Copy link
Contributor

@cladmi cladmi commented Sep 17, 2019

Contribution description

Do not remove the '-D' and '-U' values from CFLAGS.
This prevents issues where a '-D' could contain a space.

Some values way be duplicated from the 'riotbuild.h' header and the
command line but with the same value so without conflict.

To not put too many things in the command line, the -DMODULE_NAME are
only put in CFLAGS_WITH_MACROS.

Also, as now, the deferred value of CFLAGS is used for 'riotbuild.h',
macros set after the inclusion of Makefile.include will be taken into
account.

Testing procedure

I added a test for all the related issues.
They are documented in the README.md.

Test CFLAGS with spaces

make -C tests/build_system_cflags_spaces flash test

RIOT_CI_BUILD=1 make --no-print-directory -C tests/build_system_cflags_spaces flash test
Building application "cflags_with_spaces" for "native" with MCU "native".

   text    data     bss     dec     hex filename
  20378     568   47652   68598   10bf6 /home/harter/work/git/RIOT/tests/build_system_cflags_spaces/bin/native/cflags_with_spaces.elf
true
/home/harter/work/git/RIOT/tests/build_system_cflags_spaces/bin/native/cflags_with_spaces.elf  
RIOT native interrupts/signals initialized.
LED_RED_OFF
LED_GREEN_ON
RIOT native board initialized.
RIOT native hardware initialization complete.

main(): This is RIOT! (Version: buildtest)
The output of the configuration variables:
SUPER_STRING: I love sentences with spaces
DEFINED_AFTER_MAKEFILE_INCLUDE: 0
CFLAGS_STRING_FROM_DOCKER: 
Rebuild on a CFLAGS change set after `Makefile.include`

CONFIGURATION_VALUE=1 make -C tests/build_system_cflags_spaces flash test

RIOT_CI_BUILD=1 make --no-print-directory -C tests/build_system_cflags_spaces ; CONFIGURATION_VALUE=1 RIOT_CI_BUILD=1 make --no-print-directory -C tests/build_system_cflags_spaces flash test
Building application "cflags_with_spaces" for "native" with MCU "native".

   text    data     bss     dec     hex filename
  20378     568   47652   68598   10bf6 /home/harter/work/git/RIOT/tests/build_system_cflags_spaces/bin/native/cflags_with_spaces.elf
Building application "cflags_with_spaces" for "native" with MCU "native".

   text    data     bss     dec     hex filename
  20378     568   47652   68598   10bf6 /home/harter/work/git/RIOT/tests/build_system_cflags_spaces/bin/native/cflags_with_spaces.elf
true 
/home/harter/work/git/RIOT/tests/build_system_cflags_spaces/bin/native/cflags_with_spaces.elf  
RIOT native interrupts/signals initialized.
LED_RED_OFF
LED_GREEN_ON
RIOT native board initialized.
RIOT native hardware initialization complete.

main(): This is RIOT! (Version: buildtest)
The output of the configuration variables:
SUPER_STRING: I love sentences with spaces
DEFINED_AFTER_MAKEFILE_INCLUDE: 1
CFLAGS_STRING_FROM_DOCKER: 
Passing a CFLAGS macro with space to a DOCKER build

I needed to escape the space in the CFLAGS when defining it from command line.
There may be another solution but did not find it.

DOCKER_ENVIRONMENT_CMDLINE=$'-e CFLAGS=-DSTRING_FROM_DOCKER=\'\\\"with\ space\\\"\''

DOCKER_ENVIRONMENT_CMDLINE=$'-e CFLAGS=-DSTRING_FROM_DOCKER=\'\\\"with\ space\\\"\'' \
  BUILD_IN_DOCKER=1 make
grep '#define STRING_FROM_DOCKER "with space"' bin/native/riotbuild/riotbuild.h \
  || { echo 'ERROR CFLAGS not passed correctly' >&2; false; }

...
#define STRING_FROM_DOCKER "with space"

The impact in the build will be that some macros may be repeated between riotbuild.h and the command line but with the same value.

Issues/PRs references

Fixes #5776
Fixes #9589
Fixes #12219

@HendrikVE
Copy link
Contributor

Cool! Works for me when defining a string like this: CFLAGS += -DMY_STRING_NAME='"this is my string with spaces"'

@cladmi
Copy link
Contributor Author

cladmi commented Sep 17, 2019

Still not completely working with the example from #12219

I will see with 'genconfigheader.sh' too.

@cladmi
Copy link
Contributor Author

cladmi commented Sep 17, 2019

Passing the value from environment variable is tricky, even without docker but if defined in the Makefile it is working directly, same as #12262 (comment)

I need help with shell definition and escaping here :/

When used in a standard build, I managed to have the definition working from environment when doing:

CFLAGS=$'-DSPACE_VALUE=\'"with space"\'' QUIET=0 RIOT_CI_BUILD=1 make --no-print-directory -C examples/hello-world/; grep '#define SPACE_VALUE' examples/hello-world/bin/native/riotbuild/riotbuild.h 
Building application "hello-world" for "native" with MCU "native".

'/home/harter/work/git/RIOT/dist/tools/genconfigheader/genconfigheader.sh' -DSPACE_VALUE='"with space"' -DDEVELHELP -Werror -Wall -Wextra -pedantic -std=gnu99 -m32 -fstack-protector-all -ffunction-sections -fdata-sections -DDEBUG_ASSERT_VERBOSE -DRIOT_APPLICATION=\"hello-world\" -DBOARD_NATIVE=\"native\" -DRIOT_BOARD=BOARD_NATIVE -DCPU_NATIVE=\"native\" -DRIOT_CPU=CPU_NATIVE -DMCU_NATIVE=\"native\" -DRIOT_MCU=MCU_NATIVE -fno-common -Wall -Wextra -Wmissing-include-dirs -fno-delete-null-pointer-checks -fdiagnostics-color -Wstrict-prototypes -Wold-style-definition -gz -Wformat=2 -Wformat-overflow -Wformat-truncation -include '/home/harter/work/git/RIOT/examples/hello-world/bin/native/riotbuild/riotbuild.h' -DRIOT_VERSION=\"buildtest\" -DMODULE_AUTO_INIT -DMODULE_BOARD -DMODULE_CORE -DMODULE_CORE_MSG -DMODULE_CPU -DMODULE_NATIVE_DRIVERS -DMODULE_PERIPH -DMODULE_PERIPH_COMMON -DMODULE_PERIPH_GPIO -DMODULE_PERIPH_PM -DMODULE_PERIPH_UART -DMODULE_SYS \
        | '/home/harter/work/git/RIOT/dist/tools/lazysponge/lazysponge.py' --verbose '/home/harter/work/git/RIOT/examples/hello-world/bin/native/riotbuild/riotbuild.h'
Keeping old /home/harter/work/git/RIOT/examples/hello-world/bin/native/riotbuild/riotbuild.h (f73837f33d6e2f259b9104bf952c7b48)
DIRS=" " "make" -C /home/harter/work/git/RIOT/examples/hello-world -f /home/harter/work/git/RIOT/makefiles/application.inc.mk
gcc /home/harter/work/git/RIOT/examples/hello-world/bin/native/cpu/startup.o -Wl,--start-group /home/harter/work/git/RIOT/examples/hello-world/bin/native/application_hello-world.a  /home/harter/work/git/RIOT/examples/hello-world/bin/native/auto_init.a /home/harter/work/git/RIOT/examples/hello-world/bin/native/board.a /home/harter/work/git/RIOT/examples/hello-world/bin/native/core.a /home/harter/work/git/RIOT/examples/hello-world/bin/native/cpu.a /home/harter/work/git/RIOT/examples/hello-world/bin/native/native-drivers.a /home/harter/work/git/RIOT/examples/hello-world/bin/native/periph.a /home/harter/work/git/RIOT/examples/hello-world/bin/native/sys.a /home/harter/work/git/RIOT/examples/hello-world/bin/native/periph_common.a -lm -Wl,--end-group -m32 -ldl -Wl,--gc-sections -ffunction-sections -Wl,-Map=/home/harter/work/git/RIOT/examples/hello-world/bin/native/hello-world.map -o /home/harter/work/git/RIOT/examples/hello-world/bin/native/hello-world.elf
size  /home/harter/work/git/RIOT/examples/hello-world/bin/native/hello-world.elf
   text    data     bss     dec     hex filename
  22918     568   47652   71138   115e2 /home/harter/work/git/RIOT/examples/hello-world/bin/native/hello-world.elf
rm -f /home/harter/work/git/RIOT/examples/hello-world/bin/native/.test
#define SPACE_VALUE "with space"

But I currently did not manage to escape it enough for defining it with DOCKER_ENVIRONMENT_CMDLINE as shown in #12219

@cladmi
Copy link
Contributor Author

cladmi commented Sep 17, 2019

This works for the #12219 case with DOCKER_ENVIRONMENT_CMDLINE:

The space is still escaped when defined from the environment. There may be another way, but I do not find it.

env RIOT_CI_BUILD=1 QUIET=0 DOCKER="sudo docker"  BUILD_IN_DOCKER=1 DOCKER_ENVIRONMENT_CMDLINE=$'-e USEMODULE=esp_wifi -e CFLAGS=-DESP_WIFI_SSID=\'\\\"has\ space\\\"\'' make BOARD=esp32-wroom-32 -C tests/lwip

And the CFLAGS and the riotbuild.h have the expected value

grep SSID tests/lwip/bin/esp32-wroom-32/riotbuild/riotbuild.h  
/* Generated from CFLAGS: -DESP_WIFI_SSID="has space" -DDEVELHELP -Werror -DSCHED_PRIO_LEVELS=32 -DSDK_NOT_USED -DCONFIG_FREERTOS_UNICORE=1 -DESP_PLATFORM -DLOG_TAG_IN_BRACKETS -Wno-unused-parameter -Wformat=0 -mlongcalls -mtext-section-literals -fstrict-volatile-bitfields -fdata-sections -ffunction-sections -fzero-initialized-in-bss -DSCHED_PRIO_LEVELS=32 -Os -DFLASH_MODE_DOUT=1 -DFLASH_MODE_DOUT=1 -DFLASH_MODE_DOUT=1 -DFLASH_MODE_DOUT=1 -DFLASH_MODE_DOUT=1 -DFLASH_MODE_DOUT=1 -DRIOT_APPLICATION="tests_lwip" -DBOARD_ESP32_WROOM_32="esp32-wroom-32" -DRIOT_BOARD=BOARD_ESP32_WROOM_32 -DCPU_ESP32="esp32" -DRIOT_CPU=CPU_ESP32 -DMCU_ESP32="esp32" -DRIOT_MCU=MCU_ESP32 -std=c99 -fno-common -Wall -Wextra -Wmissing-include-dirs -fno-delete-null-pointer-checks -fdiagnostics-color -Wstrict-prototypes -Wold-style-definition -Wformat=2 -DSOCK_HAS_IPV6 -include /data/riotbuild/riotbase/tests/lwip/bin/esp32-wroom-32/riotbuild/riotbuild.h -DRIOT_VERSION="buildtest" -DMODULE_AUTO_INIT -DMODULE_BOARD -DMODULE_BOARDS_COMMON_ESP32 -DMODULE_CORE -DMODULE_CORE_MBOX -DMODULE_CORE_MSG -DMODULE_CPU -DMODULE_DIV -DMODULE_ESP_IDF -DMODULE_ESP_IDF_DRIVER -DMODULE_ESP_IDF_ESP32 -DMODULE_ESP_IDF_HEAP -DMODULE_ESP_IDF_NVS_FLASH -DMODULE_ESP_IDF_SOC -DMODULE_ESP_IDF_SPI_FLASH -DMODULE_ESP_IDF_WPA_SUPPLICANT_CRYPTO -DMODULE_ESP_IDF_WPA_SUPPLICANT_PORT -DMODULE_ESP_WIFI -DMODULE_ESP_WIFI_ANY -DMODULE_FMT -DMODULE_GNRC -DMODULE_GNRC_NETAPI -DMODULE_GNRC_NETIF -DMODULE_GNRC_NETIF_ETHERNET -DMODULE_GNRC_NETIF_HDR -DMODULE_GNRC_NETREG -DMODULE_GNRC_PKT -DMODULE_GNRC_PKTBUF -DMODULE_GNRC_PKTBUF_STATIC -DMODULE_IPV6_ADDR -DMODULE_ISRPIPE -DMODULE_L2UTIL -DMODULE_LOG -DMODULE_LUID -DMODULE_LWIP -DMODULE_LWIP_API -DMODULE_LWIP_CONTRIB -DMODULE_LWIP_CORE -DMODULE_LWIP_ETHERNET -DMODULE_LWIP_IPV6 -DMODULE_LWIP_IPV6_AUTOCONFIG -DMODULE_LWIP_NETDEV -DMODULE_LWIP_NETIF -DMODULE_LWIP_RAW -DMODULE_LWIP_SOCK -DMODULE_LWIP_SOCK_IP -DMODULE_LWIP_SOCK_TCP -DMODULE_LWIP_SOCK_UDP -DMODULE_LWIP_TCP -DMODULE_LWIP_UDP -DMODULE_MTD -DMODULE_NETDEV_DEFAULT -DMODULE_NETDEV_ETH -DMODULE_NETIF -DMODULE_NETOPT -DMODULE_NEWLIB -DMODULE_NEWLIB_SYSCALLS_DEFAULT -DMODULE_OD -DMODULE_PERIPH -DMODULE_PERIPH_ADC_CTRL -DMODULE_PERIPH_COMMON -DMODULE_PERIPH_CPUID -DMODULE_PERIPH_FLASH -DMODULE_PERIPH_GPIO -DMODULE_PERIPH_HWRNG -DMODULE_PERIPH_PM -DMODULE_PERIPH_RTC -DMODULE_PERIPH_TIMER -DMODULE_PERIPH_UART -DMODULE_PRNG -DMODULE_PRNG_TINYMT32 -DMODULE_PS -DMODULE_PTHREAD -DMODULE_RANDOM -DMODULE_RIOT_FREERTOS -DMODULE_SEMA -DMODULE_SHELL -DMODULE_SHELL_COMMANDS -DMODULE_SOCK_IP -DMODULE_SOCK_TCP -DMODULE_SOCK_UDP -DMODULE_STDIN -DMODULE_STDIO_UART -DMODULE_STDIO_UART_RX -DMODULE_SYS -DMODULE_TIMEX -DMODULE_TINYMT32 -DMODULE_TSRB -DMODULE_XTENSA -DMODULE_XTIMER */
#define ESP_WIFI_SSID "has space"

@cladmi
Copy link
Contributor Author

cladmi commented Sep 17, 2019

I will add an automated test for this. It would only cover the ones defined inside Makefile but at least show that #5776 is fixed.

@cladmi
Copy link
Contributor Author

cladmi commented Sep 18, 2019

Automated and manual test added to verify the 3 things being fixed.

@cladmi cladmi force-pushed the pr/cflags/fix_spaces_and_rebuild branch from 5bbbeb9 to 2d70e23 Compare September 18, 2019 09:47
@cladmi
Copy link
Contributor Author

cladmi commented Sep 18, 2019

(forced push to fix the last commit signature)

@aabadie aabadie added Area: build system Area: Build system Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) labels Sep 27, 2019
@aabadie
Copy link
Contributor

aabadie commented Sep 27, 2019

@cladmi, I briefly looked at this PR and must say that I like it. I already had issues with -D values containing spaces. It's also very nice that you added the tests.

What is status here ? Is it ready for review now (e.g. are all issues mentioned above fixed) ? If yes, I'll trigger Murdock.

@cladmi
Copy link
Contributor Author

cladmi commented Sep 27, 2019

Yes all issues fixed. They need manual testing for some of the things but they are described in the README.

aabadie
aabadie previously approved these changes Sep 27, 2019
Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the README of the test application and everything went fine.

Note that this PR is also fixing the DEFAULT_CHANNEL variable not taken into account after a previous build, which is already pretty awesome.

I couldn't find any obvious mistake or unjustified change in this PR.

One last word: ACK

@aabadie aabadie added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Sep 27, 2019
@aabadie
Copy link
Contributor

aabadie commented Sep 27, 2019

I triggered Murdock and it is already reporting issues, probably with packages. Can you have a look @cladmi ?

@aabadie aabadie self-requested a review September 27, 2019 13:04
@aabadie aabadie dismissed their stale review September 27, 2019 13:04

Issues found by CI

@cladmi
Copy link
Contributor Author

cladmi commented Sep 27, 2019

Looks like the ones depending on dist/tools/cmake/generate-xcompile-toolchain.sh I will see what is missing.

@cladmi
Copy link
Contributor Author

cladmi commented Sep 27, 2019

I currently do not correctly understand how both packages are building.

If I have this:

diff --git a/dist/tools/cmake/generate-xcompile-toolchain.sh b/dist/tools/cmake/generate-xcompile-toolchain.sh
index 55f4af8c4..705f34578 100755
--- a/dist/tools/cmake/generate-xcompile-toolchain.sh
+++ b/dist/tools/cmake/generate-xcompile-toolchain.sh
@@ -8,7 +8,7 @@ echo "SET(CMAKE_LINKER \"${LINK}\" CACHE STRING \"\")"
 echo "SET(CMAKE_RANLIB \"${RANLIB}\" CACHE STRING \"\")"
 # disable linker test
 echo "SET(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)"
-echo "SET(CMAKE_C_FLAGS \"${CFLAGS}\" CACHE STRING \"\")"
+printf "SET(CMAKE_C_FLAGS '%s' CACHE STRING "'"")\n' "${CFLAGS}"
 echo "SET(CMAKE_EXE_LINKER_FLAGS \"${LFLAGS}\" CACHE STRING \"\")"
 # search for programs in the build host directories
 echo "SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)"

it does not complain about the parentheses.

diff --git a/pkg/relic/Makefile b/pkg/relic/Makefile
index 7e2466c9d..cb5b72ded 100644
--- a/pkg/relic/Makefile
+++ b/pkg/relic/Makefile
@@ -18,7 +18,7 @@ all: $(PKG_BUILDDIR)/Makefile
 
 $(PKG_BUILDDIR)/Makefile: $(TOOLCHAIN_FILE)
        cd $(PKG_BUILDDIR) && \
-       COMP="$(filter-out -Werror -Werror=old-style-definition -Werror=strict-prototypes -std=gnu99, $(CFLAGS) ) " \
+       COMP='$(filter-out -Werror -Werror=old-style-definition -Werror=strict-prototypes -std=gnu99,$(CFLAGS)) ' \
        cmake -DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) \
                  -DCHECK=off -DTESTS=0 -DBENCH=0 -DSHLIB=off -Wno-dev $(RELIC_CONFIG_FLAGS) .
 

EDIT: passing it through a target specific 'export COMP =' may even remove the need for escaping anything.

Relic does not fail about having two different values for the macros.

But I do not understand then why relic must get the CFLAGS from both this file, and the COMP.

I do not have ccn-lite yet.

@cladmi
Copy link
Contributor Author

cladmi commented Sep 27, 2019

ccn-lite does not like the change in the 'generate_config'.

I had to change the CFLAGS += -include '$(RIOTBUILD_CONFIG_HEADER_C)' to remove the single quotes already as it of course does not work in the file.

But currently, it puts ; between each element of CFLAGS.

vim bin/pkg/iotlab-m3/ccn-lite/src/ccnl-core/CMakeFiles/ccnl-core.dir/flags.make

C_FLAGS = '-Werror;-mno-thumb-interwork;-mcpu=cortex-m3;-mlittle-endian;-mthumb;-mfloat-abi=soft;-ffunction-sections;-fdata-sections;-fno-builtin;-fshort-enums;-ggdb;-g3;-Os;-std=c99;-fno-common;-Wall;-Wextra;-Wmissing-include-dirs;-fno-delete-null-pointer-checks;-fdiagnostics-color;-Wstrict-prototypes;-Wold-style-definition;-gz;-Wformat=2;-Wformat-overflow;-Wformat-truncation;-include;/home/cladmi/git/work/RIOT/examples/ccn-lite-relay/bin/iotlab-m3/riotbuild/riotbuild.h;-Wno-format-nonliteral' -Wextra -Wall -Werror -std=c99 -g   -isystem /usr/arm-none-eabi/include/newlib-nano -I/home/cladmi/git/work/RIOT/core/include -I/home/cladmi/git/work/RIOT/drivers/include -I/home/cladmi/git/work/RIOT/sys/include -I/home/cladmi/git/work/RIOT/boards/iotlab-m3/include -I/home/cladmi/git/work/RIOT/boards/common/iotlab/include -I/home/cladmi/git/work/RIOT/cpu/stm32f1/include -I/home/cladmi/git/work/RIOT/cpu/stm32_common/include -I/home/cladmi/git/work/RIOT/cpu/cortexm_common/include -I/home/cladmi/git/work/RIOT/cpu/cortexm_common/include/vendor -I/home/cladmi/git/work/RIOT/sys/libc/include -I/home/cladmi/git/work/RIOT/examples/ccn-lite-relay/bin/pkg/iotlab-m3/ccn-lite/src/ccnl-riot/include -I/home/cladmi/git/work/RIOT/examples/ccn-lite-relay/bin/pkg/iotlab-m3/ccn-lite/src/ccnl-core/include -I/home/cladmi/git/work/RIOT/examples/ccn-lite-relay/bin/pkg/iotlab-m3/ccn-lite/src/ccnl-pkt/include -I/home/cladmi/git/work/RIOT/examples/ccn-lite-relay/bin/pkg/iotlab-m3/ccn-lite/src/ccnl-fwd/include -I/home/cladmi/git/work/RIOT/sys/net/gnrc/netif/include -I/home/cladmi/git/work/RIOT/sys/posix/include -I/home/cladmi/git/work/RIOT/drivers/at86rf2xx/include

Need more debugging and I have no idea about how cmake handles this.

@cladmi
Copy link
Contributor Author

cladmi commented Sep 27, 2019

https://cmake.org/cmake/help/v3.0/command/set.html?highlight=set

set(<variable> <value1> ... <valueN>)
In this case is set to a semicolon separated list of values.

Looks like a reason at least.

@cladmi
Copy link
Contributor Author

cladmi commented Sep 27, 2019

I am only supposed to define a string with " and not ' so it gave strange behavior it seems.
But for then it cannot have any \ or " in it.

It may be a thing to use the bracket arguments https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#bracket-argument
I will try.

@cladmi
Copy link
Contributor Author

cladmi commented Sep 27, 2019

I updated the file generating the cmake configuration. At the same time I migrated it to use printf but I could remove that part if wanted.
The commits are not ordered but will wait for a build result before fixing it.

@cladmi
Copy link
Contributor Author

cladmi commented Sep 27, 2019

Note as I checked, the bracket arguments are only supported since cmake 3 but it is already required in riot to have newer than this, and xenial had 3.5 already and debian jessie had 3.0.2.

CMake quoted strings do not accept having \ or " inside. So use the
"bracket argument" format.
I migrated all variables to use this format.

Migrate to 'printf' to not rely on having \" inside the string everywhere.

This prepares for having macros defined in the CFLAGS again.
export COMP by using the environment insteal of through the shell to
prevnet issues with `\"` being defined when keeping macros in CFLAGS.

Another solution was to use COMP='...' but could there could still have
issues with single quotes in CFLAGS.
Do not remove the '-D' and '-U' values from CFLAGS.
This prevents issues where a '-D' could contain a space.

Some values way be duplicated from the 'riotbuild.h' header and the
command line but with the same value so without conflict.

To not put too many things in the command line, the -DMODULE_NAME are
only put in CFLAGS_WITH_MACROS.

Also, as now, the deferred value of CFLAGS is used for 'riotbuild.h',
macros set after the inclusion of `Makefile.include` will be taken into
account.
This tests passing CFLAGS with spaces to an application and also that
even if the CFLAGS are defined after Makefile.include, they trigger
a rebuild when modified.

This includes an example how to pass macros with spaces to a docker
build.

The test as both an automated part for the CFLAGS with spaces, and a
manual part for the two other features.
@cladmi cladmi force-pushed the pr/cflags/fix_spaces_and_rebuild branch from 00a8924 to d6b109f Compare September 27, 2019 17:30
@cladmi
Copy link
Contributor Author

cladmi commented Sep 27, 2019

I put the commit in order.

It would be good to re-run the test suit too.
I know I had times when trying horrible things where relic was compiling but crashing during test.

@aabadie
Copy link
Contributor

aabadie commented Sep 27, 2019

It seems you had a hard time with this one ;)

@aabadie aabadie added CI: run tests If set, CI server will run tests on hardware for the labeled PR CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 27, 2019
@cladmi
Copy link
Contributor Author

cladmi commented Sep 27, 2019

Took me a while to already get cmake to give me the compilation commands it was executing, so before it was trying everything possible, and after relic worked, ccn-lite got completely broken so yeah :D

I still do not understand the COMP but I think I prefer not knowing.

@miri64 miri64 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 27, 2019
@miri64
Copy link
Member

miri64 commented Sep 27, 2019

Error in murdock seemed unrelated.

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-ran the test locally as explained in the test application README and all worked. pkg_relic was also run with success on Murdock, so there's no problem on this side.

Code changes are still good and commented.

ACK and go!

@aabadie aabadie merged commit 68aae9c into RIOT-OS:master Sep 28, 2019
@kb2ma kb2ma added this to the Release 2019.10 milestone Sep 29, 2019
@cladmi
Copy link
Contributor Author

cladmi commented Sep 30, 2019

Thank you for the review!

@cladmi cladmi deleted the pr/cflags/fix_spaces_and_rebuild branch September 30, 2019 10:12
@kaspar030
Copy link
Contributor

This causes an absolute path to be part of riotbuild.h (e.g., "-include /home/kaspar/src/riot.tmp/examples/hello-world/bin/samr21-xpro/riotbuild/riotbuild.h"), which unfortunately makes caching less effective.

Can we remove at least that define?

@kaspar030
Copy link
Contributor

which unfortunately makes caching less effective.

Some data:

These are the ccache stats after two consecutive builds of all samr21-xpro configurations, of this PR's merge commit:

cache directory                     /data/riotbuild/.ccache                                                                        
primary config                      /data/riotbuild/.ccache/ccache.conf
secondary config      (readonly)    /etc/ccache.conf        
stats zero time                     Mon Sep 30 17:59:37 2019
cache hit (direct)                  2197
cache hit (preprocessed)           72539  
cache miss                          8164  
cache hit rate                     90.15 %
cleanups performed                    16   
files in cache                     53264   
cache size                         304.4 MB
max files                        3500000                   
max cache size                      14.0 GB                

This is from the merge commit before:

cache directory                     /data/riotbuild/.ccache
primary config                      /data/riotbuild/.ccache/ccache.conf
secondary config      (readonly)    /etc/ccache.conf
stats zero time                     Mon Sep 30 18:06:54 2019
cache hit (direct)                 29659
cache hit (preprocessed)           44990
cache miss                          8075
cache hit rate                     90.24 %
cleanups performed                    16
files in cache                     37035
cache size                         193.1 MB
max files                        3500000
max cache size                      14.0 GB

@cladmi
Copy link
Contributor Author

cladmi commented Oct 1, 2019

The include cannot be removed from CFLAGS_WITH_MACROS as depending on the deferred value of CFLAGS makes that it rebuilds with CFLAGS defined after Makefile.include.

To get more information on the caching:

If the same path is used when building and the same application, there should not be any reason to have changes on caching except that there are more characters in a comment than before.
But of course, if the comment changes, it may be possible that the ccache will be discarded due to export CCACHE_CPP2=yes that will keep the comment. Like on a different application.

How were the measures done?

Real issue

The real issue is that the comment in there is useless, it is just there to trigger creating a new file when CFLAGS change and so force re-building due to timestamp update.
I have an easy fix for that.

Question, is there any real reason to rely, to passing macros with this file?
What would happen if this file is empty?
Is there any module that do not rely on getting the flags through CFLAGS?

@kaspar030
Copy link
Contributor

If the same path is used when building and the same application, there should not be any reason to have changes on caching except that there are more characters in a comment than before.

Well, Murdock builds in different paths (per worker thread).

How were the measures done?

I used this script. It basically runs a murdock build twice, but limited to one board and one worker. Also, before the first run, the ccache is emptied and the statistics zeroed. I run this script in a loop over the latest merge commits.
You'll need to send over an ssh key if you'd like to reproduce.

The real issue is that the comment in there is useless, it is just there to trigger creating a new file when CFLAGS change and so force re-building due to timestamp update.

Isn't lazysponge supposed to make sure of that? Change the file stamp on update, I mean?

Question, is there any real reason to rely, to passing macros with this file?

That's a good one. 😉 I'd be happy to remove the file altogether.

Anyhow, for now I propose we either remove the comment in that file, or hack removing the -include <absolute path> entry from it.

@kaspar030
Copy link
Contributor

Question, is there any real reason to rely, to passing macros with this file?

That's a good one. wink I'd be happy to remove the file altogether.

The main reason we introduced this (in #5097) seems to be shorter build command lines.

@cladmi
Copy link
Contributor Author

cladmi commented Oct 1, 2019

If the same path is used when building and the same application, there should not be any reason to have changes on caching except that there are more characters in a comment than before.

Well, Murdock builds in different paths (per worker thread).

How were the measures done?

I used this script. It basically runs a murdock build twice, but limited to one board and one worker. Also, before the first run, the ccache is emptied and the statistics zeroed. I run this script in a loop over the latest merge commits.
You'll need to send over an ssh key if you'd like to reproduce.

Ok so it is a murdock build and not a normal local one. It was not clear with your /home/kaspar/src/riot.tmp/examples/hello-world/bin/samr21-xpro/riotbuild/riotbuild.h path

I still find it bad that a different build path is used, as docker can mount the volume anywhere, and so could reproduce the /data/riotbuild scheme there is with BUILD_IN_DOCKER.
It puts in a position where there incremental builds are not possible at all.

However, I agree the issue here must still be fixed as affects inter applications caching.

The main reason we introduced this (in #5097) seems to be shorter build command lines.

I do not see this as a good reason.

Anyhow, for now I propose we either remove the comment in that file, or hack removing the -include <absolute path> entry from it.

lazysponge relies on the file content being different, so if you remove the comment, the file timestamp will not be updated on CFLAGS change.
So it need to use an intermediate file, the PR is almost ready.

@kaspar030
Copy link
Contributor

I still find it bad that a different build path is used, as docker can mount the volume anywhere, and so could reproduce the /data/riotbuild scheme there is with BUILD_IN_DOCKER.

Docker can do this, but it would require a fresh container for each build (or use of "docker exec"), and both take >1s. Compare that to the total build time of ~2s on average or ~0.5s for the smaller applications.

@cladmi
Copy link
Contributor Author

cladmi commented Oct 1, 2019

And a fix in #12348
It is creating a riotbuild.h.in as before, and the cleaned riotbuild.h

still find it bad that a different build path is used, as docker can mount the volume anywhere, and so could reproduce the /data/riotbuild scheme there is with BUILD_IN_DOCKER.

Docker can do this, but it would require a fresh container for each build (or use of "docker exec"), and both take >1s. Compare that to the total build time of ~2s on average or ~0.5s for the smaller applications.

If each worker has a dedicated directory on the host, and not each job, this one could be updated and still be mapped to the same one inside the container.
But I do not know the low level details, there may be other issues.

@larseggert
Copy link
Contributor

Is there some additional quoting needed for strings that include special characters like $ or !?

@cladmi
Copy link
Contributor Author

cladmi commented Oct 14, 2019

Is there some additional quoting needed for strings that include special characters like $ or !?

It is likely. If you define them inside a Makefile, they will be passed once to a shell in make. So somehow I think in the same way as if you used it on the command line when compiling.
If you define them in the environment variable, they need to be escaped for the definition and maybe for then the passing on the command line while compiling.

Do you have an example ?

@larseggert
Copy link
Contributor

larseggert commented Oct 14, 2019

1c$Ht3! as ESP_WIFI_PASS. The $ disappears. When I quote it as 1c\$$Ht3! it is correct in riotbuild.h, but then i get an error because the redefinition in riotbuild.h is not the same as the command line define

@larseggert
Copy link
Contributor

(This is from within a Makefile.)

@larseggert
Copy link
Contributor

larseggert commented Oct 14, 2019

What does work is to use \\x24 instead of $

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
7 participants