Can haz subproject options.

pull/15/head
Jussi Pakkanen 11 years ago
parent 374ffe9f86
commit 11c812769a
  1. 8
      interpreter.py
  2. 7
      meson.py
  3. 2
      mesongui.py
  4. 5
      optinterpreter.py
  5. 7
      test cases/common/50 subproject options/meson.build
  6. 1
      test cases/common/50 subproject options/meson_options.txt
  7. 5
      test cases/common/50 subproject options/subproject/meson.build
  8. 1
      test cases/common/50 subproject options/subproject/meson_options.txt

@ -19,6 +19,7 @@ import coredata
import dependencies
import mlog
import build
import optinterpreter
import os, sys, platform, subprocess, shutil
class InterpreterException(coredata.MesonException):
@ -558,6 +559,11 @@ class Interpreter():
self.build = build
self.subproject = subproject
self.source_root = os.path.join(build.environment.get_source_dir(), subproject)
option_file = os.path.join(self.source_root, 'meson_options.txt')
if os.path.exists(option_file):
oi = optinterpreter.OptionInterpreter(self.subproject)
oi.process(option_file)
self.build.environment.merge_options(oi.options)
code = open(os.path.join(self.source_root, environment.build_filename)).read()
if len(code.strip()) == 0:
raise InvalidCode('Builder file is empty.')
@ -754,6 +760,8 @@ class Interpreter():
optname = args[0]
if not isinstance(optname, str):
raise InterpreterException('Argument of get_option must be a string.')
if self.subproject != '':
optname = self.subproject + '-' + optname
if optname not in self.environment.coredata.user_options:
raise InterpreterException('Tried to access unknown option "%s".' % optname)
return self.environment.coredata.user_options[optname].value

@ -17,7 +17,7 @@
from optparse import OptionParser
import sys, stat, traceback, pickle
import os.path
import environment, interpreter, optinterpreter
import environment, interpreter
import backends, build
import mlog, coredata
@ -121,11 +121,6 @@ itself as required.'''
else:
mlog.log('Build type:', mlog.bold('native build'))
b = build.Build(env)
option_file = os.path.join(self.source_dir, 'meson_options.txt')
if os.path.exists(option_file):
oi = optinterpreter.OptionInterpreter()
oi.process(option_file)
env.merge_options(oi.options)
intr = interpreter.Interpreter(b)
intr.run()
if options.backend == 'ninja':

@ -413,7 +413,7 @@ class MesonGui():
self.ui.save_button.clicked.connect(self.save)
def fill_data(self):
self.ui.project_label.setText(self.build.project)
self.ui.project_label.setText(self.build.projects[''])
self.ui.srcdir_label.setText(self.src_dir)
self.ui.builddir_label.setText(self.build_dir)
if self.coredata.cross_file is None:

@ -69,8 +69,9 @@ option_types = {'string' : UserStringOption,
}
class OptionInterpreter:
def __init__(self):
def __init__(self, subproject):
self.options = {}
self.subproject = subproject
def process(self, option_file):
try:
@ -137,6 +138,8 @@ class OptionInterpreter:
opt_name = posargs[0]
if not isinstance(opt_name, str):
raise OptionException('Positional argument must be a string.')
if self.subproject != '':
opt_name = self.subproject + '-' + opt_name
opt = option_types[opt_type](kwargs)
if opt.description == '':
opt.description = opt_name

@ -0,0 +1,7 @@
project('suboptions', 'c')
subproject('subproject')
if not get_option('opt')
error('option unset when it should be set')
endif

@ -0,0 +1 @@
option('opt', type : 'boolean', value : true)

@ -0,0 +1,5 @@
project('subproject', 'c')
if get_option('opt')
error('option unset when it should be set.')
endif

@ -0,0 +1 @@
option('opt', type : 'boolean', value : false)
Loading…
Cancel
Save