Skip to content

Commit 8624fdf

Browse files
committed
Build metadata check added
1 parent 7490b1c commit 8624fdf

File tree

3 files changed

+54
-31
lines changed

3 files changed

+54
-31
lines changed

targets/targets.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8250,7 +8250,7 @@
82508250
"detect_code": ["1703"],
82518251
"macros_add": ["GD32E10X"],
82528252
"release_versions": ["5"]
8253-
},
8253+
},
82548254
"TT_M4G9": {
82558255
"inherits": ["Target"],
82568256
"core": "Cortex-M4",
@@ -8280,5 +8280,9 @@
82808280
"detect_code": ["8013"],
82818281
"release_versions": ["5"],
82828282
"bootloader_supported": true
8283+
},
8284+
"__build_tools_metadata__": {
8285+
"version": "1",
8286+
"public": false
82838287
}
82848288
}

tools/build_api.py

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,27 @@ def add_result_to_report(report, result):
122122
report[target][toolchain][id_name].append(result_wrap)
123123

124124
def get_toolchain_name(target, toolchain_name):
125-
126-
if toolchain_name == "ARM" or toolchain_name == "ARMC6" :
127-
if("ARM" in target.supported_toolchains or "ARMC6" in target.supported_toolchains):
128-
return "ARMC6"
129-
elif ("ARMC5" in target.supported_toolchains):
130-
if toolchain_name == "ARM":
131-
return "ARM" #note that returning ARM here means, use ARMC5 toolchain
125+
if int(target.build_tools_metadata["version"]) > 0:
126+
if toolchain_name == "ARM" or toolchain_name == "ARMC6" :
127+
if("ARM" in target.supported_toolchains or "ARMC6" in target.supported_toolchains):
128+
return "ARMC6"
129+
elif ("ARMC5" in target.supported_toolchains):
130+
if toolchain_name == "ARM":
131+
return "ARM" #note that returning ARM here means, use ARMC5 toolchain
132+
else:
133+
return "ARMC6" #ARMC6 explicitly specified by user, try ARMC6 anyway although the target doesnt explicitly specify ARMC6, as ARMC6 is our default ARM toolchain
134+
elif toolchain_name == "uARM":
135+
if ("ARMC5" in target.supported_toolchains):
136+
return "uARM" #use ARM_MICRO to use AC5+microlib
132137
else:
133-
return "ARMC6" #ARMC6 explicitly specified by user, try ARMC6 anyway although the target doesnt explicitly specify ARMC6, as ARMC6 is our default ARM toolchain
134-
elif toolchain_name == "uARM":
135-
if ("ARMC5" in target.supported_toolchains):
136-
return "uARM" #use ARM_MICRO to use AC5+microlib
137-
else:
138-
target.default_toolchain = "uARM"
139-
return "ARMC6" #use AC6+microlib
138+
target.default_toolchain = "uARM"
139+
return "ARMC6" #use AC6+microlib
140+
else:
141+
if toolchain_name == "ARM":
142+
if CORE_ARCH[target.core] == 8:
143+
return "ARMC6"
144+
elif getattr(target, "default_toolchain", None) == "uARM":
145+
return "uARM"
140146

141147
return toolchain_name
142148

@@ -295,17 +301,23 @@ def get_mbed_official_release(version):
295301
return mbed_official_release
296302

297303
def target_supports_toolchain(target, toolchain_name):
298-
if toolchain_name in target.supported_toolchains:
299-
return True
304+
if int(target.build_tools_metadata["version"]) > 0:
305+
if toolchain_name in target.supported_toolchains:
306+
return True
307+
else:
308+
if(toolchain_name == "ARM"):
309+
#we cant find ARM, see if one ARMC5, ARMC6 or uARM listed
310+
return any(tc in target.supported_toolchains for tc in ("ARMC5","ARMC6","uARM"))
311+
if(toolchain_name == "ARMC6"):
312+
#we did not find ARMC6, but check for ARM is listed
313+
return any(tc in target.supported_toolchains for tc in ("ARM",))
314+
return False
300315
else:
301-
if(toolchain_name == "ARM"):
302-
#we cant find ARM, see if one ARMC5, ARMC6 or uARM listed
303-
return any(tc in target.supported_toolchains for tc in ("ARMC5","ARMC6","uARM"))
304-
if(toolchain_name == "ARMC6"):
305-
#we did not find ARMC6, but check for ARM is listed
306-
return any(tc in target.supported_toolchains for tc in ("ARM",))
307-
308-
return False
316+
ARM_COMPILERS = ("ARM", "ARMC6", "uARM")
317+
if toolchain_name in ARM_COMPILERS:
318+
return any(tc in target.supported_toolchains for tc in ARM_COMPILERS)
319+
else:
320+
return toolchain_name in target.supported_toolchains
309321

310322
def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
311323
macros=None, clean=False, jobs=1,
@@ -336,7 +348,7 @@ def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
336348
# If the configuration object was not yet created, create it now
337349
config = config or Config(target, src_paths, app_config=app_config)
338350
target = config.target
339-
351+
340352
if not target_supports_toolchain(target, toolchain_name):
341353
raise NotSupportedException(
342354
"Target {} is not supported by toolchain {}".format(
@@ -536,13 +548,13 @@ def build_project(src_paths, build_path, target, toolchain_name,
536548
if clean and exists(build_path):
537549
rmtree(build_path)
538550
mkdir(build_path)
539-
551+
540552
toolchain = prepare_toolchain(
541553
src_paths, build_path, target, toolchain_name, macros=macros,
542554
clean=clean, jobs=jobs, notify=notify, config=config,
543555
app_config=app_config, build_profile=build_profile, ignore=ignore)
544556
toolchain.version_check()
545-
557+
546558
# The first path will give the name to the library
547559
name = (name or toolchain.config.name or
548560
basename(normpath(abspath(src_paths[0]))))

tools/targets/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def wrapper(*args, **kwargs):
103103
# need to be computed differently than regular attributes
104104
CUMULATIVE_ATTRIBUTES = ['extra_labels', 'macros', 'device_has', 'features', 'components']
105105

106+
default_build_tools_metadata = {u'version':0, u'public':False}
106107

107108
def get_resolution_order(json_data, target_name, order, level=0):
108109
""" Return the order in which target descriptions are searched for
@@ -125,18 +126,23 @@ def get_resolution_order(json_data, target_name, order, level=0):
125126

126127
def target(name, json_data):
127128
"""Construct a target object"""
129+
if name.startswith("_"):
130+
raise Exception("Invalid target name '%s' specified, target name should not start with '_'" % name)
131+
128132
try:
129133
resolution_order = get_resolution_order(json_data, name, [])
130134
except KeyError as exc:
131135
raise_from(NotSupportedException(
132136
"target {} has an incomplete target definition".format(name)
133137
), exc)
134138
resolution_order_names = [tgt for tgt, _ in resolution_order]
139+
135140
return Target(name=name,
136141
json_data={key: value for key, value in json_data.items()
137142
if key in resolution_order_names},
138143
resolution_order=resolution_order,
139-
resolution_order_names=resolution_order_names)
144+
resolution_order_names=resolution_order_names,
145+
build_tools_metadata=json_data.get("__build_tools_metadata__", default_build_tools_metadata))
140146

141147
def generate_py_target(new_targets, name):
142148
"""Add one or more new target(s) represented as a Python dictionary
@@ -151,11 +157,12 @@ def generate_py_target(new_targets, name):
151157
total_data = {}
152158
total_data.update(new_targets)
153159
total_data.update(base_targets)
160+
154161
return target(name, total_data)
155162

156-
class Target(namedtuple("Target", "name json_data resolution_order resolution_order_names")):
163+
class Target(namedtuple("Target", "name json_data resolution_order resolution_order_names build_tools_metadata")):
157164
"""An object to represent a Target (MCU/Board)"""
158-
165+
159166
# Default location of the 'targets.json' file
160167
__targets_json_location_default = os.path.join(
161168
os.path.dirname(os.path.abspath(__file__)), '..', '..', 'targets', 'targets.json')

0 commit comments

Comments
 (0)