Merge pull request #4626 from Ericson2314/consolidate-properties

Go through coreutils.compiler_options.{build.host.target}
pull/4883/head
Jussi Pakkanen 6 years ago committed by GitHub
commit 902aaf2ce6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      mesonbuild/backend/backends.py
  2. 13
      mesonbuild/backend/ninjabackend.py
  3. 26
      mesonbuild/backend/vs2010backend.py
  4. 22
      mesonbuild/compilers/c.py
  5. 15
      mesonbuild/compilers/compilers.py
  6. 1
      mesonbuild/compilers/cs.py
  7. 13
      mesonbuild/compilers/d.py
  8. 1
      mesonbuild/compilers/java.py
  9. 88
      mesonbuild/coredata.py
  10. 21
      mesonbuild/environment.py
  11. 13
      mesonbuild/interpreter.py
  12. 6
      mesonbuild/mconf.py
  13. 3
      mesonbuild/mintro.py
  14. 21
      mesonbuild/modules/gnome.py
  15. 2
      run_tests.py
  16. 10
      run_unittests.py

@ -20,7 +20,7 @@ from .. import mesonlib
from .. import mlog from .. import mlog
import json import json
import subprocess import subprocess
from ..mesonlib import MesonException, OrderedSet from ..mesonlib import MachineChoice, MesonException, OrderedSet
from ..mesonlib import classify_unity_sources from ..mesonlib import classify_unity_sources
from ..mesonlib import File from ..mesonlib import File
from ..compilers import CompilerArgs, VisualStudioCCompiler from ..compilers import CompilerArgs, VisualStudioCCompiler
@ -185,9 +185,14 @@ class Backend:
self.environment.coredata.base_options) self.environment.coredata.base_options)
def get_compiler_options_for_target(self, target): def get_compiler_options_for_target(self, target):
return OptionOverrideProxy(target.option_overrides, if self.environment.is_cross_build() and not target.is_cross:
# no code depends on builtins for now for_machine = MachineChoice.BUILD
self.environment.coredata.compiler_options) else:
for_machine = MachineChoice.HOST
return OptionOverrideProxy(
target.option_overrides,
self.environment.coredata.compiler_options[for_machine])
def get_option_for_target(self, option_name, target): def get_option_for_target(self, option_name, target):
if option_name in target.option_overrides: if option_name in target.option_overrides:
@ -574,10 +579,14 @@ class Backend:
# Add compile args added using add_global_arguments() # Add compile args added using add_global_arguments()
# These override per-project arguments # These override per-project arguments
commands += self.build.get_global_args(compiler, target.is_cross) commands += self.build.get_global_args(compiler, target.is_cross)
if self.environment.is_cross_build() and not target.is_cross:
for_machine = MachineChoice.BUILD
else:
for_machine = MachineChoice.HOST
if not target.is_cross: if not target.is_cross:
# Compile args added from the env: CFLAGS/CXXFLAGS, etc. We want these # Compile args added from the env: CFLAGS/CXXFLAGS, etc. We want these
# to override all the defaults, but not the per-target compile args. # to override all the defaults, but not the per-target compile args.
commands += self.environment.coredata.get_external_args(compiler.get_language()) commands += self.environment.coredata.get_external_args(for_machine, compiler.get_language())
# Always set -fPIC for shared libraries # Always set -fPIC for shared libraries
if isinstance(target, build.SharedLibrary): if isinstance(target, build.SharedLibrary):
commands += compiler.get_pic_args() commands += compiler.get_pic_args()

@ -31,7 +31,7 @@ from .. import dependencies
from .. import compilers from .. import compilers
from ..compilers import CompilerArgs, CCompiler, VisualStudioCCompiler from ..compilers import CompilerArgs, CCompiler, VisualStudioCCompiler
from ..linkers import ArLinker from ..linkers import ArLinker
from ..mesonlib import File, MesonException, OrderedSet from ..mesonlib import File, MachineChoice, MesonException, OrderedSet
from ..mesonlib import get_compiler_for_source, has_path_sep from ..mesonlib import get_compiler_for_source, has_path_sep
from .backends import CleanTrees from .backends import CleanTrees
from ..build import InvalidArguments from ..build import InvalidArguments
@ -1460,7 +1460,7 @@ int dummy;
or langname == 'cs': or langname == 'cs':
continue continue
crstr = '' crstr = ''
cross_args = self.environment.properties.host.get_external_link_args(langname) cross_args = self.environment.coredata.get_external_link_args(MachineChoice.HOST, langname)
if is_cross: if is_cross:
crstr = '_CROSS' crstr = '_CROSS'
rule = 'rule %s%s_LINKER\n' % (langname, crstr) rule = 'rule %s%s_LINKER\n' % (langname, crstr)
@ -2467,6 +2467,11 @@ rule FORTRAN_DEP_HACK%s
if not isinstance(target, build.StaticLibrary): if not isinstance(target, build.StaticLibrary):
commands += self.get_link_whole_args(linker, target) commands += self.get_link_whole_args(linker, target)
if self.environment.is_cross_build() and not target.is_cross:
for_machine = MachineChoice.BUILD
else:
for_machine = MachineChoice.HOST
if not isinstance(target, build.StaticLibrary): if not isinstance(target, build.StaticLibrary):
# Add link args added using add_project_link_arguments() # Add link args added using add_project_link_arguments()
commands += self.build.get_project_link_args(linker, target.subproject, target.is_cross) commands += self.build.get_project_link_args(linker, target.subproject, target.is_cross)
@ -2476,7 +2481,7 @@ rule FORTRAN_DEP_HACK%s
if not target.is_cross: if not target.is_cross:
# Link args added from the env: LDFLAGS. We want these to # Link args added from the env: LDFLAGS. We want these to
# override all the defaults but not the per-target link args. # override all the defaults but not the per-target link args.
commands += self.environment.coredata.get_external_link_args(linker.get_language()) commands += self.environment.coredata.get_external_link_args(for_machine, linker.get_language())
# Now we will add libraries and library paths from various sources # Now we will add libraries and library paths from various sources
@ -2522,7 +2527,7 @@ rule FORTRAN_DEP_HACK%s
# to be after all internal and external libraries so that unresolved # to be after all internal and external libraries so that unresolved
# symbols from those can be found here. This is needed when the # symbols from those can be found here. This is needed when the
# *_winlibs that we want to link to are static mingw64 libraries. # *_winlibs that we want to link to are static mingw64 libraries.
commands += linker.get_option_link_args(self.environment.coredata.compiler_options) commands += linker.get_option_link_args(self.environment.coredata.compiler_options[for_machine])
dep_targets = [] dep_targets = []
dep_targets.extend(self.guess_external_link_dependencies(linker, target, commands, internal)) dep_targets.extend(self.guess_external_link_dependencies(linker, target, commands, internal))

@ -25,7 +25,9 @@ from .. import dependencies
from .. import mlog from .. import mlog
from .. import compilers from .. import compilers
from ..compilers import CompilerArgs from ..compilers import CompilerArgs
from ..mesonlib import MesonException, File, python_command, replace_if_different from ..mesonlib import (
MesonException, MachineChoice, File, python_command, replace_if_different
)
from ..environment import Environment, build_filename from ..environment import Environment, build_filename
def autodetect_vs_version(build): def autodetect_vs_version(build):
@ -878,10 +880,14 @@ class Vs2010Backend(backends.Backend):
file_inc_dirs = dict((lang, []) for lang in target.compilers) file_inc_dirs = dict((lang, []) for lang in target.compilers)
# The order in which these compile args are added must match # The order in which these compile args are added must match
# generate_single_compile() and generate_basic_compiler_args() # generate_single_compile() and generate_basic_compiler_args()
if self.environment.is_cross_build() and not target.is_cross:
for_machine = MachineChoice.BUILD
else:
for_machine = MachineChoice.HOST
for l, comp in target.compilers.items(): for l, comp in target.compilers.items():
if l in file_args: if l in file_args:
file_args[l] += compilers.get_base_compile_args(self.get_base_options_for_target(target), comp) 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) file_args[l] += comp.get_option_compile_args(self.environment.coredata.compiler_options[for_machine])
# Add compile args added using add_project_arguments() # Add compile args added using add_project_arguments()
for l, args in self.build.projects_args.get(target.subproject, {}).items(): for l, args in self.build.projects_args.get(target.subproject, {}).items():
@ -893,9 +899,10 @@ class Vs2010Backend(backends.Backend):
if l in file_args: if l in file_args:
file_args[l] += args file_args[l] += args
if not target.is_cross: if not target.is_cross:
# Compile args added from the env: CFLAGS/CXXFLAGS, etc. We want these # Compile args added from the env or cross file: CFLAGS/CXXFLAGS,
# to override all the defaults, but not the per-target compile args. # etc. We want these to override all the defaults, but not the
for key, opt in self.environment.coredata.compiler_options.items(): # per-target compile args.
for key, opt in self.environment.coredata.compiler_options[for_machine].items():
l, suffix = key.split('_', 1) l, suffix = key.split('_', 1)
if suffix == 'args' and l in file_args: if suffix == 'args' and l in file_args:
file_args[l] += opt.value file_args[l] += opt.value
@ -1054,9 +1061,10 @@ class Vs2010Backend(backends.Backend):
# These override per-project link arguments # These override per-project link arguments
extra_link_args += self.build.get_global_link_args(compiler, target.is_cross) extra_link_args += self.build.get_global_link_args(compiler, target.is_cross)
if not target.is_cross: if not target.is_cross:
# Link args added from the env: LDFLAGS. We want these to # Link args added from the env: LDFLAGS, or the cross file. We
# override all the defaults but not the per-target link args. # want these to override all the defaults but not the
extra_link_args += self.environment.coredata.get_external_link_args(compiler.get_language()) # per-target link args.
extra_link_args += self.environment.coredata.get_external_link_args(for_machine, compiler.get_language())
# Only non-static built targets need link args and link dependencies # Only non-static built targets need link args and link dependencies
extra_link_args += target.link_args extra_link_args += target.link_args
# External deps must be last because target link libraries may depend on them. # External deps must be last because target link libraries may depend on them.
@ -1079,7 +1087,7 @@ class Vs2010Backend(backends.Backend):
# to be after all internal and external libraries so that unresolved # to be after all internal and external libraries so that unresolved
# symbols from those can be found here. This is needed when the # symbols from those can be found here. This is needed when the
# *_winlibs that we want to link to are static mingw64 libraries. # *_winlibs that we want to link to are static mingw64 libraries.
extra_link_args += compiler.get_option_link_args(self.environment.coredata.compiler_options) extra_link_args += compiler.get_option_link_args(self.environment.coredata.compiler_options[for_machine])
(additional_libpaths, additional_links, extra_link_args) = self.split_link_args(extra_link_args.to_native()) (additional_libpaths, additional_links, extra_link_args) = self.split_link_args(extra_link_args.to_native())
# Add more libraries to be linked if needed # Add more libraries to be linked if needed

@ -25,9 +25,9 @@ from .. import mlog
from .. import coredata from .. import coredata
from . import compilers from . import compilers
from ..mesonlib import ( from ..mesonlib import (
EnvironmentException, MesonException, version_compare, Popen_safe, listify, EnvironmentException, MachineChoice, MesonException, Popen_safe, listify,
for_windows, for_darwin, for_cygwin, for_haiku, for_openbsd, version_compare, for_windows, for_darwin, for_cygwin, for_haiku,
darwin_get_object_archs for_openbsd, darwin_get_object_archs
) )
from .c_function_attributes import C_FUNC_ATTRIBUTES from .c_function_attributes import C_FUNC_ATTRIBUTES
@ -427,12 +427,16 @@ class CCompiler(Compiler):
# Read c_args/cpp_args/etc from the cross-info file (if needed) # Read c_args/cpp_args/etc from the cross-info file (if needed)
args += self.get_cross_extra_flags(env, link=(mode == 'link')) args += self.get_cross_extra_flags(env, link=(mode == 'link'))
if not self.is_cross: if not self.is_cross:
if env.is_cross_build() and not self.is_cross:
for_machine = MachineChoice.BUILD
else:
for_machine = MachineChoice.HOST
if mode == 'preprocess': if mode == 'preprocess':
# Add CPPFLAGS from the env. # Add CPPFLAGS from the env.
args += env.coredata.get_external_preprocess_args(self.language) args += env.coredata.get_external_preprocess_args(for_machine, self.language)
elif mode == 'compile': elif mode == 'compile':
# Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
sys_args = env.coredata.get_external_args(self.language) sys_args = env.coredata.get_external_args(for_machine, self.language)
# Apparently it is a thing to inject linker flags both # Apparently it is a thing to inject linker flags both
# via CFLAGS _and_ LDFLAGS, even though the former are # via CFLAGS _and_ LDFLAGS, even though the former are
# also used during linking. These flags can break # also used during linking. These flags can break
@ -441,7 +445,7 @@ class CCompiler(Compiler):
args += cleaned_sys_args args += cleaned_sys_args
elif mode == 'link': elif mode == 'link':
# Add LDFLAGS from the env # Add LDFLAGS from the env
args += env.coredata.get_external_link_args(self.language) args += env.coredata.get_external_link_args(for_machine, self.language)
args += self.get_compiler_check_args() args += self.get_compiler_check_args()
# extra_args must override all other arguments, so we add them last # extra_args must override all other arguments, so we add them last
args += extra_args args += extra_args
@ -1081,7 +1085,11 @@ class CCompiler(Compiler):
commands = self.get_exelist() + ['-v', '-E', '-'] commands = self.get_exelist() + ['-v', '-E', '-']
commands += self.get_always_args() commands += self.get_always_args()
# Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
commands += env.coredata.get_external_args(self.language) if env.is_cross_build() and not self.is_cross:
for_machine = MachineChoice.BUILD
else:
for_machine = MachineChoice.HOST
commands += env.coredata.get_external_args(for_machine, self.language)
mlog.debug('Finding framework path by running: ', ' '.join(commands), '\n') mlog.debug('Finding framework path by running: ', ' '.join(commands), '\n')
os_env = os.environ.copy() os_env = os.environ.copy()
os_env['LC_ALL'] = 'C' os_env['LC_ALL'] = 'C'

@ -21,8 +21,8 @@ from .. import coredata
from .. import mlog from .. import mlog
from .. import mesonlib from .. import mesonlib
from ..mesonlib import ( from ..mesonlib import (
EnvironmentException, MesonException, OrderedSet, version_compare, EnvironmentException, MachineChoice, MesonException, OrderedSet,
Popen_safe version_compare, Popen_safe
) )
"""This file contains the data files of all compilers Meson knows """This file contains the data files of all compilers Meson knows
@ -1011,7 +1011,11 @@ class Compiler:
opts = {} # build afresh every time opts = {} # build afresh every time
# Take default values from env variables. # Take default values from env variables.
compile_args, link_args = self.get_args_from_envvars() if not self.is_cross:
compile_args, link_args = self.get_args_from_envvars()
else:
compile_args = []
link_args = []
description = 'Extra arguments passed to the {}'.format(self.get_display_language()) description = 'Extra arguments passed to the {}'.format(self.get_display_language())
opts.update({ opts.update({
self.language + '_args': coredata.UserArrayOption( self.language + '_args': coredata.UserArrayOption(
@ -1083,10 +1087,9 @@ class Compiler:
def get_cross_extra_flags(self, environment, link): def get_cross_extra_flags(self, environment, link):
extra_flags = [] extra_flags = []
if self.is_cross and environment: if self.is_cross and environment:
props = environment.properties.host extra_flags += environment.coredata.get_external_args(MachineChoice.HOST, self.language)
extra_flags += props.get_external_args(self.language)
if link: if link:
extra_flags += props.get_external_link_args(self.language) extra_flags += environment.coredata.get_external_link_args(MachineChoice.HOST, self.language)
return extra_flags return extra_flags
def _get_compile_output(self, dirname, mode): def _get_compile_output(self, dirname, mode):

@ -32,6 +32,7 @@ class CsCompiler(Compiler):
self.language = 'cs' self.language = 'cs'
super().__init__(exelist, version) super().__init__(exelist, version)
self.id = id self.id = id
self.is_cross = False
self.runner = runner self.runner = runner
def get_display_language(self): def get_display_language(self):

@ -14,7 +14,9 @@
import os.path, subprocess import os.path, subprocess
from ..mesonlib import EnvironmentException, version_compare, is_windows, is_osx from ..mesonlib import (
EnvironmentException, MachineChoice, version_compare, is_windows, is_osx
)
from .compilers import ( from .compilers import (
CompilerType, CompilerType,
@ -306,12 +308,17 @@ class DCompiler(Compiler):
# Add link flags needed to find dependencies # Add link flags needed to find dependencies
args += d.get_link_args() args += d.get_link_args()
if env.is_cross_build() and not self.is_cross:
for_machine = MachineChoice.BUILD
else:
for_machine = MachineChoice.HOST
if mode == 'compile': if mode == 'compile':
# Add DFLAGS from the env # Add DFLAGS from the env
args += env.coredata.get_external_args(self.language) args += env.coredata.get_external_args(for_machine, self.language)
elif mode == 'link': elif mode == 'link':
# Add LDFLAGS from the env # Add LDFLAGS from the env
args += env.coredata.get_external_link_args(self.language) args += env.coredata.get_external_link_args(for_machine, self.language)
# extra_args must override all other arguments, so we add them last # extra_args must override all other arguments, so we add them last
args += extra_args args += extra_args
return args return args

@ -23,6 +23,7 @@ class JavaCompiler(Compiler):
self.language = 'java' self.language = 'java'
super().__init__(exelist, version) super().__init__(exelist, version)
self.id = 'unknown' self.id = 'unknown'
self.is_cross = False
self.javarunner = 'java' self.javarunner = 'java'
def get_soname_args(self, *args): def get_soname_args(self, *args):

@ -19,7 +19,8 @@ from itertools import chain
from pathlib import PurePath from pathlib import PurePath
from collections import OrderedDict from collections import OrderedDict
from .mesonlib import ( from .mesonlib import (
MesonException, default_libdir, default_libexecdir, default_prefix MesonException, MachineChoice, PerMachine,
default_libdir, default_libexecdir, default_prefix
) )
from .wrap import WrapMode from .wrap import WrapMode
import ast import ast
@ -261,9 +262,9 @@ class CoreData:
self.init_builtins() self.init_builtins()
self.backend_options = {} self.backend_options = {}
self.user_options = {} self.user_options = {}
self.compiler_options = {} self.compiler_options = PerMachine({}, {}, {})
self.base_options = {} self.base_options = {}
self.external_preprocess_args = {} # CPPFLAGS only self.external_preprocess_args = PerMachine({}, {}, {}) # CPPFLAGS only
self.cross_file = self.__load_cross_file(options.cross_file) self.cross_file = self.__load_cross_file(options.cross_file)
self.compilers = OrderedDict() self.compilers = OrderedDict()
self.cross_compilers = OrderedDict() self.cross_compilers = OrderedDict()
@ -457,16 +458,18 @@ class CoreData:
mode = 'custom' mode = 'custom'
self.builtins['buildtype'].set_value(mode) self.builtins['buildtype'].set_value(mode)
def get_all_compiler_options(self):
# TODO think about cross and command-line interface. (Only .build is mentioned here.)
yield self.compiler_options.build
def _get_all_nonbuiltin_options(self): def _get_all_nonbuiltin_options(self):
yield self.backend_options yield self.backend_options
yield self.user_options yield self.user_options
yield self.compiler_options yield from self.get_all_compiler_options()
yield self.base_options yield self.base_options
def get_all_options(self): def get_all_options(self):
return chain( return chain([self.builtins], self._get_all_nonbuiltin_options())
iter([self.builtins]),
self._get_all_nonbuiltin_options())
def validate_option_value(self, option_name, override_value): def validate_option_value(self, option_name, override_value):
for opts in self.get_all_options(): for opts in self.get_all_options():
@ -475,14 +478,14 @@ class CoreData:
return opt.validate_value(override_value) return opt.validate_value(override_value)
raise MesonException('Tried to validate unknown option %s.' % option_name) raise MesonException('Tried to validate unknown option %s.' % option_name)
def get_external_args(self, lang): def get_external_args(self, for_machine: MachineChoice, lang):
return self.compiler_options[lang + '_args'].value return self.compiler_options[for_machine][lang + '_args'].value
def get_external_link_args(self, lang): def get_external_link_args(self, for_machine: MachineChoice, lang):
return self.compiler_options[lang + '_link_args'].value return self.compiler_options[for_machine][lang + '_link_args'].value
def get_external_preprocess_args(self, lang): def get_external_preprocess_args(self, for_machine: MachineChoice, lang):
return self.external_preprocess_args[lang] return self.external_preprocess_args[for_machine][lang]
def merge_user_options(self, options): def merge_user_options(self, options):
for (name, value) in options.items(): for (name, value) in options.items():
@ -493,7 +496,7 @@ class CoreData:
if type(oldval) != type(value): if type(oldval) != type(value):
self.user_options[name] = value self.user_options[name] = value
def set_options(self, options, subproject=''): def set_options(self, options, subproject='', warn_unknown=True):
# Set prefix first because it's needed to sanitize other options # Set prefix first because it's needed to sanitize other options
prefix = self.builtins['prefix'].value prefix = self.builtins['prefix'].value
if 'prefix' in options: if 'prefix' in options:
@ -517,8 +520,7 @@ class CoreData:
break break
else: else:
unknown_options.append(k) unknown_options.append(k)
if unknown_options and warn_unknown:
if unknown_options:
unknown_options = ', '.join(sorted(unknown_options)) unknown_options = ', '.join(sorted(unknown_options))
sub = 'In subproject {}: '.format(subproject) if subproject else '' sub = 'In subproject {}: '.format(subproject) if subproject else ''
mlog.warning('{}Unknown options: "{}"'.format(sub, unknown_options)) mlog.warning('{}Unknown options: "{}"'.format(sub, unknown_options))
@ -553,36 +555,54 @@ class CoreData:
self.set_options(options, subproject) self.set_options(options, subproject)
def process_new_compilers(self, lang: str, comp, cross_comp, cmd_line_options): def process_new_compilers(self, lang: str, comp, cross_comp, env):
from . import compilers from . import compilers
self.compilers[lang] = comp self.compilers[lang] = comp
# Native compiler always exist so always add its options.
new_options = comp.get_options()
if cross_comp is not None: if cross_comp is not None:
self.cross_compilers[lang] = cross_comp self.cross_compilers[lang] = cross_comp
new_options.update(cross_comp.get_options())
# Native compiler always exist so always add its options.
new_options_for_build = comp.get_options()
preproc_flags_for_build = comp.get_preproc_flags()
if cross_comp is not None:
new_options_for_host = cross_comp.get_options()
preproc_flags_for_host = cross_comp.get_preproc_flags()
else:
new_options_for_host = comp.get_options()
preproc_flags_for_host = comp.get_preproc_flags()
opts_machines_list = [
(new_options_for_build, preproc_flags_for_build, MachineChoice.BUILD),
(new_options_for_host, preproc_flags_for_host, MachineChoice.HOST),
]
optprefix = lang + '_' optprefix = lang + '_'
for k, o in new_options.items(): for new_options, preproc_flags, for_machine in opts_machines_list:
if not k.startswith(optprefix): for k, o in new_options.items():
raise MesonException('Internal error, %s has incorrect prefix.' % k) if not k.startswith(optprefix):
if k in cmd_line_options: raise MesonException('Internal error, %s has incorrect prefix.' % k)
o.set_value(cmd_line_options[k]) if k in env.properties[for_machine]:
self.compiler_options.setdefault(k, o) # Get from configuration files.
o.set_value(env.properties[for_machine][k])
# Unlike compiler and linker flags, preprocessor flags are not in if (env.machines.matches_build_machine(for_machine) and
# compiler_options because they are not visible to user. k in env.cmd_line_options):
preproc_flags = comp.get_preproc_flags() # TODO think about cross and command-line interface.
preproc_flags = shlex.split(preproc_flags) o.set_value(env.cmd_line_options[k])
self.external_preprocess_args.setdefault(lang, preproc_flags) self.compiler_options[for_machine].setdefault(k, o)
# Unlike compiler and linker flags, preprocessor flags are not in
# compiler_options because they are not visible to user.
preproc_flags = shlex.split(preproc_flags)
self.external_preprocess_args[for_machine].setdefault(lang, preproc_flags)
enabled_opts = [] enabled_opts = []
for optname in comp.base_options: for optname in comp.base_options:
if optname in self.base_options: if optname in self.base_options:
continue continue
oobj = compilers.base_options[optname] oobj = compilers.base_options[optname]
if optname in cmd_line_options: if optname in env.cmd_line_options:
oobj.set_value(cmd_line_options[optname]) oobj.set_value(env.cmd_line_options[optname])
enabled_opts.append(optname) enabled_opts.append(optname)
self.base_options[optname] = oobj self.base_options[optname] = oobj
self.emit_base_options_warnings(enabled_opts) self.emit_base_options_warnings(enabled_opts)

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import configparser, os, platform, re, sys, shlex, shutil, subprocess import configparser, os, platform, re, sys, shlex, shutil, subprocess, typing
from . import coredata from . import coredata
from .linkers import ArLinker, ArmarLinker, VisualStudioLinker, DLinker, CcrxLinker from .linkers import ArLinker, ArmarLinker, VisualStudioLinker, DLinker, CcrxLinker
@ -1101,7 +1101,7 @@ class Environment:
def detect_compilers(self, lang: str, need_cross_compiler: bool): def detect_compilers(self, lang: str, need_cross_compiler: bool):
(comp, cross_comp) = self.compilers_from_language(lang, need_cross_compiler) (comp, cross_comp) = self.compilers_from_language(lang, need_cross_compiler)
if comp is not None: if comp is not None:
self.coredata.process_new_compilers(lang, comp, cross_comp, self.cmd_line_options) self.coredata.process_new_compilers(lang, comp, cross_comp, self)
return comp, cross_comp return comp, cross_comp
def detect_static_linker(self, compiler): def detect_static_linker(self, compiler):
@ -1283,14 +1283,10 @@ class MesonConfigFile:
return out return out
class Properties: class Properties:
def __init__(self): def __init__(
self.properties = {} self,
properties: typing.Optional[typing.Dict[str, typing.Union[str, typing.List[str]]]] = None):
def get_external_args(self, language): self.properties = properties or {}
return mesonlib.stringlistify(self.properties.get(language + '_args', []))
def get_external_link_args(self, language):
return mesonlib.stringlistify(self.properties.get(language + '_link_args', []))
def has_stdlib(self, language): def has_stdlib(self, language):
return language + '_stdlib' in self.properties return language + '_stdlib' in self.properties
@ -1304,6 +1300,11 @@ class Properties:
def get_sys_root(self): def get_sys_root(self):
return self.properties.get('sys_root', None) return self.properties.get('sys_root', None)
def __eq__(self, other):
if isinstance(other, type(self)):
return self.properties == other.properties
return NotImplemented
# TODO consider removing so Properties is less freeform # TODO consider removing so Properties is less freeform
def __getitem__(self, key): def __getitem__(self, key):
return self.properties[key] return self.properties[key]

@ -36,6 +36,7 @@ import os, shutil, uuid
import re, shlex import re, shlex
import subprocess import subprocess
from collections import namedtuple from collections import namedtuple
from itertools import chain
from pathlib import PurePath from pathlib import PurePath
import functools import functools
@ -998,8 +999,13 @@ class CompilerHolder(InterpreterObject):
idir = os.path.join(self.environment.get_source_dir(), idir = os.path.join(self.environment.get_source_dir(),
i.held_object.get_curdir(), idir) i.held_object.get_curdir(), idir)
args += self.compiler.get_include_args(idir, False) args += self.compiler.get_include_args(idir, False)
native = kwargs.get('native', None)
if native:
for_machine = MachineChoice.BUILD
else:
for_machine = MachineChoice.HOST
if not nobuiltins: if not nobuiltins:
opts = self.environment.coredata.compiler_options opts = self.environment.coredata.compiler_options[for_machine]
args += self.compiler.get_option_compile_args(opts) args += self.compiler.get_option_compile_args(opts)
if mode == 'link': if mode == 'link':
args += self.compiler.get_option_link_args(opts) args += self.compiler.get_option_link_args(opts)
@ -2454,8 +2460,9 @@ external dependencies (including libraries) must go to "dependencies".''')
def get_option_internal(self, optname): def get_option_internal(self, optname):
# Some base options are not defined in some environments, return the # Some base options are not defined in some environments, return the
# default value from compilers.base_options in that case. # default value from compilers.base_options in that case.
for d in [self.coredata.base_options, compilers.base_options, for d in chain(
self.coredata.builtins, self.coredata.compiler_options]: [self.coredata.base_options, compilers.base_options, self.coredata.builtins],
self.coredata.get_all_compiler_options()):
try: try:
return d[optname] return d[optname]
except KeyError: except KeyError:

@ -139,7 +139,8 @@ class Conf:
self.print_options('Core options', core_options) self.print_options('Core options', core_options)
self.print_options('Backend options', self.coredata.backend_options) self.print_options('Backend options', self.coredata.backend_options)
self.print_options('Base options', self.coredata.base_options) self.print_options('Base options', self.coredata.base_options)
self.print_options('Compiler options', self.coredata.compiler_options) # TODO others
self.print_options('Compiler options', self.coredata.compiler_options.build)
self.print_options('Directories', dir_options) self.print_options('Directories', dir_options)
self.print_options('Project options', self.coredata.user_options) self.print_options('Project options', self.coredata.user_options)
self.print_options('Testing options', test_options) self.print_options('Testing options', test_options)
@ -154,6 +155,9 @@ def run(options):
save = False save = False
if len(options.cmd_line_options) > 0: if len(options.cmd_line_options) > 0:
c.set_options(options.cmd_line_options) c.set_options(options.cmd_line_options)
if not c.build.environment.is_cross_build():
# TODO think about cross and command-line interface.
c.coredata.compiler_options.host = c.coredata.compiler_options.build
coredata.update_cmd_line_file(builddir, options) coredata.update_cmd_line_file(builddir, options)
save = True save = True
elif options.clearcache: elif options.clearcache:

@ -204,7 +204,8 @@ def list_buildoptions(coredata: cdata.CoreData):
add_keys(optlist, core_options, 'core') add_keys(optlist, core_options, 'core')
add_keys(optlist, coredata.backend_options, 'backend') add_keys(optlist, coredata.backend_options, 'backend')
add_keys(optlist, coredata.base_options, 'base') add_keys(optlist, coredata.base_options, 'base')
add_keys(optlist, coredata.compiler_options, 'compiler') # TODO others
add_keys(optlist, coredata.compiler_options.build, 'compiler')
add_keys(optlist, dir_options, 'directory') add_keys(optlist, dir_options, 'directory')
add_keys(optlist, coredata.user_options, 'user') add_keys(optlist, coredata.user_options, 'user')
add_keys(optlist, test_options, 'test') add_keys(optlist, test_options, 'test')

@ -31,7 +31,9 @@ from . import GResourceTarget, GResourceHeaderTarget, GResourceObjectTarget, Gir
from . import get_include_args from . import get_include_args
from . import ExtensionModule from . import ExtensionModule
from . import ModuleReturnValue from . import ModuleReturnValue
from ..mesonlib import MesonException, OrderedSet, Popen_safe, extract_as_list from ..mesonlib import (
MachineChoice, MesonException, OrderedSet, Popen_safe, extract_as_list
)
from ..dependencies import Dependency, PkgConfigDependency, InternalDependency from ..dependencies import Dependency, PkgConfigDependency, InternalDependency
from ..interpreterbase import noKwargs, permittedKwargs, FeatureNew, FeatureNewKwargs from ..interpreterbase import noKwargs, permittedKwargs, FeatureNew, FeatureNewKwargs
@ -660,11 +662,7 @@ class GnomeModule(ExtensionModule):
ret = [] ret = []
for lang in langs: for lang in langs:
if state.environment.is_cross_build(): link_args = state.environment.coredata.get_external_link_args(MachineChoice.HOST, lang)
link_args = state.environment.properties.host.get_external_link_args(lang)
else:
link_args = state.environment.coredata.get_external_link_args(lang)
for link_arg in link_args: for link_arg in link_args:
if link_arg.startswith('-L'): if link_arg.startswith('-L'):
ret.append(link_arg) ret.append(link_arg)
@ -849,10 +847,7 @@ class GnomeModule(ExtensionModule):
def _get_external_args_for_langs(self, state, langs): def _get_external_args_for_langs(self, state, langs):
ret = [] ret = []
for lang in langs: for lang in langs:
if state.environment.is_cross_build(): ret += state.environment.coredata.get_external_args(MachineChoice.HOST, lang)
ret += state.environment.properties.host.get_external_args(lang)
else:
ret += state.environment.coredata.get_external_args(lang)
return ret return ret
@staticmethod @staticmethod
@ -1177,13 +1172,11 @@ This will become a hard error in the future.''')
ldflags.update(internal_ldflags) ldflags.update(internal_ldflags)
ldflags.update(external_ldflags) ldflags.update(external_ldflags)
cflags.update(state.environment.coredata.get_external_args(MachineChoice.HOST, 'c'))
ldflags.update(state.environment.coredata.get_external_link_args(MachineChoice.HOST, 'c'))
if state.environment.is_cross_build(): if state.environment.is_cross_build():
cflags.update(state.environment.properties.host.get_external_args('c'))
ldflags.update(state.environment.properties.host.get_external_link_args('c'))
compiler = state.environment.coredata.cross_compilers.get('c') compiler = state.environment.coredata.cross_compilers.get('c')
else: else:
cflags.update(state.environment.coredata.get_external_args('c'))
ldflags.update(state.environment.coredata.get_external_link_args('c'))
compiler = state.environment.coredata.compilers.get('c') compiler = state.environment.coredata.compilers.get('c')
compiler_flags = self._get_langs_compilers_flags(state, [('c', compiler)]) compiler_flags = self._get_langs_compilers_flags(state, [('c', compiler)])

@ -80,7 +80,7 @@ def get_fake_env(sdir='', bdir=None, prefix='', opts=None):
if opts is None: if opts is None:
opts = get_fake_options(prefix) opts = get_fake_options(prefix)
env = Environment(sdir, bdir, opts) env = Environment(sdir, bdir, opts)
env.coredata.compiler_options['c_args'] = FakeCompilerOptions() env.coredata.compiler_options.host['c_args'] = FakeCompilerOptions()
env.machines.host.cpu_family = 'x86_64' # Used on macOS inside find_library env.machines.host.cpu_family = 'x86_64' # Used on macOS inside find_library
return env return env

@ -798,7 +798,7 @@ class InternalTests(unittest.TestCase):
env = get_fake_env() env = get_fake_env()
compiler = env.detect_c_compiler(False) compiler = env.detect_c_compiler(False)
env.coredata.compilers = {'c': compiler} env.coredata.compilers = {'c': compiler}
env.coredata.compiler_options['c_link_args'] = FakeCompilerOptions() env.coredata.compiler_options.host['c_link_args'] = FakeCompilerOptions()
p1 = Path(tmpdir) / '1' p1 = Path(tmpdir) / '1'
p2 = Path(tmpdir) / '2' p2 = Path(tmpdir) / '2'
p1.mkdir() p1.mkdir()
@ -2937,10 +2937,10 @@ recommended as it is not supported on some platforms''')
# c_args value should be parsed with shlex # c_args value should be parsed with shlex
self.init(testdir, extra_args=['-Dc_args=foo bar "one two"']) self.init(testdir, extra_args=['-Dc_args=foo bar "one two"'])
obj = mesonbuild.coredata.load(self.builddir) obj = mesonbuild.coredata.load(self.builddir)
self.assertEqual(obj.compiler_options['c_args'].value, ['foo', 'bar', 'one two']) self.assertEqual(obj.compiler_options.host['c_args'].value, ['foo', 'bar', 'one two'])
self.setconf('-Dc_args="foo bar" one two') self.setconf('-Dc_args="foo bar" one two')
obj = mesonbuild.coredata.load(self.builddir) obj = mesonbuild.coredata.load(self.builddir)
self.assertEqual(obj.compiler_options['c_args'].value, ['foo bar', 'one', 'two']) self.assertEqual(obj.compiler_options.host['c_args'].value, ['foo bar', 'one', 'two'])
self.wipe() self.wipe()
# Setting a 2nd time the same option should override the first value # Setting a 2nd time the same option should override the first value
@ -2953,7 +2953,7 @@ recommended as it is not supported on some platforms''')
self.assertEqual(obj.builtins['bindir'].value, 'bar') self.assertEqual(obj.builtins['bindir'].value, 'bar')
self.assertEqual(obj.builtins['buildtype'].value, 'release') self.assertEqual(obj.builtins['buildtype'].value, 'release')
self.assertEqual(obj.base_options['b_sanitize'].value, 'thread') self.assertEqual(obj.base_options['b_sanitize'].value, 'thread')
self.assertEqual(obj.compiler_options['c_args'].value, ['bar']) self.assertEqual(obj.compiler_options.host['c_args'].value, ['bar'])
self.setconf(['--bindir=bar', '--bindir=foo', self.setconf(['--bindir=bar', '--bindir=foo',
'-Dbuildtype=release', '-Dbuildtype=plain', '-Dbuildtype=release', '-Dbuildtype=plain',
'-Db_sanitize=thread', '-Db_sanitize=address', '-Db_sanitize=thread', '-Db_sanitize=address',
@ -2962,7 +2962,7 @@ recommended as it is not supported on some platforms''')
self.assertEqual(obj.builtins['bindir'].value, 'foo') self.assertEqual(obj.builtins['bindir'].value, 'foo')
self.assertEqual(obj.builtins['buildtype'].value, 'plain') self.assertEqual(obj.builtins['buildtype'].value, 'plain')
self.assertEqual(obj.base_options['b_sanitize'].value, 'address') self.assertEqual(obj.base_options['b_sanitize'].value, 'address')
self.assertEqual(obj.compiler_options['c_args'].value, ['foo']) self.assertEqual(obj.compiler_options.host['c_args'].value, ['foo'])
self.wipe() self.wipe()
except KeyError: except KeyError:
# Ignore KeyError, it happens on CI for compilers that does not # Ignore KeyError, it happens on CI for compilers that does not

Loading…
Cancel
Save