aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2015-03-04 23:53:35 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2015-03-04 23:53:35 +0200
commitec491e200ba82f6f6d0df2f10ae4a607efeb3657 (patch)
treefab7d7f7fd904510399cd71d6575128bb103def8
parent4745b07e9924ad5dd48d23766833be0ba5749a99 (diff)
downloadmeson-ec491e200ba82f6f6d0df2f10ae4a607efeb3657.zip
meson-ec491e200ba82f6f6d0df2f10ae4a607efeb3657.tar.gz
meson-ec491e200ba82f6f6d0df2f10ae4a607efeb3657.tar.bz2
A very simple module implementation to get things going.
-rw-r--r--.gitignore2
-rwxr-xr-xinstall_meson.py8
-rw-r--r--interpreter.py26
-rw-r--r--modules/modtest.py16
-rw-r--r--test cases/common/74 modules/meson.build4
5 files changed, 55 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 084bbf4..773d3fe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,7 @@
/.project
/.pydevproject
-/__pycache__
+__pycache__
/install dir
/work area
diff --git a/install_meson.py b/install_meson.py
index 4bae6d8..6a1efdf 100755
--- a/install_meson.py
+++ b/install_meson.py
@@ -39,6 +39,7 @@ else:
install_root = os.path.join(options.destdir, options.prefix[1:])
script_dir = os.path.join(install_root, 'share/meson')
+module_dir = os.path.join(script_dir, 'modules')
bin_dir = os.path.join(install_root, 'bin')
bin_script = os.path.join(script_dir, 'meson.py')
gui_script = os.path.join(script_dir, 'mesongui.py')
@@ -97,3 +98,10 @@ print('Installing manfiles to %s.' % man_dir)
open(out_manfile, 'wb').write(gzip.compress(open(in_manfile, 'rb').read()))
open(out_confmanfile, 'wb').write(gzip.compress(open(in_confmanfile, 'rb').read()))
open(out_guimanfile, 'wb').write(gzip.compress(open(in_guimanfile, 'rb').read()))
+
+print('Installing modules to %s.' % module_dir)
+if os.path.exists('modules/__pycache__'):
+ shutil.rmtree('modules/__pycache__')
+if os.path.exists(module_dir):
+ shutil.rmtree(module_dir)
+shutil.copytree('modules', module_dir)
diff --git a/interpreter.py b/interpreter.py
index ffbee6d..c8947c2 100644
--- a/interpreter.py
+++ b/interpreter.py
@@ -22,6 +22,7 @@ import optinterpreter
import wrap
import mesonlib
import os, sys, platform, subprocess, shutil, uuid, re
+import importlib
class InterpreterException(coredata.MesonException):
pass
@@ -592,6 +593,19 @@ class CompilerHolder(InterpreterObject):
mlog.log('Has header "%s":' % string, h)
return haz
+class ModuleHolder(InterpreterObject):
+ def __init__(self, modname):
+ InterpreterObject.__init__(self)
+ self.modname = modname
+ self.m = importlib.import_module('modules.' + modname)
+
+ def method_call(self, method_name, args, kwargs):
+ try:
+ fn = getattr(self.m, method_name)
+ except AttributeError:
+ raise InvalidArguments('Module %s does not have method %s.' % (self.modname, method_name))
+ fn(args, kwargs)
+
class MesonMain(InterpreterObject):
def __init__(self, build, interpreter):
InterpreterObject.__init__(self)
@@ -708,6 +722,7 @@ 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,
@@ -741,6 +756,7 @@ class Interpreter():
'pkgconfig_gen' : self.func_pkgconfig_gen,
'vcs_tag' : self.func_vcs_tag,
'set_variable' : self.func_set_variable,
+ 'import' : self.func_import,
}
def get_build_def_files(self):
@@ -798,6 +814,16 @@ class Interpreter():
value = self.to_native(args[1])
self.set_variable(varname, value)
+ def func_import(self, node, args, kwargs):
+ if len(args) != 1:
+ raise InvalidCode('Import takes one argument.')
+ modname = args[0]
+ if not isinstance(modname, str):
+ raise InvalidCode('Argument to import was not a string')
+ if not modname in self.modules:
+ self.modules[modname] = ModuleHolder(modname)
+ return self.modules[modname]
+
def set_variable(self, varname, variable):
if variable is None:
raise InvalidCode('Can not assign None to variable.')
diff --git a/modules/modtest.py b/modules/modtest.py
new file mode 100644
index 0000000..e6d4c5f
--- /dev/null
+++ b/modules/modtest.py
@@ -0,0 +1,16 @@
+# Copyright 2012-2015 The Meson development team
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+def print_hello(args, kwargs):
+ print('Hello from a Meson module')
diff --git a/test cases/common/74 modules/meson.build b/test cases/common/74 modules/meson.build
new file mode 100644
index 0000000..e9750cd
--- /dev/null
+++ b/test cases/common/74 modules/meson.build
@@ -0,0 +1,4 @@
+project('module test', 'c')
+
+modtest = import('modtest')
+modtest.print_hello()