aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2018-05-13 10:36:58 -0400
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2018-06-06 20:02:37 +0000
commitfa72cd7173c0e2798d622052ae3fcee2ad947c0b (patch)
treefff491a3f72dee0cd11a8564621da986042da948
parent6eeea9dd546e881ef9eb38f61a0a7a96d67a77fc (diff)
downloadmeson-fa72cd7173c0e2798d622052ae3fcee2ad947c0b.zip
meson-fa72cd7173c0e2798d622052ae3fcee2ad947c0b.tar.gz
meson-fa72cd7173c0e2798d622052ae3fcee2ad947c0b.tar.bz2
Move get_args_from_envvars() from environment to compilers
-rw-r--r--mesonbuild/compilers/compilers.py53
-rw-r--r--mesonbuild/environment.py53
-rw-r--r--mesonbuild/interpreter.py2
-rwxr-xr-xrun_unittests.py2
4 files changed, 54 insertions, 56 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 6a310ba..7ac0753 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import contextlib, os.path, re, tempfile
+import contextlib, os.path, re, tempfile, shlex
import subprocess
from ..linkers import StaticLinker
@@ -57,6 +57,15 @@ clike_suffixes += ('h', 'll', 's')
soregex = re.compile(r'.*\.so(\.[0-9]+)?(\.[0-9]+)?(\.[0-9]+)?$')
+# Environment variables that each lang uses.
+cflags_mapping = {'c': 'CFLAGS',
+ 'cpp': 'CXXFLAGS',
+ 'objc': 'OBJCFLAGS',
+ 'objcpp': 'OBJCXXFLAGS',
+ 'fortran': 'FFLAGS',
+ 'd': 'DFLAGS',
+ 'vala': 'VALAFLAGS'}
+
# All these are only for C-like languages; see `clike_langs` above.
def sort_clike(lang):
@@ -716,6 +725,48 @@ class Compiler:
"""
return []
+ def get_args_from_envvars(self):
+ """
+ Returns a tuple of (compile_flags, link_flags) for the specified language
+ from the inherited environment
+ """
+ def log_var(var, val):
+ if val:
+ mlog.log('Appending {} from environment: {!r}'.format(var, val))
+
+ lang = self.get_language()
+ compiler_is_linker = False
+ if hasattr(self, 'get_linker_exelist'):
+ compiler_is_linker = (self.get_exelist() == self.get_linker_exelist())
+
+ if lang not in cflags_mapping:
+ return [], [], []
+
+ compile_flags = os.environ.get(cflags_mapping[lang], '')
+ log_var(cflags_mapping[lang], compile_flags)
+ compile_flags = shlex.split(compile_flags)
+
+ # Link flags (same for all languages)
+ link_flags = os.environ.get('LDFLAGS', '')
+ log_var('LDFLAGS', link_flags)
+ link_flags = shlex.split(link_flags)
+ if compiler_is_linker:
+ # When the compiler is used as a wrapper around the linker (such as
+ # with GCC and Clang), the compile flags can be needed while linking
+ # too. This is also what Autotools does. However, we don't want to do
+ # this when the linker is stand-alone such as with MSVC C/C++, etc.
+ link_flags = compile_flags + link_flags
+
+ # Pre-processor flags (not for fortran or D)
+ preproc_flags = ''
+ if lang in ('c', 'cpp', 'objc', 'objcpp'):
+ preproc_flags = os.environ.get('CPPFLAGS', '')
+ log_var('CPPFLAGS', preproc_flags)
+ preproc_flags = shlex.split(preproc_flags)
+ compile_flags += preproc_flags
+
+ return preproc_flags, compile_flags, link_flags
+
def get_options(self):
return {} # build afresh every time
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 2453f51..fb1e070 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -72,15 +72,6 @@ from .compilers import (
build_filename = 'meson.build'
-# Environment variables that each lang uses.
-cflags_mapping = {'c': 'CFLAGS',
- 'cpp': 'CXXFLAGS',
- 'objc': 'OBJCFLAGS',
- 'objcpp': 'OBJCXXFLAGS',
- 'fortran': 'FFLAGS',
- 'd': 'DFLAGS',
- 'vala': 'VALAFLAGS'}
-
def detect_gcovr(version='3.1', log=False):
gcovr_exe = 'gcovr'
try:
@@ -952,50 +943,6 @@ class Environment:
out = out.split('\n')[index].lstrip('libraries: =').split(':')
return [os.path.normpath(p) for p in out]
-def get_args_from_envvars(compiler):
- """
- @compiler: Compiler to fetch environment flags for
-
- Returns a tuple of (compile_flags, link_flags) for the specified language
- from the inherited environment
- """
- def log_var(var, val):
- if val:
- mlog.log('Appending {} from environment: {!r}'.format(var, val))
-
- lang = compiler.get_language()
- compiler_is_linker = False
- if hasattr(compiler, 'get_linker_exelist'):
- compiler_is_linker = (compiler.get_exelist() == compiler.get_linker_exelist())
-
- if lang not in cflags_mapping:
- return [], [], []
-
- compile_flags = os.environ.get(cflags_mapping[lang], '')
- log_var(cflags_mapping[lang], compile_flags)
- compile_flags = shlex.split(compile_flags)
-
- # Link flags (same for all languages)
- link_flags = os.environ.get('LDFLAGS', '')
- log_var('LDFLAGS', link_flags)
- link_flags = shlex.split(link_flags)
- if compiler_is_linker:
- # When the compiler is used as a wrapper around the linker (such as
- # with GCC and Clang), the compile flags can be needed while linking
- # too. This is also what Autotools does. However, we don't want to do
- # this when the linker is stand-alone such as with MSVC C/C++, etc.
- link_flags = compile_flags + link_flags
-
- # Pre-processor flags (not for fortran or D)
- preproc_flags = ''
- if lang in ('c', 'cpp', 'objc', 'objcpp'):
- preproc_flags = os.environ.get('CPPFLAGS', '')
- log_var('CPPFLAGS', preproc_flags)
- preproc_flags = shlex.split(preproc_flags)
- compile_flags += preproc_flags
-
- return preproc_flags, compile_flags, link_flags
-
class CrossBuildInfo:
def __init__(self, filename):
self.config = {'properties': {}}
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index cd608db..dcd54a3 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -2471,7 +2471,7 @@ to directly access options of other subprojects.''')
# If <language>_args/_link_args settings are given on the
# command line, use them, otherwise take them from env.
- (preproc_args, compile_args, link_args) = environment.get_args_from_envvars(comp)
+ (preproc_args, compile_args, link_args) = comp.get_args_from_envvars()
for optspec in self.build.environment.cmd_line_options.projectoptions:
(optname, optvalue) = optspec.split('=', maxsplit=1)
if optname == lang + '_link_args':
diff --git a/run_unittests.py b/run_unittests.py
index 1400db7..79799ea 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -3427,7 +3427,7 @@ def unset_envs():
# For unit tests we must fully control all command lines
# so that there are no unexpected changes coming from the
# environment, for example when doing a package build.
- varnames = ['CPPFLAGS', 'LDFLAGS'] + list(mesonbuild.environment.cflags_mapping.values())
+ varnames = ['CPPFLAGS', 'LDFLAGS'] + list(mesonbuild.compilers.compilers.cflags_mapping.values())
for v in varnames:
if v in os.environ:
del os.environ[v]