aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorMartin Kelly <mkelly@xevo.com>2018-04-24 16:53:18 -0700
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2018-05-30 18:29:16 +0000
commit0f86df4d232ef335705e75f0e1303af0e7c3a45c (patch)
tree8ee4af76c2b621392a1fada5fed6b8cb05437bca /mesonbuild
parentb6995aac709e7eeb2626a3d023cfde3ad9999d95 (diff)
downloadmeson-0f86df4d232ef335705e75f0e1303af0e7c3a45c.zip
meson-0f86df4d232ef335705e75f0e1303af0e7c3a45c.tar.gz
meson-0f86df4d232ef335705e75f0e1303af0e7c3a45c.tar.bz2
make ExternalProgram get_path() a bit smarter
Currently, ExternalProgram get_path() assumes the last component in the path is always the actual command path. However, this is not always right. For example, in the command "python -u", we should return "python" and not "-u". However, in other cases, like "python script.py", then the last component is the right one. The heuristic that seems to capture this is to use the last argument that is still a file. This means options get ignored, but "python script.py" still works. Let's use this heuristic, at least for now.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/dependencies/base.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index 0114a14..cc3c2d0 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -742,6 +742,17 @@ class ExternalProgram:
self.command = listify(command)
else:
self.command = self._search(name, search_dir)
+
+ # Set path to be the last item that is actually a file (in order to
+ # skip options in something like ['python', '-u', 'file.py']. If we
+ # can't find any components, default to the last component of the path.
+ self.path = self.command[-1]
+ for i in range(len(self.command) - 1, -1, -1):
+ arg = self.command[i]
+ if arg is not None and os.path.isfile(arg):
+ self.path = arg
+ break
+
if not silent:
if self.found():
mlog.log('Program', mlog.bold(name), 'found:', mlog.green('YES'),
@@ -889,11 +900,7 @@ class ExternalProgram:
return self.command[:]
def get_path(self):
- if self.found():
- # Assume that the last element is the full path to the script or
- # binary being run
- return self.command[-1]
- return None
+ return self.path
def get_name(self):
return self.name