Skip to content

Commit

Permalink
Merge pull request #4626 from Ericson2314/consolidate-properties
Browse files Browse the repository at this point in the history
Go through coreutils.compiler_options.{build.host.target}
  • Loading branch information
jpakkane authored Feb 4, 2019
2 parents 59791fc + 19f81d3 commit 902aaf2
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 103 deletions.
19 changes: 14 additions & 5 deletions mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .. import mlog
import json
import subprocess
from ..mesonlib import MesonException, OrderedSet
from ..mesonlib import MachineChoice, MesonException, OrderedSet
from ..mesonlib import classify_unity_sources
from ..mesonlib import File
from ..compilers import CompilerArgs, VisualStudioCCompiler
Expand Down Expand Up @@ -185,9 +185,14 @@ def get_base_options_for_target(self, target):
self.environment.coredata.base_options)

def get_compiler_options_for_target(self, target):
return OptionOverrideProxy(target.option_overrides,
# no code depends on builtins for now
self.environment.coredata.compiler_options)
if self.environment.is_cross_build() and not target.is_cross:
for_machine = MachineChoice.BUILD
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):
if option_name in target.option_overrides:
Expand Down Expand Up @@ -574,10 +579,14 @@ def generate_basic_compiler_args(self, target, compiler, no_warn_args=False):
# Add compile args added using add_global_arguments()
# These override per-project arguments
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:
# Compile args added from the env: CFLAGS/CXXFLAGS, etc. We want these
# 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
if isinstance(target, build.SharedLibrary):
commands += compiler.get_pic_args()
Expand Down
13 changes: 9 additions & 4 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from .. import compilers
from ..compilers import CompilerArgs, CCompiler, VisualStudioCCompiler
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 .backends import CleanTrees
from ..build import InvalidArguments
Expand Down Expand Up @@ -1460,7 +1460,7 @@ def generate_dynamic_link_rules(self, outfile):
or langname == 'cs':
continue
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:
crstr = '_CROSS'
rule = 'rule %s%s_LINKER\n' % (langname, crstr)
Expand Down Expand Up @@ -2467,6 +2467,11 @@ def generate_link(self, target, outfile, outname, obj_list, linker, extra_args=[
if not isinstance(target, build.StaticLibrary):
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):
# Add link args added using add_project_link_arguments()
commands += self.build.get_project_link_args(linker, target.subproject, target.is_cross)
Expand All @@ -2476,7 +2481,7 @@ def generate_link(self, target, outfile, outname, obj_list, linker, extra_args=[
if not target.is_cross:
# Link args added from the env: LDFLAGS. We want these to
# 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

Expand Down Expand Up @@ -2522,7 +2527,7 @@ def generate_link(self, target, outfile, outname, obj_list, linker, extra_args=[
# to be after all internal and external libraries so that unresolved
# symbols from those can be found here. This is needed when the
# *_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.extend(self.guess_external_link_dependencies(linker, target, commands, internal))
Expand Down
26 changes: 17 additions & 9 deletions mesonbuild/backend/vs2010backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
from .. import mlog
from .. import compilers
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

def autodetect_vs_version(build):
Expand Down Expand Up @@ -878,10 +880,14 @@ def gen_vcxproj(self, target, ofname, guid):
file_inc_dirs = dict((lang, []) for lang in target.compilers)
# The order in which these compile args are added must match
# 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():
if l in file_args:
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()
for l, args in self.build.projects_args.get(target.subproject, {}).items():
Expand All @@ -893,9 +899,10 @@ def gen_vcxproj(self, target, ofname, guid):
if l in file_args:
file_args[l] += args
if not target.is_cross:
# Compile args added from the env: CFLAGS/CXXFLAGS, etc. We want these
# to override all the defaults, but not the per-target compile args.
for key, opt in self.environment.coredata.compiler_options.items():
# Compile args added from the env or cross file: CFLAGS/CXXFLAGS,
# etc. We want these to override all the defaults, but not the
# per-target compile args.
for key, opt in self.environment.coredata.compiler_options[for_machine].items():
l, suffix = key.split('_', 1)
if suffix == 'args' and l in file_args:
file_args[l] += opt.value
Expand Down Expand Up @@ -1054,9 +1061,10 @@ def gen_vcxproj(self, target, ofname, guid):
# These override per-project link arguments
extra_link_args += self.build.get_global_link_args(compiler, target.is_cross)
if not target.is_cross:
# Link args added from the env: LDFLAGS. We want these to
# override all the defaults but not the per-target link args.
extra_link_args += self.environment.coredata.get_external_link_args(compiler.get_language())
# Link args added from the env: LDFLAGS, or the cross file. We
# want these to override all the defaults but not the
# 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
extra_link_args += target.link_args
# External deps must be last because target link libraries may depend on them.
Expand All @@ -1079,7 +1087,7 @@ def gen_vcxproj(self, target, ofname, guid):
# to be after all internal and external libraries so that unresolved
# symbols from those can be found here. This is needed when the
# *_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())

# Add more libraries to be linked if needed
Expand Down
22 changes: 15 additions & 7 deletions mesonbuild/compilers/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
from .. import coredata
from . import compilers
from ..mesonlib import (
EnvironmentException, MesonException, version_compare, Popen_safe, listify,
for_windows, for_darwin, for_cygwin, for_haiku, for_openbsd,
darwin_get_object_archs
EnvironmentException, MachineChoice, MesonException, Popen_safe, listify,
version_compare, for_windows, for_darwin, for_cygwin, for_haiku,
for_openbsd, darwin_get_object_archs
)
from .c_function_attributes import C_FUNC_ATTRIBUTES

Expand Down Expand Up @@ -427,12 +427,16 @@ def _get_compiler_check_args(self, env, extra_args, dependencies, mode='compile'
# Read c_args/cpp_args/etc from the cross-info file (if needed)
args += self.get_cross_extra_flags(env, link=(mode == 'link'))
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':
# 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':
# 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
# via CFLAGS _and_ LDFLAGS, even though the former are
# also used during linking. These flags can break
Expand All @@ -441,7 +445,7 @@ def _get_compiler_check_args(self, env, extra_args, dependencies, mode='compile'
args += cleaned_sys_args
elif mode == 'link':
# 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()
# extra_args must override all other arguments, so we add them last
args += extra_args
Expand Down Expand Up @@ -1081,7 +1085,11 @@ def find_framework_paths(self, env):
commands = self.get_exelist() + ['-v', '-E', '-']
commands += self.get_always_args()
# 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')
os_env = os.environ.copy()
os_env['LC_ALL'] = 'C'
Expand Down
15 changes: 9 additions & 6 deletions mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from .. import mlog
from .. import mesonlib
from ..mesonlib import (
EnvironmentException, MesonException, OrderedSet, version_compare,
Popen_safe
EnvironmentException, MachineChoice, MesonException, OrderedSet,
version_compare, Popen_safe
)

"""This file contains the data files of all compilers Meson knows
Expand Down Expand Up @@ -1011,7 +1011,11 @@ def get_options(self):
opts = {} # build afresh every time

# 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())
opts.update({
self.language + '_args': coredata.UserArrayOption(
Expand Down Expand Up @@ -1083,10 +1087,9 @@ def has_multi_link_arguments(self, args, env):
def get_cross_extra_flags(self, environment, link):
extra_flags = []
if self.is_cross and environment:
props = environment.properties.host
extra_flags += props.get_external_args(self.language)
extra_flags += environment.coredata.get_external_args(MachineChoice.HOST, self.language)
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

def _get_compile_output(self, dirname, mode):
Expand Down
1 change: 1 addition & 0 deletions mesonbuild/compilers/cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, exelist, version, id, runner=None):
self.language = 'cs'
super().__init__(exelist, version)
self.id = id
self.is_cross = False
self.runner = runner

def get_display_language(self):
Expand Down
13 changes: 10 additions & 3 deletions mesonbuild/compilers/d.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

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 (
CompilerType,
Expand Down Expand Up @@ -306,12 +308,17 @@ def _get_compiler_check_args(self, env, extra_args, dependencies, mode='compile'
# Add link flags needed to find dependencies
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':
# 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':
# 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
args += extra_args
return args
Expand Down
1 change: 1 addition & 0 deletions mesonbuild/compilers/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(self, exelist, version):
self.language = 'java'
super().__init__(exelist, version)
self.id = 'unknown'
self.is_cross = False
self.javarunner = 'java'

def get_soname_args(self, *args):
Expand Down
Loading

0 comments on commit 902aaf2

Please sign in to comment.