aboutsummaryrefslogtreecommitdiff
path: root/tools/patman/tools.py
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-01-09 20:13:43 -0700
committerSimon Glass <sjg@chromium.org>2022-01-25 12:36:11 -0700
commit596fd10a79e95197ec9fa1ebe7b9e6f7bf81e217 (patch)
tree70fd7fcf19b7dc6e9e2f23118af3ad22aa73f2cb /tools/patman/tools.py
parent5b7968693f9c2aefea5bd50dc1f143ec3a1caa42 (diff)
downloadu-boot-596fd10a79e95197ec9fa1ebe7b9e6f7bf81e217.zip
u-boot-596fd10a79e95197ec9fa1ebe7b9e6f7bf81e217.tar.gz
u-boot-596fd10a79e95197ec9fa1ebe7b9e6f7bf81e217.tar.bz2
patman: Add a function to find a tool on the path
The Run() function automatically uses the PATH variable to locate a tool when running it. Add a function that does this manually, so we don't have to run a tool to find out if it is present. This is needed by the new Bintool class, which wants to check which tools are present. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/patman/tools.py')
-rw-r--r--tools/patman/tools.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tools/patman/tools.py b/tools/patman/tools.py
index 24e2bf5..a27db05 100644
--- a/tools/patman/tools.py
+++ b/tools/patman/tools.py
@@ -378,6 +378,29 @@ def run_result(name, *args, **kwargs):
raise ValueError(msg)
raise
+def tool_find(name):
+ """Search the current path for a tool
+
+ This uses both PATH and any value from SetToolPaths() to search for a tool
+
+ Args:
+ name (str): Name of tool to locate
+
+ Returns:
+ str: Full path to tool if found, else None
+ """
+ name = os.path.expanduser(name) # Expand paths containing ~
+ paths = []
+ pathvar = os.environ.get('PATH')
+ if pathvar:
+ paths = pathvar.split(':')
+ if tool_search_paths:
+ paths += tool_search_paths
+ for path in paths:
+ fname = os.path.join(path, name)
+ if os.path.isfile(fname) and os.access(fname, os.X_OK):
+ return fname
+
def Run(name, *args, **kwargs):
"""Run a tool with some arguments