Skip to content

Commit 56e6cbf

Browse files
committed
Add support for ARDUINO_CI_UNIT_TEST_EXTRA_COMPILER_FLAGS environment variable
1 parent 137ee77 commit 56e6cbf

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## [Unreleased]
99
### Added
1010

11+
- Added support for `ARDUINO_CI_UNIT_TEST_EXTRA_COMPILER_FLAGS` environment variable.
12+
1113
### Changed
1214

1315
### Deprecated

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
@@ -485,6 +485,18 @@ def test_args(aux_libraries, ci_gcc_config)
485485
ret
486486
end
487487

488+
# Allow users to inject extra compiler flags though environment variable.
489+
def extra_compiler_flags_for_unittest
490+
return [] unless ENV["ARDUINO_CI_UNIT_TEST_EXTRA_COMPILER_FLAGS"]
491+
492+
delimiter = if ENV["ARDUINO_CI_TEST_EXTRA_COMPILER_FLAGS_DELIMITER"]
493+
yield(ENV["ARDUINO_CI_TEST_EXTRA_COMPILER_FLAGS_DELIMITER"])
494+
else
495+
" "
496+
end
497+
ENV["ARDUINO_CI_UNIT_TEST_EXTRA_COMPILER_FLAGS"].split(delimiter)
498+
end
499+
488500
# build a file for running a test of the given unit test file
489501
#
490502
# The dependent libraries configuration is appended with data from library.properties internal to the library under test
@@ -505,6 +517,7 @@ def build_for_test(test_file, gcc_binary)
505517
]
506518
end
507519
arg_sets << @test_args
520+
arg_sets << extra_compiler_flags_for_unittest
508521
arg_sets << [test_file.to_s, "-l#{LIBRARY_NAME}"]
509522
args = arg_sets.flatten(1)
510523
return nil unless run_gcc(gcc_binary, *args)
@@ -555,6 +568,7 @@ def build_shared_library(aux_libraries, gcc_binary, ci_gcc_config)
555568
@test_args = test_args(@full_dependencies, ci_gcc_config) # build full set of include directories to be cached for later
556569

557570
arg_sets << @test_args
571+
arg_sets << extra_compiler_flags_for_unittest
558572
arg_sets << cpp_files_arduino.map(&:to_s) # Arduino.cpp, Godmode.cpp, and stdlib.cpp
559573
arg_sets << cpp_files_unittest.map(&:to_s) # ArduinoUnitTests.cpp
560574
arg_sets << cpp_files.map(&:to_s) # CPP files for the primary application library under test

0 commit comments

Comments
 (0)