From 765b44a070f7f338d63b15e8c37197e5a304f638 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 13 Jan 2021 08:49:22 +0000 Subject: [PATCH] ccache for obs build --- 0002-ccache-for-obs-build.patch | 68 +++++++++++++++++++++++++++++++++ obs-build.spec | 3 +- 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 0002-ccache-for-obs-build.patch diff --git a/0002-ccache-for-obs-build.patch b/0002-ccache-for-obs-build.patch new file mode 100644 index 0000000..8cf7588 --- /dev/null +++ b/0002-ccache-for-obs-build.patch @@ -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 diff --git a/obs-build.spec b/obs-build.spec index 1423d7f..f237562 100644 --- a/obs-build.spec +++ b/obs-build.spec @@ -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 -- Gitee