mirror of https://github.com/ARMmbed/mbed-os.git
Find extra targets in all source folders
parent
58c52fa2e7
commit
2c4475cacc
|
@ -32,6 +32,7 @@ from tools.toolchains import mbedToolchain
|
|||
from tools.targets import TARGET_NAMES, TARGET_MAP
|
||||
from tools.options import get_default_options_parser
|
||||
from tools.options import extract_profile
|
||||
from tools.options import extract_mcus
|
||||
from tools.build_api import build_library, build_mbed_libs, build_lib
|
||||
from tools.build_api import mcu_toolchain_matrix
|
||||
from tools.build_api import print_build_results
|
||||
|
@ -134,7 +135,7 @@ if __name__ == '__main__':
|
|||
|
||||
|
||||
# Get target list
|
||||
targets = options.mcu if options.mcu else TARGET_NAMES
|
||||
targets = extract_mcus(parser, options) if options.mcu else TARGET_NAMES
|
||||
|
||||
# Get toolchains list
|
||||
toolchains = options.tool if options.tool else TOOLCHAINS
|
||||
|
|
|
@ -26,6 +26,7 @@ sys.path.insert(0, ROOT)
|
|||
|
||||
from tools.utils import args_error
|
||||
from tools.options import get_default_options_parser
|
||||
from tools.options import extract_mcus
|
||||
from tools.build_api import get_config
|
||||
from config import Config
|
||||
from utils import argparse_filestring_type
|
||||
|
@ -49,7 +50,7 @@ if __name__ == '__main__':
|
|||
# Target
|
||||
if options.mcu is None :
|
||||
args_error(parser, "argument -m/--mcu is required")
|
||||
target = options.mcu[0]
|
||||
target = extract_mcus(parser, options)[0]
|
||||
|
||||
# Toolchain
|
||||
if options.tool is None:
|
||||
|
|
|
@ -42,6 +42,7 @@ from tools.tests import test_known, test_name_known
|
|||
from tools.targets import TARGET_MAP
|
||||
from tools.options import get_default_options_parser
|
||||
from tools.options import extract_profile
|
||||
from tools.options import extract_mcus
|
||||
from tools.build_api import build_project
|
||||
from tools.build_api import mcu_toolchain_matrix
|
||||
from tools.build_api import mcu_toolchain_list
|
||||
|
@ -200,7 +201,7 @@ if __name__ == '__main__':
|
|||
# Target
|
||||
if options.mcu is None :
|
||||
args_error(parser, "argument -m/--mcu is required")
|
||||
mcu = options.mcu[0]
|
||||
mcu = extract_mcus(parser, options)[0]
|
||||
|
||||
# Toolchain
|
||||
if options.tool is None:
|
||||
|
|
|
@ -17,9 +17,9 @@ limitations under the License.
|
|||
from json import load
|
||||
from os.path import join, dirname
|
||||
from os import listdir
|
||||
from argparse import ArgumentParser
|
||||
from argparse import ArgumentParser, ArgumentTypeError
|
||||
from tools.toolchains import TOOLCHAINS
|
||||
from tools.targets import TARGET_NAMES
|
||||
from tools.targets import TARGET_NAMES, Target, update_target_data
|
||||
from tools.utils import argparse_force_uppercase_type, \
|
||||
argparse_lowercase_hyphen_type, argparse_many, \
|
||||
argparse_filestring_type, args_error, argparse_profile_filestring_type,\
|
||||
|
@ -47,10 +47,7 @@ def get_default_options_parser(add_clean=True, add_options=True,
|
|||
parser.add_argument("-m", "--mcu",
|
||||
help=("build for the given MCU (%s)" %
|
||||
', '.join(targetnames)),
|
||||
metavar="MCU",
|
||||
type=argparse_many(
|
||||
argparse_force_uppercase_type(
|
||||
targetnames, "MCU")))
|
||||
metavar="MCU")
|
||||
|
||||
parser.add_argument("-t", "--tool",
|
||||
help=("build using the given TOOLCHAIN (%s)" %
|
||||
|
@ -130,3 +127,19 @@ def mcu_is_enabled(parser, mcu):
|
|||
"See https://developer.mbed.org/platforms/Renesas-GR-PEACH/#important-notice "
|
||||
"for more information") % (mcu, mcu))
|
||||
return True
|
||||
|
||||
def extract_mcus(parser, options):
|
||||
try:
|
||||
extra_targets = [join(src, "custom_targets.json") for src in options.source_dir]
|
||||
for filename in extra_targets:
|
||||
Target.add_extra_targets(filename)
|
||||
update_target_data()
|
||||
except KeyError:
|
||||
pass
|
||||
targetnames = TARGET_NAMES
|
||||
targetnames.sort()
|
||||
try:
|
||||
return argparse_many(argparse_force_uppercase_type(targetnames, "MCU"))(options.mcu)
|
||||
except ArgumentTypeError as exc:
|
||||
args_error(parser, "argument -m/--mcu: {}".format(str(exc)))
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ from tools.utils import argparse_filestring_type, argparse_profile_filestring_ty
|
|||
from tools.utils import argparse_force_lowercase_type
|
||||
from tools.utils import argparse_force_uppercase_type
|
||||
from tools.utils import print_large_string
|
||||
from tools.options import extract_profile, list_profiles
|
||||
from tools.options import extract_profile, list_profiles, extract_mcus
|
||||
|
||||
def setup_project(ide, target, program=None, source_dir=None, build=None, export_path=None):
|
||||
"""Generate a name, if not provided, and find dependencies
|
||||
|
@ -247,7 +247,8 @@ def main():
|
|||
profile = extract_profile(parser, options, toolchain_name, fallback="debug")
|
||||
if options.clean:
|
||||
rmtree(BUILD_DIR)
|
||||
export(options.mcu, options.ide, build=options.build,
|
||||
mcu = extract_mcus(parser, options)[0]
|
||||
export(mcu, options.ide, build=options.build,
|
||||
src=options.source_dir, macros=options.macros,
|
||||
project_id=options.program, zip_proj=zip_proj,
|
||||
build_profile=profile, app_config=options.app_config)
|
||||
|
|
|
@ -127,35 +127,35 @@ class Target(namedtuple("Target", "name json_data resolution_order resolution_or
|
|||
|
||||
@staticmethod
|
||||
def _merge_dict(dct, merge_dct):
|
||||
""" Recursive dict merge. Inspired by `dict.update()` however instead of
|
||||
updating only top-level keys, dict_merge recurses down into dicts nested
|
||||
to an arbitrary depth, updating keys.
|
||||
The provided ``merge_dct`` is merged into ``dct`` in place.
|
||||
:param dct: dict onto which the merge is executed
|
||||
:param merge_dct: dct merged into dct
|
||||
:return: None
|
||||
"""
|
||||
for k, v in merge_dct.iteritems():
|
||||
if (k in dct and isinstance(dct[k], dict)
|
||||
and isinstance(merge_dct[k], Mapping)):
|
||||
Target._merge_dict(dct[k], merge_dct[k])
|
||||
else:
|
||||
dct[k] = merge_dct[k]
|
||||
""" Recursive dict merge. Inspired by `dict.update()` however instead of
|
||||
updating only top-level keys, dict_merge recurses down into dicts nested
|
||||
to an arbitrary depth, updating keys.
|
||||
The provided ``merge_dct`` is merged into ``dct`` in place.
|
||||
:param dct: dict onto which the merge is executed
|
||||
:param merge_dct: dct merged into dct
|
||||
:return: None
|
||||
"""
|
||||
for k, v in merge_dct.iteritems():
|
||||
if (k in dct and isinstance(dct[k], dict)
|
||||
and isinstance(merge_dct[k], Mapping)):
|
||||
Target._merge_dict(dct[k], merge_dct[k])
|
||||
else:
|
||||
dct[k] = merge_dct[k]
|
||||
|
||||
@staticmethod
|
||||
@cached
|
||||
def get_json_target_data():
|
||||
"""Load the description of JSON target data"""
|
||||
targets = json_file_to_dict(Target.__targets_json_location or
|
||||
Target.__targets_json_location_default)
|
||||
Target.__targets_json_location_default)
|
||||
return targets
|
||||
|
||||
# If extra_targets.json exists in working directory load it over the top
|
||||
extra = os.path.join('.', 'extra_targets.json')
|
||||
@staticmethod
|
||||
@cached
|
||||
def add_extra_targets(extra):
|
||||
if os.path.exists(extra):
|
||||
Target._merge_dict(targets, json_file_to_dict(extra))
|
||||
|
||||
return targets
|
||||
|
||||
@staticmethod
|
||||
def set_targets_json_location(location=None):
|
||||
"""Set the location of the targets.json file"""
|
||||
|
@ -561,6 +561,9 @@ def set_targets_json_location(location=None):
|
|||
# re-initialization does not create new variables, it keeps the old ones
|
||||
# instead. This ensures compatibility with code that does
|
||||
# "from tools.targets import TARGET_NAMES"
|
||||
update_target_data()
|
||||
|
||||
def update_target_data():
|
||||
TARGETS[:] = [Target.get_target(tgt) for tgt, obj
|
||||
in Target.get_json_target_data().items()
|
||||
if obj.get("public", True)]
|
||||
|
|
|
@ -28,7 +28,7 @@ sys.path.insert(0, ROOT)
|
|||
|
||||
from tools.config import ConfigException
|
||||
from tools.test_api import test_path_to_name, find_tests, print_tests, build_tests, test_spec_from_test_builds
|
||||
from tools.options import get_default_options_parser, extract_profile
|
||||
from tools.options import get_default_options_parser, extract_profile, extract_mcus
|
||||
from tools.build_api import build_project, build_library
|
||||
from tools.build_api import print_build_memory_usage
|
||||
from tools.build_api import merge_build_data
|
||||
|
@ -114,7 +114,7 @@ if __name__ == '__main__':
|
|||
# Target
|
||||
if options.mcu is None :
|
||||
args_error(parser, "argument -m/--mcu is required")
|
||||
mcu = options.mcu[0]
|
||||
mcu = extract_mcus(parser, options)[0]
|
||||
|
||||
# Toolchain
|
||||
if options.tool is None:
|
||||
|
|
Loading…
Reference in New Issue