ninja backend: Detect ninja only once and log it

Needed for the CI, but good to have in general too.
pull/1931/head
Nirbheek Chauhan 8 years ago
parent b5a79b491e
commit e307865596
  1. 11
      mesonbuild/backend/ninjabackend.py
  2. 5
      mesonbuild/environment.py

@ -177,6 +177,9 @@ int dummy;
def generate(self, interp): def generate(self, interp):
self.interpreter = interp self.interpreter = interp
self.ninja_command = environment.detect_ninja(log=True)
if self.ninja_command is None:
raise MesonException('Could not detect Ninja v1.5 or newer')
outfilename = os.path.join(self.environment.get_build_dir(), self.ninja_filename) outfilename = os.path.join(self.environment.get_build_dir(), self.ninja_filename)
tempfilename = outfilename + '~' tempfilename = outfilename + '~'
with open(tempfilename, 'w') as outfile: with open(tempfilename, 'w') as outfile:
@ -210,10 +213,9 @@ int dummy;
# http://clang.llvm.org/docs/JSONCompilationDatabase.html # http://clang.llvm.org/docs/JSONCompilationDatabase.html
def generate_compdb(self): def generate_compdb(self):
ninja_exe = environment.detect_ninja()
native_compilers = ['%s_COMPILER' % i for i in self.build.compilers] native_compilers = ['%s_COMPILER' % i for i in self.build.compilers]
cross_compilers = ['%s_CROSS_COMPILER' % i for i in self.build.cross_compilers] cross_compilers = ['%s_CROSS_COMPILER' % i for i in self.build.cross_compilers]
ninja_compdb = [ninja_exe, '-t', 'compdb'] + native_compilers + cross_compilers ninja_compdb = [self.ninja_command, '-t', 'compdb'] + native_compilers + cross_compilers
builddir = self.environment.get_build_dir() builddir = self.environment.get_build_dir()
try: try:
jsondb = subprocess.check_output(ninja_compdb, cwd=builddir) jsondb = subprocess.check_output(ninja_compdb, cwd=builddir)
@ -2509,11 +2511,8 @@ rule FORTRAN_DEP_HACK
default = 'default all\n\n' default = 'default all\n\n'
outfile.write(default) outfile.write(default)
ninja_command = environment.detect_ninja()
if ninja_command is None:
raise MesonException('Could not detect Ninja v1.6 or newer')
elem = NinjaBuildElement(self.all_outputs, 'clean', 'CUSTOM_COMMAND', 'PHONY') elem = NinjaBuildElement(self.all_outputs, 'clean', 'CUSTOM_COMMAND', 'PHONY')
elem.add_item('COMMAND', [ninja_command, '-t', 'clean']) elem.add_item('COMMAND', [self.ninja_command, '-t', 'clean'])
elem.add_item('description', 'Cleaning.') elem.add_item('description', 'Cleaning.')
# If we have custom targets in this project, add all their outputs to # If we have custom targets in this project, add all their outputs to

@ -89,16 +89,19 @@ def find_coverage_tools():
genhtml_exe = None genhtml_exe = None
return gcovr_exe, lcov_exe, genhtml_exe return gcovr_exe, lcov_exe, genhtml_exe
def detect_ninja(version='1.5'): def detect_ninja(version='1.5', log=False):
for n in ['ninja', 'ninja-build']: for n in ['ninja', 'ninja-build']:
try: try:
p, found = Popen_safe([n, '--version'])[0:2] p, found = Popen_safe([n, '--version'])[0:2]
except (FileNotFoundError, PermissionError): except (FileNotFoundError, PermissionError):
# Doesn't exist in PATH or isn't executable # Doesn't exist in PATH or isn't executable
continue continue
found = found.strip()
# Perhaps we should add a way for the caller to know the failure mode # Perhaps we should add a way for the caller to know the failure mode
# (not found or too old) # (not found or too old)
if p.returncode == 0 and mesonlib.version_compare(found, '>=' + version): if p.returncode == 0 and mesonlib.version_compare(found, '>=' + version):
if log:
mlog.log('Found ninja-{} at {}'.format(found, shlex.quote(shutil.which(n))))
return n return n
def detect_native_windows_arch(): def detect_native_windows_arch():

Loading…
Cancel
Save