aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2015-03-13 19:55:09 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2015-03-13 19:55:09 +0200
commit1ac00031f9c16e197b8fcab3dafc07d63c9bdb67 (patch)
treeaf8e18737daedf63988c2d8f06192807eaaee017
parent96839e58938a5c43cf742785378ea9a20e6390ec (diff)
downloadmeson-1ac00031f9c16e197b8fcab3dafc07d63c9bdb67.zip
meson-1ac00031f9c16e197b8fcab3dafc07d63c9bdb67.tar.gz
meson-1ac00031f9c16e197b8fcab3dafc07d63c9bdb67.tar.bz2
Persist modules so they are imported only once for the lifetime of a build directory.
-rw-r--r--build.py1
-rw-r--r--coredata.py1
-rw-r--r--interpreter.py16
-rw-r--r--test cases/frameworks/4 qt5/meson.build2
4 files changed, 9 insertions, 11 deletions
diff --git a/build.py b/build.py
index 4072102..85f6edf 100644
--- a/build.py
+++ b/build.py
@@ -74,7 +74,6 @@ class Build:
self.pkgconfig_gens = []
self.install_script = None
self.install_dirs = []
- self.modules = {}
def has_language(self, language):
for i in self.compilers:
diff --git a/coredata.py b/coredata.py
index 15c327a..11410af 100644
--- a/coredata.py
+++ b/coredata.py
@@ -54,6 +54,7 @@ class CoreData():
self.deps = {}
self.ext_progs = {}
self.ext_libs = {}
+ self.modules = {}
def get_builtin_option(self, optname):
if optname == 'type':
diff --git a/interpreter.py b/interpreter.py
index 37b37bb..bda466d 100644
--- a/interpreter.py
+++ b/interpreter.py
@@ -600,15 +600,15 @@ class ModuleState:
pass
class ModuleHolder(InterpreterObject):
- def __init__(self, modname, interpreter):
+ def __init__(self, modname, module, interpreter):
InterpreterObject.__init__(self)
self.modname = modname
- self.m = importlib.import_module('modules.' + modname).initialize()
+ self.held_object = module
self.interpreter = interpreter
def method_call(self, method_name, args, kwargs):
try:
- fn = getattr(self.m, method_name)
+ fn = getattr(self.held_object, method_name)
except AttributeError:
raise InvalidArguments('Module %s does not have method %s.' % (self.modname, method_name))
state = ModuleState()
@@ -735,7 +735,6 @@ class Interpreter():
self.global_args_frozen = False
self.subprojects = {}
self.subproject_stack = []
- self.modules = {}
def build_func_dict(self):
self.funcs = {'project' : self.func_project,
@@ -865,11 +864,10 @@ class Interpreter():
modname = args[0]
if not isinstance(modname, str):
raise InvalidCode('Argument to import was not a string')
- if not modname in self.modules:
- mh = mh = ModuleHolder(modname, self)
- self.modules[modname] = mh
- self.build.modules[modname] = mh.m
- return self.modules[modname]
+ if not modname in self.environment.coredata.modules:
+ module = importlib.import_module('modules.' + modname).initialize()
+ self.environment.coredata.modules[modname] = module
+ return ModuleHolder(modname, self.environment.coredata.modules[modname], self)
def set_variable(self, varname, variable):
if variable is None:
diff --git a/test cases/frameworks/4 qt5/meson.build b/test cases/frameworks/4 qt5/meson.build
index dd57ef5..9542331 100644
--- a/test cases/frameworks/4 qt5/meson.build
+++ b/test cases/frameworks/4 qt5/meson.build
@@ -10,7 +10,7 @@ endif
q5exe = executable('qt5app',
sources : ['main.cpp', 'mainWindow.cpp', # Sources that don't need preprocessing.
qt5.preprocess(moc_headers : ['mainWindow.h'], # These need to be fed through the moc tool before use.
- ui_files : 'mainWindow.ui', # XML files that need to be compiled with the uic tol.
+ ui_files : 'mainWindow.ui', # XML files that need to be compiled with the uic tol.
qresources : 'stuff.qrc', # Resource file for rcc compiler.
)],
dependencies : qt5dep)