tests/build_system_cflags_spaces: test CFLAGS macros handling
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.
This commit is contained in:
parent
41d10cf005
commit
d6b109f720
14
tests/build_system_cflags_spaces/Makefile
Normal file
14
tests/build_system_cflags_spaces/Makefile
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
APPLICATION = cflags_with_spaces
|
||||||
|
BOARD ?= native
|
||||||
|
RIOTBASE ?= $(CURDIR)/../..
|
||||||
|
|
||||||
|
CFLAGS += -DSUPER_STRING='"I love sentences with spaces"'
|
||||||
|
|
||||||
|
include $(RIOTBASE)/Makefile.include
|
||||||
|
|
||||||
|
# Changing this value should trigger a rebuild even if defined after
|
||||||
|
# Makefile.include
|
||||||
|
CONFIGURATION_VALUE ?= 0
|
||||||
|
CFLAGS += -DDEFINED_AFTER_MAKEFILE_INCLUDE=$(CONFIGURATION_VALUE)
|
||||||
|
# Exported to be available in the automated test
|
||||||
|
test: export CONFIGURATION_VALUE ?=
|
||||||
43
tests/build_system_cflags_spaces/README.md
Normal file
43
tests/build_system_cflags_spaces/README.md
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
Build system cflags with space test
|
||||||
|
===================================
|
||||||
|
|
||||||
|
This tests that the build system now handles CFLAGS correctly.
|
||||||
|
|
||||||
|
There is an automated test for CFLAGS with spaces when defined in the Makefile.
|
||||||
|
|
||||||
|
|
||||||
|
Other manual tests
|
||||||
|
------------------
|
||||||
|
|
||||||
|
There are also 2 other manual tests that can be run
|
||||||
|
|
||||||
|
|
||||||
|
### Modifying CFLAGS defined after including Makefile.include
|
||||||
|
|
||||||
|
CFLAGS defined after `Makefile.include` trigger a rebuild when changed.
|
||||||
|
|
||||||
|
Running the test once should work and then when changing `CONFIGURATION_VALUE`
|
||||||
|
it should pass too.
|
||||||
|
|
||||||
|
make flash test
|
||||||
|
CONFIGURATION_VALUE=1 make flash test
|
||||||
|
|
||||||
|
|
||||||
|
### Setting CFLAGS with space for docker
|
||||||
|
|
||||||
|
This one is a trickier as CFLAGS are modified in the Makefile, so cannot be
|
||||||
|
detected automatically in the docker handling. The solution is to pass it with
|
||||||
|
`DOCKER_ENVIRONMENT_CMDLINE`.
|
||||||
|
|
||||||
|
When the CFLAGS is defined like this, I did not find another solution than
|
||||||
|
escaping the 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"
|
||||||
|
```
|
||||||
37
tests/build_system_cflags_spaces/main.c
Normal file
37
tests/build_system_cflags_spaces/main.c
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 Freie Universität Berlin
|
||||||
|
*
|
||||||
|
* This file is subject to the terms and conditions of the GNU Lesser
|
||||||
|
* General Public License v2.1. See the file LICENSE in the top level
|
||||||
|
* directory for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup tests
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief Test the CFLAGS handling
|
||||||
|
*
|
||||||
|
* @author Gaëtan Harter <gaetan.harter@fu-berlin.de>
|
||||||
|
*
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* Define a CFLAGS string with spaces from outside docker */
|
||||||
|
/* DOCKER_ENVIRONMENT_CMDLINE=$'-e CFLAGS=-DSTRING_FROM_DOCKER=\'\\\"with\ space\\\"\''*/
|
||||||
|
#ifndef STRING_FROM_DOCKER
|
||||||
|
#define STRING_FROM_DOCKER ""
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
puts("The output of the configuration variables:");
|
||||||
|
printf("SUPER_STRING: %s\n", SUPER_STRING);
|
||||||
|
printf("DEFINED_AFTER_MAKEFILE_INCLUDE: %u\n", DEFINED_AFTER_MAKEFILE_INCLUDE);
|
||||||
|
printf("CFLAGS_STRING_FROM_DOCKER: %s\n", STRING_FROM_DOCKER);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
38
tests/build_system_cflags_spaces/tests/01-run.py
Executable file
38
tests/build_system_cflags_spaces/tests/01-run.py
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# Copyright (C) 2019 Freie Universität Berlin
|
||||||
|
#
|
||||||
|
# This file is subject to the terms and conditions of the GNU Lesser
|
||||||
|
# General Public License v2.1. See the file LICENSE in the top level
|
||||||
|
# directory for more details.
|
||||||
|
|
||||||
|
"""
|
||||||
|
Test for passing `CFLAGS` with spaces to the application.
|
||||||
|
|
||||||
|
It also tests that even if a `CFLAGS` is set after including Makefile.include,
|
||||||
|
changing its value will trigger a rebuild.
|
||||||
|
|
||||||
|
There is also a way to test passing additional values with spaces to docker
|
||||||
|
documented in the `README.md`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from testrunner import run
|
||||||
|
|
||||||
|
|
||||||
|
# Verify the macro matches the configuration value
|
||||||
|
CONFIGURATION_VALUE = os.environ['CONFIGURATION_VALUE']
|
||||||
|
|
||||||
|
|
||||||
|
def testfunc(child):
|
||||||
|
child.expect_exact('The output of the configuration variables:')
|
||||||
|
child.expect_exact('SUPER_STRING: I love sentences with spaces')
|
||||||
|
child.expect_exact('DEFINED_AFTER_MAKEFILE_INCLUDE: %s' %
|
||||||
|
CONFIGURATION_VALUE)
|
||||||
|
# This one is not tested here, see the output in 'riotbuild.h'
|
||||||
|
child.expect(r'CFLAGS_STRING_FROM_DOCKER: .*')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(run(testfunc))
|
||||||
Loading…
x
Reference in New Issue
Block a user