Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

### Fixed
- **`load_config`:** `toolchain.extra_cflags` and `toolchain.extra_ldflags` must be YAML lists of strings so scalar values cannot silently split into per-character compiler flags.
- **Ninja backend: header changes now trigger a rebuild.** The generated `cc`
rule declared no depfile, so Ninja only knew about the sources listed in
`build.yaml`. Editing a header left stale object files in place and the build
Expand Down
20 changes: 18 additions & 2 deletions ebuild/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,29 @@ def _parse_target(raw: Any) -> TargetConfig:

def _parse_toolchain(raw: Dict[str, Any]) -> ToolchainConfig:
"""Parse toolchain section into a ToolchainConfig."""
extra_cflags = raw.get("extra_cflags", [])
extra_ldflags = raw.get("extra_ldflags", [])

for field_name, value in (
("extra_cflags", extra_cflags),
("extra_ldflags", extra_ldflags),
):
if not isinstance(value, list):
raise ConfigError(
f"Toolchain field '{field_name}' must be a list."
)
if not all(isinstance(item, str) for item in value):
raise ConfigError(
f"Toolchain field '{field_name}' must contain only strings."
)

Comment on lines +160 to +175
return ToolchainConfig(
compiler=raw.get("compiler", "gcc"),
arch=raw.get("arch", "x86_64"),
prefix=raw.get("prefix"),
sysroot=raw.get("sysroot"),
extra_cflags=raw.get("extra_cflags", []),
extra_ldflags=raw.get("extra_ldflags", []),
extra_cflags=extra_cflags,
extra_ldflags=extra_ldflags,
)


Expand Down
27 changes: 27 additions & 0 deletions tests/ebuild/test_config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,30 @@ def test_toolchain_mapping_is_parsed(tmp_path):
assert config.toolchain.sysroot == "/opt/arm-none-eabi"
assert config.toolchain.extra_cflags == ["-mcpu=cortex-m4"]
assert config.toolchain.extra_ldflags == ["--specs=nosys.specs"]


@pytest.mark.parametrize("field_name", ["extra_cflags", "extra_ldflags"])
def test_toolchain_flag_fields_must_be_lists(tmp_path, field_name):
path = write_config(
tmp_path,
{
"project": {"name": "demo"},
"toolchain": {field_name: "-O2"},
},
)

with pytest.raises(ConfigError, match=rf"field '{field_name}' must be a list"):
load_config(path)


def test_toolchain_flag_items_must_be_strings(tmp_path):
path = write_config(
tmp_path,
{
"project": {"name": "demo"},
"toolchain": {"extra_cflags": ["-O2", 42]},
},
)

with pytest.raises(ConfigError, match="extra_cflags.*must contain only strings"):
load_config(path)
Loading