| Anthony DiGirolamo | eea0d77 | 2020-08-06 12:00:36 -0700 | [diff] [blame] | 1 | # Copyright 2020 The Pigweed Authors |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 4 | # use this file except in compliance with the License. You may obtain a copy of |
| 5 | # the License at |
| 6 | # |
| 7 | # https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations under |
| 13 | # the License. |
| 14 | |
| Anthony DiGirolamo | eea0d77 | 2020-08-06 12:00:36 -0700 | [diff] [blame] | 15 | import("//build_overrides/pigweed.gni") |
| Wyatt Hepler | d49f8fe | 2020-10-15 10:13:47 -0700 | [diff] [blame] | 16 | |
| Anthony DiGirolamo | eea0d77 | 2020-08-06 12:00:36 -0700 | [diff] [blame] | 17 | declare_args() { |
| Anthony DiGirolamo | c36af65 | 2020-09-29 14:34:27 -0700 | [diff] [blame] | 18 | # Enable/disable Arduino builds via group("arduino"). |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame] | 19 | # Set to the full path of where cores are installed. |
| 20 | pw_arduino_build_CORE_PATH = "" |
| Anthony DiGirolamo | c36af65 | 2020-09-29 14:34:27 -0700 | [diff] [blame] | 21 | |
| Anthony DiGirolamo | eea0d77 | 2020-08-06 12:00:36 -0700 | [diff] [blame] | 22 | # Expected args for an Arduino build: |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame] | 23 | pw_arduino_build_CORE_NAME = "" |
| Anthony DiGirolamo | 62de81b | 2020-10-20 17:31:36 -0700 | [diff] [blame] | 24 | |
| 25 | # TODO(tonymd): "teensy/avr" here should match the folders in this dir: |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame] | 26 | # "../third_party/arduino/cores/$pw_arduino_build_CORE_NAME/hardware/*") |
| Anthony DiGirolamo | 62de81b | 2020-10-20 17:31:36 -0700 | [diff] [blame] | 27 | # For teensy: "teensy/avr", for adafruit-samd: "samd/1.6.2" |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame] | 28 | pw_arduino_build_PACKAGE_NAME = "" |
| 29 | pw_arduino_build_BOARD = "" |
| Anthony DiGirolamo | eea0d77 | 2020-08-06 12:00:36 -0700 | [diff] [blame] | 30 | |
| 31 | # Menu options should be a list of strings. |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame] | 32 | pw_arduino_build_MENU_OPTIONS = [] |
| Anthony DiGirolamo | eea0d77 | 2020-08-06 12:00:36 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame] | 35 | if (pw_arduino_build_CORE_PATH != "") { |
| 36 | # Check that enough pw_arduino_build_* args are set to find and use a core. |
| 37 | _required_args_message = |
| 38 | "The following build args must all be set: " + |
| 39 | "pw_arduino_build_CORE_PATH, pw_arduino_build_CORE_NAME, " + |
| 40 | "pw_arduino_build_PACKAGE_NAME." |
| 41 | assert(pw_arduino_build_CORE_NAME != "", |
| 42 | "Missing 'pw_arduino_build_CORE_NAME' build arg. " + |
| 43 | _required_args_message) |
| 44 | assert(pw_arduino_build_PACKAGE_NAME != "", |
| 45 | "Missing 'pw_arduino_build_PACKAGE_NAME' build arg. " + |
| 46 | _required_args_message) |
| Anthony DiGirolamo | eea0d77 | 2020-08-06 12:00:36 -0700 | [diff] [blame] | 47 | |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame] | 48 | _arduino_selected_core_path = |
| Michael Spang | c8b9390 | 2021-05-30 15:53:56 -0400 | [diff] [blame^] | 49 | rebase_path("$pw_arduino_build_CORE_PATH/$pw_arduino_build_CORE_NAME", |
| 50 | root_build_dir) |
| Anthony DiGirolamo | eea0d77 | 2020-08-06 12:00:36 -0700 | [diff] [blame] | 51 | |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame] | 52 | arduino_builder_script = |
| 53 | get_path_info("py/pw_arduino_build/__main__.py", "abspath") |
| Anthony DiGirolamo | c36af65 | 2020-09-29 14:34:27 -0700 | [diff] [blame] | 54 | |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame] | 55 | # Check pw_arduino_build_BOARD is set |
| 56 | assert(pw_arduino_build_BOARD != "", |
| 57 | "pw_arduino_build_BOARD build arg not set. " + |
| 58 | "To see supported boards run: " + |
| 59 | "arduino_builder --arduino-package-path " + |
| 60 | _arduino_selected_core_path + " --arduino-package-name " + |
| 61 | pw_arduino_build_PACKAGE_NAME + " list-boards") |
| Anthony DiGirolamo | 50a196f | 2020-09-27 10:03:16 -0700 | [diff] [blame] | 62 | |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame] | 63 | _compiler_path_override = |
| Michael Spang | c8b9390 | 2021-05-30 15:53:56 -0400 | [diff] [blame^] | 64 | rebase_path(getenv("_PW_ACTUAL_ENVIRONMENT_ROOT") + "/cipd/pigweed/bin", |
| 65 | root_build_dir) |
| Anthony DiGirolamo | 50a196f | 2020-09-27 10:03:16 -0700 | [diff] [blame] | 66 | |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame] | 67 | arduino_core_library_path = "$_arduino_selected_core_path/hardware/" + |
| 68 | "$pw_arduino_build_PACKAGE_NAME/libraries" |
| Anthony DiGirolamo | 50a196f | 2020-09-27 10:03:16 -0700 | [diff] [blame] | 69 | |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame] | 70 | arduino_global_args = [ |
| 71 | "--arduino-package-path", |
| 72 | _arduino_selected_core_path, |
| 73 | "--arduino-package-name", |
| 74 | pw_arduino_build_PACKAGE_NAME, |
| 75 | "--compiler-path-override", |
| 76 | _compiler_path_override, |
| 77 | |
| 78 | # Save config files to "out/arduino_debug/gen/arduino_builder_config.json" |
| 79 | "--config-file", |
| Michael Spang | c8b9390 | 2021-05-30 15:53:56 -0400 | [diff] [blame^] | 80 | rebase_path(root_gen_dir, root_build_dir) + "/arduino_builder_config.json", |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame] | 81 | "--save-config", |
| 82 | ] |
| 83 | |
| 84 | arduino_board_args = [ |
| 85 | "--build-path", |
| Michael Spang | c8b9390 | 2021-05-30 15:53:56 -0400 | [diff] [blame^] | 86 | ".", |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame] | 87 | "--board", |
| 88 | pw_arduino_build_BOARD, |
| 89 | ] |
| 90 | if (pw_arduino_build_MENU_OPTIONS != []) { |
| 91 | arduino_board_args += [ "--menu-options" ] |
| 92 | arduino_board_args += pw_arduino_build_MENU_OPTIONS |
| 93 | } |
| 94 | |
| 95 | arduino_show_command_args = arduino_global_args + [ |
| 96 | "show", |
| 97 | "--delimit-with-newlines", |
| 98 | ] + arduino_board_args |
| 99 | |
| 100 | arduino_run_command_args = |
| 101 | arduino_global_args + [ "run" ] + arduino_board_args |
| 102 | } |