Hi mclow.lists, danalbert, jroelofs,

In order to get the bots running quicker I would like to be able to use ccache 
with the test suite. This patch adds support for running the test suite using 
ccache. To use ccache pass `--param=use_ccache=true` when running the test 
suite.

ccache will not cache any command that invokes ld, so the build step needs to be
split into two separate compile commands. The cost of splitting the build step
into two parts when not using ccache seems to be minimal. On my machine I saw a
difference of ~5 seconds on a 5 minute test suite run.

A full test suite run with ccache generates about 250MB of cached data.

I recorded the following times for running the test suite in the following 
configurations:
- no ccache: 340s
- initial ccache run: 380s
- rerun with ccache (no changes): 53s.
- rerun with ccache (<string> changed): 80s
- rerun with ccache (<cmath> changed): 169s
- rerun with ccache (<valarray> changed): 69s

http://reviews.llvm.org/D6647

Files:
  test/lit.cfg

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: test/lit.cfg
===================================================================
--- test/lit.cfg
+++ test/lit.cfg
@@ -29,12 +29,14 @@
     """
 
     def __init__(self, cxx_under_test, use_verify_for_fail,
-                 cpp_flags, ld_flags, exec_env):
+                 cpp_flags, ld_flags, exec_env,
+                 use_ccache=False):
         self.cxx_under_test = cxx_under_test
         self.use_verify_for_fail = use_verify_for_fail
         self.cpp_flags = list(cpp_flags)
         self.ld_flags = list(ld_flags)
         self.exec_env = dict(exec_env)
+        self.use_ccache = use_ccache
 
     def execute(self, test, lit_config):
         while True:
@@ -100,20 +102,44 @@
         report += '\n'
         return cmd, report, rc
 
-    def _build(self, exec_path, source_path, compile_only=False,
-               use_verify=False):
-        cmd = [self.cxx_under_test, '-o', exec_path,
-               source_path] + self.cpp_flags
-
-        if compile_only:
-            cmd += ['-c']
-        else:
-            cmd += self.ld_flags
-
+    def _compile(self, output_path, source_path, use_verify=False):
+        cmd = [self.cxx_under_test, '-c', '-o', output_path, source_path]
+        cmd += self.cpp_flags
         if use_verify:
             cmd += ['-Xclang', '-verify']
+        if self.use_ccache:
+            cmd = ['ccache'] + cmd
+        out, err, rc = lit.util.executeCommand(cmd)
+        return cmd, out, err, rc
 
+    def _link(self, exec_path, object_path):
+        cmd = [self.cxx_under_test, '-o', exec_path, object_path]
+        cmd += self.cpp_flags + self.ld_flags
         out, err, rc = lit.util.executeCommand(cmd)
+        return cmd, out, err, rc
+
+    def _compile_and_link(self, exec_path, source_path):
+        object_file = tempfile.NamedTemporaryFile(suffix=".o", delete=False)
+        object_path = object_file.name
+        object_file.close()
+        try:
+            cmd, out, err, rc = self._compile(object_path, source_path)
+            if rc != 0:
+                return cmd, out, err, rc
+            return self._link(exec_path, object_path)
+        finally:
+            try:
+                os.remove(object_path)
+            except:
+                pass
+
+    def _build(self, exec_path, source_path, compile_only=False,
+               use_verify=False):
+        if compile_only:
+            cmd, out, err, rc = self._compile(exec_path, source_path, use_verify)
+        else:
+            assert not use_verify
+            cmd, out, err, rc = self._compile_and_link(exec_path, source_path)
         return self._make_report(cmd, out, err, rc)
 
     def _clean(self, exec_path):
@@ -190,6 +216,7 @@
         self.link_flags = ['-nodefaultlibs']
         self.use_system_lib = False
         self.use_clang_verify = False
+        self.use_ccache = False
 
         if platform.system() not in ('Darwin', 'FreeBSD', 'Linux'):
             self.lit_config.fatal("unrecognized system")
@@ -221,6 +248,7 @@
         self.configure_obj_root()
         self.configure_use_system_lib()
         self.configure_use_clang_verify()
+        self.configure_ccache()
         self.configure_env()
         self.configure_std_flag()
         self.configure_compile_flags()
@@ -240,7 +268,8 @@
             self.use_clang_verify,
             cpp_flags=self.compile_flags,
             ld_flags=self.link_flags,
-            exec_env=self.env)
+            exec_env=self.env,
+            use_ccache=self.use_ccache)
 
     def configure_cxx(self):
         # Gather various compiler parameters.
@@ -325,6 +354,11 @@
             self.lit_config.note(
                 "inferred use_clang_verify as: %r" % self.use_clang_verify)
 
+    def configure_ccache(self):
+        self.use_ccache = self.get_lit_bool('use_ccache', False)
+        if self.use_ccache:
+            self.lit_config.note('enabling ccache')
+
     def configure_features(self):
         additional_features = self.get_lit_conf('additional_features')
         if additional_features:
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to