Skip to content

Commit f947978

Browse files
bruchar1dcbaker
authored andcommitted
fix reconfigure subproject base options
1 parent 9e270f0 commit f947978

File tree

8 files changed

+51
-29
lines changed

8 files changed

+51
-29
lines changed

mesonbuild/ast/introspection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def _add_languages(self, raw_langs: T.List[TYPE_var], required: bool, for_machin
170170
lang = lang.lower()
171171
if lang not in self.coredata.compilers[for_machine]:
172172
try:
173-
comp = detect_compiler_for(self.environment, lang, for_machine, True)
173+
comp = detect_compiler_for(self.environment, lang, for_machine, True, self.subproject)
174174
except mesonlib.MesonException:
175175
# do we even care about introspecting this language?
176176
if required:
@@ -183,7 +183,7 @@ def _add_languages(self, raw_langs: T.List[TYPE_var], required: bool, for_machin
183183
v = copy.copy(self.coredata.options[k])
184184
k = k.evolve(subproject=self.subproject)
185185
options[k] = v
186-
self.coredata.add_compiler_options(options, lang, for_machine, self.environment)
186+
self.coredata.add_compiler_options(options, lang, for_machine, self.environment, self.subproject)
187187

188188
def func_dependency(self, node: BaseNode, args: T.List[TYPE_var], kwargs: T.Dict[str, TYPE_var]) -> None:
189189
args = self.flatten_args(args)

mesonbuild/compilers/detect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ def compiler_from_language(env: 'Environment', lang: str, for_machine: MachineCh
101101
}
102102
return lang_map[lang](env, for_machine) if lang in lang_map else None
103103

104-
def detect_compiler_for(env: 'Environment', lang: str, for_machine: MachineChoice, skip_sanity_check: bool) -> T.Optional[Compiler]:
104+
def detect_compiler_for(env: 'Environment', lang: str, for_machine: MachineChoice, skip_sanity_check: bool, subproject: str) -> T.Optional[Compiler]:
105105
comp = compiler_from_language(env, lang, for_machine)
106106
if comp is None:
107107
return comp
108108
assert comp.for_machine == for_machine
109-
env.coredata.process_compiler_options(lang, comp, env)
109+
env.coredata.process_compiler_options(lang, comp, env, subproject)
110110
if not skip_sanity_check:
111111
comp.sanity_check(env.get_scratch_dir(), env)
112112
env.coredata.compilers[comp.for_machine][lang] = comp

mesonbuild/coredata.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,15 +1016,24 @@ def set_default_options(self, default_options: T.MutableMapping[OptionKey, str],
10161016

10171017
self.set_options(options, subproject=subproject, first_invocation=env.first_invocation)
10181018

1019-
def add_compiler_options(self, options: 'MutableKeyedOptionDictType', lang: str, for_machine: MachineChoice,
1020-
env: 'Environment') -> None:
1019+
def add_compiler_options(self, options: MutableKeyedOptionDictType, lang: str, for_machine: MachineChoice,
1020+
env: Environment, subproject: str) -> None:
10211021
for k, o in options.items():
10221022
value = env.options.get(k)
10231023
if value is not None:
10241024
o.set_value(value)
1025-
self.options[k] = o # override compiler option on reconfigure
1025+
if not subproject:
1026+
self.options[k] = o # override compiler option on reconfigure
10261027
self.options.setdefault(k, o)
10271028

1029+
if subproject:
1030+
sk = k.evolve(subproject=subproject)
1031+
value = env.options.get(sk) or value
1032+
if value is not None:
1033+
o.set_value(value)
1034+
self.options[sk] = o # override compiler option on reconfigure
1035+
self.options.setdefault(sk, o)
1036+
10281037
def add_lang_args(self, lang: str, comp: T.Type['Compiler'],
10291038
for_machine: MachineChoice, env: 'Environment') -> None:
10301039
"""Add global language arguments that are needed before compiler/linker detection."""
@@ -1034,20 +1043,31 @@ def add_lang_args(self, lang: str, comp: T.Type['Compiler'],
10341043
# `self.options.update()`` is perfectly safe.
10351044
self.options.update(compilers.get_global_options(lang, comp, for_machine, env))
10361045

1037-
def process_compiler_options(self, lang: str, comp: 'Compiler', env: 'Environment') -> None:
1046+
def process_compiler_options(self, lang: str, comp: Compiler, env: Environment, subproject: str) -> None:
10381047
from . import compilers
10391048

1040-
self.add_compiler_options(comp.get_options(), lang, comp.for_machine, env)
1049+
self.add_compiler_options(comp.get_options(), lang, comp.for_machine, env, subproject)
10411050

10421051
enabled_opts: T.List[OptionKey] = []
10431052
for key in comp.base_options:
1044-
if key not in self.options:
1045-
self.options[key] = copy.deepcopy(compilers.base_options[key])
1046-
if key in env.options:
1047-
self.options[key].set_value(env.options[key])
1048-
enabled_opts.append(key)
1049-
elif key in env.options:
1050-
self.options[key].set_value(env.options[key])
1053+
if subproject:
1054+
skey = key.evolve(subproject=subproject)
1055+
else:
1056+
skey = key
1057+
if skey not in self.options:
1058+
self.options[skey] = copy.deepcopy(compilers.base_options[key])
1059+
if skey in env.options:
1060+
self.options[skey].set_value(env.options[skey])
1061+
enabled_opts.append(skey)
1062+
elif subproject and key in env.options:
1063+
self.options[skey].set_value(env.options[key])
1064+
enabled_opts.append(skey)
1065+
if subproject and key not in self.options:
1066+
self.options[key] = copy.deepcopy(self.options[skey])
1067+
elif skey in env.options:
1068+
self.options[skey].set_value(env.options[skey])
1069+
elif subproject and key in env.options:
1070+
self.options[skey].set_value(env.options[key])
10511071
self.emit_base_options_warnings(enabled_opts)
10521072

10531073
def emit_base_options_warnings(self, enabled_opts: T.List[OptionKey]) -> None:

mesonbuild/interpreter/interpreter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,7 @@ def add_languages_for(self, args: T.List[str], required: bool, for_machine: Mach
15061506
skip_sanity_check = self.should_skip_sanity_check(for_machine)
15071507
if skip_sanity_check:
15081508
mlog.log('Cross compiler sanity tests disabled via the cross file.', once=True)
1509-
comp = compilers.detect_compiler_for(self.environment, lang, for_machine, skip_sanity_check)
1509+
comp = compilers.detect_compiler_for(self.environment, lang, for_machine, skip_sanity_check, self.subproject)
15101510
if comp is None:
15111511
raise InvalidArguments(f'Tried to use unknown language "{lang}".')
15121512
except mesonlib.MesonException:
@@ -1520,7 +1520,7 @@ def add_languages_for(self, args: T.List[str], required: bool, for_machine: Mach
15201520
raise
15211521
else:
15221522
# update new values from commandline, if it applies
1523-
self.coredata.process_compiler_options(lang, comp, self.environment)
1523+
self.coredata.process_compiler_options(lang, comp, self.environment, self.subproject)
15241524

15251525
# Add per-subproject compiler options. They inherit value from main project.
15261526
if self.subproject:
@@ -1529,7 +1529,7 @@ def add_languages_for(self, args: T.List[str], required: bool, for_machine: Mach
15291529
v = copy.copy(self.coredata.options[k])
15301530
k = k.evolve(subproject=self.subproject)
15311531
options[k] = v
1532-
self.coredata.add_compiler_options(options, lang, for_machine, self.environment)
1532+
self.coredata.add_compiler_options(options, lang, for_machine, self.environment, self.subproject)
15331533

15341534
if for_machine == MachineChoice.HOST or self.environment.is_cross_build():
15351535
logger_fun = mlog.log

mesonbuild/modules/java.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, interpreter: Interpreter):
3232

3333
def __get_java_compiler(self, state: ModuleState) -> Compiler:
3434
if 'java' not in state.environment.coredata.compilers[MachineChoice.BUILD]:
35-
detect_compiler_for(state.environment, 'java', MachineChoice.BUILD, False)
35+
detect_compiler_for(state.environment, 'java', MachineChoice.BUILD, False, state.subproject)
3636
return state.environment.coredata.compilers[MachineChoice.BUILD]['java']
3737

3838
@FeatureNew('java.generate_native_headers', '0.62.0')

run_project_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ def have_working_compiler(lang: str, use_tmp: bool) -> bool:
981981
return False
982982
if not compiler:
983983
return False
984-
env.coredata.process_compiler_options(lang, compiler, env)
984+
env.coredata.process_compiler_options(lang, compiler, env, '')
985985
try:
986986
compiler.sanity_check(env.get_scratch_dir(), env)
987987
except mesonlib.MesonException:

unittests/allplatformstests.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ def test_build_generated_pyx_directly(self):
944944
testdir = os.path.join("test cases/cython", '2 generated sources')
945945
env = get_fake_env(testdir, self.builddir, self.prefix)
946946
try:
947-
detect_compiler_for(env, "cython", MachineChoice.HOST, True)
947+
detect_compiler_for(env, "cython", MachineChoice.HOST, True, '')
948948
except EnvironmentException:
949949
raise SkipTest("Cython is not installed")
950950
self.init(testdir)
@@ -969,7 +969,7 @@ def test_build_pyx_depfiles(self):
969969
testdir = os.path.join("test cases/cython", '2 generated sources')
970970
env = get_fake_env(testdir, self.builddir, self.prefix)
971971
try:
972-
cython = detect_compiler_for(env, "cython", MachineChoice.HOST, True)
972+
cython = detect_compiler_for(env, "cython", MachineChoice.HOST, True, '')
973973
if not version_compare(cython.version, '>=0.29.33'):
974974
raise SkipTest('Cython is too old')
975975
except EnvironmentException:
@@ -2355,7 +2355,7 @@ def test_templates(self):
23552355
env = get_fake_env()
23562356
for l in ['cpp', 'cs', 'd', 'java', 'cuda', 'fortran', 'objc', 'objcpp', 'rust', 'vala']:
23572357
try:
2358-
comp = detect_compiler_for(env, l, MachineChoice.HOST, True)
2358+
comp = detect_compiler_for(env, l, MachineChoice.HOST, True, '')
23592359
with tempfile.TemporaryDirectory() as d:
23602360
comp.sanity_check(d, env)
23612361
langs.append(l)
@@ -2373,7 +2373,7 @@ def test_templates(self):
23732373
if is_windows() and lang == 'fortran' and target_type == 'library':
23742374
# non-Gfortran Windows Fortran compilers do not do shared libraries in a Fortran standard way
23752375
# see "test cases/fortran/6 dynamic"
2376-
fc = detect_compiler_for(env, 'fortran', MachineChoice.HOST, True)
2376+
fc = detect_compiler_for(env, 'fortran', MachineChoice.HOST, True, '')
23772377
if fc.get_id() in {'intel-cl', 'pgi'}:
23782378
continue
23792379
# test empty directory
@@ -4433,18 +4433,18 @@ def test_env_flags_to_linker(self) -> None:
44334433
env = get_fake_env()
44344434

44354435
# Get the compiler so we know which compiler class to mock.
4436-
cc = detect_compiler_for(env, 'c', MachineChoice.HOST, True)
4436+
cc = detect_compiler_for(env, 'c', MachineChoice.HOST, True, '')
44374437
cc_type = type(cc)
44384438

44394439
# Test a compiler that acts as a linker
44404440
with mock.patch.object(cc_type, 'INVOKES_LINKER', True):
4441-
cc = detect_compiler_for(env, 'c', MachineChoice.HOST, True)
4441+
cc = detect_compiler_for(env, 'c', MachineChoice.HOST, True, '')
44424442
link_args = env.coredata.get_external_link_args(cc.for_machine, cc.language)
44434443
self.assertEqual(sorted(link_args), sorted(['-DCFLAG', '-flto']))
44444444

44454445
# And one that doesn't
44464446
with mock.patch.object(cc_type, 'INVOKES_LINKER', False):
4447-
cc = detect_compiler_for(env, 'c', MachineChoice.HOST, True)
4447+
cc = detect_compiler_for(env, 'c', MachineChoice.HOST, True, '')
44484448
link_args = env.coredata.get_external_link_args(cc.for_machine, cc.language)
44494449
self.assertEqual(sorted(link_args), sorted(['-flto']))
44504450

unittests/platformagnostictests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,11 @@ def test_reconfigure_base_options(self):
282282
self.assertIn('\nMessage: b_ndebug: true\n', out)
283283
self.assertIn('\nMessage: c_std: c89\n', out)
284284

285-
out = self.init(testdir, extra_args=['--reconfigure', '-Db_ndebug=if-release', '-Dsub:b_ndebug=false', '-Dc_std=c99'])
285+
out = self.init(testdir, extra_args=['--reconfigure', '-Db_ndebug=if-release', '-Dsub:b_ndebug=false', '-Dc_std=c99', '-Dsub:c_std=c11'])
286286
self.assertIn('\nMessage: b_ndebug: if-release\n', out)
287287
self.assertIn('\nMessage: c_std: c99\n', out)
288+
self.assertIn('\nsub| Message: b_ndebug: false\n', out)
289+
self.assertIn('\nsub| Message: c_std: c11\n', out)
288290

289291
def test_setup_with_unknown_option(self):
290292
testdir = os.path.join(self.common_test_dir, '1 trivial')

0 commit comments

Comments
 (0)