[libvirt PATCH 2/2] gitlab: Enable improved ccache usage

Andrea Bolognani abologna at redhat.com
Mon Mar 30 17:31:03 UTC 2020


Setting CC="ccache cc" works in most cases, but sometimes it will
break the build: in particular, we have experienced issues in the
past with that approach when using cgo to build our Go bindings.

A more robust approach is to have a directory containing symlinks
from the compiler name to the ccache binary: in that case, ccache
itself will invoke the compiler, and the build system will be none
the wiser.

Since libvirt-jenkins-ci commit 2563aebb6c5c, container images
contain a suitable symlink directory, so all that's needed to
enable the new approach is to add this directory to $PATH.

Since we're touching this anyway, we make a few more changes:
$CCACHE_DIR is no longer created manually, because ccache will
take care of creating it for us if it doesn't already exist; the
ccache setup is moved out of the job template and into
script_variables, removing unnecessary duplication; a limit is
set on the size of the cache (500 MB, which is twice the amount
used by a fresh build on my Fedora 31 machine).

Signed-off-by: Andrea Bolognani <abologna at redhat.com>
---
 .gitlab-ci.yml | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3203434b99..99e7b510c7 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -8,6 +8,10 @@ stages:
 
 .script_variables: &script_variables |
   export MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"
+  export CCACHE_BASEDIR="$(pwd)"
+  export CCACHE_DIR="$CCACHE_BASEDIR/ccache"
+  export CCACHE_MAXSIZE="500M"
+  export PATH="$CCACHE_WRAPPERSDIR:$PATH"
 
 # Common templates
 
@@ -20,10 +24,6 @@ stages:
     key: "$CI_JOB_NAME"
   before_script:
     - *script_variables
-    - mkdir -p ccache
-    - export CC="ccache gcc"
-    - export CCACHE_BASEDIR=${PWD}
-    - export CCACHE_DIR=${PWD}/ccache
   script:
     - mkdir build
     - cd build
@@ -48,10 +48,6 @@ stages:
     key: "$CI_JOB_NAME"
   before_script:
     - *script_variables
-    - mkdir -p ccache
-    - export CC="ccache ${ABI}-gcc"
-    - export CCACHE_BASEDIR=${PWD}
-    - export CCACHE_DIR=${PWD}/ccache
   script:
     - mkdir build
     - cd build
-- 
2.25.1




More information about the libvir-list mailing list