Skip to content

Commit dd3708c

Browse files
committed
Handle target overrides that have a path correctly
1 parent c180324 commit dd3708c

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

tools/config/__init__.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from copy import deepcopy
1919
import os
20-
from os.path import dirname, abspath, exists, join
20+
from os.path import dirname, abspath, exists, join, isabs
2121
import sys
2222
from collections import namedtuple
2323
from os.path import splitext, relpath
@@ -30,6 +30,10 @@
3030
from tools.targets import CUMULATIVE_ATTRIBUTES, TARGET_MAP, \
3131
generate_py_target, get_resolution_order
3232

33+
PATH_OVERRIDES = set(["target.bootloader_img"])
34+
BOOTLOADER_OVERRIDES = set(["target.bootloader_img", "target.restrict_size",
35+
"target.mbed_app_start", "target.mbed_app_size"])
36+
3337
# Base class for all configuration exceptions
3438
class ConfigException(Exception):
3539
"""Config system only exception. Makes it easier to distinguish config
@@ -84,6 +88,8 @@ def get_full_name(name, unit_name, unit_kind, label=None,
8488
else:
8589
prefix = unit_name + '.'
8690
return prefix + name
91+
if name in BOOTLOADER_OVERRIDES:
92+
return name
8793
# The name has a prefix, so check if it is valid
8894
if not allow_prefix:
8995
raise ConfigException("Invalid parameter name '%s' in '%s'" %
@@ -362,8 +368,6 @@ class Config(object):
362368
"artifact_name": str}
363369
}
364370

365-
__unused_overrides = set(["target.bootloader_img", "target.restrict_size",
366-
"target.mbed_app_start", "target.mbed_app_size"])
367371

368372
# Allowed features in configurations
369373
__allowed_features = [
@@ -441,7 +445,7 @@ def __init__(self, tgt, top_level_dirs=None, app_config=None):
441445
self.target = tgt
442446
self.target = deepcopy(self.target)
443447
self.target_labels = self.target.labels
444-
for override in self.__unused_overrides:
448+
for override in BOOTLOADER_OVERRIDES:
445449
_, attr = override.split(".")
446450
setattr(self.target, attr, None)
447451

@@ -491,7 +495,7 @@ def add_config_files(self, flist):
491495
@property
492496
def has_regions(self):
493497
"""Does this config have regions defined?"""
494-
for override in self.__unused_overrides:
498+
for override in BOOTLOADER_OVERRIDES:
495499
_, attr = override.split(".")
496500
if getattr(self.target, attr, None):
497501
return True
@@ -552,8 +556,11 @@ def regions(self):
552556
def _generate_bootloader_build(self, rom_start, rom_size):
553557
start = rom_start
554558
if self.target.bootloader_img:
555-
basedir = abspath(dirname(self.app_config_location))
556-
filename = join(basedir, self.target.bootloader_img)
559+
if isabs(self.target.bootloader_img):
560+
filename = self.target.bootloader_img
561+
else:
562+
basedir = abspath(dirname(self.app_config_location))
563+
filename = join(basedir, self.target.bootloader_img)
557564
if not exists(filename):
558565
raise ConfigException("Bootloader %s not found" % filename)
559566
part = intelhex_offset(filename, offset=rom_start)
@@ -685,19 +692,22 @@ def _process_config_and_overrides(self, data, params, unit_name, unit_kind):
685692

686693
# Consider the others as overrides
687694
for name, val in overrides.items():
688-
if (name.startswith("target.") and
689-
(unit_kind is "application" or
690-
name in self.__unused_overrides)):
691-
_, attribute = name.split(".")
692-
setattr(self.target, attribute, val)
693-
continue
695+
if (name in PATH_OVERRIDES and "__config_path" in data):
696+
val = os.path.join(
697+
os.path.dirname(data["__config_path"]), val)
694698

695699
# Get the full name of the parameter
696700
full_name = ConfigParameter.get_full_name(name, unit_name,
697701
unit_kind, label)
698702
if full_name in params:
699703
params[full_name].set_value(val, unit_name, unit_kind,
700704
label)
705+
elif (name.startswith("target.") and
706+
(unit_kind is "application" or
707+
name in BOOTLOADER_OVERRIDES)):
708+
_, attribute = name.split(".")
709+
setattr(self.target, attribute, val)
710+
continue
701711
else:
702712
self.config_errors.append(
703713
ConfigException(
@@ -750,7 +760,7 @@ def get_target_config_data(self):
750760
rel_names = [tgt for tgt, _ in
751761
get_resolution_order(self.target.json_data, tname,
752762
[])]
753-
if full_name in self.__unused_overrides:
763+
if full_name in BOOTLOADER_OVERRIDES:
754764
continue
755765
if (full_name not in params) or \
756766
(params[full_name].defined_by[7:] not in rel_names):

0 commit comments

Comments
 (0)