diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2018-03-11 17:25:02 +0200 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2018-04-15 13:32:38 +0530 |
commit | bdb57cf62a56e292d3ebf9f4ba39be07674707f8 (patch) | |
tree | adfeea68e5ac560d6ef6fb032d541c6fd14f0d2e /mesonbuild | |
parent | de65adb8b100731ff31eee92da44b4cc10ac5aa3 (diff) | |
download | meson-bdb57cf62a56e292d3ebf9f4ba39be07674707f8.zip meson-bdb57cf62a56e292d3ebf9f4ba39be07674707f8.tar.gz meson-bdb57cf62a56e292d3ebf9f4ba39be07674707f8.tar.bz2 |
Convert Gnome module to use find_program from interpreter.
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/coredata.py | 1 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 19 | ||||
-rw-r--r-- | mesonbuild/mesonmain.py | 3 | ||||
-rw-r--r-- | mesonbuild/modules/__init__.py | 15 | ||||
-rw-r--r-- | mesonbuild/modules/gnome.py | 30 | ||||
-rw-r--r-- | mesonbuild/modules/python3.py | 8 |
6 files changed, 36 insertions, 40 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index a696cca..918671a 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -185,7 +185,6 @@ class CoreData: self.compilers = OrderedDict() self.cross_compilers = OrderedDict() self.deps = OrderedDict() - self.modules = {} # Only to print a warning if it changes between Meson invocations. self.pkgconf_envvar = os.environ.get('PKG_CONFIG_PATH', '') diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 6d7f2a9..c958b6f 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1508,7 +1508,7 @@ permitted_kwargs = {'add_global_arguments': {'language'}, class Interpreter(InterpreterBase): def __init__(self, build, backend, subproject='', subdir='', subproject_dir='subprojects', - default_project_options=[]): + modules = None, default_project_options=[]): super().__init__(build.environment.get_source_dir(), subdir) self.an_unpicklable_object = mesonlib.an_unpicklable_object self.build = build @@ -1516,6 +1516,10 @@ class Interpreter(InterpreterBase): self.coredata = self.environment.get_coredata() self.backend = backend self.subproject = subproject + if modules is None: + self.modules = {} + else: + self.modules = modules # Subproject directory is usually the name of the subproject, but can # be different for dependencies provided by wrap files. self.subproject_directory_name = subdir.split(os.path.sep)[-1] @@ -1696,13 +1700,13 @@ class Interpreter(InterpreterBase): plainname = modname.split('-', 1)[1] mlog.warning('Module %s has no backwards or forwards compatibility and might not exist in future releases.' % modname, location=node) modname = 'unstable_' + plainname - if modname not in self.environment.coredata.modules: + if modname not in self.modules: try: module = importlib.import_module('mesonbuild.modules.' + modname) except ImportError: raise InvalidArguments('Module "%s" does not exist' % (modname, )) - self.environment.coredata.modules[modname] = module.initialize() - return ModuleHolder(modname, self.environment.coredata.modules[modname], self) + self.modules[modname] = module.initialize(self) + return ModuleHolder(modname, self.modules[modname], self) @stringArgs @noKwargs @@ -1879,15 +1883,16 @@ external dependencies (including libraries) must go to "dependencies".''') self.global_args_frozen = True mlog.log() with mlog.nested(): - mlog.log('Executing subproject ', mlog.bold(dirname), '.\n', sep='') + mlog.log('\nExecuting subproject ', mlog.bold(dirname), '.\n', sep='') subi = Interpreter(self.build, self.backend, dirname, subdir, self.subproject_dir, - mesonlib.stringlistify(kwargs.get('default_options', []))) + self.modules, mesonlib.stringlistify(kwargs.get('default_options', []))) subi.subprojects = self.subprojects subi.subproject_stack = self.subproject_stack + [dirname] current_active = self.active_projectname subi.run() mlog.log('\nSubproject', mlog.bold(dirname), 'finished.') + if 'version' in kwargs: pv = subi.project_version wanted = kwargs['version'] @@ -2308,6 +2313,8 @@ to directly access options of other subprojects.''') def func_find_program(self, node, args, kwargs): if not args: raise InterpreterException('No program name specified.') + 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.') diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index 651224e..daf5907 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -210,7 +210,8 @@ class MesonApp: # Post-conf scripts must be run after writing coredata or else introspection fails. g.run_postconf_scripts() except: - os.unlink(cdf) + if 'cdf' in locals(): + os.unlink(cdf) raise def run_script_command(args): diff --git a/mesonbuild/modules/__init__.py b/mesonbuild/modules/__init__.py index bf513fd..55bbbd3 100644 --- a/mesonbuild/modules/__init__.py +++ b/mesonbuild/modules/__init__.py @@ -18,26 +18,15 @@ class permittedSnippetKwargs: return f(s, interpreter, state, args, kwargs) return wrapped -_found_programs = {} - class ExtensionModule: - def __init__(self): + def __init__(self, interpreter): + self.interpreter = interpreter self.snippets = set() # List of methods that operate only on the interpreter. def is_snippet(self, funcname): return funcname in self.snippets -def find_program(program_name, target_name): - if program_name in _found_programs: - return _found_programs[program_name] - program = dependencies.ExternalProgram(program_name) - if not program.found(): - m = "Target {!r} can't be generated as {!r} could not be found" - raise MesonException(m.format(target_name, program_name)) - _found_programs[program_name] = program - return program - def get_include_args(include_dirs, prefix='-I'): ''' diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 4dc29c3..74d0f29 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -25,7 +25,7 @@ from .. import mesonlib from .. import compilers from .. import interpreter from . import GResourceTarget, GResourceHeaderTarget, GirTarget, TypelibTarget, VapiTarget -from . import find_program, get_include_args +from . import get_include_args from . import ExtensionModule from . import ModuleReturnValue from ..mesonlib import MesonException, OrderedSet, Popen_safe, extract_as_list @@ -45,14 +45,14 @@ gdbuswarning_printed = False gresource_warning_printed = False _gir_has_extra_lib_arg = None -def gir_has_extra_lib_arg(): +def gir_has_extra_lib_arg(intr_obj): global _gir_has_extra_lib_arg if _gir_has_extra_lib_arg is not None: return _gir_has_extra_lib_arg _gir_has_extra_lib_arg = False try: - g_ir_scanner = find_program('g-ir-scanner', '').get_command() + g_ir_scanner = intr_obj.func_find_program(None, '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): @@ -302,7 +302,7 @@ class GnomeModule(ExtensionModule): link_command.append('-Wl,-rpath,' + libdir) if depends: depends.append(lib) - if gir_has_extra_lib_arg() and use_gir_args: + if gir_has_extra_lib_arg(self.interpreter) and use_gir_args: link_command.append('--extra-library=' + lib.name) else: link_command.append('-l' + lib.name) @@ -369,7 +369,7 @@ class GnomeModule(ExtensionModule): mlog.log('dependency {!r} not handled to build gir files'.format(dep)) continue - if gir_has_extra_lib_arg() and use_gir_args: + if gir_has_extra_lib_arg(self.interpreter) and use_gir_args: fixed_ldflags = OrderedSet() for ldflag in ldflags: if ldflag.startswith("-l"): @@ -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 = find_program('g-ir-scanner', 'Gir') - gicompiler = find_program('g-ir-compiler', 'Gir') + giscanner = self.interpreter.func_find_program(None, 'g-ir-scanner', {}) + gicompiler = self.interpreter.func_find_program(None, '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 = [find_program('glib-compile-schemas', 'gsettings-compile')] + cmd = [self.interpreter.func_find_program(None, '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 = [find_program('gdbus-codegen', target_name)] + cmd = [self.interpreter.func_find_program(None, '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 = [find_program('glib-mkenums', 'mkenums')] + cmd + cmd = [self.interpreter.func_find_program(None, ['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 = [find_program('glib-genmarshal', output + '_genmarshal')] + cmd = [self.interpreter.func_find_program(None, '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 = [find_program(os.environ['VAPIGEN'], target_name)] + cmd = [self.interpreter.func_find_program(None, os.environ['VAPIGEN'], {}), target_name] else: - cmd = [find_program('vapigen', target_name)] + cmd = [self.interpreter.func_find_program(None, 'vapigen'), target_name] 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) @@ -1412,5 +1412,5 @@ G_END_DECLS''' created_values.append(rv) return ModuleReturnValue(rv, created_values) -def initialize(): - return GnomeModule() +def initialize(*args, **kwargs): + return GnomeModule(*args, **kwargs) diff --git a/mesonbuild/modules/python3.py b/mesonbuild/modules/python3.py index d2bf1dc..79da29a 100644 --- a/mesonbuild/modules/python3.py +++ b/mesonbuild/modules/python3.py @@ -23,8 +23,8 @@ from ..build import known_shmod_kwargs class Python3Module(ExtensionModule): - def __init__(self): - super().__init__() + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) self.snippets.add('extension_module') @permittedSnippetKwargs(known_shmod_kwargs) @@ -69,5 +69,5 @@ class Python3Module(ExtensionModule): return ModuleReturnValue(path, []) -def initialize(): - return Python3Module() +def initialize(*args, **kwargs): + return Python3Module(*args, **kwargs) |