Skip to content

Commit

Permalink
Use a single coredata dictionary for options
Browse files Browse the repository at this point in the history
This patches takes the options work to it's logical conclusion: A single
flat dictionary of OptionKey: UserOptions. This allows us to simplify a
large number of cases, as we don't need to check if an option is in this
dict or that one (or any of 5 or 6, actually).
  • Loading branch information
dcbaker committed Dec 7, 2020
1 parent 3879229 commit 6efed37
Show file tree
Hide file tree
Showing 33 changed files with 318 additions and 353 deletions.
4 changes: 2 additions & 2 deletions mesonbuild/ast/introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def func_project(self, node: BaseNode, args: T.List[TYPE_nvar], kwargs: T.Dict[s
if os.path.exists(self.option_file):
oi = optinterpreter.OptionInterpreter(self.subproject)
oi.process(self.option_file)
self.coredata.merge_user_options(oi.options)
self.coredata.update_project_options(oi.options)

def_opts = self.flatten_args(kwargs.get('default_options', []))
_project_default_options = mesonlib.stringlistify(def_opts)
Expand Down Expand Up @@ -269,7 +269,7 @@ def traverse_nodes(inqueue: T.List[BaseNode]) -> T.List[BaseNode]:
return new_target

def build_library(self, node: BaseNode, args: T.List[TYPE_nvar], kwargs: T.Dict[str, TYPE_nvar]) -> T.Optional[T.Dict[str, T.Any]]:
default_library = self.coredata.get_builtin_option('default_library')
default_library = self.coredata.get_option(OptionKey('default_library'))
if default_library == 'shared':
return self.build_target(node, args, kwargs, SharedLibrary)
elif default_library == 'static':
Expand Down
16 changes: 8 additions & 8 deletions mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from .. import mlog
from ..compilers import languages_using_ldflags
from ..mesonlib import (
File, MachineChoice, MesonException, OrderedSet, OptionOverrideProxy,
File, MachineChoice, MesonException, OptionType, OrderedSet, OptionOverrideProxy,
classify_unity_sources, unholder, OptionKey
)

Expand Down Expand Up @@ -213,19 +213,19 @@ def get_target_filename_abs(self, target):

def get_base_options_for_target(self, target: build.BuildTarget) -> OptionOverrideProxy:
return OptionOverrideProxy(target.option_overrides_base,
self.environment.coredata.builtins,
{k: v for k, v in self.environment.coredata.base_options.items()})
{k: v for k, v in self.environment.coredata.options.items()
if k.type in {OptionType.BASE, OptionType.BUILTIN}})

def get_compiler_options_for_target(self, target: build.BuildTarget) -> OptionOverrideProxy:
comp_reg = self.environment.coredata.compiler_options
comp_reg = {k: v for k, v in self.environment.coredata.options.items() if k.is_compiler()}
comp_override = target.option_overrides_compiler
return OptionOverrideProxy(comp_override, comp_reg)

def get_option_for_target(self, option_name: 'OptionKey', target: build.BuildTarget):
if option_name in target.option_overrides_base:
override = target.option_overrides_base[option_name]
return self.environment.coredata.validate_option_value(option_name, override)
return self.environment.coredata.get_builtin_option(str(option_name), target.subproject)
return self.environment.coredata.get_option(option_name.evolve(subproject=target.subproject))

def get_target_filename_for_linking(self, target):
# On some platforms (msvc for instance), the file that is used for
Expand All @@ -250,7 +250,7 @@ def get_target_filename_for_linking(self, target):

@lru_cache(maxsize=None)
def get_target_dir(self, target):
if self.environment.coredata.get_builtin_option('layout') == 'mirror':
if self.environment.coredata.get_option(OptionKey('layout')) == 'mirror':
dirname = target.get_subdir()
else:
dirname = 'meson-out'
Expand Down Expand Up @@ -541,7 +541,7 @@ def rpaths_for_bundled_shared_libraries(self, target, exclude_system=True):
return paths

def determine_rpath_dirs(self, target):
if self.environment.coredata.get_builtin_option('layout') == 'mirror':
if self.environment.coredata.get_option(OptionKey('layout')) == 'mirror':
result = target.get_link_dep_subdirs()
else:
result = OrderedSet()
Expand Down Expand Up @@ -1183,7 +1183,7 @@ def create_install_data(self) -> InstallData:
self.environment.get_build_dir(),
self.environment.get_prefix(),
strip_bin,
self.environment.coredata.get_builtin_option('install_umask'),
self.environment.coredata.get_option(OptionKey('install_umask')),
self.environment.get_build_command() + ['introspect'],
self.environment.coredata.version)
self.generate_depmf_install(d)
Expand Down
30 changes: 15 additions & 15 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def generate(self):
outfile.write('# Do not edit by hand.\n\n')
outfile.write('ninja_required_version = 1.8.2\n\n')

num_pools = self.environment.coredata.backend_options[OptionKey('backend_max_links')].value
num_pools = self.environment.coredata.options[OptionKey('backend_max_links')].value
if num_pools > 0:
outfile.write('''pool link_pool
depth = {}
Expand All @@ -526,8 +526,8 @@ def generate(self):
self.generate_install()
self.generate_dist()
key = OptionKey('b_coverage')
if (key in self.environment.coredata.base_options and
self.environment.coredata.base_options[key].value):
if (key in self.environment.coredata.options and
self.environment.coredata.options[key].value):
self.add_build_comment(NinjaComment('Coverage rules'))
self.generate_coverage_rules()
self.add_build_comment(NinjaComment('Suffix'))
Expand Down Expand Up @@ -794,7 +794,7 @@ def generate_target(self, target):
order_deps=header_deps)
obj_list.append(o)

use_pch = self.environment.coredata.base_options.get(OptionKey('b_pch'))
use_pch = self.environment.coredata.options.get(OptionKey('b_pch'))
if use_pch and target.has_pch():
pch_objects = self.generate_pch(target, header_deps=header_deps)
else:
Expand Down Expand Up @@ -1050,9 +1050,9 @@ def generate_install(self):
def generate_tests(self):
self.serialize_tests()
cmd = self.environment.get_build_command(True) + ['test', '--no-rebuild']
if not self.environment.coredata.get_builtin_option('stdsplit'):
if not self.environment.coredata.get_option(OptionKey('stdsplit')):
cmd += ['--no-stdsplit']
if self.environment.coredata.get_builtin_option('errorlogs'):
if self.environment.coredata.get_option(OptionKey('errorlogs')):
cmd += ['--print-errorlogs']
elem = NinjaBuildElement(self.all_outputs, 'meson-test', 'CUSTOM_COMMAND', ['all', 'PHONY'])
elem.add_item('COMMAND', cmd)
Expand Down Expand Up @@ -1431,7 +1431,7 @@ def generate_vala_compile(self, target):
valac_outputs.append(vala_c_file)

args = self.generate_basic_compiler_args(target, valac)
args += valac.get_colorout_args(self.environment.coredata.base_options.get(OptionKey('b_colorout')).value)
args += valac.get_colorout_args(self.environment.coredata.options.get(OptionKey('b_colorout')).value)
# Tell Valac to output everything in our private directory. Sadly this
# means it will also preserve the directory components of Vala sources
# found inside the build tree (generated sources).
Expand Down Expand Up @@ -1768,7 +1768,7 @@ def generate_swift_target(self, target):
self.create_target_source_introspection(target, swiftc, compile_args + header_imports + module_includes, relsrc, rel_generated)

def generate_static_link_rules(self):
num_pools = self.environment.coredata.backend_options[OptionKey('backend_max_links')].value
num_pools = self.environment.coredata.options[OptionKey('backend_max_links')].value
if 'java' in self.environment.coredata.compilers.host:
self.generate_java_link()
for for_machine in MachineChoice:
Expand Down Expand Up @@ -1801,7 +1801,7 @@ def generate_static_link_rules(self):
extra=pool))

def generate_dynamic_link_rules(self):
num_pools = self.environment.coredata.backend_options[OptionKey('backend_max_links')].value
num_pools = self.environment.coredata.options[OptionKey('backend_max_links')].value
for for_machine in MachineChoice:
complist = self.environment.coredata.compilers[for_machine]
for langname, compiler in complist.items():
Expand Down Expand Up @@ -2391,7 +2391,7 @@ def generate_single_compile(self, target, src, is_generated=False, header_deps=N
commands += self.get_compile_debugfile_args(compiler, target, rel_obj)

# PCH handling
if self.environment.coredata.base_options.get(OptionKey('b_pch')):
if self.environment.coredata.options.get(OptionKey('b_pch')):
commands += self.get_pch_include_args(compiler, target)
pchlist = target.get_pch(compiler.language)
else:
Expand Down Expand Up @@ -2573,7 +2573,7 @@ def get_target_type_link_args(self, target, linker):
commands += linker.get_pie_link_args()
elif isinstance(target, build.SharedLibrary):
if isinstance(target, build.SharedModule):
options = self.environment.coredata.base_options
options = self.environment.coredata.options
commands += linker.get_std_shared_module_link_args(options)
else:
commands += linker.get_std_shared_lib_link_args()
Expand Down Expand Up @@ -2810,7 +2810,7 @@ def generate_link(self, target: build.BuildTarget, outname, obj_list, linker: T.
#
# We shouldn't check whether we are making a static library, because
# in the LTO case we do use a real compiler here.
commands += linker.get_option_link_args(self.environment.coredata.compiler_options)
commands += linker.get_option_link_args(self.environment.coredata.options)

dep_targets = []
dep_targets.extend(self.guess_external_link_dependencies(linker, target, commands, internal))
Expand Down Expand Up @@ -2904,7 +2904,7 @@ def generate_gcov_clean(self):

def get_user_option_args(self):
cmds = []
for (k, v) in self.environment.coredata.user_options.items():
for (k, v) in self.environment.coredata.options.items():
cmds.append('-D' + str(k) + '=' + (v.value if isinstance(v.value, str) else str(v.value).lower()))
# The order of these arguments must be the same between runs of Meson
# to ensure reproducible output. The order we pass them shouldn't
Expand Down Expand Up @@ -3027,8 +3027,8 @@ def generate_ending(self):
if ctlist:
elem.add_dep(self.generate_custom_target_clean(ctlist))

if OptionKey('b_coverage') in self.environment.coredata.base_options and \
self.environment.coredata.base_options[OptionKey('b_coverage')].value:
if OptionKey('b_coverage') in self.environment.coredata.options and \
self.environment.coredata.options[OptionKey('b_coverage')].value:
self.generate_gcov_clean()
elem.add_dep('clean-gcda')
elem.add_dep('clean-gcno')
Expand Down
30 changes: 15 additions & 15 deletions mesonbuild/backend/vs2010backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ def generate(self):
self.platform = 'ARM'
else:
raise MesonException('Unsupported Visual Studio platform: ' + target_machine)
self.buildtype = self.environment.coredata.get_builtin_option('buildtype')
self.optimization = self.environment.coredata.get_builtin_option('optimization')
self.debug = self.environment.coredata.get_builtin_option('debug')
self.buildtype = self.environment.coredata.get_option(OptionKey('buildtype'))
self.optimization = self.environment.coredata.get_option(OptionKey('optimization'))
self.debug = self.environment.coredata.get_option(OptionKey('debug'))
sln_filename = os.path.join(self.environment.get_build_dir(), self.build.project_name + '.sln')
projlist = self.generate_projects()
self.gen_testproj('RUN_TESTS', os.path.join(self.environment.get_build_dir(), 'RUN_TESTS.vcxproj'))
Expand Down Expand Up @@ -316,7 +316,7 @@ def generate_solution(self, sln_filename, projlist):
prj_templ = 'Project("{%s}") = "%s", "%s", "{%s}"\n'
for prj in projlist:
coredata = self.environment.coredata
if coredata.get_builtin_option('layout') == 'mirror':
if coredata.get_option(OptionKey('layout')) == 'mirror':
self.generate_solution_dirs(ofile, prj[1].parents)
target = self.build.targets[prj[0]]
lang = 'default'
Expand Down Expand Up @@ -403,7 +403,7 @@ def generate_solution(self, sln_filename, projlist):
replace_if_different(sln_filename, sln_filename_tmp)

def generate_projects(self):
startup_project = self.environment.coredata.backend_options[OptionKey('backend_startup_project')].value
startup_project = self.environment.coredata.options[OptionKey('backend_startup_project')].value
projlist = []
startup_idx = 0
for (i, (name, target)) in enumerate(self.build.targets.items()):
Expand Down Expand Up @@ -785,7 +785,7 @@ def gen_vcxproj(self, target, ofname, guid):
build_args += compiler.get_optimization_args(self.optimization)
build_args += compiler.get_debug_args(self.debug)
buildtype_link_args = compiler.get_buildtype_linker_args(self.buildtype)
vscrt_type = self.environment.coredata.base_options[OptionKey('b_vscrt')]
vscrt_type = self.environment.coredata.options[OptionKey('b_vscrt')]
project_name = target.name
target_name = target.name
root = ET.Element('Project', {'DefaultTargets': "Build",
Expand Down Expand Up @@ -878,7 +878,7 @@ def gen_vcxproj(self, target, ofname, guid):
# Exception handling has to be set in the xml in addition to the "AdditionalOptions" because otherwise
# cl will give warning D9025: overriding '/Ehs' with cpp_eh value
if 'cpp' in target.compilers:
eh = self.environment.coredata.compiler_options[OptionKey('eh', machine=target.for_machine, lang='cpp')]
eh = self.environment.coredata.options[OptionKey('eh', machine=target.for_machine, lang='cpp')]
if eh.value == 'a':
ET.SubElement(clconf, 'ExceptionHandling').text = 'Async'
elif eh.value == 's':
Expand Down Expand Up @@ -926,7 +926,7 @@ def gen_vcxproj(self, target, ofname, guid):
file_args[l] += compilers.get_base_compile_args(
self.get_base_options_for_target(target), comp)
file_args[l] += comp.get_option_compile_args(
self.environment.coredata.compiler_options[target.for_machine][comp.language])
self.environment.coredata.options[target.for_machine][comp.language])

# Add compile args added using add_project_arguments()
for l, args in self.build.projects_args[target.for_machine].get(target.subproject, {}).items():
Expand All @@ -940,7 +940,7 @@ def gen_vcxproj(self, target, ofname, guid):
# Compile args added from the env or cross file: CFLAGS/CXXFLAGS, etc. We want these
# to override all the defaults, but not the per-target compile args.
for l in file_args.keys():
opts = self.environment.coredata.compiler_options[OptionKey('args', machine=target.for_machine, lang='cpp')]
opts = self.environment.coredata.options[OptionKey('args', machine=target.for_machine, lang='cpp')]
file_args[l] += opts.value
for args in file_args.values():
# This is where Visual Studio will insert target_args, target_defines,
Expand Down Expand Up @@ -1075,7 +1075,7 @@ def gen_vcxproj(self, target, ofname, guid):
ET.SubElement(clconf, 'FavorSizeOrSpeed').text = 'Speed'
# Note: SuppressStartupBanner is /NOLOGO and is 'true' by default
pch_sources = {}
if self.environment.coredata.base_options.get(OptionKey('b_pch')):
if self.environment.coredata.options.get(OptionKey('b_pch')):
for lang in ['c', 'cpp']:
pch = target.get_pch(lang)
if not pch:
Expand Down Expand Up @@ -1111,7 +1111,7 @@ def gen_vcxproj(self, target, ofname, guid):
ET.SubElement(link, 'GenerateDebugInformation').text = 'false'
if not isinstance(target, build.StaticLibrary):
if isinstance(target, build.SharedModule):
options = self.environment.coredata.base_options
options = self.environment.coredata.options
extra_link_args += compiler.get_std_shared_module_link_args(options)
# Add link args added using add_project_link_arguments()
extra_link_args += self.build.get_project_link_args(compiler, target.subproject, target.for_machine)
Expand Down Expand Up @@ -1145,7 +1145,7 @@ def gen_vcxproj(self, target, ofname, guid):
# symbols from those can be found here. This is needed when the
# *_winlibs that we want to link to are static mingw64 libraries.
extra_link_args += compiler.get_option_link_args(
self.environment.coredata.compiler_options[compiler.for_machine][comp.language])
self.environment.coredata.options[compiler.for_machine][comp.language])
(additional_libpaths, additional_links, extra_link_args) = self.split_link_args(extra_link_args.to_native())

# Add more libraries to be linked if needed
Expand Down Expand Up @@ -1224,7 +1224,7 @@ def gen_vcxproj(self, target, ofname, guid):
# /nologo
ET.SubElement(link, 'SuppressStartupBanner').text = 'true'
# /release
if not self.environment.coredata.get_builtin_option('debug'):
if not self.environment.coredata.get_option(OptionKey('debug')):
ET.SubElement(link, 'SetChecksum').text = 'true'

meson_file_group = ET.SubElement(root, 'ItemGroup')
Expand Down Expand Up @@ -1424,9 +1424,9 @@ def gen_testproj(self, target_name, ofname):
ET.SubElement(midl, 'ProxyFileName').text = '%(Filename)_p.c'
# FIXME: No benchmarks?
test_command = self.environment.get_build_command() + ['test', '--no-rebuild']
if not self.environment.coredata.get_builtin_option('stdsplit'):
if not self.environment.coredata.get_option(OptionKey('stdsplit')):
test_command += ['--no-stdsplit']
if self.environment.coredata.get_builtin_option('errorlogs'):
if self.environment.coredata.get_option(OptionKey('errorlogs')):
test_command += ['--print-errorlogs']
self.serialize_tests()
self.add_custom_build(root, 'run_tests', '"%s"' % ('" "'.join(test_command)))
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/backend/xcodebackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def gen_id(self):
return str(uuid.uuid4()).upper().replace('-', '')[:24]

def get_target_dir(self, target):
dirname = os.path.join(target.get_subdir(), self.environment.coredata.get_builtin_option('buildtype'))
dirname = os.path.join(target.get_subdir(), self.environment.coredata.get_option(mesonlib.OptionKey('buildtype')))
os.makedirs(os.path.join(self.environment.get_build_dir(), dirname), exist_ok=True)
return dirname

Expand Down
Loading

0 comments on commit 6efed37

Please sign in to comment.