diff options
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/utils.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index d6bcfa37e8..077fddc0ee 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
@@ -899,11 +899,20 @@ def copyfile(src, dest, newmtime = None, sstat = None): | |||
899 | newmtime = sstat[stat.ST_MTIME] | 899 | newmtime = sstat[stat.ST_MTIME] |
900 | return newmtime | 900 | return newmtime |
901 | 901 | ||
902 | def which(path, item, direction = 0, history = False): | 902 | def which(path, item, direction = 0, history = False, executable=False): |
903 | """ | 903 | """ |
904 | Locate a file in a PATH | 904 | Locate `item` in the list of paths `path` (colon separated string like $PATH). |
905 | If `direction` is non-zero then the list is reversed. | ||
906 | If `history` is True then the list of candidates also returned as result,history. | ||
907 | If `executable` is True then the candidate has to be an executable file, | ||
908 | otherwise the candidate simply has to exist. | ||
905 | """ | 909 | """ |
906 | 910 | ||
911 | if executable: | ||
912 | is_candidate = lambda p: os.path.isfile(p) and os.access(p, os.X_OK) | ||
913 | else: | ||
914 | is_candidate = lambda p: os.path.exists(p) | ||
915 | |||
907 | hist = [] | 916 | hist = [] |
908 | paths = (path or "").split(':') | 917 | paths = (path or "").split(':') |
909 | if direction != 0: | 918 | if direction != 0: |
@@ -912,7 +921,7 @@ def which(path, item, direction = 0, history = False): | |||
912 | for p in paths: | 921 | for p in paths: |
913 | next = os.path.join(p, item) | 922 | next = os.path.join(p, item) |
914 | hist.append(next) | 923 | hist.append(next) |
915 | if os.path.exists(next): | 924 | if is_candidate(next): |
916 | if not os.path.isabs(next): | 925 | if not os.path.isabs(next): |
917 | next = os.path.abspath(next) | 926 | next = os.path.abspath(next) |
918 | if history: | 927 | if history: |