blob: 0d1704c19f9a45c6f989d6014ecd708d4b58537a [file] [log] [blame]
Anthony DiGirolamoeea0d772020-08-06 12:00:36 -07001# 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 DiGirolamoeea0d772020-08-06 12:00:36 -070015import("//build_overrides/pigweed.gni")
Wyatt Heplerd49f8fe2020-10-15 10:13:47 -070016
Anthony DiGirolamoeea0d772020-08-06 12:00:36 -070017declare_args() {
Anthony DiGirolamoc36af652020-09-29 14:34:27 -070018 # Enable/disable Arduino builds via group("arduino").
Anthony DiGirolamo383be052020-11-26 12:06:41 -080019 # Set to the full path of where cores are installed.
20 pw_arduino_build_CORE_PATH = ""
Anthony DiGirolamoc36af652020-09-29 14:34:27 -070021
Anthony DiGirolamoeea0d772020-08-06 12:00:36 -070022 # Expected args for an Arduino build:
Anthony DiGirolamo383be052020-11-26 12:06:41 -080023 pw_arduino_build_CORE_NAME = ""
Anthony DiGirolamo62de81b2020-10-20 17:31:36 -070024
25 # TODO(tonymd): "teensy/avr" here should match the folders in this dir:
Anthony DiGirolamo383be052020-11-26 12:06:41 -080026 # "../third_party/arduino/cores/$pw_arduino_build_CORE_NAME/hardware/*")
Anthony DiGirolamo62de81b2020-10-20 17:31:36 -070027 # For teensy: "teensy/avr", for adafruit-samd: "samd/1.6.2"
Anthony DiGirolamo383be052020-11-26 12:06:41 -080028 pw_arduino_build_PACKAGE_NAME = ""
29 pw_arduino_build_BOARD = ""
Anthony DiGirolamoeea0d772020-08-06 12:00:36 -070030
31 # Menu options should be a list of strings.
Anthony DiGirolamo383be052020-11-26 12:06:41 -080032 pw_arduino_build_MENU_OPTIONS = []
Anthony DiGirolamoeea0d772020-08-06 12:00:36 -070033}
34
Anthony DiGirolamo383be052020-11-26 12:06:41 -080035if (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 DiGirolamoeea0d772020-08-06 12:00:36 -070047
Anthony DiGirolamo383be052020-11-26 12:06:41 -080048 _arduino_selected_core_path =
49 rebase_path("$pw_arduino_build_CORE_PATH/$pw_arduino_build_CORE_NAME")
Anthony DiGirolamoeea0d772020-08-06 12:00:36 -070050
Anthony DiGirolamo383be052020-11-26 12:06:41 -080051 arduino_builder_script =
52 get_path_info("py/pw_arduino_build/__main__.py", "abspath")
Anthony DiGirolamoc36af652020-09-29 14:34:27 -070053
Anthony DiGirolamo383be052020-11-26 12:06:41 -080054 # 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 DiGirolamo50a196f2020-09-27 10:03:16 -070061
Anthony DiGirolamo383be052020-11-26 12:06:41 -080062 _compiler_path_override =
63 rebase_path(getenv("_PW_ACTUAL_ENVIRONMENT_ROOT") + "/cipd/pigweed/bin")
Anthony DiGirolamo50a196f2020-09-27 10:03:16 -070064
Anthony DiGirolamo383be052020-11-26 12:06:41 -080065 arduino_core_library_path = "$_arduino_selected_core_path/hardware/" +
66 "$pw_arduino_build_PACKAGE_NAME/libraries"
Anthony DiGirolamo50a196f2020-09-27 10:03:16 -070067
Anthony DiGirolamo383be052020-11-26 12:06:41 -080068 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}