diff --git a/backends.py b/backends.py index 8b859aa41..0c8266e06 100644 --- a/backends.py +++ b/backends.py @@ -834,8 +834,11 @@ class NinjaBackend(Backend): default = 'default all\n\n' outfile.write(default) + ninja_command = environment.detect_ninja() + if ninja_command is None: + raise RuntimeError('Could not detect ninja command') elem = NinjaBuildElement('clean', 'CUSTOM_COMMAND', '') - elem.add_item('COMMAND', ['ninja', '-t', 'clean']) + elem.add_item('COMMAND', [ninja_command, '-t', 'clean']) elem.add_item('description', 'Cleaning') if self.environment.coredata.coverage: self.generate_gcov_clean(outfile) diff --git a/environment.py b/environment.py index 325329557..f7f42e1ea 100644 --- a/environment.py +++ b/environment.py @@ -532,6 +532,26 @@ def is_osx(): def is_windows(): return platform.system().lower() == 'windows' +def is_debianlike(): + try: + open('/etc/debian_version', 'r') + return True + except FileNotFoundError: + return False + +def detect_ninja(): + for n in ['ninja', 'ninja-build']: + # Plain 'ninja' or 'ninja -h' yields an error + # code. Thanks a bunch, guys. + try: + p = subprocess.Popen([n, '-t', 'list'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + except FileNotFoundError: + continue + p.communicate() + if p.returncode == 0: + return n + + header_suffixes = ['h', 'hh', 'hpp', 'hxx', 'H'] cpp_suffixes = ['cc', 'cpp', 'cxx', 'hh', 'hpp', 'hxx'] c_suffixes = ['c'] diff --git a/run_tests.py b/run_tests.py index e89346e16..158aadd7d 100755 --- a/run_tests.py +++ b/run_tests.py @@ -23,9 +23,12 @@ install_dir = os.path.join(os.path.split(os.path.abspath(__file__))[0], 'install meson_command = './meson.py' if True: # Currently we have only one backend. backend_flags = [] - compile_commands = ['ninja'] - test_commands = ['ninja', 'test'] - install_commands = ['ninja', 'install'] + ninja_command = environment.detect_ninja() + if ninja_command is None: + raise RuntimeError('Could not find Ninja executable.') + compile_commands = [ninja_command] + test_commands = [ninja_command, 'test'] + install_commands = [ninja_command, 'install'] def run_test(testdir): shutil.rmtree(test_build_dir)