mirror of https://github.com/ARMmbed/mbed-os.git
commit
99dbc8be4c
|
@ -48,9 +48,9 @@ class HookError(Exception):
|
||||||
caches = {}
|
caches = {}
|
||||||
def cached(func):
|
def cached(func):
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
if not caches.has_key(func):
|
if not caches.has_key((func.__name__, args)):
|
||||||
caches[func] = func(*args, **kwargs)
|
caches[(func.__name__, args)] = func(*args, **kwargs)
|
||||||
return caches[func]
|
return caches[(func.__name__, args)]
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
class Target:
|
class Target:
|
||||||
|
@ -58,17 +58,21 @@ class Target:
|
||||||
# need to be computed differently than regular attributes
|
# need to be computed differently than regular attributes
|
||||||
__cumulative_attributes = ['extra_labels', 'macros', 'device_has', 'features']
|
__cumulative_attributes = ['extra_labels', 'macros', 'device_has', 'features']
|
||||||
|
|
||||||
# {target_name: target_instance} map for all the targets in the system
|
# Location of the 'targets.json' file
|
||||||
__target_map = {}
|
__targets_json_location = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'hal', 'targets.json')
|
||||||
|
|
||||||
# List of targets that were added dynamically using "add_py_targets" (see below)
|
|
||||||
__py_targets = set()
|
|
||||||
|
|
||||||
# Load the description of JSON target data
|
# Load the description of JSON target data
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@cached
|
@cached
|
||||||
def get_json_target_data():
|
def get_json_target_data():
|
||||||
return json_file_to_dict(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'hal', 'targets.json'))
|
return json_file_to_dict(Target.__targets_json_location)
|
||||||
|
|
||||||
|
# Set the location of the targets.json file
|
||||||
|
@staticmethod
|
||||||
|
def set_targets_json_location(location):
|
||||||
|
Target.__targets_json_location = location
|
||||||
|
# Invalidate caches, since the location of the JSON file changed
|
||||||
|
caches.clear()
|
||||||
|
|
||||||
# Get the members of this module using Python's "inspect" module
|
# Get the members of this module using Python's "inspect" module
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -168,42 +172,26 @@ class Target:
|
||||||
return v
|
return v
|
||||||
|
|
||||||
# Add one or more new target(s) represented as a Python dictionary in 'new_targets'
|
# Add one or more new target(s) represented as a Python dictionary in 'new_targets'
|
||||||
# It it an error to add a target with a name that exists in "targets.json"
|
# It is an error to add a target with a name that already exists.
|
||||||
# However, it is OK to add a target that was previously added via "add_py_targets"
|
|
||||||
# (this makes testing easier without changing the regular semantics)
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def add_py_targets(new_targets):
|
def add_py_targets(new_targets):
|
||||||
crt_data = Target.get_json_target_data()
|
crt_data = Target.get_json_target_data()
|
||||||
# First add all elemnts to the internal dictionary
|
|
||||||
for tk, tv in new_targets.items():
|
for tk, tv in new_targets.items():
|
||||||
if crt_data.has_key(tk) and (not tk in Target.__py_targets):
|
if crt_data.has_key(tk):
|
||||||
raise Exception("Attempt to add target '%s' that already exists" % tk)
|
raise Exception("Attempt to add target '%s' that already exists" % tk)
|
||||||
|
# Add target data to the internal target dictionary
|
||||||
crt_data[tk] = tv
|
crt_data[tk] = tv
|
||||||
Target.__py_targets.add(tk)
|
# Create the new target and add it to the relevant data structures
|
||||||
# Then create the new instances and update global variables if needed
|
|
||||||
for tk, tv in new_targets.items():
|
|
||||||
# Is the target already created?
|
|
||||||
old_target = Target.__target_map.get(tk, None)
|
|
||||||
# Instantiate this target. If it is public, update the data in
|
|
||||||
# in TARGETS, TARGET_MAP, TARGET_NAMES
|
|
||||||
new_target = Target(tk)
|
new_target = Target(tk)
|
||||||
if tv.get("public", True):
|
TARGETS.append(new_target)
|
||||||
if old_target: # remove the old target from TARGETS and TARGET_NAMES
|
TARGET_MAP[tk] = new_target
|
||||||
TARGETS.remove(old_target)
|
TARGET_NAMES.append(tk)
|
||||||
TARGET_NAMES.remove(tk)
|
|
||||||
# Add the new target
|
|
||||||
TARGETS.append(new_target)
|
|
||||||
TARGET_MAP[tk] = new_target
|
|
||||||
TARGET_NAMES.append(tk)
|
|
||||||
# Update the target cache
|
|
||||||
Target.__target_map[tk] = new_target
|
|
||||||
|
|
||||||
# Return the target instance starting from the target name
|
# Return the target instance starting from the target name
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@cached
|
||||||
def get_target(name):
|
def get_target(name):
|
||||||
if not Target.__target_map.has_key(name):
|
return Target(name)
|
||||||
Target.__target_map[name] = Target(name)
|
|
||||||
return Target.__target_map[name]
|
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -414,3 +402,15 @@ def get_target_detect_codes():
|
||||||
for detect_code in target.detect_code:
|
for detect_code in target.detect_code:
|
||||||
result[detect_code] = target.name
|
result[detect_code] = target.name
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
# Sets the location of the JSON file that contains the targets
|
||||||
|
def set_targets_json_location(location):
|
||||||
|
# First instruct Target about the new location
|
||||||
|
Target.set_targets_json_location(location)
|
||||||
|
# Then re-initialize TARGETS, TARGET_MAP and TARGET_NAMES
|
||||||
|
# The 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"
|
||||||
|
TARGETS[:] = [Target.get_target(name) for name, value in Target.get_json_target_data().items() if value.get("public", True)]
|
||||||
|
TARGET_MAP.clear()
|
||||||
|
TARGET_MAP.update(dict([(t.name, t) for t in TARGETS]))
|
||||||
|
TARGET_NAMES[:] = TARGET_MAP.keys()
|
||||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from tools.build_api import get_config
|
from tools.build_api import get_config
|
||||||
|
from tools.targets import set_targets_json_location, Target
|
||||||
from tools.config import ConfigException, Config
|
from tools.config import ConfigException, Config
|
||||||
import os, sys
|
import os, sys
|
||||||
|
|
||||||
|
@ -43,6 +44,8 @@ def test_tree(full_name, name):
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
err_msg = None
|
err_msg = None
|
||||||
try:
|
try:
|
||||||
|
# Use 'set_targets_json_location' to remove the previous custom targets from the target list
|
||||||
|
set_targets_json_location(Target._Target__targets_json_location)
|
||||||
cfg, macros, features = get_config(full_name, target, "GCC_ARM")
|
cfg, macros, features = get_config(full_name, target, "GCC_ARM")
|
||||||
macros = Config.config_macros_to_macros(macros)
|
macros = Config.config_macros_to_macros(macros)
|
||||||
except ConfigException as e:
|
except ConfigException as e:
|
||||||
|
|
Loading…
Reference in New Issue