During reconfigure, show that no compiler was found, if compiler fails sanity check.

pull/11778/head
Volker Weißmann 2 years ago committed by Jussi Pakkanen
parent 8d81611114
commit 2699fd4b8a
  1. 2
      mesonbuild/ast/introspection.py
  2. 12
      mesonbuild/compilers/detect.py
  3. 1
      mesonbuild/coredata.py
  4. 9
      mesonbuild/interpreter/interpreter.py
  5. 2
      mesonbuild/modules/java.py
  6. 14
      unittests/allplatformstests.py

@ -181,7 +181,7 @@ class IntrospectionInterpreter(AstInterpreter):
lang = lang.lower()
if lang not in self.coredata.compilers[for_machine]:
try:
comp = detect_compiler_for(self.environment, lang, for_machine)
comp = detect_compiler_for(self.environment, lang, for_machine, True)
except mesonlib.MesonException:
# do we even care about introspecting this language?
if required:

@ -111,11 +111,15 @@ def compiler_from_language(env: 'Environment', lang: str, for_machine: MachineCh
}
return lang_map[lang](env, for_machine) if lang in lang_map else None
def detect_compiler_for(env: 'Environment', lang: str, for_machine: MachineChoice) -> T.Optional[Compiler]:
def detect_compiler_for(env: 'Environment', lang: str, for_machine: MachineChoice, skip_sanity_check: bool) -> T.Optional[Compiler]:
comp = compiler_from_language(env, lang, for_machine)
if comp is not None:
assert comp.for_machine == for_machine
env.coredata.process_new_compiler(lang, comp, env)
if comp is None:
return comp
assert comp.for_machine == for_machine
env.coredata.process_new_compiler(lang, comp, env)
if not skip_sanity_check:
comp.sanity_check(env.get_scratch_dir(), env)
env.coredata.compilers[comp.for_machine][lang] = comp
return comp

@ -918,7 +918,6 @@ class CoreData:
def process_new_compiler(self, lang: str, comp: 'Compiler', env: 'Environment') -> None:
from . import compilers
self.compilers[comp.for_machine][lang] = comp
self.add_compiler_options(comp.get_options(), lang, comp.for_machine, env)
enabled_opts: T.List[OptionKey] = []

@ -1491,13 +1491,12 @@ class Interpreter(InterpreterBase, HoldableObject):
comp = self.coredata.compilers[for_machine].get(lang)
if not comp:
try:
comp = compilers.detect_compiler_for(self.environment, lang, for_machine)
skip_sanity_check = self.should_skip_sanity_check(for_machine)
if skip_sanity_check:
mlog.log_once('Cross compiler sanity tests disabled via the cross file.')
comp = compilers.detect_compiler_for(self.environment, lang, for_machine, skip_sanity_check)
if comp is None:
raise InvalidArguments(f'Tried to use unknown language "{lang}".')
if self.should_skip_sanity_check(for_machine):
mlog.log_once('Cross compiler sanity tests disabled via the cross file.')
else:
comp.sanity_check(self.environment.get_scratch_dir(), self.environment)
except mesonlib.MesonException:
if not required:
mlog.log('Compiler for language',

@ -42,7 +42,7 @@ class JavaModule(NewExtensionModule):
def __get_java_compiler(self, state: ModuleState) -> Compiler:
if 'java' not in state.environment.coredata.compilers[MachineChoice.BUILD]:
detect_compiler_for(state.environment, 'java', MachineChoice.BUILD)
detect_compiler_for(state.environment, 'java', MachineChoice.BUILD, False)
return state.environment.coredata.compilers[MachineChoice.BUILD]['java']
@FeatureNew('java.generate_native_headers', '0.62.0')

@ -841,7 +841,7 @@ class AllPlatformTests(BasePlatformTests):
testdir = os.path.join("test cases/cython", '2 generated sources')
env = get_fake_env(testdir, self.builddir, self.prefix)
try:
detect_compiler_for(env, "cython", MachineChoice.HOST)
detect_compiler_for(env, "cython", MachineChoice.HOST, True)
except EnvironmentException:
raise SkipTest("Cython is not installed")
self.init(testdir)
@ -866,7 +866,7 @@ class AllPlatformTests(BasePlatformTests):
testdir = os.path.join("test cases/cython", '2 generated sources')
env = get_fake_env(testdir, self.builddir, self.prefix)
try:
cython = detect_compiler_for(env, "cython", MachineChoice.HOST)
cython = detect_compiler_for(env, "cython", MachineChoice.HOST, True)
if not version_compare(cython.version, '>=0.29.33'):
raise SkipTest('Cython is too old')
except EnvironmentException:
@ -2141,7 +2141,7 @@ class AllPlatformTests(BasePlatformTests):
env = get_fake_env()
for l in ['cpp', 'cs', 'd', 'java', 'cuda', 'fortran', 'objc', 'objcpp', 'rust']:
try:
comp = detect_compiler_for(env, l, MachineChoice.HOST)
comp = detect_compiler_for(env, l, MachineChoice.HOST, True)
with tempfile.TemporaryDirectory() as d:
comp.sanity_check(d, env)
langs.append(l)
@ -2158,7 +2158,7 @@ class AllPlatformTests(BasePlatformTests):
if is_windows() and lang == 'fortran' and target_type == 'library':
# non-Gfortran Windows Fortran compilers do not do shared libraries in a Fortran standard way
# see "test cases/fortran/6 dynamic"
fc = detect_compiler_for(env, 'fortran', MachineChoice.HOST)
fc = detect_compiler_for(env, 'fortran', MachineChoice.HOST, True)
if fc.get_id() in {'intel-cl', 'pgi'}:
continue
# test empty directory
@ -4177,18 +4177,18 @@ class AllPlatformTests(BasePlatformTests):
env = get_fake_env()
# Get the compiler so we know which compiler class to mock.
cc = detect_compiler_for(env, 'c', MachineChoice.HOST)
cc = detect_compiler_for(env, 'c', MachineChoice.HOST, True)
cc_type = type(cc)
# Test a compiler that acts as a linker
with mock.patch.object(cc_type, 'INVOKES_LINKER', True):
cc = detect_compiler_for(env, 'c', MachineChoice.HOST)
cc = detect_compiler_for(env, 'c', MachineChoice.HOST, True)
link_args = env.coredata.get_external_link_args(cc.for_machine, cc.language)
self.assertEqual(sorted(link_args), sorted(['-DCFLAG', '-flto']))
# And one that doesn't
with mock.patch.object(cc_type, 'INVOKES_LINKER', False):
cc = detect_compiler_for(env, 'c', MachineChoice.HOST)
cc = detect_compiler_for(env, 'c', MachineChoice.HOST, True)
link_args = env.coredata.get_external_link_args(cc.for_machine, cc.language)
self.assertEqual(sorted(link_args), sorted(['-flto']))

Loading…
Cancel
Save