Skip to content

Commit

Permalink
config: Fix target.requires
Browse files Browse the repository at this point in the history
Apparently the old tools allowed a user to specify a required lib in the
"target_overrides" section of the config, even if no root "requires" are
defined. This commit adds support for this workflow.

Fixes #162
  • Loading branch information
rwalton-arm authored and Patater committed Jan 15, 2021
1 parent 45c1ef4 commit 6a99b43
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/mbed_tools/build/_internal/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def __setitem__(self, key: Hashable, item: Any) -> None:
def _handle_overrides(self, overrides: Iterable[Override]) -> None:
for override in overrides:
logger.debug("Applying override '%s.%s'", override.namespace, override.name)
if override.name == "requires":
self.data["requires"] = self.data.get("requires", set()) | override.value
continue

if override.name in self.data:
_apply_override(self.data, override)
continue
Expand Down
24 changes: 24 additions & 0 deletions tests/build/test_generate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,27 @@ def test_requires_config_option(program):

assert "MBED_CONF_PLATFORM_STDIO_BAUD_RATE=9600" in config_text
assert "MBED_LFS_READ_SIZE=64" not in config_text


def test_target_requires_config_option(program):
create_mbed_app_json(program.root, target_overrides={"*": {"target.requires": ["ble"]}})
create_mbed_lib_json(
program.mbed_os.root / "bare-metal" / "mbed_lib.json",
"ble",
target_overrides={"*": {"target.requires": ["platform"]}},
)
create_mbed_lib_json(
program.mbed_os.root / "platform" / "mbed_lib.json", "platform", config={"stdio-baud-rate": {"value": 9600}},
)
create_mbed_lib_json(
program.mbed_os.root / "storage" / "mbed_lib.json",
"filesystem",
config={"read_size": {"macro_name": "MBED_LFS_READ_SIZE", "value": 64}},
)

generate_config("K64F", "GCC_ARM", program)

config_text = program.files.cmake_config_file.read_text()

assert "MBED_CONF_PLATFORM_STDIO_BAUD_RATE=9600" in config_text
assert "MBED_LFS_READ_SIZE=64" not in config_text

0 comments on commit 6a99b43

Please sign in to comment.