aboutsummaryrefslogtreecommitdiff
path: root/run_unittests.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2016-11-29 03:15:03 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2016-12-04 00:32:24 +0530
commitcee9638cc43682b6e371cc2becae745876c73bda (patch)
tree58f414d5acc2144e286c9f58d01039528a8dd2fa /run_unittests.py
parentc1efaafec46ad837a2e9a0d409dd98302b619141 (diff)
downloadmeson-cee9638cc43682b6e371cc2becae745876c73bda.zip
meson-cee9638cc43682b6e371cc2becae745876c73bda.tar.gz
meson-cee9638cc43682b6e371cc2becae745876c73bda.tar.bz2
Compiler check and extra args should always override
We want compiler check arguments (-O0, -fpermissive, etc) to override all other arguments, and we want extra_args passed in by the build file to always override everything. To do this properly, we must split include arguments out, append them first, append all other arguments as usual, and then append the rest. As part of this, we also add the compiler check flags to the cc.compiles() and cc.links() helper functions since they also most likely need them. Also includes a unit test for all this.
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-xrun_unittests.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/run_unittests.py b/run_unittests.py
index 8b1f13f..b8d23b8 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -94,6 +94,16 @@ class LinuxlikeTests(unittest.TestCase):
with open(os.path.join(self.builddir, 'meson-logs', 'meson-log.txt')) as f:
return f.readlines()
+ def get_meson_log_compiler_checks(self):
+ '''
+ Fetch a list command-lines run by meson for compiler checks.
+ Each command-line is returned as a list of arguments.
+ '''
+ log = self.get_meson_log()
+ prefix = 'Command line:'
+ cmds = [l[len(prefix):].split() for l in log if l.startswith(prefix)]
+ return cmds
+
def introspect(self, arg):
out = subprocess.check_output(self.mintro_command + [arg, self.builddir])
return json.loads(out.decode('utf-8'))
@@ -262,5 +272,23 @@ class LinuxlikeTests(unittest.TestCase):
self.assertEqual(self.get_soname(bothset), 'libbothset.so.1.2.3')
self.assertEqual(len(glob(bothset[:-3] + '*')), 3)
+ def test_compiler_check_flags_order(self):
+ '''
+ Test that compiler check flags override all other flags. This can't be
+ an ordinary test case because it needs the environment to be set.
+ '''
+ Oflag = '-O3'
+ os.environ['CFLAGS'] = os.environ['CXXFLAGS'] = Oflag
+ testdir = os.path.join(self.common_test_dir, '43 has function')
+ self.init(testdir)
+ cmds = self.get_meson_log_compiler_checks()
+ for cmd in cmds:
+ # Verify that -I flags from the `args` kwarg are first
+ # This is set in the '43 has function' test case
+ self.assertEqual(cmd[2], '-I/tmp')
+ # Verify that -O3 set via the environment is overriden by -O0
+ Oargs = [arg for arg in cmd if arg.startswith('-O')]
+ self.assertEqual(Oargs, [Oflag, '-O0'])
+
if __name__ == '__main__':
unittest.main()