diff --git a/mesonbuild/build.py b/mesonbuild/build.py index dd4f7b759..fb56ceaa9 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -546,10 +546,14 @@ class BuildTarget(Target): d = [d] newd = [] for i in d: - if hasattr(i, 'held_object'): - newd.append(i.held_object) - else: - newd.append(i) + if isinstance(i, list): + i = self.unpack_holder(i) + elif hasattr(i, 'held_object'): + i = i.held_object + for t in ['dependencies', 'link_with', 'include_directories', 'sources']: + if hasattr(i, t): + setattr(i, t, self.unpack_holder(getattr(i, t))) + newd.append(i) return newd def copy_kwargs(self, kwargs): @@ -557,10 +561,14 @@ class BuildTarget(Target): # This sucks quite badly. Arguments # are holders but they can't be pickled # so unpack those known. - if 'dependencies' in self.kwargs: - self.kwargs['dependencies'] = self.unpack_holder(self.kwargs['dependencies']) - if 'link_with' in self.kwargs: - self.kwargs['link_with'] = self.unpack_holder(self.kwargs['link_with']) + for k, v in self.kwargs.items(): + if isinstance(v, list): + self.kwargs[k] = self.unpack_holder(v) + if hasattr(v, 'held_object'): + self.kwargs[k] = v.held_object + for t in ['dependencies', 'link_with', 'include_directories', 'sources']: + if t in self.kwargs: + self.kwargs[t] = self.unpack_holder(self.kwargs[t]) def extract_objects(self, srclist): obj_src = [] @@ -1490,8 +1498,12 @@ class CustomTarget(Target): def process_kwargs(self, kwargs): super().process_kwargs(kwargs) - self.sources = kwargs.get('input', []) - self.sources = flatten(self.sources) + sources = flatten(kwargs.get('input', [])) + self.sources = [] + for s in sources: + if hasattr(s, 'held_object'): + s = s.held_object + self.sources.append(s) if 'output' not in kwargs: raise InvalidArguments('Missing keyword argument "output".') self.outputs = kwargs['output'] diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 13c3119ce..58a145a87 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1308,6 +1308,7 @@ class Interpreter(InterpreterBase): def __init__(self, build, backend, subproject='', subdir='', subproject_dir='subprojects', default_project_options=[]): super().__init__(build.environment.get_source_dir(), subdir) + self.an_unpicklable_object = mesonlib.an_unpicklable_object self.build = build self.environment = build.environment self.coredata = self.environment.get_coredata() @@ -1521,7 +1522,13 @@ class Interpreter(InterpreterBase): if not isinstance(d, (dependencies.Dependency, dependencies.ExternalLibrary, dependencies.InternalDependency)): raise InterpreterException('Dependencies must be external deps') final_deps.append(d) - dep = dependencies.InternalDependency(version, incs, compile_args, link_args, libs, sources, final_deps) + dep = dependencies.InternalDependency(version, + mesonlib.unholder_array(incs), + compile_args, + link_args, + mesonlib.unholder_array(libs), + mesonlib.unholder_array(sources), + final_deps) return DependencyHolder(dep) @noKwargs @@ -2288,6 +2295,7 @@ class Interpreter(InterpreterBase): for i in cmd_args: if not isinstance(i, (str, mesonlib.File, TargetHolder)): raise InterpreterException('Command line arguments must be strings, files or targets.') + cmd_args = mesonlib.unholder_array(cmd_args) env = self.unpack_env_kwarg(kwargs) should_fail = kwargs.get('should_fail', False) if not isinstance(should_fail, bool): diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py index 1f7664ebf..213b2bb00 100644 --- a/mesonbuild/interpreterbase.py +++ b/mesonbuild/interpreterbase.py @@ -61,6 +61,7 @@ class permittedKwargs: self.permitted = permitted def __call__(self, f): + @wraps(f) def wrapped(s, node, args, kwargs): for k in kwargs: if k not in self.permitted: diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index 415bc50a4..4760e04a2 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -21,6 +21,11 @@ import collections from glob import glob +# Put this in objects that should not get dumped to pickle files +# by accident. +import threading +an_unpicklable_object = threading.Lock() + class MesonException(Exception): '''Exceptions thrown by Meson''' @@ -704,6 +709,14 @@ def windows_proof_rmtree(f): # Try one last time and throw if it fails. shutil.rmtree(f) +def unholder_array(entries): + result = [] + for e in entries: + if hasattr(e, 'held_object'): + e = e.held_object + result.append(e) + return result + class OrderedSet(collections.MutableSet): """A set that preserves the order in which items are added, by first insertion. diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 5ec3b5fe6..a2274f2e9 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -328,8 +328,10 @@ class GnomeModule(ExtensionModule): if isinstance(dep, InternalDependency): cflags.update(get_include_args(dep.include_directories)) for lib in dep.libraries: - ldflags.update(self._get_link_args(state, lib.held_object, depends, include_rpath)) - libdepflags = self._get_dependencies_flags(lib.held_object.get_external_deps(), state, depends, include_rpath, + if hasattr(lib, 'held_object'): + lib = lib.held_object + ldflags.update(self._get_link_args(state, lib, depends, include_rpath)) + libdepflags = self._get_dependencies_flags(lib.get_external_deps(), state, depends, include_rpath, use_gir_args) cflags.update(libdepflags[0]) ldflags.update(libdepflags[1]) @@ -340,9 +342,11 @@ class GnomeModule(ExtensionModule): ldflags.update(extdepflags[1]) gi_includes.update(extdepflags[2]) for source in dep.sources: - if hasattr(source, 'held_object') and isinstance(source.held_object, GirTarget): + if hasattr(source, 'held_object'): + source = source.held_object + if isinstance(source, GirTarget): gi_includes.update([os.path.join(state.environment.get_build_dir(), - source.held_object.get_subdir())]) + source.get_subdir())]) # This should be any dependency other than an internal one. elif isinstance(dep, Dependency): cflags.update(dep.get_compile_args()) diff --git a/test cases/failing/57 kwarg in module/meson.build b/test cases/failing/58 kwarg in module/meson.build similarity index 100% rename from test cases/failing/57 kwarg in module/meson.build rename to test cases/failing/58 kwarg in module/meson.build