Move option file parsing to after the project() inputs have been decoded to access default options.

pull/1260/head
Jussi Pakkanen 8 years ago
parent 8f5b67434d
commit f85c348b94
  1. 13
      mesonbuild/interpreter.py
  2. 9
      test cases/unit/3 subproject defaults/meson.build
  3. 3
      test cases/unit/3 subproject defaults/meson_options.txt

@ -1147,12 +1147,7 @@ class Interpreter(InterpreterBase):
self.backend = backend
self.subproject = subproject
self.subproject_dir = subproject_dir
option_file = os.path.join(self.source_root, self.subdir, 'meson_options.txt')
if os.path.exists(option_file):
oi = optinterpreter.OptionInterpreter(self.subproject, \
self.build.environment.cmd_line_options.projectoptions)
oi.process(option_file)
self.build.environment.merge_options(oi.options)
self.option_file = os.path.join(self.source_root, self.subdir, 'meson_options.txt')
self.load_root_meson_file()
self.sanity_check_ast()
self.builtin.update({'meson': MesonMain(build, self)})
@ -1501,6 +1496,12 @@ class Interpreter(InterpreterBase):
self.build.project_name = args[0]
if self.environment.first_invocation and 'default_options' in kwargs:
self.parse_default_options(kwargs['default_options'])
if os.path.exists(self.option_file):
oi = optinterpreter.OptionInterpreter(self.subproject, \
self.build.environment.cmd_line_options.projectoptions,
)
oi.process(self.option_file)
self.build.environment.merge_options(oi.options)
if len(args) < 2:
raise InvalidArguments('Not enough arguments to project(). Needs at least the project name and one language')
self.active_projectname = args[0]

@ -0,0 +1,9 @@
project('subproject defaults', 'c',
default_options : ['defopoverride=defopt', # This should be overridden.
'fromcmdline=defopt'] # This should get the value set in command line.
)
assert(get_option('fromcmdline') == 'cmdline', 'Default option defined in cmd line is incorrect: ' + get_option('fromcmdline'))
assert(get_option('defopoverride') == 'defopt', 'Default option without cmd line override is incorrect: ' + get_option('defopoverride'))
assert(get_option('fromoptfile') == 'optfile', 'Default value from option file is incorrect: ' + get_option('fromoptfile'))

@ -0,0 +1,3 @@
option('defopoverride', type : 'string', value : 'optfile', description : 'A value for overriding.')
option('fromcmdline', type : 'string', value : 'optfile', description : 'A value for overriding.')
option('fromoptfile', type : 'string', value : 'optfile', description : 'A value for not overriding.')
Loading…
Cancel
Save