def get_fake_env(sdir='', bdir=None, prefix='', opts=None): if opts is None: opts = get_fake_options(prefix) env = Environment(sdir, bdir, opts) env.coredata.options[OptionKey('args', lang='c')] = FakeCompilerOptions() env.machines.host.cpu_family = 'x86_64' # Used on macOS inside find_library return env
def test_qt5dependency_vscrt(self): ''' Test that qt5 dependencies use the debug module suffix when b_vscrt is set to 'mdd' ''' # Verify that the `b_vscrt` option is available env = get_fake_env() cc = detect_c_compiler(env, MachineChoice.HOST) if OptionKey('b_vscrt') not in cc.base_options: raise SkipTest('Compiler does not support setting the VS CRT') # Verify that qmake is for Qt5 if not shutil.which('qmake-qt5'): if not shutil.which('qmake') and not is_ci(): raise SkipTest('QMake not found') output = subprocess.getoutput('qmake --version') if 'Qt version 5' not in output and not is_ci(): raise SkipTest('Qmake found, but it is not for Qt 5.') # Setup with /MDd testdir = os.path.join(self.framework_test_dir, '4 qt') self.init(testdir, extra_args=['-Db_vscrt=mdd']) # Verify that we're linking to the debug versions of Qt DLLs build_ninja = os.path.join(self.builddir, 'build.ninja') with open(build_ninja, encoding='utf-8') as f: contents = f.read() m = re.search('build qt5core.exe: cpp_LINKER.*Qt5Cored.lib', contents) self.assertIsNotNone(m, msg=contents)
def get_options(self) -> 'KeyedOptionDictType': opts = FortranCompiler.get_options(self) key = OptionKey('std', machine=self.for_machine, lang=self.language) opts[key].choices = [ 'none', 'legacy', 'f95', 'f2003', 'f2008', 'f2018' ] return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args = [] key = OptionKey('std', machine=self.for_machine, lang=self.language) std = options[key] if std.value != 'none': args.append('-std=' + std.value) return args
def wrapped(*args, **kwargs): env = get_fake_env() cc = detect_c_compiler(env, MachineChoice.HOST) key = OptionKey(feature) if key not in cc.base_options: raise unittest.SkipTest( f'{feature} not available with {cc.id}') return f(*args, **kwargs)
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args = [] key = OptionKey('std', machine=self.for_machine, lang=self.language) std = options[key] stds = {'legacy': 'none', 'f95': 'f95', 'f2003': 'f03', 'f2008': 'f08', 'f2018': 'f18'} if std.value != 'none': args.append('/stand:' + stds[std.value]) return args
def get_options(self) -> 'KeyedOptionDictType': opts = FortranCompiler.get_options(self) fortran_stds = ['legacy', 'f95', 'f2003'] if version_compare(self.version, '>=4.4.0'): fortran_stds += ['f2008'] if version_compare(self.version, '>=8.0.0'): fortran_stds += ['f2018'] key = OptionKey('std', machine=self.for_machine, lang=self.language) opts[key].choices = ['none'] + fortran_stds return opts
def get_options(self) -> 'KeyedOptionDictType': opts = super().get_options() key = OptionKey('std', machine=self.for_machine, lang=self.language) opts.update({ key: coredata.UserComboOption( 'Fortran language standard to use', ['none'], 'none', ), }) return opts
def configure(self, build_for_testing): self.build_for_testing = build_for_testing meson_options = {} if os.path.exists("meson_options.txt"): meson_options = self._parse_options("meson_options.txt") meson_flags = [ '-Db_colorout=never', '-Dwerror=true', '-Dwarning_level=3', ] if build_for_testing: meson_flags.append('--buildtype=debug') else: meson_flags.append('--buildtype=debugoptimized') if OptionKey('tests') in meson_options: meson_flags.append( self._configure_option(meson_options, OptionKey('tests'), build_for_testing)) if OptionKey('examples') in meson_options: meson_flags.append( self._configure_option(meson_options, OptionKey('examples'), build_for_testing)) if OptionKey('itests') in meson_options: meson_flags.append( self._configure_option(meson_options, OptionKey('itests'), INTEGRATION_TEST)) if MESON_FLAGS.get(self.package) is not None: meson_flags.extend(MESON_FLAGS.get(self.package)) try: check_call_cmd('meson', 'setup', '--reconfigure', 'build', *meson_flags) except: shutil.rmtree('build') check_call_cmd('meson', 'setup', 'build', *meson_flags)
def test_compiler_checks_vscrt(self): ''' Test that the correct VS CRT is used when running compiler checks ''' # Verify that the `b_vscrt` option is available env = get_fake_env() cc = detect_c_compiler(env, MachineChoice.HOST) if OptionKey('b_vscrt') not in cc.base_options: raise SkipTest('Compiler does not support setting the VS CRT') def sanitycheck_vscrt(vscrt): checks = self.get_meson_log_sanitychecks() self.assertTrue(len(checks) > 0) for check in checks: self.assertIn(vscrt, check) testdir = os.path.join(self.common_test_dir, '1 trivial') self.init(testdir) sanitycheck_vscrt('/MDd') self.new_builddir() self.init(testdir, extra_args=['-Dbuildtype=debugoptimized']) sanitycheck_vscrt('/MD') self.new_builddir() self.init(testdir, extra_args=['-Dbuildtype=release']) sanitycheck_vscrt('/MD') self.new_builddir() self.init(testdir, extra_args=['-Db_vscrt=md']) sanitycheck_vscrt('/MD') self.new_builddir() self.init(testdir, extra_args=['-Db_vscrt=mdd']) sanitycheck_vscrt('/MDd') self.new_builddir() self.init(testdir, extra_args=['-Db_vscrt=mt']) sanitycheck_vscrt('/MT') self.new_builddir() self.init(testdir, extra_args=['-Db_vscrt=mtd']) sanitycheck_vscrt('/MTd')
def get_options(self) -> 'MutableKeyedOptionDictType': opts = FortranCompiler.get_options(self) fortran_stds = ['f95', 'f2003', 'f2008', 'gnu', 'legacy', 'f2008ts'] key = OptionKey('std', machine=self.for_machine, lang=self.language) opts[key].choices = ['none'] + fortran_stds return opts
def test_builtin_options_documented(self): ''' Test that universal options and base options are documented in Builtin-Options.md. ''' from itertools import tee md = None with open('docs/markdown/Builtin-options.md', encoding='utf-8') as f: md = f.read() self.assertIsNotNone(md) found_entries = set() sections = re.finditer(r"^## (.+)$", md, re.MULTILINE) # Extract the content for this section content = self._get_section_content("Universal options", sections, md) subsections = tee(re.finditer(r"^### (.+)$", content, re.MULTILINE)) subcontent1 = self._get_section_content("Directories", subsections[0], content) subcontent2 = self._get_section_content("Core options", subsections[1], content) subcontent3 = self._get_section_content("Module options", sections, md) for subcontent in (subcontent1, subcontent2, subcontent3): # Find the option names options = set() # Match either a table row or a table heading separator: | ------ | rows = re.finditer(r"^\|(?: (\w+) .* | *-+ *)\|", subcontent, re.MULTILINE) # Skip the header of the first table next(rows) # Skip the heading separator of the first table next(rows) for m in rows: value = m.group(1) # End when the `buildtype` table starts if value is None: break options.add(value) self.assertEqual(len(found_entries & options), 0) found_entries |= options self.assertEqual(found_entries, { *(str(k.evolve(module=None)) for k in mesonbuild.coredata.BUILTIN_OPTIONS), *(str(k.evolve(module=None)) for k in mesonbuild.coredata.BUILTIN_OPTIONS_PER_MACHINE), }) # Check that `buildtype` table inside `Core options` matches how # setting of builtin options behaves # # Find all tables inside this subsection tables = re.finditer(r"^\| (\w+) .* \|\n\| *[-|\s]+ *\|$", subcontent2, re.MULTILINE) # Get the table we want using the header of the first column table = self._get_section_content('buildtype', tables, subcontent2) # Get table row data rows = re.finditer(r"^\|(?: (\w+)\s+\| (\w+)\s+\| (\w+) .* | *-+ *)\|", table, re.MULTILINE) env = get_fake_env() for m in rows: buildtype, debug, opt = m.groups() if debug == 'true': debug = True elif debug == 'false': debug = False else: raise RuntimeError(f'Invalid debug value {debug!r} in row:\n{m.group()}') env.coredata.set_option(OptionKey('buildtype'), buildtype) self.assertEqual(env.coredata.options[OptionKey('buildtype')].value, buildtype) self.assertEqual(env.coredata.options[OptionKey('optimization')].value, opt) self.assertEqual(env.coredata.options[OptionKey('debug')].value, debug)