aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2017-07-17 17:26:21 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2017-07-17 17:26:21 +0530
commite307865596274094b582ce851bcd48092d5f6a03 (patch)
treed51f02143502f6f7fbb75038804fe8c816f8d88b
parentb5a79b491efc54848d31f4d230fedca38dd4b846 (diff)
downloadmeson-e307865596274094b582ce851bcd48092d5f6a03.zip
meson-e307865596274094b582ce851bcd48092d5f6a03.tar.gz
meson-e307865596274094b582ce851bcd48092d5f6a03.tar.bz2
ninja backend: Detect ninja only once and log it
Needed for the CI, but good to have in general too.
-rw-r--r--mesonbuild/backend/ninjabackend.py11
-rw-r--r--mesonbuild/environment.py5
2 files changed, 9 insertions, 7 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 7f974ee..ece4e8b 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -177,6 +177,9 @@ int dummy;
def generate(self, 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)
tempfilename = outfilename + '~'
with open(tempfilename, 'w') as outfile:
@@ -210,10 +213,9 @@ int dummy;
# http://clang.llvm.org/docs/JSONCompilationDatabase.html
def generate_compdb(self):
- ninja_exe = environment.detect_ninja()
native_compilers = ['%s_COMPILER' % i for i in self.build.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()
try:
jsondb = subprocess.check_output(ninja_compdb, cwd=builddir)
@@ -2509,11 +2511,8 @@ rule FORTRAN_DEP_HACK
default = 'default all\n\n'
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.add_item('COMMAND', [ninja_command, '-t', 'clean'])
+ elem.add_item('COMMAND', [self.ninja_command, '-t', 'clean'])
elem.add_item('description', 'Cleaning.')
# If we have custom targets in this project, add all their outputs to
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index b0002a0..b3d72e6 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -89,16 +89,19 @@ def find_coverage_tools():
genhtml_exe = None
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']:
try:
p, found = Popen_safe([n, '--version'])[0:2]
except (FileNotFoundError, PermissionError):
# Doesn't exist in PATH or isn't executable
continue
+ found = found.strip()
# 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):
+ if log:
+ mlog.log('Found ninja-{} at {}'.format(found, shlex.quote(shutil.which(n))))
return n
def detect_native_windows_arch():