Skip to content

Commit a4661b3

Browse files
committed
Add support for ARDUINO_CI_UNIT_TEST_EXTRA_COMPILER_FLAGS environment variable
1 parent 29ab7b3 commit a4661b3

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
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

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

6969
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.
7070

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

7289
## Indirectly Overriding Build Behavior (medium term use), and Advanced Options
7390

lib/arduino_ci/cpp_library.rb

Lines changed: 14 additions & 0 deletions
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)