diff options
author | Fabio Baltieri <fabiobaltieri@google.com> | 2023-01-25 12:20:52 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-01-25 19:59:27 +0000 |
commit | 2a81b85c1b0a806891ed6d838650e83ee66d2b2b (patch) | |
tree | 8f6f405d874279df615ff6a9d596eb6f46a1217f | |
parent | 5756bbb429dc258ff3f2334fd6161fa49512e820 (diff) | |
download | chrome-ec-2a81b85c1b0a806891ed6d838650e83ee66d2b2b.tar.gz |
util: check_zephyr_project_config: keep paths as Path objects
Use Path objects for ZEPHYR_BASE and use the site module to add module
paths instead modifying sys.path.
BRANCH=none
BUG=none
TEST=pytest
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Change-Id: If6f3b60d90d9acaff91609d55acffbfb605e0961
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4188740
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
-rwxr-xr-x | util/check_zephyr_project_config.py | 21 | ||||
-rwxr-xr-x | util/check_zephyr_project_config_unittest.py | 7 |
2 files changed, 14 insertions, 14 deletions
diff --git a/util/check_zephyr_project_config.py b/util/check_zephyr_project_config.py index 1cd7f9c2e4..6a48e348fd 100755 --- a/util/check_zephyr_project_config.py +++ b/util/check_zephyr_project_config.py @@ -10,22 +10,21 @@ import argparse import logging import os import pathlib +import site import sys import tempfile EC_BASE = pathlib.Path(__file__).parent.parent -ZEPHYR_BASE = os.environ.get("ZEPHYR_BASE") -if not ZEPHYR_BASE: - ZEPHYR_BASE = os.path.join( - EC_BASE.resolve().parent.parent, - "third_party", - "zephyr", - "main", +if "ZEPHYR_BASE" in os.environ: + ZEPHYR_BASE = pathlib.Path(os.environ.get("ZEPHYR_BASE")) +else: + ZEPHYR_BASE = pathlib.Path( + EC_BASE.resolve().parent.parent / "third_party" / "zephyr" / "main" ) -sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts")) -sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts", "kconfig")) +site.addsitedir(ZEPHYR_BASE / "scripts") +site.addsitedir(ZEPHYR_BASE / "scripts" / "kconfig") # pylint:disable=import-error,wrong-import-position import kconfiglib import zephyr_module @@ -114,8 +113,8 @@ class KconfigCheck: with open(pathlib.Path(temp_dir) / "Kconfig.dts", "w") as file: file.write("") - os.environ["ZEPHYR_BASE"] = ZEPHYR_BASE - os.environ["srctree"] = ZEPHYR_BASE + os.environ["ZEPHYR_BASE"] = str(ZEPHYR_BASE) + os.environ["srctree"] = str(ZEPHYR_BASE) os.environ["KCONFIG_BINARY_DIR"] = temp_dir os.environ["ARCH_DIR"] = "arch" os.environ["ARCH"] = "*" diff --git a/util/check_zephyr_project_config_unittest.py b/util/check_zephyr_project_config_unittest.py index 258f56b58f..0229085725 100755 --- a/util/check_zephyr_project_config_unittest.py +++ b/util/check_zephyr_project_config_unittest.py @@ -56,14 +56,15 @@ class TestKconfigCheck(unittest.TestCase): ) process_kconfig_mock.assert_called_once_with("project", "meta") kconfig_mock.assert_called_once_with( - check_zephyr_project_config.ZEPHYR_BASE + "/Kconfig" + str(check_zephyr_project_config.ZEPHYR_BASE / "Kconfig") ) self.assertEqual( - os.environ["ZEPHYR_BASE"], check_zephyr_project_config.ZEPHYR_BASE + os.environ["ZEPHYR_BASE"], + str(check_zephyr_project_config.ZEPHYR_BASE), ) self.assertEqual( - os.environ["srctree"], check_zephyr_project_config.ZEPHYR_BASE + os.environ["srctree"], str(check_zephyr_project_config.ZEPHYR_BASE) ) self.assertEqual(os.environ["ARCH_DIR"], "arch") self.assertEqual(os.environ["ARCH"], "*") |