[Buildroot] [PATCH 10/13] autobuild-run: use a built-in has_prog() implementation

André Erdmann dywi at mailerd.de
Wed Feb 25 21:17:27 UTC 2015


No need to call subprocess.call(["which",name]).

Signed-off-by: André Erdmann <dywi at mailerd.de>
---
 scripts/autobuild-run | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/scripts/autobuild-run b/scripts/autobuild-run
index 9c3e36c..29d1bbb 100755
--- a/scripts/autobuild-run
+++ b/scripts/autobuild-run
@@ -109,9 +109,20 @@ def check_version():
         print("ERROR: script version too old, please upgrade.")
         sys.exit(1)
 
-def has_prog(name):
-    with open(os.devnull, "w") as devnull:
-        return subprocess.call(["which", name], stdout=devnull, stderr=devnull) == os.EX_OK
+def has_prog(name, flags=os.X_OK, env=os.environ):
+    if not name or name[0] == os.sep: raise ValueError(name)
+
+    prog_path = env.get("PATH", None)
+    # for windows compatibility, we'd need to take PATHEXT into account
+
+    if prog_path:
+        for prog_dir in filter(None, prog_path.split(os.pathsep)):
+            # os.join() not necessary: non-empty prog_dir and name[0] != os.sep
+            prog = prog_dir + os.sep + name
+            if os.access(prog, flags):
+                return True
+    # --
+    return False
 
 def check_requirements(http_login, http_password):
     needed_progs = ["make", "git", "gcc", "timeout"]
-- 
2.3.0



More information about the buildroot mailing list