Improved compiler identification
Ccache currently guesses the compiler type based on the name of the executable. This was the easy thing to do when the need first arose (d875edef19d0ab157b2f6408330bb1392fd38f60), and the same method has subsequently been used for other compiler types. However, in some cases complex workarounds are needed since ccache can't fully trust the classification as it's just a guess. This method is inherently brittle since the compiler could be an anonymous /usr/bin/cc or a wrapper script with a custom name. Also, to implement features that require very specific functionality from compilers (e.g. #815), guessing compiler from just filename simply won't do.
To improve this, we could cache the output of $compiler --version or similar and deduce compiler type and version from that output when ccache is called for compilation.
Implementation sketch:
# To determine the key to use for caching "compiler --version":
if config.compiler_check() is "none":
compiler_check_key = None
else:
compiler_check_key = CCACHE_VERSION + basename(compiler)
if config.compiler_check() is a command string:
compiler_check_key += execute(config.compiler_check())
elif config.compiler_check() is "string:value":
compiler_check_key += value
elif config.compiler_check() is "content":
compiler_check_key += read_file(compiler)
else: # config.compiler_check() is "mtime"
compiler_check_key += get_mtime(compiler) + get_size(compiler)
# To determine compiler type and version:
compiler_version_output = None
if compiler_check_key:
compiler_version_output = get_cached_compiler_version(compiler_check_key)
if not compiler_version_output:
compiler_version_output = execute(compiler --version)
# Note: Another methods could be used based on the compiler name.
if not compiler_version_output:
statistics.increment(failed_to_get_compiler_version)
fall back to running the original compiler
if compiler_check_key:
put_cached_compiler_version(compiler_check_key, compiler_version_output)
compiler_info = classify_compiler(compiler_version_output)
# To add compiler information to the input hash:
input_hash.hash(basename(compiler) + compiler_version_output)
# TODO:
# - If config.compiler_type() is set, use that value instead.
# - Allow compiler_type to be "type version" instead just "type"?
# - Or perhaps we should just remove support for configuring compiler type since it's no longer needed?