Skip to content

Commit

Permalink
Merge pull request #199 from bridadan/targets-json-search
Browse files Browse the repository at this point in the history
Searching project recursively for target information
  • Loading branch information
mazimkhan authored Oct 20, 2016
2 parents 1ca0f3d + 30d1781 commit 201db51
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 14 deletions.
11 changes: 6 additions & 5 deletions mbed_greentea/mbed_greentea_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,12 @@ def run_test_thread(test_result_queue, test_queue, opts, mut, build, build_path,
test_platforms_match = 0
test_report = {}

disk = mut['mount_point']
port = mut['serial_port']
micro = mut['platform_name']
program_cycle_s = get_platform_property(micro, "program_cycle_s")
forced_reset_timeout = get_platform_property(micro, "forced_reset_timeout")

while not test_queue.empty():
try:
test = test_queue.get(False)
Expand All @@ -419,11 +425,6 @@ def run_test_thread(test_result_queue, test_queue, opts, mut, build, build_path,

test_result = 'SKIPPED'

disk = mut['mount_point']
port = mut['serial_port']
micro = mut['platform_name']
program_cycle_s = get_platform_property(micro, "program_cycle_s")
forced_reset_timeout = get_platform_property(micro, "forced_reset_timeout")
copy_method = opts.copy_method if opts.copy_method else 'shell'
verbose = opts.verbose_test_result_only
enum_host_tests_path = get_local_host_tests_dir(opts.enum_host_tests)
Expand Down
53 changes: 44 additions & 9 deletions mbed_greentea/mbed_target_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,22 +395,57 @@ def get_platform_property_from_targets(platform, property):
:return: property value, None if property not found
"""

def get_platform_property_from_targets(targets, platform, property):
"""! Get a platforms's property from the target data structure in
targets.json. Takes into account target inheritance.
@param targets Data structure parsed from targets.json
@param platform Name of the platform
@param property Name of the property
@return property value, None if property not found
"""

result = None
if platform in targets:
if property in targets[platform]:
result = targets[platform][property]
elif 'inherits' in targets[platform]:
result = None
for inherited_target in targets[platform]['inherits']:
result = get_platform_property_from_targets(targets, inherited_target, property)

# Stop searching after finding the first value for the property
if result:
break

return result

result = None
targets_json_path = [
'./mbed-os/core/hal/targets.json',
'./core/hal/targets.json',
'./mbed-os/mbed/hal/targets.json',
'./mbed/hal/targets.json']
targets_json_path = []
for root, dirs, files in os.walk(os.getcwd(), followlinks=True):
ignored_dirs = ['.build', 'BUILD', 'tools']

for ignored_dir in ignored_dirs:
if ignored_dir in dirs:
dirs.remove(ignored_dir)

if 'targets.json' in files:
targets_json_path.append(os.path.join(root, 'targets.json'))

if not targets_json_path:
gt_logger.gt_log_warn("No targets.json files found, using default target properties")

for targets_path in targets_json_path:
try:
with open(targets_path, 'r') as f:
targets = json.load(f)

# Load property from targets.json
if platform in targets:
if property in targets[platform]:
result = targets[platform][property]
break
result = get_platform_property_from_targets(targets, platform, property)

# If a valid property was found, stop looking
if result:
break
except Exception:
continue
return result

0 comments on commit 201db51

Please sign in to comment.