diff options
| author | Nirbheek Chauhan <nirbheek@centricular.com> | 2017-05-07 01:00:25 +0530 |
|---|---|---|
| committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2017-05-07 01:56:47 +0530 |
| commit | 333085160d6cbff2b4a47fac76cb507cd1f6d1c7 (patch) | |
| tree | 9c67da50c2695cbf8ea5dc61ccb7847af13db611 /mesonbuild/dependencies.py | |
| parent | b1df1a2bec053937ecb09f425248c1dbcee9237a (diff) | |
| download | meson-333085160d6cbff2b4a47fac76cb507cd1f6d1c7.tar.gz | |
run_command: Refactor + improve errors and test
Refactor to use ExternalProgram for the command instead of duplicating
that code (badly). Also improve messages to say "or not executable"
when a script/command is not found.
Also allow ExternalPrograms to be passed as arguments to
run_command(). The only thing we're doing by preventing that is
forcing people to use prog.path()
Diffstat (limited to 'mesonbuild/dependencies.py')
| -rw-r--r-- | mesonbuild/dependencies.py | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/mesonbuild/dependencies.py b/mesonbuild/dependencies.py index ef7be3a5e..37e2cbd26 100644 --- a/mesonbuild/dependencies.py +++ b/mesonbuild/dependencies.py @@ -465,8 +465,9 @@ class ExternalProgram: @staticmethod def _shebang_to_cmd(script): """ - Windows does not understand shebangs, so we check if the file has a - shebang and manually parse it to figure out the interpreter to use + Check if the file has a shebang and manually parse it to figure out + the interpreter to use. This is useful if the script is not executable + or if we're on Windows (which does not understand shebangs). """ try: with open(script) as f: @@ -504,15 +505,17 @@ class ExternalProgram: if os.path.exists(trial): if self._is_executable(trial): return [trial] + # Now getting desperate. Maybe it is a script file that is + # a) not chmodded executable, or + # b) we are on windows so they can't be directly executed. + return self._shebang_to_cmd(trial) else: - for ext in self.windows_exts: - trial_ext = '{}.{}'.format(trial, ext) - if os.path.exists(trial_ext): - return [trial_ext] - return False - # Now getting desperate. Maybe it is a script file that is a) not chmodded - # executable or b) we are on windows so they can't be directly executed. - return self._shebang_to_cmd(trial) + if mesonlib.is_windows(): + for ext in self.windows_exts: + trial_ext = '{}.{}'.format(trial, ext) + if os.path.exists(trial_ext): + return [trial_ext] + return False def _search(self, name, search_dir): ''' @@ -525,7 +528,8 @@ class ExternalProgram: # Do a standard search in PATH command = shutil.which(name) if not mesonlib.is_windows(): - # On UNIX-like platforms, the standard PATH search is enough + # On UNIX-like platforms, shutil.which() is enough to find + # all executables whether in PATH or with an absolute path return [command] # HERE BEGINS THE TERROR OF WINDOWS if command: @@ -567,9 +571,9 @@ class ExternalProgram: return self.command[:] def get_path(self): - # Assume that the last element is the full path to the script - # If it's not a script, this will be an array of length 1 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 |
