summaryrefslogtreecommitdiff
path: root/zephyr/zmake/zmake/util.py
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2021-07-02 11:41:24 -0600
committerCommit Bot <commit-bot@chromium.org>2021-07-12 19:15:42 +0000
commit6580c97e48e7abca694f8f5d3e955bdf12a6ec55 (patch)
treebcda10463444802c8004fb46b4cb86ef5bc3a017 /zephyr/zmake/zmake/util.py
parent0a639566d7e7769b7f627614c3359128c0c42763 (diff)
downloadchrome-ec-6580c97e48e7abca694f8f5d3e955bdf12a6ec55.tar.gz
zephyr: zmake: run black on all files, enable check in run_tests.sh
Run black on all files. Enable check in run_tests.sh to enforce future formatting requirements. BUG=b:192389533 BRANCH=none TEST=run_tests.sh Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: I5d93ef61d32d0dab4fe4bf3a77faf3f6693be627 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3002839 Commit-Queue: Yuval Peress <peress@chromium.org> Reviewed-by: Yuval Peress <peress@chromium.org>
Diffstat (limited to 'zephyr/zmake/zmake/util.py')
-rw-r--r--zephyr/zmake/zmake/util.py82
1 files changed, 47 insertions, 35 deletions
diff --git a/zephyr/zmake/zmake/util.py b/zephyr/zmake/zmake/util.py
index ca38831ef6..18d03dd7f0 100644
--- a/zephyr/zmake/zmake/util.py
+++ b/zephyr/zmake/zmake/util.py
@@ -18,26 +18,27 @@ def locate_cros_checkout():
variable, then scanning upwards from the current directory,
and finally from a known set of common paths.
"""
+
def propose_checkouts():
- yield os.getenv('CROS_WORKON_SRCROOT')
+ yield os.getenv("CROS_WORKON_SRCROOT")
path = pathlib.Path.cwd()
- while path.resolve() != pathlib.Path('/'):
+ while path.resolve() != pathlib.Path("/"):
yield path
- path = path / '..'
+ path = path / ".."
- yield '/mnt/host/source'
- yield pathlib.Path.home() / 'trunk'
- yield pathlib.Path.home() / 'chromiumos'
+ yield "/mnt/host/source"
+ yield pathlib.Path.home() / "trunk"
+ yield pathlib.Path.home() / "chromiumos"
for path in propose_checkouts():
if not path:
continue
path = pathlib.Path(path)
- if (path / '.repo').is_dir():
+ if (path / ".repo").is_dir():
return path.resolve()
- raise FileNotFoundError('Unable to locate a ChromiumOS checkout')
+ raise FileNotFoundError("Unable to locate a ChromiumOS checkout")
def locate_zephyr_base(checkout, version):
@@ -50,8 +51,14 @@ def locate_zephyr_base(checkout, version):
Returns:
The path to the Zephyr source.
"""
- return (checkout / 'src' / 'third_party' / 'zephyr' / 'main' /
- 'v{}.{}'.format(*version[:2]))
+ return (
+ checkout
+ / "src"
+ / "third_party"
+ / "zephyr"
+ / "main"
+ / "v{}.{}".format(*version[:2])
+ )
def read_kconfig_file(path):
@@ -66,13 +73,14 @@ def read_kconfig_file(path):
result = {}
with open(path) as f:
for line in f:
- line, _, _ = line.partition('#')
+ line, _, _ = line.partition("#")
line = line.strip()
if line:
- name, _, value = line.partition('=')
+ name, _, value = line.partition("=")
result[name.strip()] = value.strip()
return result
+
def read_kconfig_autoconf_value(path, key):
"""Parse an autoconf.h file for a resolved kconfig value
@@ -83,8 +91,8 @@ def read_kconfig_autoconf_value(path, key):
Returns:
The value associated with the key or nothing if the key wasn't found.
"""
- prog = re.compile(r'^#define\s{}\s(\S+)$'.format(key))
- with open(path / 'autoconf.h') as f:
+ prog = re.compile(r"^#define\s{}\s(\S+)$".format(key))
+ with open(path / "autoconf.h") as f:
for line in f:
m = prog.match(line)
if m:
@@ -105,7 +113,7 @@ def write_kconfig_file(path, config, only_if_changed=True):
return
with open(path, "w") as f:
for name, value in config.items():
- f.write('{}={}\n'.format(name, value))
+ f.write("{}={}\n".format(name, value))
def parse_zephyr_version(version_string):
@@ -117,10 +125,11 @@ def parse_zephyr_version(version_string):
Returns:
A 2-tuple or 3-tuple of integers representing the version.
"""
- match = re.fullmatch(r'v?(\d+)[._](\d+)(?:[._](\d+))?', version_string)
+ 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))
+ "{} does not look like a Zephyr version.".format(version_string)
+ )
return tuple(int(x) for x in match.groups() if x is not None)
@@ -133,17 +142,19 @@ def read_zephyr_version(zephyr_base):
Returns:
A 3-tuple of the version number (major, minor, patchset).
"""
- version_file = pathlib.Path(zephyr_base) / 'VERSION'
+ version_file = pathlib.Path(zephyr_base) / "VERSION"
file_vars = {}
with open(version_file) as f:
for line in f:
- key, sep, value = line.partition('=')
+ key, sep, value = line.partition("=")
file_vars[key.strip()] = value.strip()
- return (int(file_vars['VERSION_MAJOR']),
- int(file_vars['VERSION_MINOR']),
- int(file_vars['PATCHLEVEL']))
+ return (
+ int(file_vars["VERSION_MAJOR"]),
+ int(file_vars["VERSION_MINOR"]),
+ int(file_vars["PATCHLEVEL"]),
+ )
def repr_command(argv):
@@ -155,7 +166,7 @@ def repr_command(argv):
Returns:
A string which could be pasted into a shell for execution.
"""
- return ' '.join(shlex.quote(str(arg)) for arg in argv)
+ return " ".join(shlex.quote(str(arg)) for arg in argv)
def update_symlink(target_path, link_path):
@@ -166,11 +177,13 @@ def update_symlink(target_path, link_path):
link_path: A Path-like object of the symlink.
"""
target = target_path.resolve()
- if (not link_path.is_symlink()
- or pathlib.Path(os.readlink(link_path)).resolve() != target):
- if link_path.exists():
- link_path.unlink()
- link_path.symlink_to(target)
+ if (
+ not link_path.is_symlink()
+ or pathlib.Path(os.readlink(link_path)).resolve() != target
+ ):
+ if link_path.exists():
+ link_path.unlink()
+ link_path.symlink_to(target)
def log_multi_line(logger, level, message):
@@ -200,21 +213,20 @@ def resolve_build_dir(platform_ec_dir, project_dir, build_dir):
if build_dir:
return build_dir
- if not pathlib.Path.exists(project_dir / 'zmake.yaml'):
+ if not pathlib.Path.exists(project_dir / "zmake.yaml"):
raise OSError("Invalid configuration")
# Resolve project_dir to absolute path.
project_dir = project_dir.resolve()
# Compute the path of project_dir relative to platform_ec_dir.
- project_relative_path = pathlib.Path.relative_to(project_dir,
- platform_ec_dir)
+ project_relative_path = pathlib.Path.relative_to(project_dir, platform_ec_dir)
# Make sure that the project_dir is a subdirectory of platform_ec_dir.
if platform_ec_dir / project_relative_path != project_dir:
raise OSError(
- 'Can\'t resolve project directory {} which is not a subdirectory'
- ' of the platform/ec directory {}'.format(project_dir,
- platform_ec_dir))
+ "Can't resolve project directory {} which is not a subdirectory"
+ " of the platform/ec directory {}".format(project_dir, platform_ec_dir)
+ )
- return platform_ec_dir / 'build' / project_relative_path
+ return platform_ec_dir / "build" / project_relative_path