Skip to content

Commit 318cdd4

Browse files
committed
Add support for ARDUINO_CI_UNIT_TEST_EXTRA_COMPILER_FLAGS environment variable
1 parent 33a136d commit 318cdd4

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

CHANGELOG.md

+1
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

+17
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

+14
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,18 @@ 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 [] unless ENV["ARDUINO_CI_UNIT_TEST_EXTRA_COMPILER_FLAGS"]
489+
490+
delimiter = if ENV["ARDUINO_CI_TEST_EXTRA_COMPILER_FLAGS_DELIMITER"]
491+
yield(ENV["ARDUINO_CI_TEST_EXTRA_COMPILER_FLAGS_DELIMITER"])
492+
else
493+
" "
494+
end
495+
ENV["ARDUINO_CI_UNIT_TEST_EXTRA_COMPILER_FLAGS"].split(delimiter)
496+
end
497+
486498
# build a file for running a test of the given unit test file
487499
#
488500
# The dependent libraries configuration is appended with data from library.properties internal to the library under test
@@ -503,6 +515,7 @@ def build_for_test(test_file, gcc_binary)
503515
]
504516
end
505517
arg_sets << @test_args
518+
arg_sets << extra_compiler_flags_for_unittest
506519
arg_sets << [test_file.to_s, "-l#{LIBRARY_NAME}"]
507520
args = arg_sets.flatten(1)
508521
return nil unless run_gcc(gcc_binary, *args)
@@ -550,6 +563,7 @@ def build_shared_library(aux_libraries, gcc_binary, ci_gcc_config)
550563
@test_args = test_args(@full_dependencies, ci_gcc_config) # build full set of include directories to be cached for later
551564

552565
arg_sets << @test_args
566+
arg_sets << extra_compiler_flags_for_unittest
553567
arg_sets << cpp_files_arduino.map(&:to_s) # Arduino.cpp, Godmode.cpp, and stdlib.cpp
554568
arg_sets << cpp_files_unittest.map(&:to_s) # ArduinoUnitTests.cpp
555569
arg_sets << cpp_files.map(&:to_s) # CPP files for the primary application library under test

0 commit comments

Comments
 (0)