diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2021-03-23 20:52:49 -0700 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2021-03-30 18:52:17 +0300 |
commit | 2cd0723c42ae2076c7ba2b888fd7a5235d5cbf17 (patch) | |
tree | 8a403fc8589838c8305f34cdb22b0e8db72ea8ce /run_unittests.py | |
parent | 692f6733122b2bf053299f8a0cdbcab3d5bfbfb5 (diff) | |
download | meson-2cd0723c42ae2076c7ba2b888fd7a5235d5cbf17.zip meson-2cd0723c42ae2076c7ba2b888fd7a5235d5cbf17.tar.gz meson-2cd0723c42ae2076c7ba2b888fd7a5235d5cbf17.tar.bz2 |
Split environment variable and command line cflags
They are supposed to have different behavior. The environment variables
apply to both the compiler and linker when the compiler acts as a
linker, but the command line ones do not.
Fixes #8345
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-x | run_unittests.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/run_unittests.py b/run_unittests.py index fd75c8c..1eba4df 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -5634,6 +5634,28 @@ class AllPlatformTests(BasePlatformTests): matches += 1 self.assertEqual(matches, 1) + def test_env_flags_to_linker(self) -> None: + # Compilers that act as drivers should add their compiler flags to the + # linker, those that do not shouldn't + with mock.patch.dict(os.environ, {'CFLAGS': '-DCFLAG', 'LDFLAGS': '-flto'}): + env = get_fake_env() + + # Get the compiler so we know which compiler class to mock. + cc = env.detect_compiler_for('c', MachineChoice.HOST) + cc_type = type(cc) + + # Test a compiler that acts as a linker + with mock.patch.object(cc_type, 'INVOKES_LINKER', True): + cc = env.detect_compiler_for('c', MachineChoice.HOST) + link_args = env.coredata.get_external_link_args(cc.for_machine, cc.language) + self.assertEqual(sorted(link_args), sorted(['-DCFLAG', '-flto'])) + + # And one that doesn't + with mock.patch.object(cc_type, 'INVOKES_LINKER', False): + cc = env.detect_compiler_for('c', MachineChoice.HOST) + link_args = env.coredata.get_external_link_args(cc.for_machine, cc.language) + self.assertEqual(sorted(link_args), sorted(['-flto'])) + class FailureTests(BasePlatformTests): ''' Tests that test failure conditions. Build files here should be dynamically |