Skip to content

Commit 656a871

Browse files
authored
Merge pull request #18 from per1234/build-property
Add Arduino CLI compile flags input
2 parents 598911a + f883dd5 commit 656a871

File tree

8 files changed

+161
-10
lines changed

8 files changed

+161
-10
lines changed

.github/workflows/test-integration.yml

+12-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ on:
44
pull_request:
55
paths:
66
- '.github/workflows/test-integration.yml'
7-
- '.github/workflows/testdata'
7+
- '.github/workflows/testdata/**'
88
- 'action.yml'
99
- 'action-setup.sh'
1010
- 'compilesketches/**'
1111

1212
push:
1313
paths:
1414
- '.github/workflows/test-integration.yml'
15-
- '.github/workflows/testdata'
15+
- '.github/workflows/testdata/**'
1616
- 'action.yml'
1717
- 'action-setup.sh'
1818
- 'compilesketches/**'
@@ -78,18 +78,27 @@ jobs:
7878
# Use action from local path
7979
uses: ./
8080
with:
81-
cli-version: 0.13.0
81+
cli-version: 0.15.1
8282
platforms: ${{ matrix.board.platforms }}
8383
fqbn: ${{ matrix.board.fqbn }}
8484
libraries: ${{ matrix.board.libraries }}
8585
sketch-paths: |
8686
- ${{ env.TESTDATA_SKETCHES_PATH }}/BareMinimum
8787
- ${{ env.TESTDATA_SKETCHES_PATH }}/ServoLibrary
88+
- ${{ env.TESTDATA_SKETCHES_PATH }}/TestCompileFlags
89+
cli-compile-flags: |
90+
- --build-property
91+
- compiler.cpp.extra_flags="-DSTRING_MACRO="hello world"" -DINT_MACRO=2 -DFLAG_MACRO
92+
- --export-binaries
8893
enable-deltas-report: true
8994
enable-warnings-report: true
9095
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
9196
verbose: true
9297

98+
- name: Verify --export-binaries flag was used by compilation command
99+
run: |
100+
[ -d ${{ env.TESTDATA_SKETCHES_PATH }}/BareMinimum/build ]
101+
93102
- name: Set report artifact name
94103
id: report-artifact-name
95104
run: |

.github/workflows/testdata/reports/all-inputs/arduino-avr-uno.json

+51-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"commit_hash": "d4343a2e7d8123726f2c53d2ac186df41b59e946",
3-
"commit_url": "https://github.com/arduino/compile-sketches/commit/d4343a2e7d8123726f2c53d2ac186df41b59e946",
2+
"commit_hash": "d2ed774ec1f37e6e497b6d629963cbc79632e9f9",
3+
"commit_url": "https://github.com/arduino/compile-sketches/commit/d2ed774ec1f37e6e497b6d629963cbc79632e9f9",
44
"boards": [
55
{
66
"board": "arduino:avr:uno",
@@ -102,6 +102,55 @@
102102
"absolute": 0
103103
}
104104
}
105+
},
106+
{
107+
"name": ".github/workflows/testdata/sketches/TestCompileFlags",
108+
"compilation_success": true,
109+
"sizes": [
110+
{
111+
"name": "flash",
112+
"maximum": 32256,
113+
"current": {
114+
"absolute": 444,
115+
"relative": 1.38
116+
},
117+
"previous": {
118+
"absolute": 444,
119+
"relative": 1.38
120+
},
121+
"delta": {
122+
"absolute": 0,
123+
"relative": 0.0
124+
}
125+
},
126+
{
127+
"name": "RAM for global variables",
128+
"maximum": 2048,
129+
"current": {
130+
"absolute": 9,
131+
"relative": 0.44
132+
},
133+
"previous": {
134+
"absolute": 9,
135+
"relative": 0.44
136+
},
137+
"delta": {
138+
"absolute": 0,
139+
"relative": 0.0
140+
}
141+
}
142+
],
143+
"warnings": {
144+
"current": {
145+
"absolute": 1
146+
},
147+
"previous": {
148+
"absolute": 1
149+
},
150+
"delta": {
151+
"absolute": 0
152+
}
153+
}
105154
}
106155
],
107156
"sizes": [

.github/workflows/testdata/reports/all-inputs/esp8266-esp8266-huzzah.json

+51-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"commit_hash": "d4343a2e7d8123726f2c53d2ac186df41b59e946",
3-
"commit_url": "https://github.com/arduino/compile-sketches/commit/d4343a2e7d8123726f2c53d2ac186df41b59e946",
2+
"commit_hash": "d2ed774ec1f37e6e497b6d629963cbc79632e9f9",
3+
"commit_url": "https://github.com/arduino/compile-sketches/commit/d2ed774ec1f37e6e497b6d629963cbc79632e9f9",
44
"boards": [
55
{
66
"board": "esp8266:esp8266:huzzah",
@@ -102,6 +102,55 @@
102102
"absolute": 0
103103
}
104104
}
105+
},
106+
{
107+
"name": ".github/workflows/testdata/sketches/TestCompileFlags",
108+
"compilation_success": true,
109+
"sizes": [
110+
{
111+
"name": "flash",
112+
"maximum": 1044464,
113+
"current": {
114+
"absolute": 256684,
115+
"relative": 24.58
116+
},
117+
"previous": {
118+
"absolute": 256684,
119+
"relative": 24.58
120+
},
121+
"delta": {
122+
"absolute": 0,
123+
"relative": 0.0
124+
}
125+
},
126+
{
127+
"name": "RAM for global variables",
128+
"maximum": 81920,
129+
"current": {
130+
"absolute": 26776,
131+
"relative": 32.69
132+
},
133+
"previous": {
134+
"absolute": 26776,
135+
"relative": 32.69
136+
},
137+
"delta": {
138+
"absolute": 0,
139+
"relative": 0.0
140+
}
141+
}
142+
],
143+
"warnings": {
144+
"current": {
145+
"absolute": 1
146+
},
147+
"previous": {
148+
"absolute": 1
149+
},
150+
"delta": {
151+
"absolute": 0
152+
}
153+
}
105154
}
106155
],
107156
"sizes": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#if INT_MACRO != 2
2+
#error
3+
#endif
4+
5+
#ifndef FLAG_MACRO
6+
#error
7+
#endif
8+
9+
void setup() {
10+
char string[]=STRING_MACRO; // Will fail if the macro is not a string literal
11+
}
12+
void loop(){}

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This action checks whether [Arduino](https://www.arduino.cc/) sketches compile a
2727
- [Repository](#repository-1)
2828
- [Archive download](#archive-download-1)
2929
- [`sketch-paths`](#sketch-paths)
30+
- [`cli-compile-flags`](#cli-compile-flags)
3031
- [`verbose`](#verbose)
3132
- [`sketches-report-path`](#sketches-report-path)
3233
- [`github-token`](#github-token)
@@ -162,6 +163,12 @@ Keys:
162163

163164
**Default**: `"- examples"`
164165

166+
### `cli-compile-flags`
167+
168+
YAML-format list of flags to add to the Arduino CLI command used to compile the sketches. For the available flags, see [the Arduino CLI command reference](https://arduino.github.io/arduino-cli/latest/commands/arduino-cli_compile/#options).
169+
170+
**Default**: `""`
171+
165172
### `verbose`
166173

167174
Set to true to show verbose output in the log.

action.yml

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ inputs:
2121
description: 'YAML-format list of paths containing sketches to compile.'
2222
default: '- examples'
2323
required: true
24+
cli-compile-flags:
25+
description: 'YAML-format list of flags to add to the Arduino CLI sketch compilation command.'
26+
default: ''
27+
required: false
2428
verbose:
2529
description: 'Set to true to show verbose output in the log'
2630
default: 'false'
@@ -62,6 +66,7 @@ runs:
6266
INPUT_LIBRARIES: ${{ inputs.libraries }}
6367
INPUT_PLATFORMS: ${{ inputs.platforms }}
6468
INPUT_SKETCH-PATHS: ${{ inputs.sketch-paths }}
69+
INPUT_CLI-COMPILE-FLAGS: ${{ inputs.cli-compile-flags }}
6570
INPUT_VERBOSE: ${{ inputs.verbose }}
6671
INPUT_GITHUB-TOKEN: ${{ inputs.github-token }}
6772
INPUT_ENABLE-DELTAS-REPORT: ${{ inputs.enable-deltas-report }}

compilesketches/compilesketches.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def main():
4343
platforms=os.environ["INPUT_PLATFORMS"],
4444
libraries=os.environ["INPUT_LIBRARIES"],
4545
sketch_paths=os.environ["INPUT_SKETCH-PATHS"],
46+
cli_compile_flags=os.environ["INPUT_CLI-COMPILE-FLAGS"],
4647
verbose=os.environ["INPUT_VERBOSE"],
4748
github_token=os.environ["INPUT_GITHUB-TOKEN"],
4849
enable_deltas_report=os.environ["INPUT_ENABLE-DELTAS-REPORT"],
@@ -64,6 +65,7 @@ class CompileSketches:
6465
libraries -- YAML-format or space-separated list of libraries to install
6566
sketch_paths -- space-separated list of paths containing sketches to compile. These paths will be searched
6667
recursively for sketches.
68+
cli_compile_flags -- Arbitrary Arduino CLI flags to add to the compile command.
6769
verbose -- set to "true" for verbose output ("true", "false")
6870
github_token -- GitHub access token
6971
enable_deltas_report -- set to "true" to cause the action to determine the change in memory usage
@@ -115,8 +117,8 @@ class ReportKeys:
115117

116118
latest_release_indicator = "latest"
117119

118-
def __init__(self, cli_version, fqbn_arg, platforms, libraries, sketch_paths, verbose, github_token,
119-
enable_deltas_report, enable_warnings_report, sketches_report_path):
120+
def __init__(self, cli_version, fqbn_arg, platforms, libraries, sketch_paths, cli_compile_flags, verbose,
121+
github_token, enable_deltas_report, enable_warnings_report, sketches_report_path):
120122
"""Process, store, and validate the action's inputs."""
121123
self.cli_version = cli_version
122124

@@ -131,6 +133,7 @@ def __init__(self, cli_version, fqbn_arg, platforms, libraries, sketch_paths, ve
131133
absolute_sketch_paths = [absolute_path(path=sketch_path) for sketch_path in sketch_paths.value]
132134
self.sketch_paths = absolute_sketch_paths
133135

136+
self.cli_compile_flags = yaml.load(stream=cli_compile_flags, Loader=yaml.SafeLoader)
134137
self.verbose = parse_boolean_input(boolean_input=verbose)
135138

136139
if github_token == "":
@@ -871,7 +874,10 @@ def compile_sketch(self, sketch_path, clean_build_cache):
871874
sketch_path -- path of the sketch to compile
872875
clean_build_cache -- whether to delete cached compiled from previous compilations before compiling
873876
"""
874-
compilation_command = ["compile", "--warnings", "all", "--fqbn", self.fqbn, sketch_path]
877+
compilation_command = ["compile", "--warnings", "all", "--fqbn", self.fqbn]
878+
if self.cli_compile_flags is not None:
879+
compilation_command.extend(self.cli_compile_flags)
880+
compilation_command.append(sketch_path)
875881

876882
if clean_build_cache:
877883
for cache_path in pathlib.Path("/tmp").glob(pattern="arduino*"):

compilesketches/tests/test_compilesketches.py

+14
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def get_compilesketches_object(
2525
platforms="- name: FooVendor:BarArchitecture",
2626
libraries="foo libraries",
2727
sketch_paths="foo sketch_paths",
28+
cli_compile_flags="--foo",
2829
verbose="false",
2930
github_token="",
3031
github_api=unittest.mock.sentinel.github_api,
@@ -41,6 +42,7 @@ def get_compilesketches_object(
4142
platforms=platforms,
4243
libraries=libraries,
4344
sketch_paths=sketch_paths,
45+
cli_compile_flags=cli_compile_flags,
4446
verbose=verbose,
4547
github_token=github_token,
4648
enable_deltas_report=enable_deltas_report,
@@ -89,6 +91,7 @@ class ActionInputs:
8991
platforms = "- name: FooVendor:BarArchitecture"
9092
libraries = "foo libraries"
9193
sketch_paths = "foo/Sketch bar/OtherSketch"
94+
cli_compile_flags = "--foo"
9295
verbose = "true"
9396
github_token = "FooGitHubToken"
9497
enable_size_deltas_report = "FooEnableSizeDeltasReport"
@@ -102,6 +105,7 @@ class ActionInputs:
102105
monkeypatch.setenv("INPUT_PLATFORMS", ActionInputs.platforms)
103106
monkeypatch.setenv("INPUT_LIBRARIES", ActionInputs.libraries)
104107
monkeypatch.setenv("INPUT_SKETCH-PATHS", ActionInputs.sketch_paths)
108+
monkeypatch.setenv("INPUT_CLI-COMPILE-FLAGS", ActionInputs.cli_compile_flags)
105109
monkeypatch.setenv("INPUT_VERBOSE", ActionInputs.verbose)
106110
monkeypatch.setenv("INPUT_GITHUB-TOKEN", ActionInputs.github_token)
107111
monkeypatch.setenv("INPUT_ENABLE-DELTAS-REPORT", ActionInputs.enable_deltas_report)
@@ -227,6 +231,7 @@ def compile_sketches(self):
227231
platforms=setup_action_inputs.platforms,
228232
libraries=setup_action_inputs.libraries,
229233
sketch_paths=setup_action_inputs.sketch_paths,
234+
cli_compile_flags=setup_action_inputs.cli_compile_flags,
230235
verbose=setup_action_inputs.verbose,
231236
github_token=setup_action_inputs.github_token,
232237
enable_deltas_report=setup_action_inputs.enable_deltas_report,
@@ -246,6 +251,8 @@ def test_compilesketches():
246251
sketch_paths = "examples/FooSketchPath examples/BarSketchPath"
247252
expected_sketch_paths_list = [compilesketches.absolute_path(path="examples/FooSketchPath"),
248253
compilesketches.absolute_path(path="examples/BarSketchPath")]
254+
cli_compile_flags = "- --foo\n- --bar"
255+
expected_cli_compile_flags = ["--foo", "--bar"]
249256
verbose = "false"
250257
github_token = "fooGitHubToken"
251258
expected_deltas_base_ref = unittest.mock.sentinel.deltas_base_ref
@@ -262,6 +269,7 @@ def test_compilesketches():
262269
platforms=platforms,
263270
libraries=libraries,
264271
sketch_paths=sketch_paths,
272+
cli_compile_flags=cli_compile_flags,
265273
verbose=verbose,
266274
github_token=github_token,
267275
enable_deltas_report=enable_deltas_report,
@@ -275,12 +283,18 @@ def test_compilesketches():
275283
assert compile_sketches.platforms == platforms
276284
assert compile_sketches.libraries == libraries
277285
assert compile_sketches.sketch_paths == expected_sketch_paths_list
286+
assert compile_sketches.cli_compile_flags == expected_cli_compile_flags
278287
assert compile_sketches.verbose is False
279288
assert compile_sketches.deltas_base_ref == expected_deltas_base_ref
280289
assert compile_sketches.enable_deltas_report is True
281290
assert compile_sketches.enable_warnings_report is True
282291
assert compile_sketches.sketches_report_path == pathlib.PurePath(sketches_report_path)
283292

293+
assert get_compilesketches_object(cli_compile_flags="").cli_compile_flags is None
294+
assert get_compilesketches_object(cli_compile_flags="- --foo").cli_compile_flags == ["--foo"]
295+
assert get_compilesketches_object(cli_compile_flags="- --foo\n- \"bar baz\"").cli_compile_flags == ["--foo",
296+
"bar baz"]
297+
284298
# Test invalid enable_deltas_report value
285299
with pytest.raises(expected_exception=SystemExit, match="1"):
286300
get_compilesketches_object(enable_deltas_report="fooInvalidEnableSizeDeltasBoolean")

0 commit comments

Comments
 (0)