summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2023-01-12 14:49:08 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-01-17 18:35:12 +0000
commit92e23477494e6815a90bded7386f8e1ad138f87d (patch)
treeaca833ceb66b05fd9bbb7f7b7e105a96e2bb1eed
parent435ced35da433c5eccf33b30711d106e6b3e7307 (diff)
downloadchrome-ec-92e23477494e6815a90bded7386f8e1ad138f87d.tar.gz
zephyr: zmake: Allow tool path customization
Allow callers of zmake to customize the precise execution of external tools by specifying TOOL_PATH_${program} environment variables. This enables bazel to locate tools where it likes, and we can just tell zmake where they are. BUG=b:259306777 BRANCH=none TEST=tests pass Change-Id: I58b153fbb890766f7ac7e9f590aa098a93576cb4 Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4166335 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Aaron Massey <aaronmassey@google.com>
-rw-r--r--zephyr/zmake/zmake/build_config.py2
-rw-r--r--zephyr/zmake/zmake/output_packers.py2
-rw-r--r--zephyr/zmake/zmake/util.py21
-rw-r--r--zephyr/zmake/zmake/zmake.py10
4 files changed, 30 insertions, 5 deletions
diff --git a/zephyr/zmake/zmake/build_config.py b/zephyr/zmake/zmake/build_config.py
index 7a6dedb98b..1b2b6efff1 100644
--- a/zephyr/zmake/zmake/build_config.py
+++ b/zephyr/zmake/zmake/build_config.py
@@ -97,7 +97,7 @@ class BuildConfig:
return jobclient.popen(
[
- "/usr/bin/cmake",
+ util.get_tool_path("cmake"),
"-S",
project_dir,
"-B",
diff --git a/zephyr/zmake/zmake/output_packers.py b/zephyr/zmake/zmake/output_packers.py
index d2203fa7b4..e0e342fd66 100644
--- a/zephyr/zmake/zmake/output_packers.py
+++ b/zephyr/zmake/zmake/output_packers.py
@@ -172,7 +172,7 @@ class BinmanPacker(BasePacker):
proc = jobclient.popen(
[
- "binman",
+ util.get_tool_path("binman"),
"-v",
"5",
"build",
diff --git a/zephyr/zmake/zmake/util.py b/zephyr/zmake/zmake/util.py
index e0e0ff98b1..8679895697 100644
--- a/zephyr/zmake/zmake/util.py
+++ b/zephyr/zmake/zmake/util.py
@@ -7,6 +7,7 @@ import os
import pathlib
import re
import shlex
+import shutil
def c_str(input_str):
@@ -184,3 +185,23 @@ def log_multi_line(logger, level, message):
for line in message.splitlines():
if line:
logger.log(level, line)
+
+
+def get_tool_path(program):
+ """Get the path to a program.
+
+ First, the TOOL_PATH_${program} environment variable is checked,
+ and if unspecified, the PATH environment variable is searched.
+
+ This allows callers to customize which tools zmake uses.
+
+ Args:
+ program: The program to locate
+
+ Returns:
+ The Path to the program.
+ """
+ path = os.environ.get(f"TOOL_PATH_{program}")
+ if path:
+ return pathlib.Path(path)
+ return pathlib.Path(shutil.which(program))
diff --git a/zephyr/zmake/zmake/zmake.py b/zephyr/zmake/zmake/zmake.py
index 1c1dcfb36c..6454049d53 100644
--- a/zephyr/zmake/zmake/zmake.py
+++ b/zephyr/zmake/zmake/zmake.py
@@ -761,7 +761,11 @@ class Zmake:
"""Builds one sub-dir of a configured project (build-ro, etc)."""
with self.jobserver.get_job():
- cmd = ["/usr/bin/ninja", "-C", dirs[build_name].as_posix()]
+ cmd = [
+ util.get_tool_path("ninja"),
+ "-C",
+ dirs[build_name].as_posix(),
+ ]
if self.goma:
# Go nuts ninja, goma does the heavy lifting!
cmd.append("-j1024")
@@ -827,7 +831,7 @@ class Zmake:
else:
self.logger.info("Running lcov on %s.", build_dir)
cmd = [
- "/usr/bin/lcov",
+ util.get_tool_path("lcov"),
"--gcov-tool",
gcov,
"-q",
@@ -879,7 +883,7 @@ class Zmake:
# Merge info files into a single lcov.info
self.logger.info("Merging coverage data into %s.", output_file)
cmd = [
- "/usr/bin/lcov",
+ util.get_tool_path("lcov"),
"-o",
output_file,
"--rc",