diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2018-04-15 13:56:45 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2018-04-15 14:13:35 +0530 |
commit | 6cdd14fc4eca8bddd4716ab5a9ebf09476846e6b (patch) | |
tree | 43842b6fb6f1aad526886d7678aa701ba229683f | |
parent | 0e6a332d0cf8538c5f62a3def646c477c0d772b5 (diff) | |
download | meson-6cdd14fc4eca8bddd4716ab5a9ebf09476846e6b.zip meson-6cdd14fc4eca8bddd4716ab5a9ebf09476846e6b.tar.gz meson-6cdd14fc4eca8bddd4716ab5a9ebf09476846e6b.tar.bz2 |
find_program: Don't spam when called from a module
The user doesn't need to know whether or not the program was found,
especially not when it's spammed for every gnome.foo() function
-rw-r--r-- | mesonbuild/interpreter.py | 47 | ||||
-rw-r--r-- | mesonbuild/modules/gnome.py | 18 | ||||
-rw-r--r-- | mesonbuild/modules/unstable_icestorm.py | 10 |
3 files changed, 40 insertions, 35 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index e2f0f88..a130312 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2251,7 +2251,7 @@ to directly access options of other subprojects.''') break self.coredata.base_options[optname] = oobj - def program_from_cross_file(self, prognames): + def program_from_cross_file(self, prognames, silent=False): bins = self.environment.cross_info.config['binaries'] for p in prognames: if hasattr(p, 'held_object'): @@ -2262,11 +2262,11 @@ to directly access options of other subprojects.''') raise InterpreterException('Executable name must be a string.') if p in bins: exename = bins[p] - extprog = dependencies.ExternalProgram(exename) + extprog = dependencies.ExternalProgram(exename, silent=silent) progobj = ExternalProgramHolder(extprog) return progobj - def program_from_system(self, args): + def program_from_system(self, args, silent=False): # Search for scripts relative to current subdir. # Do not cache found programs because find_program('foobar') # might give different results when run from different source dirs. @@ -2285,19 +2285,21 @@ to directly access options of other subprojects.''') else: raise InvalidArguments('find_program only accepts strings and ' 'files, not {!r}'.format(exename)) - extprog = dependencies.ExternalProgram(exename, search_dir=search_dir) + extprog = dependencies.ExternalProgram(exename, search_dir=search_dir, + silent=silent) progobj = ExternalProgramHolder(extprog) if progobj.found(): return progobj - def program_from_overrides(self, command_names): + def program_from_overrides(self, command_names, silent=False): for name in command_names: if not isinstance(name, str): continue if name in self.build.find_overrides: exe = self.build.find_overrides[name] - mlog.log('Program', mlog.bold(name), 'found:', mlog.green('YES'), - '(overridden: %s)' % ' '.join(exe.command)) + if not silent: + mlog.log('Program', mlog.bold(name), 'found:', mlog.green('YES'), + '(overridden: %s)' % ' '.join(exe.command)) return ExternalProgramHolder(exe) return None @@ -2315,24 +2317,15 @@ to directly access options of other subprojects.''') % name) self.build.find_overrides[name] = exe - @permittedKwargs(permitted_kwargs['find_program']) - def func_find_program(self, node, args, kwargs): - if not args: - raise InterpreterException('No program name specified.') + def find_program_impl(self, args, native=False, required=True, silent=True): if not isinstance(args, list): args = [args] - required = kwargs.get('required', True) - if not isinstance(required, bool): - raise InvalidArguments('"required" argument must be a boolean.') - progobj = self.program_from_overrides(args) + progobj = self.program_from_overrides(args, silent=silent) if progobj is None and self.build.environment.is_cross_build(): - use_native = kwargs.get('native', False) - if not isinstance(use_native, bool): - raise InvalidArguments('Argument to "native" must be a boolean.') - if not use_native: - progobj = self.program_from_cross_file(args) + if not native: + progobj = self.program_from_cross_file(args, silent=silent) if progobj is None: - progobj = self.program_from_system(args) + progobj = self.program_from_system(args, silent=silent) if required and (progobj is None or not progobj.found()): raise InvalidArguments('Program(s) {!r} not found or not executable'.format(args)) if progobj is None: @@ -2341,6 +2334,18 @@ to directly access options of other subprojects.''') self.store_name_lookups(args) return progobj + @permittedKwargs(permitted_kwargs['find_program']) + def func_find_program(self, node, args, kwargs): + if not args: + raise InterpreterException('No program name specified.') + required = kwargs.get('required', True) + if not isinstance(required, bool): + raise InvalidArguments('"required" argument must be a boolean.') + use_native = kwargs.get('native', False) + if not isinstance(use_native, bool): + raise InvalidArguments('Argument to "native" must be a boolean.') + return self.find_program_impl(args, native=use_native, required=required, silent=False) + def func_find_library(self, node, args, kwargs): raise InvalidCode('find_library() is removed, use meson.get_compiler(\'name\').find_library() instead.\n' 'Look here for documentation: http://mesonbuild.com/Reference-manual.html#compiler-object\n' diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index a3ba172..5455118 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -52,7 +52,7 @@ def gir_has_extra_lib_arg(intr_obj): _gir_has_extra_lib_arg = False try: - g_ir_scanner = intr_obj.func_find_program(None, 'g-ir-scanner', {}).get_command() + g_ir_scanner = intr_obj.find_program_impl('g-ir-scanner').get_command() opts = Popen_safe(g_ir_scanner + ['--help'], stderr=subprocess.STDOUT)[1] _gir_has_extra_lib_arg = '--extra-library' in opts except (MesonException, FileNotFoundError, subprocess.CalledProcessError): @@ -388,8 +388,8 @@ class GnomeModule(ExtensionModule): raise MesonException('Gir takes one argument') if kwargs.get('install_dir'): raise MesonException('install_dir is not supported with generate_gir(), see "install_dir_gir" and "install_dir_typelib"') - giscanner = self.interpreter.func_find_program(None, 'g-ir-scanner', {}) - gicompiler = self.interpreter.func_find_program(None, 'g-ir-compiler', {}) + giscanner = self.interpreter.find_program_impl('g-ir-scanner') + gicompiler = self.interpreter.find_program_impl('g-ir-compiler') girtarget = args[0] while hasattr(girtarget, 'held_object'): girtarget = girtarget.held_object @@ -637,7 +637,7 @@ class GnomeModule(ExtensionModule): srcdir = os.path.join(state.build_to_src, state.subdir) outdir = state.subdir - cmd = [self.interpreter.func_find_program(None, 'glib-compile-schemas', {})] + cmd = [self.interpreter.find_program_impl('glib-compile-schemas')] cmd += ['--targetdir', outdir, srcdir] kwargs['command'] = cmd kwargs['input'] = [] @@ -876,7 +876,7 @@ This will become a hard error in the future.''') namebase = args[0] xml_file = args[1] target_name = namebase + '-gdbus' - cmd = [self.interpreter.func_find_program(None, 'gdbus-codegen', {})] + cmd = [self.interpreter.find_program_impl('gdbus-codegen')] if 'interface_prefix' in kwargs: cmd += ['--interface-prefix', kwargs.pop('interface_prefix')] if 'namespace' in kwargs: @@ -1013,7 +1013,7 @@ This will become a hard error in the future.''') elif arg not in known_custom_target_kwargs: raise MesonException( 'Mkenums does not take a %s keyword argument.' % (arg, )) - cmd = [self.interpreter.func_find_program(None, ['glib-mkenums', 'mkenums'], {})] + cmd + cmd = [self.interpreter.find_program_impl(['glib-mkenums', 'mkenums'])] + cmd custom_kwargs = {} for arg in known_custom_target_kwargs: if arg in kwargs: @@ -1209,7 +1209,7 @@ G_END_DECLS''' new_genmarshal = mesonlib.version_compare(self._get_native_glib_version(state), '>= 2.53.3') - cmd = [self.interpreter.func_find_program(None, 'glib-genmarshal', {})] + cmd = [self.interpreter.find_program_impl('glib-genmarshal')] known_kwargs = ['internal', 'nostdinc', 'skip_source', 'stdinc', 'valist_marshallers', 'extra_args'] known_custom_target_kwargs = ['build_always', 'depends', @@ -1355,9 +1355,9 @@ G_END_DECLS''' pkg_cmd, vapi_depends, vapi_packages, vapi_includes = self._extract_vapi_packages(state, kwargs) target_name = 'generate_vapi({})'.format(library) if 'VAPIGEN' in os.environ: - cmd = [self.interpreter.func_find_program(None, os.environ['VAPIGEN'], {})] + cmd = [self.interpreter.find_program_impl(os.environ['VAPIGEN'])] else: - cmd = [self.interpreter.func_find_program(None, 'vapigen', {})] + cmd = [self.interpreter.find_program_impl('vapigen')] cmd += ['--quiet', '--library=' + library, '--directory=' + build_dir] cmd += self._vapi_args_to_command('--vapidir=', 'vapi_dirs', kwargs) cmd += self._vapi_args_to_command('--metadatadir=', 'metadata_dirs', kwargs) diff --git a/mesonbuild/modules/unstable_icestorm.py b/mesonbuild/modules/unstable_icestorm.py index 9af5325..55c647f 100644 --- a/mesonbuild/modules/unstable_icestorm.py +++ b/mesonbuild/modules/unstable_icestorm.py @@ -24,11 +24,11 @@ class IceStormModule(ExtensionModule): self.yosys_bin = None def detect_binaries(self, interpreter): - self.yosys_bin = interpreter.func_find_program(None, ['yosys'], {}) - self.arachne_bin = interpreter.func_find_program(None, ['arachne-pnr'], {}) - self.icepack_bin = interpreter.func_find_program(None, ['icepack'], {}) - self.iceprog_bin = interpreter.func_find_program(None, ['iceprog'], {}) - self.icetime_bin = interpreter.func_find_program(None, ['icetime'], {}) + self.yosys_bin = interpreter.find_program_impl(['yosys']) + self.arachne_bin = interpreter.find_program_impl(['arachne-pnr']) + self.icepack_bin = interpreter.find_program_impl(['icepack']) + self.iceprog_bin = interpreter.find_program_impl(['iceprog']) + self.icetime_bin = interpreter.find_program_impl(['icetime']) def project(self, interpreter, state, args, kwargs): if not self.yosys_bin: |