Skip to content

Commit 40c3d2b

Browse files
committed
Add support for ARDUINO_CI_UNIT_TEST_EXTRA_COMPILER_FLAGS environment variable
1 parent 21b63e6 commit 40c3d2b

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
- Support for `dtostrf()`
1515
- Added a CI workflow to lint the code base
1616
- Added a CI workflow to check for spelling errors
17+
- Added support for `ARDUINO_CI_UNIT_TEST_EXTRA_COMPILER_FLAGS` environment variable.
1718

1819
### Changed
1920
- We now compile a shared library to be used for each test.

REFERENCE.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ If set, testing will fail if no unit test files are detected (or if the director
6363

6464
If set, testing will fail if no example sketches are detected. This is to avoid communicating a passing status in cases where a commit may have accidentally moved or deleted the examples.
6565

66+
### `ARDUINO_CI_UNIT_TEST_EXTRA_COMPILER_FLAGS` environment variable
67+
68+
If you want to pass on additional flags to the compiler when it runs unit tests
69+
you can set this variable, e.g.
70+
71+
```bash
72+
export ARDUINO_CI_UNIT_TEST_EXTRA_COMPILER_FLAGS="--coverage -g -O0"
73+
```
74+
75+
By default the variable will be split up by space characters. If one of the
76+
flags contain spaces use the `ARDUINO_CI_TEST_EXTRA_COMPILER_FLAGS_DELIMITER`
77+
variable to chose a different delimiter, e.g.
78+
79+
```bash
80+
export ARDUINO_CI_TEST_EXTRA_COMPILER_FLAGS_DELIMITER="|"
81+
export ARDUINO_CI_UNIT_TEST_EXTRA_COMPILER_FLAGS="-Wall|-DGREETING='Hello world'"
82+
```
6683

6784
## Indirectly Overriding Build Behavior (medium term use), and Advanced Options
6885

lib/arduino_ci/cpp_library.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,19 @@ def test_args(aux_libraries, ci_gcc_config)
483483
ret
484484
end
485485

486+
# Allow users to inject extra compiler flags though environment variable.
487+
def extra_compiler_flags_for_unittest
488+
return [] if not ENV["ARDUINO_CI_UNIT_TEST_EXTRA_COMPILER_FLAGS"]
489+
490+
if ENV["ARDUINO_CI_TEST_EXTRA_COMPILER_FLAGS_DELIMITER"]
491+
delimiter = ENV["ARDUINO_CI_TEST_EXTRA_COMPILER_FLAGS_DELIMITER"];
492+
else
493+
delimiter = " "
494+
end
495+
ret = ENV["ARDUINO_CI_UNIT_TEST_EXTRA_COMPILER_FLAGS"].split(delimiter)
496+
ret
497+
end
498+
486499
# build a file for running a test of the given unit test file
487500
#
488501
# The dependent libraries configuration is appended with data from library.properties internal to the library under test
@@ -503,6 +516,7 @@ def build_for_test(test_file, gcc_binary)
503516
]
504517
end
505518
arg_sets << @test_args
519+
arg_sets << extra_compiler_flags_for_unittest()
506520
arg_sets << [test_file.to_s, "-l#{LIBRARY_NAME}"]
507521
args = arg_sets.flatten(1)
508522
return nil unless run_gcc(gcc_binary, *args)
@@ -550,6 +564,7 @@ def build_shared_library(aux_libraries, gcc_binary, ci_gcc_config)
550564
@test_args = test_args(@full_dependencies, ci_gcc_config) # build full set of include directories to be cached for later
551565

552566
arg_sets << @test_args
567+
arg_sets << extra_compiler_flags_for_unittest()
553568
arg_sets << cpp_files_arduino.map(&:to_s) # Arduino.cpp, Godmode.cpp, and stdlib.cpp
554569
arg_sets << cpp_files_unittest.map(&:to_s) # ArduinoUnitTests.cpp
555570
arg_sets << cpp_files.map(&:to_s) # CPP files for the primary application library under test

0 commit comments

Comments
 (0)