summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Bettis <jbettis@google.com>2022-02-14 14:53:13 -0700
committerCommit Bot <commit-bot@chromium.org>2022-02-17 04:00:37 +0000
commitf041706c2b02af4cc3749faf21e7472323b382a5 (patch)
tree05965b236d8901808675871c94a1c0373f56cdfd
parent549f1e3362836ba5b0a0cb433526049acde4b9be (diff)
downloadchrome-ec-f041706c2b02af4cc3749faf21e7472323b382a5.tar.gz
zmake: Add some python type hints
Some project references were not auto-completing in VSCode, so I added type hints to help. BRANCH=None BUG=None TEST=None Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: I0819151f2053e0daf1012874beb72c112e7a80ef Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3462632 Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Auto-Submit: Jeremy Bettis <jbettis@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r--zephyr/zmake/zmake/project.py121
1 files changed, 61 insertions, 60 deletions
diff --git a/zephyr/zmake/zmake/project.py b/zephyr/zmake/zmake/project.py
index a3d786f0cd..b2c36cbb33 100644
--- a/zephyr/zmake/zmake/project.py
+++ b/zephyr/zmake/zmake/project.py
@@ -6,6 +6,7 @@
import dataclasses
import logging
import pathlib
+from typing import Dict, List
import zmake.build_config as build_config
import zmake.configlib as configlib
@@ -26,65 +27,6 @@ def module_dts_overlay_name(modpath, board_name):
return modpath / "zephyr" / "dts" / "board-overlays" / "{}.dts".format(board_name)
-def load_config_file(path):
- """Load a BUILD.py config file and create associated projects.
-
- Args:
- path: A pathlib.Path to the BUILD.py file.
-
- Returns:
- A list of Project objects specified by the file.
- """
- projects = []
-
- def register_project(**kwargs):
- projects.append(Project(ProjectConfig(**kwargs)))
-
- # The Python environment passed to the config file.
- config_globals = {
- "register_project": register_project,
- "here": path.parent.resolve(),
- }
-
- # First, load the global helper functions.
- code = compile(
- pathlib.Path(configlib.__file__).read_bytes(),
- configlib.__file__,
- "exec",
- )
- exec(code, config_globals)
-
- # Next, load the BUILD.py
- logging.debug("Loading config file %s", path)
- code = compile(path.read_bytes(), str(path), "exec")
- exec(code, config_globals)
- logging.debug("Config file %s defines %s projects", path, len(projects))
- return projects
-
-
-def find_projects(root_dir):
- """Finds all zmake projects in root_dir.
-
- Args:
- root_dir: the root dir as a pathlib.Path object
-
- Returns:
- A dictionary mapping project names to Project objects.
- """
- logging.debug("Finding zmake targets under '%s'.", root_dir)
- found_projects = {}
- for path in pathlib.Path(root_dir).rglob("BUILD.py"):
- for project in load_config_file(path):
- if project.config.project_name in found_projects:
- raise KeyError(
- "Duplicate project defined: {} (in {})".format(
- project.config.project_name, path
- )
- )
- found_projects[project.config.project_name] = project
- return found_projects
-
-
@dataclasses.dataclass
class ProjectConfig:
project_name: str
@@ -104,7 +46,7 @@ class ProjectConfig:
class Project:
"""An object encapsulating a project directory."""
- def __init__(self, config):
+ def __init__(self, config: ProjectConfig):
self.config = config
self.packer = self.config.output_packer(self)
@@ -210,3 +152,62 @@ class Project:
"either want to setup your system with a supported toolchain, or "
"manually select an unsupported toolchain with the -t flag."
)
+
+
+def load_config_file(path) -> List[Project]:
+ """Load a BUILD.py config file and create associated projects.
+
+ Args:
+ path: A pathlib.Path to the BUILD.py file.
+
+ Returns:
+ A list of Project objects specified by the file.
+ """
+ projects: List[Project] = []
+
+ def register_project(**kwargs):
+ projects.append(Project(ProjectConfig(**kwargs)))
+
+ # The Python environment passed to the config file.
+ config_globals = {
+ "register_project": register_project,
+ "here": path.parent.resolve(),
+ }
+
+ # First, load the global helper functions.
+ code = compile(
+ pathlib.Path(configlib.__file__).read_bytes(),
+ configlib.__file__,
+ "exec",
+ )
+ exec(code, config_globals)
+
+ # Next, load the BUILD.py
+ logging.debug("Loading config file %s", path)
+ code = compile(path.read_bytes(), str(path), "exec")
+ exec(code, config_globals)
+ logging.debug("Config file %s defines %s projects", path, len(projects))
+ return projects
+
+
+def find_projects(root_dir) -> Dict[str, Project]:
+ """Finds all zmake projects in root_dir.
+
+ Args:
+ root_dir: the root dir as a pathlib.Path object
+
+ Returns:
+ A dictionary mapping project names to Project objects.
+ """
+ logging.debug("Finding zmake targets under '%s'.", root_dir)
+ found_projects = {}
+ for path in pathlib.Path(root_dir).rglob("BUILD.py"):
+ for project in load_config_file(path):
+ if project.config.project_name in found_projects:
+ raise KeyError(
+ "Duplicate project defined: {} (in {})".format(
+ project.config.project_name, path
+ )
+ )
+ found_projects[project.config.project_name] = project
+ return found_projects