2019-07-04 02:18:16 -04:00
|
|
|
# The MIT License (MIT)
|
|
|
|
#
|
|
|
|
# Copyright (c) 2019 Michael Schroeder
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
# THE SOFTWARE.
|
|
|
|
#
|
|
|
|
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import re
|
2020-05-25 10:37:35 -04:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2019-07-04 02:18:16 -04:00
|
|
|
|
|
|
|
|
2020-04-20 09:44:16 -04:00
|
|
|
SUPPORTED_PORTS = ["atmel-samd", "nrf", "stm", "mimxrt10xx"]
|
2019-07-04 02:18:16 -04:00
|
|
|
|
|
|
|
def get_shared_bindings():
|
|
|
|
""" Get a list of modules in shared-bindings based on folder names
|
|
|
|
"""
|
|
|
|
return [item for item in os.listdir("./shared-bindings")]
|
|
|
|
|
|
|
|
|
|
|
|
def read_mpconfig():
|
|
|
|
""" Open 'circuitpy_mpconfig.mk' and return the contents.
|
|
|
|
"""
|
|
|
|
configs = []
|
|
|
|
with open("py/circuitpy_mpconfig.mk") as mpconfig:
|
|
|
|
configs = mpconfig.read()
|
|
|
|
|
|
|
|
return configs
|
|
|
|
|
|
|
|
|
2019-07-27 10:15:37 -04:00
|
|
|
def build_module_map():
|
2019-07-04 02:18:16 -04:00
|
|
|
""" Establish the base of the JSON file, based on the contents from
|
|
|
|
`configs`. Base will contain module names, if they're part of
|
2019-09-28 00:41:34 -04:00
|
|
|
the `FULL_BUILD`, or their default value (0, 1, or a list of
|
|
|
|
modules that determine default [see audiocore, audiomixer, etc.]).
|
2019-07-04 02:18:16 -04:00
|
|
|
|
|
|
|
"""
|
2019-07-23 21:49:37 -04:00
|
|
|
base = dict()
|
2019-07-27 10:15:37 -04:00
|
|
|
modules = get_shared_bindings()
|
|
|
|
configs = read_mpconfig()
|
2019-07-04 02:18:16 -04:00
|
|
|
full_build = False
|
|
|
|
for module in modules:
|
|
|
|
full_name = module
|
|
|
|
search_name = module.lstrip("_")
|
2020-04-30 00:54:46 -04:00
|
|
|
re_pattern = "CIRCUITPY_{}\s*\??=\s*(.+)".format(search_name.upper())
|
2019-09-28 00:41:34 -04:00
|
|
|
find_config = re.findall(re_pattern, configs)
|
2019-07-04 02:18:16 -04:00
|
|
|
if not find_config:
|
|
|
|
continue
|
2019-09-28 00:41:34 -04:00
|
|
|
find_config = ", ".join([x.strip("$()") for x in find_config])
|
|
|
|
|
|
|
|
full_build = int("CIRCUITPY_FULL_BUILD" in find_config)
|
2019-07-04 02:18:16 -04:00
|
|
|
if not full_build:
|
2019-09-28 00:41:34 -04:00
|
|
|
default_val = find_config
|
2019-07-04 02:18:16 -04:00
|
|
|
else:
|
|
|
|
default_val = "None"
|
2019-09-28 00:41:34 -04:00
|
|
|
|
2019-07-23 21:49:37 -04:00
|
|
|
base[search_name] = {
|
2019-07-04 02:18:16 -04:00
|
|
|
"name": full_name,
|
|
|
|
"full_build": str(full_build),
|
|
|
|
"default_value": default_val,
|
2019-07-27 10:15:37 -04:00
|
|
|
"excluded": {}
|
2019-07-04 02:18:16 -04:00
|
|
|
}
|
|
|
|
|
2019-07-27 10:15:37 -04:00
|
|
|
return base
|
2019-07-04 02:18:16 -04:00
|
|
|
|
2020-05-25 10:37:35 -04:00
|
|
|
def get_settings_from_makefile(port_dir, board_name):
|
|
|
|
""" Invoke make in a mode which prints the database, then parse it for
|
|
|
|
settings.
|
2019-07-04 02:18:16 -04:00
|
|
|
|
2020-05-25 10:37:35 -04:00
|
|
|
This means that the effect of all Makefile directives is taken
|
|
|
|
into account, without having to re-encode the logic that sets them
|
|
|
|
in this script, something that has proved error-prone
|
2019-07-04 02:18:16 -04:00
|
|
|
"""
|
2019-09-28 00:41:34 -04:00
|
|
|
|
2020-05-25 10:37:35 -04:00
|
|
|
status, contents = subprocess.getstatusoutput(f"make -C {port_dir} BOARD={board_name} -qp")
|
|
|
|
# Make signals errors with exit status 2; 0 and 1 are "non-error" statuses
|
|
|
|
if status not in (0, 1):
|
|
|
|
raise RuntimeError(f'Invoking make exited with {status}')
|
|
|
|
if isinstance(contents, bytes):
|
|
|
|
contents = contents.decode('utf-8', errors='replace')
|
|
|
|
settings = {}
|
|
|
|
for line in contents.split('\n'):
|
|
|
|
m = re.match(r'^([A-Z][A-Z0-9_]*) = (.*)$', line)
|
|
|
|
if m:
|
|
|
|
settings[m.group(1)] = m.group(2)
|
|
|
|
return settings
|
|
|
|
|
|
|
|
def lookup_setting(settings, key, default=''):
|
|
|
|
while True:
|
|
|
|
value = settings.get(key, default)
|
|
|
|
if not value.startswith('$'):
|
|
|
|
break
|
|
|
|
key = value[2:-1]
|
|
|
|
return value
|
2019-07-27 10:15:37 -04:00
|
|
|
|
|
|
|
def support_matrix_by_board():
|
|
|
|
""" Compiles a list of the available core modules available for each
|
|
|
|
board.
|
|
|
|
"""
|
|
|
|
base = build_module_map()
|
|
|
|
|
|
|
|
boards = dict()
|
|
|
|
for port in SUPPORTED_PORTS:
|
2020-05-25 10:37:35 -04:00
|
|
|
# each port appears to use its own define for the chipset
|
|
|
|
if port in ["atmel-samd"]:
|
|
|
|
chip_keyword = "CHIP_FAMILY"
|
|
|
|
elif port in ["nrf"]:
|
|
|
|
chip_keyword = "MCU_VARIANT"
|
|
|
|
elif port in ["stm"]:
|
|
|
|
chip_keyword = "MCU_SERIES"
|
|
|
|
|
2019-07-27 10:15:37 -04:00
|
|
|
port_dir = "ports/{}/boards".format(port)
|
|
|
|
for entry in os.scandir(port_dir):
|
|
|
|
if not entry.is_dir():
|
|
|
|
continue
|
|
|
|
board_modules = []
|
2019-07-27 11:30:57 -04:00
|
|
|
|
2020-05-25 10:37:35 -04:00
|
|
|
settings = get_settings_from_makefile(f'ports/{port}', entry.name)
|
|
|
|
|
|
|
|
board_chip = lookup_setting(settings, chip_keyword, 'Unknown Chip')
|
|
|
|
|
2019-07-27 11:30:57 -04:00
|
|
|
with open(os.path.join(entry.path, "mpconfigboard.h")) as get_name:
|
|
|
|
board_contents = get_name.read()
|
|
|
|
board_name_re = re.search("(?<=MICROPY_HW_BOARD_NAME)\s+(.+)",
|
|
|
|
board_contents)
|
|
|
|
if board_name_re:
|
|
|
|
board_name = board_name_re.group(1).strip('"')
|
|
|
|
|
2020-05-25 10:37:35 -04:00
|
|
|
board_modules = []
|
|
|
|
for module in base:
|
|
|
|
key = f'CIRCUITPY_{module.upper()}'
|
|
|
|
if int(lookup_setting(settings, key, '0')):
|
|
|
|
board_modules.append(base[module]['name'])
|
2019-07-27 11:30:57 -04:00
|
|
|
boards[board_name] = sorted(board_modules)
|
2019-07-27 10:15:37 -04:00
|
|
|
|
2019-07-27 11:30:57 -04:00
|
|
|
#print(json.dumps(boards, indent=2))
|
2019-07-27 10:15:37 -04:00
|
|
|
return boards
|
2020-05-25 10:37:35 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
print(json.dumps(support_matrix_by_board(), indent=2))
|