diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml index e738e4c..82fc8b2 100644 --- a/.github/workflows/test-integration.yml +++ b/.github/workflows/test-integration.yml @@ -4,7 +4,7 @@ on: pull_request: paths: - '.github/workflows/test-integration.yml' - - '.github/workflows/testdata' + - '.github/workflows/testdata/**' - 'action.yml' - 'action-setup.sh' - 'compilesketches/**' @@ -12,7 +12,7 @@ on: push: paths: - '.github/workflows/test-integration.yml' - - '.github/workflows/testdata' + - '.github/workflows/testdata/**' - 'action.yml' - 'action-setup.sh' - 'compilesketches/**' @@ -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: | diff --git a/.github/workflows/testdata/reports/all-inputs/arduino-avr-uno.json b/.github/workflows/testdata/reports/all-inputs/arduino-avr-uno.json index ebf7b42..c4ef529 100644 --- a/.github/workflows/testdata/reports/all-inputs/arduino-avr-uno.json +++ b/.github/workflows/testdata/reports/all-inputs/arduino-avr-uno.json @@ -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", @@ -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": [ diff --git a/.github/workflows/testdata/reports/all-inputs/esp8266-esp8266-huzzah.json b/.github/workflows/testdata/reports/all-inputs/esp8266-esp8266-huzzah.json index 6876eef..242a6ed 100644 --- a/.github/workflows/testdata/reports/all-inputs/esp8266-esp8266-huzzah.json +++ b/.github/workflows/testdata/reports/all-inputs/esp8266-esp8266-huzzah.json @@ -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", @@ -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": [ diff --git a/.github/workflows/testdata/sketches/TestCompileFlags/TestCompileFlags.ino b/.github/workflows/testdata/sketches/TestCompileFlags/TestCompileFlags.ino new file mode 100644 index 0000000..949f82b --- /dev/null +++ b/.github/workflows/testdata/sketches/TestCompileFlags/TestCompileFlags.ino @@ -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(){} diff --git a/README.md b/README.md index 360ac36..a6e6db4 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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. diff --git a/action.yml b/action.yml index 7bbb4c7..1f593b4 100644 --- a/action.yml +++ b/action.yml @@ -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' @@ -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 }} diff --git a/compilesketches/compilesketches.py b/compilesketches/compilesketches.py index bf3a6e6..678ae7b 100644 --- a/compilesketches/compilesketches.py +++ b/compilesketches/compilesketches.py @@ -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"], @@ -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 @@ -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 @@ -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 == "": @@ -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*"): diff --git a/compilesketches/tests/test_compilesketches.py b/compilesketches/tests/test_compilesketches.py index d463bae..f9bebf7 100644 --- a/compilesketches/tests/test_compilesketches.py +++ b/compilesketches/tests/test_compilesketches.py @@ -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, @@ -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, @@ -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" @@ -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) @@ -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, @@ -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 @@ -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, @@ -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")