diff options
-rw-r--r-- | data/macros.meson | 3 | ||||
-rw-r--r-- | mesonbuild/compilers.py | 75 | ||||
-rw-r--r-- | mesonbuild/coredata.py | 15 | ||||
-rw-r--r-- | mesonbuild/mconf.py | 3 | ||||
-rw-r--r-- | mesonbuild/mesonmain.py | 3 | ||||
-rw-r--r-- | mesonbuild/modules/gnome.py | 33 | ||||
-rw-r--r-- | mesonbuild/scripts/gettext.py | 4 | ||||
-rw-r--r-- | test cases/common/125 shared module/meson.build | 4 | ||||
-rw-r--r-- | test cases/common/37 has header/meson.build | 17 |
9 files changed, 96 insertions, 61 deletions
diff --git a/data/macros.meson b/data/macros.meson index 6d9fd59..b72bb85 100644 --- a/data/macros.meson +++ b/data/macros.meson @@ -12,12 +12,15 @@ --libdir=%{_libdir} \\\ --libexecdir=%{_libexecdir} \\\ --bindir=%{_bindir} \\\ + --sbindir=%{_sbindir} \\\ --includedir=%{_includedir} \\\ --datadir=%{_datadir} \\\ --mandir=%{_mandir} \\\ + --infodir=%{_infodir} \\\ --localedir=%{_datadir}/locale \\\ --sysconfdir=%{_sysconfdir} \\\ --localstatedir=%{_localstatedir} \\\ + --sharedstatedir=%{_sharedstatedir} \\\ %{_vpath_srcdir} %{_vpath_builddir} \\\ %{nil} diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index dcb4b69..e209378 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -452,11 +452,22 @@ class Compiler(): extra_flags += environment.cross_info.config['properties'].get(lang_link_args_key, []) return extra_flags + def _get_compile_output(self, dirname, mode): + # In pre-processor mode, the output is sent to stdout and discarded + if mode == 'preprocess': + return None + # Extension only matters if running results; '.exe' is + # guaranteed to be executable on every platform. + if mode == 'link': + suffix = 'exe' + else: + suffix = 'obj' + return os.path.join(dirname, 'output.' + suffix) + @contextlib.contextmanager - def compile(self, code, extra_args=None, compile_only=False): + def compile(self, code, extra_args=None, mode='link'): if extra_args is None: extra_args = [] - try: with tempfile.TemporaryDirectory() as tmpdirname: if isinstance(code, str): @@ -466,21 +477,20 @@ class Compiler(): ofile.write(code) elif isinstance(code, mesonlib.File): srcname = code.fname + output = self._get_compile_output(tmpdirname, mode) - # Extension only matters if running results; '.exe' is - # guaranteed to be executable on every platform. - if compile_only: - suffix = 'obj' - else: - suffix = 'exe' - output = os.path.join(tmpdirname, 'output.' + suffix) - + # Construct the compiler command-line commands = self.get_exelist() commands.append(srcname) commands += extra_args - commands += self.get_output_args(output) - if compile_only: + commands += self.get_always_args() + if mode == 'compile': commands += self.get_compile_only_args() + # Preprocess mode outputs to stdout, so no output args + if mode == 'preprocess': + commands += self.get_preprocess_only_args() + else: + commands += self.get_output_args(output) mlog.debug('Running compile:') mlog.debug('Working directory: ', tmpdirname) mlog.debug('Command line: ', ' '.join(commands), '\n') @@ -580,6 +590,9 @@ class CCompiler(Compiler): def get_linker_exelist(self): return self.exelist[:] + def get_preprocess_only_args(self): + return ['-E'] + def get_compile_only_args(self): return ['-c'] @@ -710,7 +723,7 @@ class CCompiler(Compiler): if extra_args is None: extra_args = [] code = '{}\n#include<{}>\nint someUselessSymbol;'.format(prefix, hname) - return self.compiles(code, env, extra_args, dependencies) + return self.compiles(code, env, extra_args, dependencies, 'preprocess') def has_header_symbol(self, hname, symbol, prefix, env, extra_args=None, dependencies=None): if extra_args is None: @@ -747,7 +760,7 @@ int main () {{ after_args.append(arg) return before_args + args + after_args - def compiles(self, code, env, extra_args=None, dependencies=None): + def compiles(self, code, env, extra_args=None, dependencies=None, mode='compile'): if extra_args is None: extra_args = [] if isinstance(extra_args, str): @@ -771,7 +784,7 @@ int main () {{ # Append both to the compiler args such that they override them args = self._override_args(args, extra_args) # We only want to compile; not link - with self.compile(code, args, compile_only=True) as p: + with self.compile(code, args, mode) as p: return p.returncode == 0 def _links_wrapper(self, code, env, extra_args, dependencies): @@ -1090,7 +1103,7 @@ void bar() { args = self.get_cross_extra_flags(env, compile=True, link=False) args += self.get_compiler_check_args() n = 'symbols_have_underscore_prefix' - with self.compile(code, args, compile_only=True) as p: + with self.compile(code, args, 'compile') as p: if p.returncode != 0: m = 'BUG: Unable to compile {!r} check: {}' raise RuntimeError(m.format(n, p.stdo)) @@ -1433,7 +1446,7 @@ class ValaCompiler(Compiler): def sanity_check(self, work_dir, environment): code = 'class MesonSanityCheck : Object { }' args = self.get_cross_extra_flags(environment, compile=True, link=False) - with self.compile(code, args, compile_only=True) as p: + with self.compile(code, args, 'compile') as p: if p.returncode != 0: msg = 'Vala compiler {!r} can not compile programs' \ ''.format(self.name_string()) @@ -1454,7 +1467,7 @@ class ValaCompiler(Compiler): vapi_args = ['--pkg', libname] args = self.get_cross_extra_flags(env, compile=True, link=False) args += vapi_args - with self.compile(code, args, compile_only=True) as p: + with self.compile(code, args, 'compile') as p: if p.returncode == 0: return vapi_args # Not found? Try to find the vapi file itself. @@ -1607,6 +1620,12 @@ class DCompiler(Compiler): def get_linker_exelist(self): return self.exelist[:] + def get_preprocess_only_args(self): + return ['-E'] + + def get_compile_only_args(self): + return ['-c'] + def depfile_for_object(self, objfile): return objfile + '.' + self.get_depfile_suffix() @@ -1689,9 +1708,6 @@ class GnuDCompiler(DCompiler): def get_output_args(self, target): return ['-o', target] - def get_compile_only_args(self): - return ['-c'] - def get_linker_output_args(self, target): return ['-o', target] @@ -1735,9 +1751,6 @@ class LLVMDCompiler(DCompiler): def get_output_args(self, target): return ['-of', target] - def get_compile_only_args(self): - return ['-c'] - def get_linker_output_args(self, target): return ['-of', target] @@ -1793,9 +1806,6 @@ class DmdDCompiler(DCompiler): def get_werror_args(self): return ['-w'] - def get_compile_only_args(self): - return ['-c'] - def get_linker_output_args(self, target): return ['-of' + target] @@ -1833,6 +1843,8 @@ class VisualStudioCCompiler(CCompiler): def __init__(self, exelist, version, is_cross, exe_wrap): CCompiler.__init__(self, exelist, version, is_cross, exe_wrap) self.id = 'msvc' + # /showIncludes is needed for build dependency tracking in Ninja + # See: https://ninja-build.org/manual.html#_deps self.always_args = ['/nologo', '/showIncludes'] self.warn_args = {'1': ['/W2'], '2': ['/W3'], @@ -1873,6 +1885,9 @@ class VisualStudioCCompiler(CCompiler): pchname = self.get_pch_name(header) return ['/FI' + base, '/Yu' + base, '/Fp' + os.path.join(pch_dir, pchname)] + def get_preprocess_only_args(self): + return ['/E'] + def get_compile_only_args(self): return ['/c'] @@ -1953,6 +1968,9 @@ class VisualStudioCCompiler(CCompiler): continue else: i = name + '.lib' + # -pthread in link flags is only used on Linux + elif i == '-pthread': + continue result.append(i) return result @@ -2436,6 +2454,9 @@ end program prog def get_output_args(self, target): return ['-o', target] + def get_preprocess_only_args(self): + return ['-E'] + def get_compile_only_args(self): return ['-c'] diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 1a5abcc..8db82fd 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -208,21 +208,24 @@ builtin_options = { 'libdir' : [ UserStringOption, 'Library directory.', default_libdir() ], 'libexecdir' : [ UserStringOption, 'Library executable directory.', default_libexecdir() ], 'bindir' : [ UserStringOption, 'Executable directory.', 'bin' ], + 'sbindir' : [ UserStringOption, 'System executable directory.', 'sbin' ], 'includedir' : [ UserStringOption, 'Header file directory.', 'include' ], 'datadir' : [ UserStringOption, 'Data file directory.', 'share' ], 'mandir' : [ UserStringOption, 'Manual page directory.', 'share/man' ], + 'infodir' : [ UserStringOption, 'Info page directory.', 'share/info' ], 'localedir' : [ UserStringOption, 'Locale data directory.', 'share/locale' ], - # sysconfdir and localstatedir are a bit special. These defaults to ${prefix}/etc and - # ${prefix}/var but nobody uses that. Instead they always set it manually to /etc and /var. - # This default values is thus pointless and not really used but we set it to this - # for consistency with other systems. + # sysconfdir, localstatedir and sharedstatedir are a bit special. These defaults to ${prefix}/etc, + # ${prefix}/var and ${prefix}/com but nobody uses that. Instead they always set it + # manually to /etc, /var and /var/lib. This default values is thus pointless and not really used + # but we set it to this for consistency with other systems. # - # Projects installing to sysconfdir and/or localstatedir probably want + # Projects installing to sysconfdir, localstatedir or sharedstatedir probably want # to set the following in project(): # - # default_options : ['sysconfdir=/etc', 'localstatedir=/var'] + # default_options : ['sysconfdir=/etc', 'localstatedir=/var', 'sharedstatedir=/var/lib'] 'sysconfdir' : [ UserStringOption, 'Sysconf data directory.', 'etc' ], 'localstatedir' : [ UserStringOption, 'Localstate data directory.', 'var' ], + 'sharedstatedir' : [ UserStringOption, 'Architecture-independent data directory.', 'com' ], 'werror' : [ UserBooleanOption, 'Treat warnings as errors.', False ], 'warning_level' : [ UserComboOption, 'Compiler warning level to use.', [ '1', '2', '3' ], '1'], 'layout' : [ UserComboOption, 'Build directory layout.', ['mirror', 'flat' ], 'mirror' ], diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py index 6061d48..2db4d37 100644 --- a/mesonbuild/mconf.py +++ b/mesonbuild/mconf.py @@ -169,12 +169,15 @@ class Conf: 'libdir', 'libexecdir', 'bindir', + 'sbindir', 'includedir', 'datadir', 'mandir', + 'infodir', 'localedir', 'sysconfdir', 'localstatedir', + 'sharedstatedir', ]: parr.append([key, coredata.get_builtin_option_description(key), self.coredata.get_builtin_option(key), coredata.get_builtin_option_choices(key)]) diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index 4f31496..3c644a8 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -41,12 +41,15 @@ add_builtin_argument('prefix') add_builtin_argument('libdir') add_builtin_argument('libexecdir') add_builtin_argument('bindir') +add_builtin_argument('sbindir') add_builtin_argument('includedir') add_builtin_argument('datadir') add_builtin_argument('mandir') +add_builtin_argument('infodir') add_builtin_argument('localedir') add_builtin_argument('sysconfdir') add_builtin_argument('localstatedir') +add_builtin_argument('sharedstatedir') add_builtin_argument('backend') add_builtin_argument('buildtype') add_builtin_argument('strip', action='store_true') diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index e291c98..7a3d51a 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -21,7 +21,7 @@ import sys import copy import subprocess from ..mesonlib import MesonException, Popen_safe -from .. import dependencies +from ..dependencies import Dependency, PkgConfigDependency, InternalDependency from .. import mlog from .. import mesonlib from .. import interpreter @@ -54,13 +54,14 @@ def gir_has_extra_lib_arg(): return _gir_has_extra_lib_arg class GnomeModule: + gir_dep = None @staticmethod def _get_native_glib_version(state): global native_glib_version if native_glib_version is None: - glib_dep = dependencies.PkgConfigDependency( - 'glib-2.0', state.environment, {'native': True}) + glib_dep = PkgConfigDependency('glib-2.0', state.environment, + {'native': True}) native_glib_version = glib_dep.get_modversion() return native_glib_version @@ -302,7 +303,7 @@ can not be used with the current version of glib-compiled-resources, due to for dep in deps: if hasattr(dep, 'held_object'): dep = dep.held_object - if isinstance(dep, dependencies.InternalDependency): + if isinstance(dep, InternalDependency): cflags.update(self._get_include_args(state, dep.include_directories)) for lib in dep.libraries: ldflags.update(self._get_link_args(state, lib.held_object, depends, include_rpath)) @@ -319,7 +320,7 @@ can not be used with the current version of glib-compiled-resources, due to gi_includes.update([os.path.join(state.environment.get_build_dir(), source.held_object.get_subdir())]) # This should be any dependency other than an internal one. - elif isinstance(dep, dependencies.Dependency): + elif isinstance(dep, Dependency): cflags.update(dep.get_compile_args()) for lib in dep.get_link_args(): if (os.path.isabs(lib) and @@ -341,7 +342,7 @@ can not be used with the current version of glib-compiled-resources, due to lib = lib.replace('-l', '--extra-library=') ldflags.update([lib]) - if isinstance(dep, dependencies.PkgConfigDependency): + if isinstance(dep, PkgConfigDependency): girdir = dep.get_pkgconfig_variable("girdir") if girdir: gi_includes.update([girdir]) @@ -367,9 +368,11 @@ can not be used with the current version of glib-compiled-resources, due to if not isinstance(girtarget, (build.Executable, build.SharedLibrary)): raise MesonException('Gir target must be an executable or shared library') try: - gir_dep = dependencies.PkgConfigDependency( - 'gobject-introspection-1.0', state.environment, {'native': True}) - pkgargs = gir_dep.get_compile_args() + if not self.gir_dep: + self.gir_dep = PkgConfigDependency('gobject-introspection-1.0', + state.environment, + {'native': True}) + pkgargs = self.gir_dep.get_compile_args() except Exception: global girwarning_printed if not girwarning_printed: @@ -470,7 +473,7 @@ can not be used with the current version of glib-compiled-resources, due to dep = dep.held_object # Add a dependency on each GirTarget listed in dependencies and add # the directory where it will be generated to the typelib includes - if isinstance(dep, dependencies.InternalDependency): + if isinstance(dep, InternalDependency): for source in dep.sources: if hasattr(source, 'held_object'): source = source.held_object @@ -492,7 +495,7 @@ can not be used with the current version of glib-compiled-resources, due to source.get_subdir()) if subdir not in typelib_includes: typelib_includes.append(subdir) - elif isinstance(dep, dependencies.PkgConfigDependency): + elif isinstance(dep, PkgConfigDependency): girdir = dep.get_pkgconfig_variable("girdir") if girdir and girdir not in typelib_includes: typelib_includes.append(girdir) @@ -972,7 +975,7 @@ can not be used with the current version of glib-compiled-resources, due to for arg in arg_list: if hasattr(arg, 'held_object'): arg = arg.held_object - if isinstance(arg, dependencies.InternalDependency): + if isinstance(arg, InternalDependency): targets = [t for t in arg.sources if isinstance(t, VapiTarget)] for target in targets: srcdir = os.path.join(state.environment.get_source_dir(), @@ -1075,11 +1078,9 @@ can not be used with the current version of glib-compiled-resources, due to # - link with with the correct library # - include the vapi and dependent vapi files in sources # - add relevant directories to include dirs - includes = [build.IncludeDirs(state.subdir, ['.'] + vapi_includes, False)] + incs = [build.IncludeDirs(state.subdir, ['.'] + vapi_includes, False)] sources = [vapi_target] + vapi_depends - return dependencies.InternalDependency( - None, includes, [], [], link_with, sources, [] - ) + return InternalDependency(None, incs, [], [], link_with, sources, []) def initialize(): return GnomeModule() diff --git a/mesonbuild/scripts/gettext.py b/mesonbuild/scripts/gettext.py index 8baf323..d463313 100644 --- a/mesonbuild/scripts/gettext.py +++ b/mesonbuild/scripts/gettext.py @@ -89,7 +89,9 @@ def run(args): subcmd = options.command langs = options.langs.split('@@') if options.langs else None extra_args = options.extra_args.split('@@') - subdir = os.environ.get('MESON_SUBDIR', options.subdir) + subdir = os.environ.get('MESON_SUBDIR', '') + if options.subdir: + subdir = options.subdir src_sub = os.path.join(os.environ['MESON_SOURCE_ROOT'], subdir) bld_sub = os.path.join(os.environ['MESON_BUILD_ROOT'], subdir) diff --git a/test cases/common/125 shared module/meson.build b/test cases/common/125 shared module/meson.build index ccb9c1a..6fd21c2 100644 --- a/test cases/common/125 shared module/meson.build +++ b/test cases/common/125 shared module/meson.build @@ -1,9 +1,5 @@ project('shared module', 'c') -if meson.backend().startswith('vs') - error('MESON_SKIP_TEST for some reason /FORCE does not work in the VS backend.') -endif - dl = meson.get_compiler('c').find_library('dl', required : false) l = shared_library('runtime', 'runtime.c') # Do NOT link the module with the runtime library. This diff --git a/test cases/common/37 has header/meson.build b/test cases/common/37 has header/meson.build index 4f9b94f..2f763ae 100644 --- a/test cases/common/37 has header/meson.build +++ b/test cases/common/37 has header/meson.build @@ -5,20 +5,23 @@ foreach comp : [meson.get_compiler('c'), meson.get_compiler('cpp')] error('Stdio missing.') endif - # stdio.h doesn't actually need stdlib.h, but I don't know any headers on - # UNIX/Linux that need other headers defined beforehand + # stdio.h doesn't actually need stdlib.h, but just test that setting the + # prefix does not result in an error. if not comp.has_header('stdio.h', prefix : '#include <stdlib.h>') error('Stdio missing.') endif - # XInput.h needs windows.h included beforehand. We only do this check on MSVC - # because MinGW often defines its own wrappers that pre-include windows.h + # XInput.h should not require type definitions from windows.h, but it does + # require macro definitions. Specifically, it requires an arch setting for + # VS2015 at least. + # We only do this check on MSVC because MinGW often defines its own wrappers + # that pre-include windows.h if comp.get_id() == 'msvc' if not comp.has_header('XInput.h', prefix : '#include <windows.h>') - error('XInput.h is missing on Windows') + error('XInput.h should not be missing on Windows') endif - if comp.has_header('XInput.h') - error('XInput.h needs windows.h') + if not comp.has_header('XInput.h', prefix : '#define _X86_') + error('XInput.h should not need windows.h') endif endif |