diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2021-03-23 20:52:49 -0700 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2021-03-30 17:35:56 +0300 |
commit | 0b54b81222f092bd859b08af993e2700bddd81be (patch) | |
tree | 8eb6042107883a5685a9a4db3296a2a01a91151d /run_unittests.py | |
parent | e80ff985fb1d4a0b840e5bf67a7e5dff08a21cdd (diff) | |
download | meson-envvarfixup.tar.gz |
Split environment variable and command line cflagsenvvarfixup
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 fd75c8c9c..1eba4dfd6 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 |