summaryrefslogtreecommitdiff
path: root/zephyr/zmake
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/zmake')
-rw-r--r--zephyr/zmake/tests/test_project.py3
-rw-r--r--zephyr/zmake/tests/test_toolchains.py1
-rw-r--r--zephyr/zmake/tests/test_version.py1
-rw-r--r--zephyr/zmake/tests/test_zmake.py70
-rw-r--r--zephyr/zmake/zmake/__main__.py57
-rw-r--r--zephyr/zmake/zmake/project.py7
-rw-r--r--zephyr/zmake/zmake/toolchains.py2
-rw-r--r--zephyr/zmake/zmake/util.py30
-rw-r--r--zephyr/zmake/zmake/zmake.py109
9 files changed, 159 insertions, 121 deletions
diff --git a/zephyr/zmake/tests/test_project.py b/zephyr/zmake/tests/test_project.py
index 4d9994a108..f7688784e7 100644
--- a/zephyr/zmake/tests/test_project.py
+++ b/zephyr/zmake/tests/test_project.py
@@ -58,7 +58,6 @@ def test_find_dts_overlays(modules):
zephyr_board=board,
output_packer=zmake.output_packers.ElfPacker,
supported_toolchains=["llvm"],
- zephyr_version="v2.7",
project_dir=pathlib.Path("/fakebuild"),
)
)
@@ -93,7 +92,6 @@ def test_prune_modules(modules):
zephyr_board="native_posix",
output_packer=zmake.output_packers.ElfPacker,
supported_toolchains=["coreboot-sdk"],
- zephyr_version="v2.7",
project_dir=pathlib.Path("/fake"),
modules=modules,
),
@@ -116,7 +114,6 @@ def test_prune_modules_unavailable():
zephyr_board="native_posix",
output_packer=zmake.output_packers.ElfPacker,
supported_toolchains=["coreboot-sdk"],
- zephyr_version="v2.7",
project_dir=pathlib.Path("/fake"),
modules=["hal_stm32", "cmsis"],
),
diff --git a/zephyr/zmake/tests/test_toolchains.py b/zephyr/zmake/tests/test_toolchains.py
index 09d37c4c4e..fb1953052a 100644
--- a/zephyr/zmake/tests/test_toolchains.py
+++ b/zephyr/zmake/tests/test_toolchains.py
@@ -66,7 +66,6 @@ def fake_project(tmp_path):
project.ProjectConfig(
project_name="foo",
zephyr_board="foo",
- zephyr_version="v2.6",
supported_toolchains=[
"coreboot-sdk",
"host",
diff --git a/zephyr/zmake/tests/test_version.py b/zephyr/zmake/tests/test_version.py
index cbc1ceff88..b2c6b43fec 100644
--- a/zephyr/zmake/tests/test_version.py
+++ b/zephyr/zmake/tests/test_version.py
@@ -57,7 +57,6 @@ def _setup_example_repos(tmp_path):
zephyr_board="foo",
output_packer=zmake.output_packers.RawBinPacker,
supported_toolchains=["coreboot-sdk"],
- zephyr_version="v2.6",
project_dir=project_path,
),
)
diff --git a/zephyr/zmake/tests/test_zmake.py b/zephyr/zmake/tests/test_zmake.py
index 589ee72c66..83862ce65d 100644
--- a/zephyr/zmake/tests/test_zmake.py
+++ b/zephyr/zmake/tests/test_zmake.py
@@ -13,6 +13,7 @@ import unittest
import unittest.mock as mock
from unittest.mock import patch
+import pytest
from testfixtures import LogCapture
import zmake.build_config
@@ -39,7 +40,6 @@ class FakeProject:
project_name="fakeproject",
zephyr_board="fakeboard",
supported_toolchains=["llvm"],
- zephyr_version="v2.5",
output_packer=zmake.output_packers.ElfPacker,
project_dir=pathlib.Path("FakeProjectDir"),
)
@@ -129,12 +129,10 @@ def do_test_with_log_level(log_level, use_configure=False, fnames=None):
re.compile(r".*build-rw"): get_test_filepath("rw"),
}
zephyr_base = mock.Mock()
- zephyr_root = mock.Mock()
zmk = zm.Zmake(
jobserver=FakeJobserver(fnames),
zephyr_base=zephyr_base,
- zephyr_root=zephyr_root,
)
with LogCapture(level=log_level) as cap:
@@ -231,5 +229,71 @@ class TestFilters(unittest.TestCase):
assert "devicetree error: 'adc' is marked as required" in list(dt_errs)[0]
+@pytest.mark.parametrize(
+ ["project_names", "format", "search_dir", "expected_output"],
+ [
+ (
+ ["link", "samus"],
+ "{config.project_name}\n",
+ None,
+ "link\nsamus\n",
+ ),
+ (
+ ["link", "samus"],
+ "{config.project_name}\n",
+ pathlib.Path("/foo/bar"),
+ "link\nsamus\n",
+ ),
+ (
+ [],
+ "{config.project_name}\n",
+ None,
+ "",
+ ),
+ (
+ ["link"],
+ "",
+ None,
+ "",
+ ),
+ (
+ ["link"],
+ "{config.zephyr_board}\n",
+ None,
+ "some_board\n",
+ ),
+ (
+ ["link"],
+ "{config.project_name} is_test={config.is_test}\n",
+ None,
+ "link is_test=False\n",
+ ),
+ ],
+)
+def test_list_projects(project_names, format, search_dir, expected_output, capsys):
+ """Test listing projects with default directory."""
+ fake_projects = {
+ name: zmake.project.Project(
+ zmake.project.ProjectConfig(
+ project_name=name,
+ zephyr_board="some_board",
+ supported_toolchains=["coreboot-sdk"],
+ output_packer=zmake.output_packers.RawBinPacker,
+ )
+ )
+ for name in project_names
+ }
+ zmk = zm.Zmake()
+ with mock.patch(
+ "zmake.project.find_projects",
+ autospec=True,
+ return_value=fake_projects,
+ ):
+ zmk.list_projects(format=format, search_dir=search_dir)
+
+ captured = capsys.readouterr()
+ assert captured.out == expected_output
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/zephyr/zmake/zmake/__main__.py b/zephyr/zmake/zmake/__main__.py
index f776c1dbaa..1f9c506ee5 100644
--- a/zephyr/zmake/zmake/__main__.py
+++ b/zephyr/zmake/zmake/__main__.py
@@ -107,7 +107,10 @@ def main(argv=None):
maybe_reexec(argv)
- parser = argparse.ArgumentParser()
+ parser = argparse.ArgumentParser(
+ prog="zmake",
+ description="Chromium OS's meta-build tool for Zephyr",
+ )
parser.add_argument(
"--checkout", type=pathlib.Path, help="Path to ChromiumOS checkout"
)
@@ -161,20 +164,13 @@ def main(argv=None):
parser.add_argument(
"--zephyr-base", type=pathlib.Path, help="Path to Zephyr OS repository"
)
- parser.add_argument(
- "--zephyr-root",
- type=pathlib.Path,
- help="Path to Zephyr OS repos, must contain subdirs like v1.2",
- )
sub = parser.add_subparsers(dest="subcommand", help="Subcommand")
sub.required = True
- configure = sub.add_parser("configure")
- configure.add_argument(
- "--ignore-unsupported-zephyr-version",
- action="store_true",
- help="Don't warn about using an unsupported Zephyr version",
+ configure = sub.add_parser(
+ "configure",
+ help="Set up a build directory to be built later by the build subcommand",
)
configure.add_argument("-t", "--toolchain", help="Name of toolchain to use")
configure.add_argument(
@@ -217,7 +213,10 @@ def main(argv=None):
help="Enable CONFIG_COVERAGE Kconfig.",
)
- build = sub.add_parser("build")
+ build = sub.add_parser(
+ "build",
+ help="Execute the build from a build directory",
+ )
build.add_argument(
"build_dir",
type=pathlib.Path,
@@ -230,16 +229,44 @@ def main(argv=None):
help="Exit with code 2 if warnings are detected",
)
- test = sub.add_parser("test")
+ list_projects = sub.add_parser(
+ "list-projects",
+ help="List projects known to zmake.",
+ )
+ list_projects.add_argument(
+ "--format",
+ default="{config.project_name}\n",
+ help=(
+ "Output format to print projects (str.format(config=project.config) is "
+ "called on this for each project)."
+ ),
+ )
+ list_projects.add_argument(
+ "search_dir",
+ type=pathlib.Path,
+ nargs="?",
+ help="Optional directory to search for BUILD.py files in.",
+ )
+
+ test = sub.add_parser(
+ "test",
+ help="Execute tests from a build directory",
+ )
test.add_argument(
"build_dir",
type=pathlib.Path,
help="The build directory used during configuration",
)
- sub.add_parser("testall")
+ sub.add_parser(
+ "testall",
+ help="Execute all known builds and tests",
+ )
- coverage = sub.add_parser("coverage")
+ coverage = sub.add_parser(
+ "coverage",
+ help="Run coverage on a build directory",
+ )
coverage.add_argument(
"build_dir",
type=pathlib.Path,
diff --git a/zephyr/zmake/zmake/project.py b/zephyr/zmake/zmake/project.py
index de3bc8413b..8e90372a35 100644
--- a/zephyr/zmake/zmake/project.py
+++ b/zephyr/zmake/zmake/project.py
@@ -55,10 +55,10 @@ def load_config_file(path):
exec(code, config_globals)
# Next, load the BUILD.py
- logging.info("Loading config file %s", path)
+ logging.debug("Loading config file %s", path)
code = compile(path.read_bytes(), str(path), "exec")
exec(code, config_globals)
- logging.info("Config file %s defines %s projects", path, len(projects))
+ logging.debug("Config file %s defines %s projects", path, len(projects))
return projects
@@ -71,7 +71,7 @@ def find_projects(root_dir):
Returns:
A dictionary mapping project names to Project objects.
"""
- logging.info("Finding zmake targets under '%s'.", root_dir)
+ 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):
@@ -91,7 +91,6 @@ class ProjectConfig:
zephyr_board: str
supported_toolchains: "list[str]"
output_packer: type
- zephyr_version: str = dataclasses.field(default="v2.7")
modules: "list[str]" = dataclasses.field(
default_factory=lambda: modules.known_modules,
)
diff --git a/zephyr/zmake/zmake/toolchains.py b/zephyr/zmake/zmake/toolchains.py
index 88b7c16e46..671c539c0f 100644
--- a/zephyr/zmake/zmake/toolchains.py
+++ b/zephyr/zmake/zmake/toolchains.py
@@ -107,7 +107,7 @@ class ZephyrToolchain(GenericToolchain):
if not self.zephyr_sdk_install_dir:
raise RuntimeError(
"No installed Zephyr SDK was found"
- " (see docs/zephyr_build.md for documentation)"
+ " (see docs/zephyr/zephyr_build.md for documentation)"
)
tc_vars = {
"ZEPHYR_SDK_INSTALL_DIR": str(self.zephyr_sdk_install_dir),
diff --git a/zephyr/zmake/zmake/util.py b/zephyr/zmake/zmake/util.py
index ca75f1b55e..ee3b245b78 100644
--- a/zephyr/zmake/zmake/util.py
+++ b/zephyr/zmake/zmake/util.py
@@ -64,19 +64,6 @@ def locate_cros_checkout():
raise FileNotFoundError("Unable to locate a ChromiumOS checkout")
-def locate_zephyr_base(zephyr_root, version):
- """Locate the path to the Zephyr RTOS in a ChromiumOS checkout.
-
- Args:
- checkout: The path to the ChromiumOS checkout.
- version: The requested zephyr version, as a tuple of integers.
-
- Returns:
- The path to the Zephyr source.
- """
- return zephyr_root / "v{}.{}".format(*version[:2])
-
-
def read_kconfig_file(path):
"""Parse a Kconfig file.
@@ -132,23 +119,6 @@ def write_kconfig_file(path, config, only_if_changed=True):
f.write("{}={}\n".format(name, value))
-def parse_zephyr_version(version_string):
- """Parse a human-readable version string (e.g., "v2.4") as a tuple.
-
- Args:
- version_string: The human-readable version string.
-
- Returns:
- A 2-tuple or 3-tuple of integers representing the version.
- """
- match = re.fullmatch(r"v?(\d+)[._](\d+)(?:[._](\d+))?", version_string)
- if not match:
- raise ValueError(
- "{} does not look like a Zephyr version.".format(version_string)
- )
- return tuple(int(x) for x in match.groups() if x is not None)
-
-
def read_zephyr_version(zephyr_base):
"""Read the Zephyr version from a Zephyr OS checkout.
diff --git a/zephyr/zmake/zmake/zmake.py b/zephyr/zmake/zmake/zmake.py
index 8fc9542dca..a906181c47 100644
--- a/zephyr/zmake/zmake/zmake.py
+++ b/zephyr/zmake/zmake/zmake.py
@@ -153,17 +153,13 @@ class Zmake:
jobs=0,
modules_dir=None,
zephyr_base=None,
- zephyr_root=None,
):
zmake.multiproc.reset()
self._checkout = checkout
- self._zephyr_base = zephyr_base
- if zephyr_root:
- self._zephyr_root = zephyr_root
+ if zephyr_base:
+ self.zephyr_base = zephyr_base
else:
- self._zephyr_root = (
- self.checkout / "src" / "third_party" / "zephyr" / "main"
- )
+ self.zephyr_base = self.checkout / "src" / "third_party" / "zephyr" / "main"
if modules_dir:
self.module_paths = zmake.modules.locate_from_directory(modules_dir)
@@ -188,28 +184,11 @@ class Zmake:
self._checkout = util.locate_cros_checkout()
return self._checkout.resolve()
- def locate_zephyr_base(self, version):
- """Locate the Zephyr OS repository.
-
- Args:
- version: If a Zephyr OS base was not supplied to Zmake,
- which version to search for as a tuple of integers.
- This argument is ignored if a Zephyr base was supplied
- to Zmake.
- Returns:
- A pathlib.Path to the found Zephyr OS repository.
- """
- if self._zephyr_base:
- return self._zephyr_base
-
- return util.locate_zephyr_base(self._zephyr_root, version)
-
def configure(
self,
project_name_or_dir,
build_dir=None,
toolchain=None,
- ignore_unsupported_zephyr_version=False,
build_after_configure=False,
test_after_configure=False,
bringup=False,
@@ -234,7 +213,6 @@ class Zmake:
project=project,
build_dir=build_dir,
toolchain=toolchain,
- ignore_unsupported_zephyr_version=ignore_unsupported_zephyr_version,
build_after_configure=build_after_configure,
test_after_configure=test_after_configure,
bringup=bringup,
@@ -247,7 +225,6 @@ class Zmake:
project,
build_dir=None,
toolchain=None,
- ignore_unsupported_zephyr_version=False,
build_after_configure=False,
test_after_configure=False,
bringup=False,
@@ -255,23 +232,6 @@ class Zmake:
allow_warnings=False,
):
"""Set up a build directory to later be built by "zmake build"."""
- supported_version = util.parse_zephyr_version(project.config.zephyr_version)
- zephyr_base = self.locate_zephyr_base(supported_version).resolve()
-
- # Ignore the patchset from the Zephyr version.
- zephyr_version = util.read_zephyr_version(zephyr_base)[:2]
-
- if (
- not ignore_unsupported_zephyr_version
- and zephyr_version != supported_version
- ):
- raise ValueError(
- "The Zephyr OS version (v{}.{}) is not supported by the "
- "project. You may wish to either configure BUILD.py to "
- "support this version, or pass "
- "--ignore-unsupported-zephyr-version.".format(*zephyr_version)
- )
-
# Resolve build_dir if needed.
if not build_dir:
build_dir = (
@@ -287,7 +247,7 @@ class Zmake:
generated_include_dir = (build_dir / "include").resolve()
base_config = zmake.build_config.BuildConfig(
- environ_defs={"ZEPHYR_BASE": str(zephyr_base), "PATH": "/usr/bin"},
+ environ_defs={"ZEPHYR_BASE": str(self.zephyr_base), "PATH": "/usr/bin"},
cmake_defs={
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"DTS_ROOT": str(self.module_paths["ec"] / "zephyr"),
@@ -307,7 +267,7 @@ class Zmake:
# Symlink the Zephyr base into the build directory so it can
# be used in the build phase.
- util.update_symlink(zephyr_base, build_dir / "zephyr_base")
+ util.update_symlink(self.zephyr_base, build_dir / "zephyr_base")
dts_overlay_config = project.find_dts_overlays(module_paths)
@@ -397,7 +357,15 @@ class Zmake:
is_configured=True,
)
elif build_after_configure:
- return self.build(build_dir=build_dir)
+ if coverage:
+ return self._coverage_compile_only(
+ project=project,
+ build_dir=build_dir,
+ lcov_file=build_dir / "lcov.info",
+ is_configured=True,
+ )
+ else:
+ return self.build(build_dir=build_dir)
def build(self, build_dir, output_files_out=None, fail_on_warnings=False):
"""Build a pre-configured build directory."""
@@ -652,17 +620,20 @@ class Zmake:
return 0
- def _coverage_compile_only(self, project, build_dir, lcov_file):
+ def _coverage_compile_only(
+ self, project, build_dir, lcov_file, is_configured=False
+ ):
self.logger.info("Building %s in %s", project.config.project_name, build_dir)
- rv = self._configure(
- project=project,
- build_dir=build_dir,
- build_after_configure=False,
- test_after_configure=False,
- coverage=True,
- )
- if rv:
- return rv
+ if not is_configured:
+ rv = self._configure(
+ project=project,
+ build_dir=build_dir,
+ build_after_configure=False,
+ test_after_configure=False,
+ coverage=True,
+ )
+ if rv:
+ return rv
# Compute the version string.
version_string = zmake.version.get_version_string(
@@ -760,21 +731,17 @@ class Zmake:
lcov_file = pathlib.Path(build_dir) / "{}.info".format(
project.config.project_name
)
- all_lcov_files.append(lcov_file)
if is_test:
# Configure and run the test.
+ all_lcov_files.append(lcov_file)
self.executor.append(
func=lambda: self._coverage_run_test(
project, project_build_dir, lcov_file
)
)
else:
- # Configure and compile the non-test project.
- self.executor.append(
- func=lambda: self._coverage_compile_only(
- project, project_build_dir, lcov_file
- )
- )
+ # Don't build non-test projects
+ self.logger.info("Skipping project %s", project.config.project_name)
if self._sequential:
rv = self.executor.wait()
if rv:
@@ -845,3 +812,19 @@ class Zmake:
if proc.wait():
raise OSError(get_process_failure_msg(proc))
return 0
+
+ def list_projects(self, format, search_dir):
+ """List project names known to zmake on stdout.
+
+ Args:
+ format: The formatting string to print projects with.
+ search_dir: Directory to start the search for
+ BUILD.py files at.
+ """
+ if not search_dir:
+ search_dir = self.module_paths["ec"] / "zephyr"
+
+ for project in zmake.project.find_projects(search_dir).values():
+ print(format.format(config=project.config), end="")
+
+ return 0