diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2020-09-03 00:12:47 +0200 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2020-09-04 15:38:12 +0200 |
commit | 492afe50a439d70df99d6e3e59572aff55e14c6b (patch) | |
tree | 80bb5b3013cacaf2884cc06e167da04b193dafc6 /mesonbuild/environment.py | |
parent | fa5c2363eb1dd94058aac1a4045d2ab546eed7b9 (diff) | |
download | meson-492afe50a439d70df99d6e3e59572aff55e14c6b.zip meson-492afe50a439d70df99d6e3e59572aff55e14c6b.tar.gz meson-492afe50a439d70df99d6e3e59572aff55e14c6b.tar.bz2 |
environment: use ExternalProgram to find ninja
This allows the NINJA environment variable to support all the Windows special
cases, especially allowing an absolute path without extension.
Based on a patch by Yonggang Luo.
Fixes: #7659
Suggested-by: Nirbheek Chauhan <nirbheek@centricular.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'mesonbuild/environment.py')
-rw-r--r-- | mesonbuild/environment.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 5600f9d..f8282c0 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -168,15 +168,19 @@ def find_coverage_tools(): return gcovr_exe, gcovr_new_rootdir, lcov_exe, genhtml_exe, llvm_cov_exe -def detect_ninja(version: str = '1.7', log: bool = False) -> str: +def detect_ninja(version: str = '1.7', log: bool = False) -> T.List[str]: r = detect_ninja_command_and_version(version, log) return r[0] if r else None -def detect_ninja_command_and_version(version: str = '1.7', log: bool = False) -> (str, str): +def detect_ninja_command_and_version(version: str = '1.7', log: bool = False) -> (T.List[str], str): + from .dependencies.base import ExternalProgram env_ninja = os.environ.get('NINJA', None) for n in [env_ninja] if env_ninja else ['ninja', 'ninja-build', 'samu']: + prog = ExternalProgram(n, silent=True) + if not prog.found(): + continue try: - p, found = Popen_safe([n, '--version'])[0:2] + p, found = Popen_safe(prog.command + ['--version'])[0:2] except (FileNotFoundError, PermissionError): # Doesn't exist in PATH or isn't executable continue @@ -184,7 +188,6 @@ def detect_ninja_command_and_version(version: str = '1.7', log: bool = False) -> # Perhaps we should add a way for the caller to know the failure mode # (not found or too old) if p.returncode == 0 and mesonlib.version_compare(found, '>=' + version): - n = shutil.which(n) if log: name = os.path.basename(n) if name.endswith('-' + found): @@ -193,8 +196,9 @@ def detect_ninja_command_and_version(version: str = '1.7', log: bool = False) -> name = 'ninja' if name == 'samu': name = 'samurai' - mlog.log('Found {}-{} at {}'.format(name, found, quote_arg(n))) - return (n, found) + mlog.log('Found {}-{} at {}'.format(name, found, + ' '.join([quote_arg(x) for x in prog.command]))) + return (prog.command, found) def get_llvm_tool_names(tool: str) -> T.List[str]: # Ordered list of possible suffixes of LLVM executables to try. Start with |