| 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 = |
| 49 | rebase_path("$pw_arduino_build_CORE_PATH/$pw_arduino_build_CORE_NAME") |
| Anthony DiGirolamo | eea0d77 | 2020-08-06 12:00:36 -0700 | [diff] [blame] | 50 | |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame^] | 51 | arduino_builder_script = |
| 52 | get_path_info("py/pw_arduino_build/__main__.py", "abspath") |
| Anthony DiGirolamo | c36af65 | 2020-09-29 14:34:27 -0700 | [diff] [blame] | 53 | |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame^] | 54 | # Check pw_arduino_build_BOARD is set |
| 55 | assert(pw_arduino_build_BOARD != "", |
| 56 | "pw_arduino_build_BOARD build arg not set. " + |
| 57 | "To see supported boards run: " + |
| 58 | "arduino_builder --arduino-package-path " + |
| 59 | _arduino_selected_core_path + " --arduino-package-name " + |
| 60 | pw_arduino_build_PACKAGE_NAME + " list-boards") |
| Anthony DiGirolamo | 50a196f | 2020-09-27 10:03:16 -0700 | [diff] [blame] | 61 | |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame^] | 62 | _compiler_path_override = |
| 63 | rebase_path(getenv("_PW_ACTUAL_ENVIRONMENT_ROOT") + "/cipd/pigweed/bin") |
| Anthony DiGirolamo | 50a196f | 2020-09-27 10:03:16 -0700 | [diff] [blame] | 64 | |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame^] | 65 | arduino_core_library_path = "$_arduino_selected_core_path/hardware/" + |
| 66 | "$pw_arduino_build_PACKAGE_NAME/libraries" |
| Anthony DiGirolamo | 50a196f | 2020-09-27 10:03:16 -0700 | [diff] [blame] | 67 | |
| Anthony DiGirolamo | 383be05 | 2020-11-26 12:06:41 -0800 | [diff] [blame^] | 68 | arduino_global_args = [ |
| 69 | "--arduino-package-path", |
| 70 | _arduino_selected_core_path, |
| 71 | "--arduino-package-name", |
| 72 | pw_arduino_build_PACKAGE_NAME, |
| 73 | "--compiler-path-override", |
| 74 | _compiler_path_override, |
| 75 | |
| 76 | # Save config files to "out/arduino_debug/gen/arduino_builder_config.json" |
| 77 | "--config-file", |
| 78 | rebase_path(root_gen_dir) + "/arduino_builder_config.json", |
| 79 | "--save-config", |
| 80 | ] |
| 81 | |
| 82 | arduino_board_args = [ |
| 83 | "--build-path", |
| 84 | rebase_path(root_build_dir), |
| 85 | "--board", |
| 86 | pw_arduino_build_BOARD, |
| 87 | ] |
| 88 | if (pw_arduino_build_MENU_OPTIONS != []) { |
| 89 | arduino_board_args += [ "--menu-options" ] |
| 90 | arduino_board_args += pw_arduino_build_MENU_OPTIONS |
| 91 | } |
| 92 | |
| 93 | arduino_show_command_args = arduino_global_args + [ |
| 94 | "show", |
| 95 | "--delimit-with-newlines", |
| 96 | ] + arduino_board_args |
| 97 | |
| 98 | arduino_run_command_args = |
| 99 | arduino_global_args + [ "run" ] + arduino_board_args |
| 100 | } |