• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15import("//build_overrides/pigweed.gni")
16import("//build_overrides/pigweed_environment.gni")
17
18declare_args() {
19  # Enable/disable Arduino builds via group("arduino").
20  # Set to the full path of where cores are installed.
21  pw_arduino_build_CORE_PATH = ""
22
23  # Expected args for an Arduino build:
24  pw_arduino_build_CORE_NAME = ""
25
26  # TODO(tonymd): "teensy/avr" here should match the folders in this dir:
27  # "../third_party/arduino/cores/$pw_arduino_build_CORE_NAME/hardware/*")
28  # For teensy: "teensy/avr", for adafruit-samd: "samd/1.6.2"
29  pw_arduino_build_PACKAGE_NAME = ""
30  pw_arduino_build_BOARD = ""
31
32  # Menu options should be a list of strings.
33  pw_arduino_build_MENU_OPTIONS = []
34}
35
36if (pw_arduino_build_CORE_PATH != "") {
37  # Check that enough pw_arduino_build_* args are set to find and use a core.
38  _required_args_message =
39      "The following build args must all be set: " +
40      "pw_arduino_build_CORE_PATH, pw_arduino_build_CORE_NAME, " +
41      "pw_arduino_build_PACKAGE_NAME."
42  assert(pw_arduino_build_CORE_NAME != "",
43         "Missing 'pw_arduino_build_CORE_NAME' build arg. " +
44             _required_args_message)
45  assert(pw_arduino_build_PACKAGE_NAME != "",
46         "Missing 'pw_arduino_build_PACKAGE_NAME' build arg. " +
47             _required_args_message)
48
49  _arduino_selected_core_path =
50      rebase_path("$pw_arduino_build_CORE_PATH/$pw_arduino_build_CORE_NAME",
51                  root_build_dir)
52
53  arduino_builder_script =
54      get_path_info("py/pw_arduino_build/__main__.py", "abspath")
55
56  # Check pw_arduino_build_BOARD is set
57  assert(pw_arduino_build_BOARD != "",
58         "pw_arduino_build_BOARD build arg not set. " +
59             "To see supported boards run: " +
60             "arduino_builder --arduino-package-path " +
61             _arduino_selected_core_path + " --arduino-package-name " +
62             pw_arduino_build_PACKAGE_NAME + " list-boards")
63
64  _compiler_path_override =
65      rebase_path(dir_cipd_pigweed + "/bin", root_build_dir)
66
67  arduino_core_library_path = "$_arduino_selected_core_path/hardware/" +
68                              "$pw_arduino_build_PACKAGE_NAME/libraries"
69
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",
80    rebase_path(root_gen_dir, root_build_dir) + "/arduino_builder_config.json",
81    "--save-config",
82  ]
83
84  arduino_board_args = [
85    "--build-path",
86    ".",
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}
103