From 11c812769af05126732d65bf6bf6da97afd42b1c Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Mon, 9 Dec 2013 20:26:12 +0200 Subject: [PATCH] Can haz subproject options. --- interpreter.py | 8 ++++++++ meson.py | 7 +------ mesongui.py | 2 +- optinterpreter.py | 5 ++++- test cases/common/50 subproject options/meson.build | 7 +++++++ test cases/common/50 subproject options/meson_options.txt | 1 + .../common/50 subproject options/subproject/meson.build | 5 +++++ .../50 subproject options/subproject/meson_options.txt | 1 + 8 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 test cases/common/50 subproject options/meson.build create mode 100644 test cases/common/50 subproject options/meson_options.txt create mode 100644 test cases/common/50 subproject options/subproject/meson.build create mode 100644 test cases/common/50 subproject options/subproject/meson_options.txt diff --git a/interpreter.py b/interpreter.py index 61f5938c3..b32e47af5 100644 --- a/interpreter.py +++ b/interpreter.py @@ -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 diff --git a/meson.py b/meson.py index 4aa7b1cf0..d96dffca6 100755 --- a/meson.py +++ b/meson.py @@ -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': diff --git a/mesongui.py b/mesongui.py index 77853de01..ad155220c 100755 --- a/mesongui.py +++ b/mesongui.py @@ -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: diff --git a/optinterpreter.py b/optinterpreter.py index 154b5fe90..756ec5f87 100644 --- a/optinterpreter.py +++ b/optinterpreter.py @@ -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 diff --git a/test cases/common/50 subproject options/meson.build b/test cases/common/50 subproject options/meson.build new file mode 100644 index 000000000..d4598b639 --- /dev/null +++ b/test cases/common/50 subproject options/meson.build @@ -0,0 +1,7 @@ +project('suboptions', 'c') + +subproject('subproject') + +if not get_option('opt') + error('option unset when it should be set') +endif diff --git a/test cases/common/50 subproject options/meson_options.txt b/test cases/common/50 subproject options/meson_options.txt new file mode 100644 index 000000000..658c4b0cf --- /dev/null +++ b/test cases/common/50 subproject options/meson_options.txt @@ -0,0 +1 @@ +option('opt', type : 'boolean', value : true) diff --git a/test cases/common/50 subproject options/subproject/meson.build b/test cases/common/50 subproject options/subproject/meson.build new file mode 100644 index 000000000..1f52e1924 --- /dev/null +++ b/test cases/common/50 subproject options/subproject/meson.build @@ -0,0 +1,5 @@ +project('subproject', 'c') + +if get_option('opt') + error('option unset when it should be set.') +endif diff --git a/test cases/common/50 subproject options/subproject/meson_options.txt b/test cases/common/50 subproject options/subproject/meson_options.txt new file mode 100644 index 000000000..071740be0 --- /dev/null +++ b/test cases/common/50 subproject options/subproject/meson_options.txt @@ -0,0 +1 @@ +option('opt', type : 'boolean', value : false)