"""
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:
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):
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")
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()
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.
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: