Skip to content

Add Arduino CLI compile flags input #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ on:
pull_request:
paths:
- '.github/workflows/test-integration.yml'
- '.github/workflows/testdata'
- '.github/workflows/testdata/**'
- 'action.yml'
- 'action-setup.sh'
- 'compilesketches/**'

push:
paths:
- '.github/workflows/test-integration.yml'
- '.github/workflows/testdata'
- '.github/workflows/testdata/**'
- 'action.yml'
- 'action-setup.sh'
- 'compilesketches/**'
Expand Down Expand Up @@ -78,18 +78,27 @@ jobs:
# Use action from local path
uses: ./
with:
cli-version: 0.13.0
cli-version: 0.15.1
platforms: ${{ matrix.board.platforms }}
fqbn: ${{ matrix.board.fqbn }}
libraries: ${{ matrix.board.libraries }}
sketch-paths: |
- ${{ env.TESTDATA_SKETCHES_PATH }}/BareMinimum
- ${{ env.TESTDATA_SKETCHES_PATH }}/ServoLibrary
- ${{ env.TESTDATA_SKETCHES_PATH }}/TestCompileFlags
cli-compile-flags: |
- --build-property
- compiler.cpp.extra_flags="-DSTRING_MACRO="hello world"" -DINT_MACRO=2 -DFLAG_MACRO
- --export-binaries
enable-deltas-report: true
enable-warnings-report: true
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
verbose: true

- name: Verify --export-binaries flag was used by compilation command
run: |
[ -d ${{ env.TESTDATA_SKETCHES_PATH }}/BareMinimum/build ]

- name: Set report artifact name
id: report-artifact-name
run: |
Expand Down
53 changes: 51 additions & 2 deletions .github/workflows/testdata/reports/all-inputs/arduino-avr-uno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"commit_hash": "d4343a2e7d8123726f2c53d2ac186df41b59e946",
"commit_url": "https://github.com/arduino/compile-sketches/commit/d4343a2e7d8123726f2c53d2ac186df41b59e946",
"commit_hash": "d2ed774ec1f37e6e497b6d629963cbc79632e9f9",
"commit_url": "https://github.com/arduino/compile-sketches/commit/d2ed774ec1f37e6e497b6d629963cbc79632e9f9",
"boards": [
{
"board": "arduino:avr:uno",
Expand Down Expand Up @@ -102,6 +102,55 @@
"absolute": 0
}
}
},
{
"name": ".github/workflows/testdata/sketches/TestCompileFlags",
"compilation_success": true,
"sizes": [
{
"name": "flash",
"maximum": 32256,
"current": {
"absolute": 444,
"relative": 1.38
},
"previous": {
"absolute": 444,
"relative": 1.38
},
"delta": {
"absolute": 0,
"relative": 0.0
}
},
{
"name": "RAM for global variables",
"maximum": 2048,
"current": {
"absolute": 9,
"relative": 0.44
},
"previous": {
"absolute": 9,
"relative": 0.44
},
"delta": {
"absolute": 0,
"relative": 0.0
}
}
],
"warnings": {
"current": {
"absolute": 1
},
"previous": {
"absolute": 1
},
"delta": {
"absolute": 0
}
}
}
],
"sizes": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"commit_hash": "d4343a2e7d8123726f2c53d2ac186df41b59e946",
"commit_url": "https://github.com/arduino/compile-sketches/commit/d4343a2e7d8123726f2c53d2ac186df41b59e946",
"commit_hash": "d2ed774ec1f37e6e497b6d629963cbc79632e9f9",
"commit_url": "https://github.com/arduino/compile-sketches/commit/d2ed774ec1f37e6e497b6d629963cbc79632e9f9",
"boards": [
{
"board": "esp8266:esp8266:huzzah",
Expand Down Expand Up @@ -102,6 +102,55 @@
"absolute": 0
}
}
},
{
"name": ".github/workflows/testdata/sketches/TestCompileFlags",
"compilation_success": true,
"sizes": [
{
"name": "flash",
"maximum": 1044464,
"current": {
"absolute": 256684,
"relative": 24.58
},
"previous": {
"absolute": 256684,
"relative": 24.58
},
"delta": {
"absolute": 0,
"relative": 0.0
}
},
{
"name": "RAM for global variables",
"maximum": 81920,
"current": {
"absolute": 26776,
"relative": 32.69
},
"previous": {
"absolute": 26776,
"relative": 32.69
},
"delta": {
"absolute": 0,
"relative": 0.0
}
}
],
"warnings": {
"current": {
"absolute": 1
},
"previous": {
"absolute": 1
},
"delta": {
"absolute": 0
}
}
}
],
"sizes": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#if INT_MACRO != 2
#error
#endif

#ifndef FLAG_MACRO
#error
#endif

void setup() {
char string[]=STRING_MACRO; // Will fail if the macro is not a string literal
}
void loop(){}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This action checks whether [Arduino](https://www.arduino.cc/) sketches compile a
- [Repository](#repository-1)
- [Archive download](#archive-download-1)
- [`sketch-paths`](#sketch-paths)
- [`cli-compile-flags`](#cli-compile-flags)
- [`verbose`](#verbose)
- [`sketches-report-path`](#sketches-report-path)
- [`github-token`](#github-token)
Expand Down Expand Up @@ -162,6 +163,12 @@ Keys:

**Default**: `"- examples"`

### `cli-compile-flags`

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).

**Default**: `""`

### `verbose`

Set to true to show verbose output in the log.
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ inputs:
description: 'YAML-format list of paths containing sketches to compile.'
default: '- examples'
required: true
cli-compile-flags:
description: 'YAML-format list of flags to add to the Arduino CLI sketch compilation command.'
default: ''
required: false
verbose:
description: 'Set to true to show verbose output in the log'
default: 'false'
Expand Down Expand Up @@ -62,6 +66,7 @@ runs:
INPUT_LIBRARIES: ${{ inputs.libraries }}
INPUT_PLATFORMS: ${{ inputs.platforms }}
INPUT_SKETCH-PATHS: ${{ inputs.sketch-paths }}
INPUT_CLI-COMPILE-FLAGS: ${{ inputs.cli-compile-flags }}
INPUT_VERBOSE: ${{ inputs.verbose }}
INPUT_GITHUB-TOKEN: ${{ inputs.github-token }}
INPUT_ENABLE-DELTAS-REPORT: ${{ inputs.enable-deltas-report }}
Expand Down
12 changes: 9 additions & 3 deletions compilesketches/compilesketches.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def main():
platforms=os.environ["INPUT_PLATFORMS"],
libraries=os.environ["INPUT_LIBRARIES"],
sketch_paths=os.environ["INPUT_SKETCH-PATHS"],
cli_compile_flags=os.environ["INPUT_CLI-COMPILE-FLAGS"],
verbose=os.environ["INPUT_VERBOSE"],
github_token=os.environ["INPUT_GITHUB-TOKEN"],
enable_deltas_report=os.environ["INPUT_ENABLE-DELTAS-REPORT"],
Expand All @@ -64,6 +65,7 @@ class CompileSketches:
libraries -- YAML-format or space-separated list of libraries to install
sketch_paths -- space-separated list of paths containing sketches to compile. These paths will be searched
recursively for sketches.
cli_compile_flags -- Arbitrary Arduino CLI flags to add to the compile command.
verbose -- set to "true" for verbose output ("true", "false")
github_token -- GitHub access token
enable_deltas_report -- set to "true" to cause the action to determine the change in memory usage
Expand Down Expand Up @@ -115,8 +117,8 @@ class ReportKeys:

latest_release_indicator = "latest"

def __init__(self, cli_version, fqbn_arg, platforms, libraries, sketch_paths, verbose, github_token,
enable_deltas_report, enable_warnings_report, sketches_report_path):
def __init__(self, cli_version, fqbn_arg, platforms, libraries, sketch_paths, cli_compile_flags, verbose,
github_token, enable_deltas_report, enable_warnings_report, sketches_report_path):
"""Process, store, and validate the action's inputs."""
self.cli_version = cli_version

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

self.cli_compile_flags = yaml.load(stream=cli_compile_flags, Loader=yaml.SafeLoader)
self.verbose = parse_boolean_input(boolean_input=verbose)

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

if clean_build_cache:
for cache_path in pathlib.Path("/tmp").glob(pattern="arduino*"):
Expand Down
14 changes: 14 additions & 0 deletions compilesketches/tests/test_compilesketches.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def get_compilesketches_object(
platforms="- name: FooVendor:BarArchitecture",
libraries="foo libraries",
sketch_paths="foo sketch_paths",
cli_compile_flags="--foo",
verbose="false",
github_token="",
github_api=unittest.mock.sentinel.github_api,
Expand All @@ -41,6 +42,7 @@ def get_compilesketches_object(
platforms=platforms,
libraries=libraries,
sketch_paths=sketch_paths,
cli_compile_flags=cli_compile_flags,
verbose=verbose,
github_token=github_token,
enable_deltas_report=enable_deltas_report,
Expand Down Expand Up @@ -89,6 +91,7 @@ class ActionInputs:
platforms = "- name: FooVendor:BarArchitecture"
libraries = "foo libraries"
sketch_paths = "foo/Sketch bar/OtherSketch"
cli_compile_flags = "--foo"
verbose = "true"
github_token = "FooGitHubToken"
enable_size_deltas_report = "FooEnableSizeDeltasReport"
Expand All @@ -102,6 +105,7 @@ class ActionInputs:
monkeypatch.setenv("INPUT_PLATFORMS", ActionInputs.platforms)
monkeypatch.setenv("INPUT_LIBRARIES", ActionInputs.libraries)
monkeypatch.setenv("INPUT_SKETCH-PATHS", ActionInputs.sketch_paths)
monkeypatch.setenv("INPUT_CLI-COMPILE-FLAGS", ActionInputs.cli_compile_flags)
monkeypatch.setenv("INPUT_VERBOSE", ActionInputs.verbose)
monkeypatch.setenv("INPUT_GITHUB-TOKEN", ActionInputs.github_token)
monkeypatch.setenv("INPUT_ENABLE-DELTAS-REPORT", ActionInputs.enable_deltas_report)
Expand Down Expand Up @@ -227,6 +231,7 @@ def compile_sketches(self):
platforms=setup_action_inputs.platforms,
libraries=setup_action_inputs.libraries,
sketch_paths=setup_action_inputs.sketch_paths,
cli_compile_flags=setup_action_inputs.cli_compile_flags,
verbose=setup_action_inputs.verbose,
github_token=setup_action_inputs.github_token,
enable_deltas_report=setup_action_inputs.enable_deltas_report,
Expand All @@ -246,6 +251,8 @@ def test_compilesketches():
sketch_paths = "examples/FooSketchPath examples/BarSketchPath"
expected_sketch_paths_list = [compilesketches.absolute_path(path="examples/FooSketchPath"),
compilesketches.absolute_path(path="examples/BarSketchPath")]
cli_compile_flags = "- --foo\n- --bar"
expected_cli_compile_flags = ["--foo", "--bar"]
verbose = "false"
github_token = "fooGitHubToken"
expected_deltas_base_ref = unittest.mock.sentinel.deltas_base_ref
Expand All @@ -262,6 +269,7 @@ def test_compilesketches():
platforms=platforms,
libraries=libraries,
sketch_paths=sketch_paths,
cli_compile_flags=cli_compile_flags,
verbose=verbose,
github_token=github_token,
enable_deltas_report=enable_deltas_report,
Expand All @@ -275,12 +283,18 @@ def test_compilesketches():
assert compile_sketches.platforms == platforms
assert compile_sketches.libraries == libraries
assert compile_sketches.sketch_paths == expected_sketch_paths_list
assert compile_sketches.cli_compile_flags == expected_cli_compile_flags
assert compile_sketches.verbose is False
assert compile_sketches.deltas_base_ref == expected_deltas_base_ref
assert compile_sketches.enable_deltas_report is True
assert compile_sketches.enable_warnings_report is True
assert compile_sketches.sketches_report_path == pathlib.PurePath(sketches_report_path)

assert get_compilesketches_object(cli_compile_flags="").cli_compile_flags is None
assert get_compilesketches_object(cli_compile_flags="- --foo").cli_compile_flags == ["--foo"]
assert get_compilesketches_object(cli_compile_flags="- --foo\n- \"bar baz\"").cli_compile_flags == ["--foo",
"bar baz"]

# Test invalid enable_deltas_report value
with pytest.raises(expected_exception=SystemExit, match="1"):
get_compilesketches_object(enable_deltas_report="fooInvalidEnableSizeDeltasBoolean")
Expand Down