!11 obs build支持ccache编译加速

From: @tracedeng
Reviewed-by: @small_leek
Signed-off-by: @small_leek
This commit is contained in:
openeuler-ci-bot 2021-01-13 17:22:40 +08:00 committed by Gitee
commit 2116da2ad8
2 changed files with 70 additions and 1 deletions

View File

@ -0,0 +1,68 @@
diff --git a/build b/build
index 6f1b474..5191c0d 100755
--- a/build
+++ b/build
@@ -434,6 +434,7 @@ cleanup_and_exit () {
umount -n $BUILD_ROOT/dev/pts 2>/dev/null || true
umount -n $BUILD_ROOT/dev/shm 2>/dev/null || true
umount -n $BUILD_ROOT/sys 2>/dev/null || true
+ umount -n $BUILD_ROOT/home/abuild/.ccache 2>/dev/null || true
test -n "$VM_ROOT" -a "$VM_ROOT" != 1 && umount $BUILD_ROOT 2>/dev/null || true
test -n "$VM_TYPE" && vm_cleanup
fi
@@ -1360,6 +1361,7 @@ for RECIPEFILE in "${RECIPEFILES[@]}" ; do
mkdir -p $BUILD_ROOT/home/abuild/.m2
chown $ABUILD_UID:$ABUILD_GID $BUILD_ROOT/home/abuild/.m2
cp $BUILD_DIR/settings.xml $BUILD_ROOT/home/abuild/.m2/
+ build-ccache "$BUILD_ROOT" "$REASON" "$ABUILD_UID" "$ABUILD_GID"
BUILD_USER_ABUILD_USED=true
else
# building as root
diff --git a/build-ccache b/build-ccache
new file mode 100755
index 0000000..7293d01
--- /dev/null
+++ b/build-ccache
@@ -0,0 +1,42 @@
+#!/bin/bash
+# Script to setup ccache.
+#
+# BUILD_ROOT here the packages will be built
+# REASON here the reason of the build
+# eg: "building {package} for '{project}' repository '{repository}' arch '{arch}' srcmd5 '{md5}'
+#
+################################################################
+
+BUILD_ROOT=$1
+REASON=$2
+ABUILD_UID=$3
+ABUILD_GID=$4
+
+CCACHE_HOME_DIR=/home/abuild/.ccache
+
+package=`echo $REASON |awk '{print $2}'`
+project=`echo $REASON |awk '{print $5}'`
+project=${project//\'/}
+
+# check ccache
+if [[ -d /srv/ccache/$project ]] && [[ -e $BUILD_ROOT/usr/bin/ccache ]] && [[ ! -z $project ]] && [[ ! -z $package ]]
+then
+ # openjdk-11 excluded
+ if [[ $package == "openjdk-11" ]]
+ then
+ exit
+ fi
+
+ echo "Building $package for $project using ccache"
+
+ # mount ccache home dir to obs-worker directory
+ mkdir -p ${BUILD_ROOT}${CCACHE_HOME_DIR}
+ chown $ABUILD_UID:$ABUILD_GID ${BUILD_ROOT}${CCACHE_HOME_DIR}
+ mount --bind /srv/ccache/$project ${BUILD_ROOT}${CCACHE_HOME_DIR}
+
+ # link all compilers to ccache
+ cp $BUILD_ROOT/usr/bin/ccache $BUILD_ROOT/usr/local/bin
+ for compiler in $(ls $BUILD_ROOT/usr/bin | grep -E '^(cc|gcc|[cg][+][+]|clang|clang[+][+])([-]?[234][.]?[0-9])*$'); do
+ ln -sf ccache $BUILD_ROOT/usr/local/bin/$compiler
+ done
+fi

View File

@ -1,12 +1,13 @@
Name: build
Version: 20191114
Release: 324.5
Release: 324.6
Summary: A tool to build binary packages
License: GPL-2.0-only OR GPL-3.0-only
Url: https://github.com/openSUSE/obs-build
Source: obs-build-%{version}.tar.gz
Patch0000: 0001-modify-for-obs-build.patch
Patch0001: 0001-add-settings.patch
Patch0002: 0002-ccache-for-obs-build.patch
BuildArch: noarch
Requires: bash binutils perl tar psmisc build-mkbaselibs
BuildRequires: bash binutils perl psmisc tar