A very simple module implementation to get things going.

pull/39/merge
Jussi Pakkanen 10 years ago
parent 4745b07e99
commit ec491e200b
  1. 2
      .gitignore
  2. 8
      install_meson.py
  3. 26
      interpreter.py
  4. 16
      modules/modtest.py
  5. 4
      test cases/common/74 modules/meson.build

2
.gitignore vendored

@ -1,7 +1,7 @@
/.project
/.pydevproject
/__pycache__
__pycache__
/install dir
/work area

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

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

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

@ -0,0 +1,4 @@
project('module test', 'c')
modtest = import('modtest')
modtest.print_hello()
Loading…
Cancel
Save