aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/backend/backends.py7
-rw-r--r--mesonbuild/backend/ninjabackend.py7
-rw-r--r--mesonbuild/backend/vs2010backend.py18
-rw-r--r--mesonbuild/compilers.py19
-rwxr-xr-xrun_tests.py7
-rwxr-xr-xrun_unittests.py21
6 files changed, 55 insertions, 24 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index a95294b..75974a5 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -405,9 +405,10 @@ class Backend:
# Add compile args added using add_global_arguments()
# These override per-project arguments
commands += self.build.get_global_args(compiler)
- # 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.external_args[compiler.get_language()]
+ 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.external_args[compiler.get_language()]
# Always set -fPIC for shared libraries
if isinstance(target, build.SharedLibrary):
commands += compiler.get_pic_args()
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 4b12da6..e12678d 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -2267,9 +2267,10 @@ rule FORTRAN_DEP_HACK
# Add link args added using add_global_link_arguments()
# These override per-project link arguments
commands += self.build.get_global_link_args(linker)
- # 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.external_link_args[linker.get_language()]
+ 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.external_link_args[linker.get_language()]
# Now we will add libraries and library paths from various sources
diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py
index f97ab87..082f3c5 100644
--- a/mesonbuild/backend/vs2010backend.py
+++ b/mesonbuild/backend/vs2010backend.py
@@ -759,11 +759,12 @@ class Vs2010Backend(backends.Backend):
for l, args in self.build.global_args.items():
if l in file_args:
file_args[l] += args
- # 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 l, args in self.environment.coredata.external_args.items():
- 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 l, args in self.environment.coredata.external_args.items():
+ if l in file_args:
+ file_args[l] += args
for args in file_args.values():
# This is where Visual Studio will insert target_args, target_defines,
# etc, which are added later from external deps (see below).
@@ -901,9 +902,10 @@ class Vs2010Backend(backends.Backend):
# Add link args added using add_global_link_arguments()
# These override per-project link arguments
extra_link_args += self.build.get_global_link_args(compiler)
- # 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.external_link_args[compiler.get_language()]
+ 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.external_link_args[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.
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index 97a1064..86ed2f4 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -956,15 +956,16 @@ class CCompiler(Compiler):
args += self.get_linker_debug_crt_args()
# Read c_args/cpp_args/etc from the cross-info file (if needed)
args += self.get_cross_extra_flags(env, link=(mode == 'link'))
- if mode == 'preprocess':
- # Add CPPFLAGS from the env.
- args += env.coredata.external_preprocess_args[self.language]
- elif mode == 'compile':
- # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
- args += env.coredata.external_args[self.language]
- elif mode == 'link':
- # Add LDFLAGS from the env
- args += env.coredata.external_link_args[self.language]
+ if not self.is_cross:
+ if mode == 'preprocess':
+ # Add CPPFLAGS from the env.
+ args += env.coredata.external_preprocess_args[self.language]
+ elif mode == 'compile':
+ # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
+ args += env.coredata.external_args[self.language]
+ elif mode == 'link':
+ # Add LDFLAGS from the env
+ args += env.coredata.external_link_args[self.language]
args += self.get_compiler_check_args()
# extra_args must override all other arguments, so we add them last
args += extra_args
diff --git a/run_tests.py b/run_tests.py
index a374839..7ef9cf4 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -114,6 +114,9 @@ def get_fake_options(prefix):
opts.prefix = prefix
return opts
+def should_run_linux_cross_tests():
+ return shutil.which('arm-linux-gnueabihf-gcc-6') and not platform.machine().startswith('arm')
+
class FakeEnvironment(object):
def __init__(self):
self.cross_info = None
@@ -154,6 +157,8 @@ if __name__ == '__main__':
units = ['InternalTests', 'AllPlatformTests']
if mesonlib.is_linux():
units += ['LinuxlikeTests']
+ if should_run_linux_cross_tests():
+ units += ['LinuxArmCrossCompileTests']
elif mesonlib.is_windows():
units += ['WindowsTests']
# Can't pass arguments to unit tests, so set the backend to use in the environment
@@ -161,7 +166,7 @@ if __name__ == '__main__':
env['MESON_UNIT_TEST_BACKEND'] = backend.name
returncode += subprocess.call([sys.executable, 'run_unittests.py', '-v'] + units, env=env)
# Ubuntu packages do not have a binary without -6 suffix.
- if shutil.which('arm-linux-gnueabihf-gcc-6') and not platform.machine().startswith('arm'):
+ if should_run_linux_cross_tests():
print('Running cross compilation tests.\n')
returncode += subprocess.call([sys.executable, 'run_cross_test.py', 'cross/ubuntu-armhf.txt'])
returncode += subprocess.call([sys.executable, 'run_project_tests.py'] + sys.argv[1:])
diff --git a/run_unittests.py b/run_unittests.py
index 85474e8..e3b7c5c 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -1540,6 +1540,27 @@ class LinuxlikeTests(BasePlatformTests):
env['LD_LIBRARY_PATH'] = installed_libdir
self.assertEqual(subprocess.call(installed_exe, env=env), 0)
+class LinuxArmCrossCompileTests(BasePlatformTests):
+ '''
+ Tests that verify cross-compilation to Linux/ARM
+ '''
+ def setUp(self):
+ super().setUp()
+ src_root = os.path.dirname(__file__)
+ self.meson_command += ['--cross=' + os.path.join(src_root, 'cross', 'ubuntu-armhf.txt')]
+
+ def test_cflags_cross_environment_pollution(self):
+ '''
+ Test that the CFLAGS environment variable does not pollute the cross
+ environment. This can't be an ordinary test case because we need to
+ inspect the compiler database.
+ '''
+ testdir = os.path.join(self.common_test_dir, '3 static')
+ os.environ['CFLAGS'] = '-DBUILD_ENVIRONMENT_ONLY'
+ self.init(testdir)
+ compdb = self.get_compdb()
+ self.assertNotIn('-DBUILD_ENVIRONMENT_ONLY', compdb[0]['command'])
+
class RewriterTests(unittest.TestCase):
def setUp(self):