diff options
author | Christoph Junghans <christoph.junghans@gmail.com> | 2018-07-09 15:06:10 -0600 |
---|---|---|
committer | scheibelp <scheibel1@llnl.gov> | 2018-07-09 14:06:10 -0700 |
commit | 8bc3f7d726d18d2c76e5bcc64d4160ae950b2cae (patch) | |
tree | f6a0cb0e0c55f11253990d4971e96358eea2ec94 | |
parent | 8770957b7ad26f9697663c39b43f493ac8ecd79c (diff) | |
download | spack-8bc3f7d726d18d2c76e5bcc64d4160ae950b2cae.tar.gz spack-8bc3f7d726d18d2c76e5bcc64d4160ae950b2cae.tar.bz2 spack-8bc3f7d726d18d2c76e5bcc64d4160ae950b2cae.tar.xz spack-8bc3f7d726d18d2c76e5bcc64d4160ae950b2cae.zip |
Add ccache support (#3761)
If the user sets "ccache: true" in spack's config.yaml, Spack will use an available
ccache executable when compiling c/c++ code. This feature is disabled by default
(i.e. "ccache: false") and the documentation is updated with how to enable
ccache support
-rw-r--r-- | etc/spack/defaults/config.yaml | 4 | ||||
-rw-r--r-- | lib/spack/docs/config_yaml.rst | 19 | ||||
-rwxr-xr-x | lib/spack/env/cc | 10 | ||||
-rw-r--r-- | lib/spack/spack/build_environment.py | 8 | ||||
-rw-r--r-- | lib/spack/spack/schema/config.py | 1 |
5 files changed, 41 insertions, 1 deletions
diff --git a/etc/spack/defaults/config.yaml b/etc/spack/defaults/config.yaml index e4914e3fa3..28628a3d49 100644 --- a/etc/spack/defaults/config.yaml +++ b/etc/spack/defaults/config.yaml @@ -90,3 +90,7 @@ config: # If set to 4, for example, `spack install` will run `make -j4`. # If not set, all available cores are used by default. # build_jobs: 4 + + + # If set to true, spack will use ccache to cache c compiles. + ccache: false diff --git a/lib/spack/docs/config_yaml.rst b/lib/spack/docs/config_yaml.rst index 35bc22d72e..1db5679278 100644 --- a/lib/spack/docs/config_yaml.rst +++ b/lib/spack/docs/config_yaml.rst @@ -191,3 +191,22 @@ to 4, for example, commands like ``spack install`` will run ``make -j4`` instead of hogging every core. To build all software in serial, set ``build_jobs`` to 1. + +-------------------- +``ccache`` +-------------------- + +When set to ``true`` Spack will use ccache to cache compiles. This is +useful specifically un two cases: (1) Use with ``spack setup``, (2) +Build the same package with many different variants. The default is +``false``. + +When enabled Spack will look inside your ``PATH`` for a ``ccache`` +executable and stop if it is not found. Some systems come with +``ccache``, but it can also be installed using ``spack install +ccache``. ``ccache`` comes with reasonable defaults for cache size +and location. (See the *Configuration settings* secion of ``man +ccache`` to learn more about the default settings and how change +them.) Please note that we currently disable ccache's ``hash_dir`` +feature to avoid an issue with the stage directory (see +https://github.com/LLNL/spack/pull/3761#issuecomment-294352232 ). diff --git a/lib/spack/env/cc b/lib/spack/env/cc index 22f6cb345c..bc4a20dc3e 100755 --- a/lib/spack/env/cc +++ b/lib/spack/env/cc @@ -342,7 +342,15 @@ case "$mode" in args=("${args[@]}" ${SPACK_LDLIBS[@]}) ;; esac -full_command=("$command" "${args[@]}") +#ccache only supports C languages, so filtering out Fortran +if [[ ( ${lang_flags} = "C" || ${lang_flags} = "CXX" ) && ${SPACK_CCACHE_BINARY} ]]; then + full_command=("${SPACK_CCACHE_BINARY}" "$command" "${args[@]}") + # #3761#issuecomment-294352232 + # workaround for stage being a temp folder + export CCACHE_NOHASHDIR=yes +else + full_command=("$command" "${args[@]}") +fi # In test command mode, write out full command for Spack tests. if [[ $SPACK_TEST_COMMAND == dump-args ]]; then diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py index 4d272b51f3..e48e570e76 100644 --- a/lib/spack/spack/build_environment.py +++ b/lib/spack/spack/build_environment.py @@ -98,6 +98,7 @@ SPACK_DEBUG = 'SPACK_DEBUG' SPACK_SHORT_SPEC = 'SPACK_SHORT_SPEC' SPACK_DEBUG_LOG_ID = 'SPACK_DEBUG_LOG_ID' SPACK_DEBUG_LOG_DIR = 'SPACK_DEBUG_LOG_DIR' +SPACK_CCACHE_BINARY = 'SPACK_CCACHE_BINARY' # Platform-specific library suffix. @@ -335,6 +336,13 @@ def set_build_environment_variables(pkg, env, dirty): env.set(SPACK_DEBUG_LOG_ID, pkg.spec.format('${PACKAGE}-${HASH:7}')) env.set(SPACK_DEBUG_LOG_DIR, spack.main.spack_working_dir) + # Find ccache binary and hand it to build environment + if spack.config.get('config:ccache'): + ccache = Executable('ccache') + if not ccache: + raise RuntimeError("No ccache binary found in PATH") + env.set(SPACK_CCACHE_BINARY, ccache) + # Add any pkgconfig directories to PKG_CONFIG_PATH for prefix in build_link_prefixes: for directory in ('lib', 'lib64', 'share'): diff --git a/lib/spack/spack/schema/config.py b/lib/spack/spack/schema/config.py index 4a5b25ed63..ac94a12558 100644 --- a/lib/spack/spack/schema/config.py +++ b/lib/spack/spack/schema/config.py @@ -69,6 +69,7 @@ schema = { 'locks': {'type': 'boolean'}, 'dirty': {'type': 'boolean'}, 'build_jobs': {'type': 'integer', 'minimum': 1}, + 'ccache': {'type': 'boolean'}, } }, }, |