Merge pull request #2017 from mesonbuild/fix2012

Do not pickle interpreter objects by accident
pull/2024/head
Jussi Pakkanen 8 years ago committed by GitHub
commit 917e12e4e7
  1. 30
      mesonbuild/build.py
  2. 10
      mesonbuild/interpreter.py
  3. 1
      mesonbuild/interpreterbase.py
  4. 13
      mesonbuild/mesonlib.py
  5. 12
      mesonbuild/modules/gnome.py
  6. 0
      test cases/failing/58 kwarg in module/meson.build

@ -546,9 +546,13 @@ class BuildTarget(Target):
d = [d]
newd = []
for i in d:
if hasattr(i, 'held_object'):
newd.append(i.held_object)
else:
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
@ -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']

@ -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):

@ -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:

@ -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.

@ -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())

Loading…
Cancel
Save