From 171aa03229bff92769583d78252fb13fc8d32247 Mon Sep 17 00:00:00 2001 From: Tristan Honscheid Date: Tue, 4 Apr 2023 13:33:49 -0600 Subject: zmake: Track project inheritance in ProjectConfig Add an `inherited_from` list field to the ProjectConfig dataclass that tracks what project(s) the current project inherited from. When using the `.variant()` project resgistration method, `inherited_from` is automatically appended with the base project's name. When the following `BUILD.py` file is processed... ``` baseboard = register_raw_project(project_name="base") variant1 = baseboard.variant(project_name="variant1") variant2 = variant1.variant(project_name="variant2") ``` ... variant1's `config.inherited_from` field will be `['base']` and variant2's will be `['base','variant1']. It is also possible to manually specify `inherited_from` when registering a project (either as a string or list of strings): ``` register_raw_project( project_name="myboard", inherited_from=["root","baseboard1"], ) ``` This method is how the EC's `BUILD.py` files are configured. In either case, the project's full name can be accessed by reading the ProjectConfig object's `full_name` property to join the names of the parent boards plus the current project name. In the case of the above example, the property would read `"root.baseboard1.myboard"`. The full name is not consumed anywhere within zmake; it is intended to be used for external reporting tools and does not affect the builds. BRANCH=None BUG=b:276947804 TEST=zephyr/zmake/run_tests.sh Change-Id: I7d7413175c9c670a64e7ade01a41e46a2fb8d743 Signed-off-by: Tristan Honscheid Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4400532 Reviewed-by: Jeremy Bettis Commit-Queue: Jack Rosenthal Reviewed-by: Jack Rosenthal --- zephyr/program/brya/BUILD.py | 1 + zephyr/program/corsola/BUILD.py | 1 + zephyr/program/geralt/BUILD.py | 1 + zephyr/program/herobrine/BUILD.py | 1 + zephyr/program/intelrvp/BUILD.py | 1 + zephyr/program/myst/BUILD.py | 1 + zephyr/program/nissa/BUILD.py | 4 +++- zephyr/program/rex/BUILD.py | 1 + zephyr/program/skyrim/BUILD.py | 1 + zephyr/zmake/tests/test_project.py | 12 +++++++++++- zephyr/zmake/zmake/project.py | 20 +++++++++++++++++++- 11 files changed, 41 insertions(+), 3 deletions(-) diff --git a/zephyr/program/brya/BUILD.py b/zephyr/program/brya/BUILD.py index 9991335ca7..6395cbc68b 100644 --- a/zephyr/program/brya/BUILD.py +++ b/zephyr/program/brya/BUILD.py @@ -33,6 +33,7 @@ def register_npcx9_variant( # Project-specific KConfig customization. *extra_kconfig_files, ], + inherited_from=["brya"], ) diff --git a/zephyr/program/corsola/BUILD.py b/zephyr/program/corsola/BUILD.py index f145953e0d..d0ef4132bc 100644 --- a/zephyr/program/corsola/BUILD.py +++ b/zephyr/program/corsola/BUILD.py @@ -27,6 +27,7 @@ def register_corsola_project( here / f"{chip_kconfig}_program.conf", here / project_name / "project.conf", ], + inherited_from=["corsola"], ) diff --git a/zephyr/program/geralt/BUILD.py b/zephyr/program/geralt/BUILD.py index f41948506a..cc4c2b1946 100644 --- a/zephyr/program/geralt/BUILD.py +++ b/zephyr/program/geralt/BUILD.py @@ -17,6 +17,7 @@ def register_geralt_project( here / "program.conf", here / project_name / "project.conf", ], + inherited_from=["geralt"], ) diff --git a/zephyr/program/herobrine/BUILD.py b/zephyr/program/herobrine/BUILD.py index 0bee6ffe2a..302262fc21 100644 --- a/zephyr/program/herobrine/BUILD.py +++ b/zephyr/program/herobrine/BUILD.py @@ -21,6 +21,7 @@ def register_variant( # Project-specific KConfig customization. here / project_name / "project.conf", ], + inherited_from=["herobrine"], ) diff --git a/zephyr/program/intelrvp/BUILD.py b/zephyr/program/intelrvp/BUILD.py index 7a79480a61..32a2eb5e97 100644 --- a/zephyr/program/intelrvp/BUILD.py +++ b/zephyr/program/intelrvp/BUILD.py @@ -37,6 +37,7 @@ def register_intelrvp_project( zephyr_board=chip, dts_overlays=dts_overlays, kconfig_files=kconfig_files, + inherited_from=["intelrvp"], ) diff --git a/zephyr/program/myst/BUILD.py b/zephyr/program/myst/BUILD.py index a8ce427b0c..27e4009c1c 100644 --- a/zephyr/program/myst/BUILD.py +++ b/zephyr/program/myst/BUILD.py @@ -21,6 +21,7 @@ def register_myst_project( # Project-specific KConfig customization. here / project_name / "project.conf", ], + inherited_from=["myst"], ) diff --git a/zephyr/program/nissa/BUILD.py b/zephyr/program/nissa/BUILD.py index 621db42e5e..0a10912552 100644 --- a/zephyr/program/nissa/BUILD.py +++ b/zephyr/program/nissa/BUILD.py @@ -4,7 +4,8 @@ """Define zmake projects for nissa.""" -# Nivviks and Craask, Pujjo, Xivu, Xivur, Uldren has NPCX993F, Nereid and Joxer, Yaviks, Yavilla has ITE81302 +# Nivviks and Craask, Pujjo, Xivu, Xivur, Uldren has NPCX993F, Nereid +# and Joxer, Yaviks, Yavilla has ITE81302 def register_nissa_project( @@ -27,6 +28,7 @@ def register_nissa_project( here / f"{chip_kconfig}_program.conf", here / project_name / "project.conf", ], + inherited_from=["nissa"], ) diff --git a/zephyr/program/rex/BUILD.py b/zephyr/program/rex/BUILD.py index ca7136c11f..89aee8b06d 100644 --- a/zephyr/program/rex/BUILD.py +++ b/zephyr/program/rex/BUILD.py @@ -25,6 +25,7 @@ def register_rex_project( here / project_name / "project.overlay", ], kconfig_files=kconfig_files, + inherited_from=["rex"], ) diff --git a/zephyr/program/skyrim/BUILD.py b/zephyr/program/skyrim/BUILD.py index ed0f929409..2719375808 100644 --- a/zephyr/program/skyrim/BUILD.py +++ b/zephyr/program/skyrim/BUILD.py @@ -21,6 +21,7 @@ def register_skyrim_project( # Project-specific KConfig customization. here / project_name / "project.conf", ], + inherited_from=["skyrim"], ) diff --git a/zephyr/zmake/tests/test_project.py b/zephyr/zmake/tests/test_project.py index 327d119bad..6acde6a48b 100644 --- a/zephyr/zmake/tests/test_project.py +++ b/zephyr/zmake/tests/test_project.py @@ -138,7 +138,11 @@ CONFIG_FILE_1 = """ register_raw_project(project_name="one", zephyr_board="one") register_host_project(project_name="two") register_npcx_project(project_name="three", zephyr_board="three") -register_binman_project(project_name="four", zephyr_board="four") +register_binman_project( + project_name="four", + zephyr_board="four", + inherited_from="baseboard" +) """ CONFIG_FILE_2 = """ @@ -146,6 +150,7 @@ register_raw_project( project_name="five", zephyr_board="foo", dts_overlays=[here / "gpio.dts"], + inherited_from=["root", "myboard"], ) """ @@ -174,9 +179,11 @@ def test_find_projects(tmp_path): assert projects["four"].config.project_dir == cf1_dir assert projects["four"].config.zephyr_board == "four" + assert projects["four"].config.full_name == "baseboard.four" assert projects["five"].config.project_dir == cf2_dir assert projects["five"].config.zephyr_board == "foo" + assert projects["five"].config.full_name == "root.myboard.five" def test_find_projects_name_conflict(tmp_path): @@ -218,6 +225,9 @@ another = some_variant.variant( tmp_path / "gpio.dts", tmp_path / "another.dts", ] + assert projects["some"].config.full_name == "some" + assert projects["some-variant"].config.full_name == "some.some-variant" + assert projects["another"].config.full_name == "some.some-variant.another" @pytest.mark.parametrize( diff --git a/zephyr/zmake/zmake/project.py b/zephyr/zmake/zmake/project.py index 3c18520b55..2c91e27ba7 100644 --- a/zephyr/zmake/zmake/project.py +++ b/zephyr/zmake/zmake/project.py @@ -52,6 +52,20 @@ class ProjectConfig: default_factory=list ) project_dir: pathlib.Path = dataclasses.field(default_factory=pathlib.Path) + inherited_from: typing.Iterable[str] = dataclasses.field( + default_factory=list + ) + + @property + def full_name(self) -> str: + """Get the full project name, e.g. baseboard.variant""" + inherited_from = ( + [self.inherited_from] + if isinstance(self.inherited_from, str) + else self.inherited_from + ) + + return ".".join([*inherited_from, self.project_name]) class Project: @@ -198,12 +212,16 @@ class ProjectRegistrationHandler: Another ProjectRegistrationHandler. """ new_config = dataclasses.asdict(self.base_config) + new_config["inherited_from"] = [ + *self.base_config.inherited_from, + self.base_config.project_name, + ] + for key, value in kwargs.items(): if isinstance(value, list): new_config[key] = [*new_config[key], *value] else: new_config[key] = value - return self.register_func(**new_config) -- cgit v1.2.1