summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhang zhigang <zg84.zhang@samsung.com>2021-07-09 07:42:23 +0000
committerGerrit Code Review <gerrit@review>2021-07-09 07:42:23 +0000
commitecf598f517a5300f74c24d1e27b1f480d8fc4d0f (patch)
treee19a82f6da3be88fdc7882ee7216b983a5615fce
parente56825b66ca9b2e90e46a51ba7d66a9fc2a31e3c (diff)
parent83d660afee1b2f5b331cea7be632baf9cec25149 (diff)
downloadbuild-ecf598f517a5300f74c24d1e27b1f480d8fc4d0f.tar.gz
build-ecf598f517a5300f74c24d1e27b1f480d8fc4d0f.tar.bz2
build-ecf598f517a5300f74c24d1e27b1f480d8fc4d0f.zip
Merge "Use ccache.tar file with --pkg-ccache option" into devel
-rw-r--r--[-rwxr-xr-x]build62
1 files changed, 57 insertions, 5 deletions
diff --git a/build b/build
index f98e1b7..374ebc9 100755..100644
--- a/build
+++ b/build
@@ -67,6 +67,7 @@ DO_CHECKS=true
SHORT_CIRCUIT=false
NO_TOPDIR_CLEANUP=false
CLEAN_BUILD=
+REMOVE_CCACHE=
KEEP_PACKS=
RECIPEFILES=()
SRCDIR=
@@ -99,6 +100,8 @@ CCACHE=
DLNOSIGNATURE=
CACHE_DIR=/var/cache/build
USEHIGHERDEPS=
+PKG_CCACHE=
+CCACHE_SETUP_START_TIME=
# This is for insserv
export YAST_IS_RUNNING=instsys
@@ -232,6 +235,10 @@ Known Parameters:
--ccache
Use ccache to speed up rebuilds
+ --pkg-ccache /path/to/ccache.tar.gz
+ path to archive of ccache directory content.
+ Its contents will be extracted to /.ccache
+
--icecream N
Use N parallel build jobs with icecream
@@ -425,9 +432,9 @@ toshellscript() {
setupccache() {
if test -n "$CCACHE" ; then
+ CCACHE_SETUP_START_TIME=`date +%s`
if mkdir -p "$BUILD_ROOT"/var/lib/build/ccache/bin; then
- for i in $(ls "$BUILD_ROOT"/usr/bin | grep -E '^(cc|gcc|[cg][+][+])([-]?[234][.]?[0-9])*$'); do
-# ln -sf /usr/bin/ccache $BUILD_ROOT/var/lib/build/ccache/bin/$i
+ for i in $(ls $BUILD_ROOT/usr/bin | grep -E '^(cc|gcc|[cg][+][+]|clang|clang[+][+])([-]?[.0-9])*$'); do
rm -f "$BUILD_ROOT"/var/lib/build/ccache/bin/$i
test -e "$BUILD_ROOT"/usr/bin/$i || continue
echo '#! /bin/sh' > "$BUILD_ROOT"/var/lib/build/ccache/bin/$i
@@ -439,11 +446,33 @@ setupccache() {
done
fi
mkdir -p "$BUILD_ROOT/.ccache"
- chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/.ccache"
- echo "export CCACHE_DIR=/.ccache" > "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
+ # overwrite /etc/profile.d/build_ccache.sh
+ echo 'export CCACHE_DIR=/.ccache' > "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
echo 'export PATH=/var/lib/build/ccache/bin:$PATH' >> "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
+
+ # Note
+ # Disable compression setting temporary
+ # Until ccache is applied to qemu-accel, it is very slow when using the function, so it will be applied later.
+ #
+ # https://ccache.dev/releasenotes.html#_ccache_4_0
+ # Changed compression algorithm from Deflate (zlib) to Zstandard, enabled by default.
+ enable_compression=false
+
+ local cconf="$BUILD_ROOT"/etc/ccache.conf
+ if test -e $cconf; then
+ grep -q "^compression*" $cconf && sed -i "s:compression.*:compression = $enable_compression:g" $cconf || echo "compression = $enable_compression" >> $cconf
+ grep -q "^cache_dir*" $cconf && sed -i "s:cache_dir.*:cache_dir = /.ccache:g" $cconf || echo "cache_dir = /.ccache" >> $cconf
else
- rm -f "$BUILD_ROOT"/var/lib/build/ccache/bin/{gcc,g++,cc,c++}
+ echo "compression = $enable_compression" >> $cconf
+ echo "cache_dir = /.ccache" >> $cconf
+ fi
+ local ccachetar="$BUILD_ROOT/.build.oldpackages/_ccache.tar"
+ test -e $ccachetar && tar -xf $ccachetar -C "$BUILD_ROOT/.ccache/"
+ rm -f $ccachetar
+ chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/.ccache"
+ else
+ CCACHE_SETUP_START_TIME=
+ rm -f "$BUILD_ROOT"/var/lib/build/ccache/bin/{gcc,g++,cc,c++,clang,clang++}
fi
}
@@ -765,6 +794,7 @@ while test -n "$1"; do
;;
-clean)
CLEAN_BUILD='--clean'
+ REMOVE_CCACHE="$CLEAN_BUILD"
;;
-kill)
KILL=true
@@ -891,6 +921,12 @@ while test -n "$1"; do
-ccache)
CCACHE=true
;;
+ -pkg-ccache)
+ needarg
+ PKG_CCACHE="$ARG"
+ shift
+ CCACHE=true
+ ;;
-statistics)
DO_STATISTICS=1
;;
@@ -1204,6 +1240,11 @@ for RECIPEFILE in "${RECIPEFILES[@]}" ; do
mount -n -tdevpts -omode=0620,gid=5 none "$BUILD_ROOT"/dev/pts
copy_oldpackages
+ # chroot based builds
+ # rsync as source and dest could be same
+ test -n "$PKG_CCACHE" -a -e "$PKG_CCACHE" && \
+ mkdir -p "$BUILD_ROOT/.build.oldpackages/" && \
+ rsync -v "$PKG_CCACHE" "$BUILD_ROOT/.build.oldpackages/_ccache.tar"
fi
# hack to process preinstallimages early
@@ -1465,6 +1506,17 @@ if test -n "$RPMS" -a "$DO_CHECKS" != false ; then
recipe_run_rpmlint
fi
+if test -n "$CCACHE" ; then
+ if test -n "$REMOVE_CCACHE" ; then
+ echo "... cleaning ccache"
+ test_cmd="ccache -h | grep -c evict-older-than"
+ clean_cmd="ccache --evict-older-than $(($(date +%s) - $CCACHE_SETUP_START_TIME))s"
+ chroot $BUILD_ROOT su -c "$test_cmd && $clean_cmd" - $BUILD_USER
+ fi
+ echo "... saving ccache"
+ tar ${REMOVE_CCACHE:+--remove-files} -cf "$BUILD_ROOT/$TOPDIR/OTHER/_ccache.tar" -C "$BUILD_ROOT/.ccache/" .
+fi
+
if test \( -n "$RPMS" -o -n "$DEBS" \) -a -n "$CREATE_BASELIBS"; then
create_baselibs
fi