aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/dependencies/base.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2018-06-29 19:33:17 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2018-07-01 13:59:48 +0000
commitec29f19c1274d72e3a2639e47caf4a7f17ffa436 (patch)
tree70ffad6c031159508e92b05ff69acbc052262480 /mesonbuild/dependencies/base.py
parentae8d044cb6dca20c1d6504a27660bcbed16db438 (diff)
downloadmeson-ec29f19c1274d72e3a2639e47caf4a7f17ffa436.zip
meson-ec29f19c1274d72e3a2639e47caf4a7f17ffa436.tar.gz
meson-ec29f19c1274d72e3a2639e47caf4a7f17ffa436.tar.bz2
Add a helper for fetching of binaries from cross files
A number of cases have to be taken care of while doing this, so refactor it into a helper on ExternalProgram and use it everywhere. 1. Command is a list of len > 1, use it as-is 2. Command is a list of len == 1 (or a string), use as a string 3. If command is an absolute path, use it as-is 4. If command is not an absolute path, search for it
Diffstat (limited to 'mesonbuild/dependencies/base.py')
-rw-r--r--mesonbuild/dependencies/base.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index 8319cb7..07d06a1 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -438,8 +438,7 @@ class PkgConfigDependency(ExternalDependency):
if self.required:
raise DependencyException('Pkg-config binary missing from cross file')
else:
- pkgname = environment.cross_info.config['binaries']['pkgconfig']
- potential_pkgbin = ExternalProgram(pkgname, silent=True)
+ potential_pkgbin = ExternalProgram.from_cross_info(environment.cross_info, 'pkgconfig')
if potential_pkgbin.found():
self.pkgbin = potential_pkgbin
PkgConfigDependency.class_pkgbin = self.pkgbin
@@ -799,6 +798,24 @@ class ExternalProgram:
return r.format(self.__class__.__name__, self.name, self.command)
@staticmethod
+ def from_cross_info(cross_info, name):
+ if name not in cross_info.config['binaries']:
+ return NonExistingExternalProgram()
+ command = cross_info.config['binaries'][name]
+ if not isinstance(command, (list, str)):
+ raise MesonException('Invalid type {!r} for binary {!r} in cross file'
+ ''.format(command, name))
+ if isinstance(command, list):
+ if len(command) == 1:
+ command = command[0]
+ # We cannot do any searching if the command is a list, and we don't
+ # need to search if the path is an absolute path.
+ if isinstance(command, list) or os.path.isabs(command):
+ return ExternalProgram(name, command=command, silent=True)
+ # Search for the command using the specified string!
+ return ExternalProgram(command, silent=True)
+
+ @staticmethod
def _shebang_to_cmd(script):
"""
Check if the file has a shebang and manually parse it to figure out