aboutsummaryrefslogtreecommitdiff
path: root/pw_arduino_build/arduino.gni
blob: 7c50f3d9a12c79a784184e7ba7de9847daa4b575 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Copyright 2020 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

import("//build_overrides/pigweed.gni")
import("//build_overrides/pigweed_environment.gni")

declare_args() {
  # Enable/disable Arduino builds via group("arduino").
  # Set to the full path of where cores are installed.
  pw_arduino_build_CORE_PATH = ""

  # Expected args for an Arduino build:
  pw_arduino_build_CORE_NAME = ""

  # TODO(tonymd): "avr/1.58.1" here should match the folders in this dir:
  # "../third_party/arduino/cores/$pw_arduino_build_CORE_NAME/hardware/*")
  # For teensy: "avr/1.58.1", for adafruit-samd: "samd/1.6.2"
  pw_arduino_build_PACKAGE_NAME = ""
  pw_arduino_build_BOARD = ""

  # Menu options should be a list of strings.
  pw_arduino_build_MENU_OPTIONS = []
}

if (pw_arduino_build_CORE_PATH != "") {
  # Check that enough pw_arduino_build_* args are set to find and use a core.
  _required_args_message =
      "The following build args must all be set: " +
      "pw_arduino_build_CORE_PATH, pw_arduino_build_CORE_NAME, " +
      "pw_arduino_build_PACKAGE_NAME."
  assert(pw_arduino_build_CORE_NAME != "",
         "Missing 'pw_arduino_build_CORE_NAME' build arg. " +
             _required_args_message)
  assert(pw_arduino_build_PACKAGE_NAME != "",
         "Missing 'pw_arduino_build_PACKAGE_NAME' build arg. " +
             _required_args_message)

  _arduino_selected_core_path =
      rebase_path("$pw_arduino_build_CORE_PATH/$pw_arduino_build_CORE_NAME",
                  root_build_dir)

  arduino_builder_script =
      get_path_info("py/pw_arduino_build/__main__.py", "abspath")

  # Check pw_arduino_build_BOARD is set
  assert(pw_arduino_build_BOARD != "",
         "pw_arduino_build_BOARD build arg not set. " +
             "To see supported boards run: " +
             "arduino_builder --arduino-package-path " +
             _arduino_selected_core_path + " --arduino-package-name " +
             pw_arduino_build_PACKAGE_NAME + " list-boards")

  arduino_core_library_path = "$_arduino_selected_core_path/hardware/" +
                              "$pw_arduino_build_PACKAGE_NAME/libraries"

  arduino_global_args = [
    "--arduino-package-path",
    _arduino_selected_core_path,
    "--arduino-package-name",
    pw_arduino_build_PACKAGE_NAME,
  ]

  if (defined(pw_env_setup_CIPD_PIGWEED)) {
    _compiler_path_override =
        rebase_path(pw_env_setup_CIPD_PIGWEED + "/bin", root_build_dir)

    arduino_global_args += [
      "--compiler-path-override",
      _compiler_path_override,
    ]
  }

  arduino_global_args += [
    # Save config files to "out/arduino_debug/gen/arduino_builder_config.json"
    "--config-file",
    rebase_path(root_gen_dir, root_build_dir) + "/arduino_builder_config.json",
    "--save-config",
  ]

  arduino_board_args = [
    "--build-path",
    ".",
    "--board",
    pw_arduino_build_BOARD,
  ]
  if (pw_arduino_build_MENU_OPTIONS != []) {
    arduino_board_args += [ "--menu-options" ]
    arduino_board_args += pw_arduino_build_MENU_OPTIONS
  }

  arduino_show_command_args = arduino_global_args + [
                                "show",
                                "--delimit-with-newlines",
                              ] + arduino_board_args

  arduino_run_command_args =
      arduino_global_args + [ "run" ] + arduino_board_args
}