Create a module return value object.

pull/1278/head
Jussi Pakkanen 8 years ago
parent 56e2c46ce1
commit de24fddbd1
  1. 11
      mesonbuild/interpreter.py
  2. 5
      mesonbuild/modules/__init__.py
  3. 4
      mesonbuild/modules/modtest.py
  4. 5
      mesonbuild/modules/pkgconfig.py

@ -28,6 +28,7 @@ from .interpreterbase import InterpreterBase
from .interpreterbase import check_stringlist, noPosargs, noKwargs, stringArgs
from .interpreterbase import InterpreterException, InvalidArguments, InvalidCode
from .interpreterbase import InterpreterObject, MutableInterpreterObject
from .modules import ModuleReturnValue
import os, sys, shutil, uuid
import re
@ -973,6 +974,7 @@ class ModuleHolder(InterpreterObject):
raise InvalidArguments('Module %s does not have method %s.' % (self.modname, method_name))
if method_name.startswith('_'):
raise InvalidArguments('Function {!r} in module {!r} is private.'.format(method_name, self.modname))
build_hash = hash(self.interpreter.build)
state = ModuleState()
state.build_to_src = os.path.relpath(self.interpreter.environment.get_source_dir(),
self.interpreter.environment.get_build_dir())
@ -988,6 +990,8 @@ class ModuleHolder(InterpreterObject):
state.global_args = self.interpreter.build.global_args
state.project_args = self.interpreter.build.projects_args.get(self.interpreter.subproject, {})
value = fn(state, args, kwargs)
if hash(self.interpreter.build) != build_hash:
raise InterpreterException('Extension module altered internal state illegally.')
return self.interpreter.module_method_callback(value)
class MesonMain(InterpreterObject):
@ -1227,7 +1231,10 @@ class Interpreter(InterpreterBase):
'join_paths': self.func_join_paths,
})
def module_method_callback(self, invalues):
def module_method_callback(self, return_object):
if not isinstance(return_object, ModuleReturnValue):
raise InterpreterException('Bug in module, it returned an invalid object')
invalues = return_object.new_objects
unwrap_single = False
if invalues is None:
return
@ -1264,7 +1271,7 @@ class Interpreter(InterpreterBase):
raise InterpreterException('Module returned a value of unknown type.')
if len(outvalues) == 1 and unwrap_single:
return outvalues[0]
return outvalues
return return_object.return_value
def get_build_def_files(self):
return self.build_def_files

@ -45,6 +45,11 @@ def get_include_args(environment, include_dirs, prefix='-I'):
return dirs_str
class ModuleReturnValue:
def __init__(self, return_value, new_objects):
self.return_value = return_value
assert(isinstance(new_objects, list))
self.new_objects = new_objects
class GResourceTarget(build.CustomTarget):
def __init__(self, name, subdir, kwargs):

@ -12,10 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from . import ModuleReturnValue
class TestModule:
def print_hello(self, state, args, kwargs):
print('Hello from a Meson module')
rv = ModuleReturnValue(None, [])
return rv
def initialize():
return TestModule()

@ -15,6 +15,8 @@
from .. import build
from .. import mesonlib
from .. import mlog
from . import ModuleReturnValue
import os
class PkgConfigModule:
@ -138,7 +140,8 @@ class PkgConfigModule:
self.generate_pkgconfig_file(state, libs, subdirs, name, description, url,
version, pcfile, pub_reqs, priv_reqs,
conflicts, priv_libs)
return build.Data(mesonlib.File(True, state.environment.get_scratch_dir(), pcfile), pkgroot)
res = build.Data(mesonlib.File(True, state.environment.get_scratch_dir(), pcfile), pkgroot)
return ModuleReturnValue(res, [res])
def initialize():
return PkgConfigModule()

Loading…
Cancel
Save