From c91a5d6a8b933caa23212774a5388973b7827aa1 Mon Sep 17 00:00:00 2001 From: Ludwig Nussel Date: Thu, 20 Jan 2022 16:21:31 +0100 Subject: [PATCH] Optionally don't copy sources around Implements --no-source-copy, --prep and --build-in-place and the shortcut --here. So it's as simple as eg $ sudo build --here $ sudo build --here package/foo.spec Follow-up calls using --no-init are super quick then of course. Esp with the previously hidden feature to specify --no-init twice. Can be used to combine with --stage, eg $ sudo build --here --no-init --no-init --stage c Only works for chroot build for now so unfortunately needs root. --- build | 45 +++++++++++++++++++++++++++++++++++++++++---- build-recipe | 8 ++++++-- build-recipe-spec | 26 +++++++++++++++++++++----- init_buildsystem | 5 +++++ 4 files changed, 73 insertions(+), 11 deletions(-) diff --git a/build b/build index 1bae97594..d92d0cafd 100755 --- a/build +++ b/build @@ -120,6 +120,9 @@ CACHE_DIR=/var/cache/build BUILD_DIST_TMP= BUILD_SUCCEEDED= COPY_SOURCES_ASIS= +NO_SOURCE_COPY= +NOPREP= +BUILD_IN_PLACE= RECIPE_BUILD_START_TIME= CCACHE_SETUP_START_TIME= @@ -190,7 +193,7 @@ Known Parameters: --wipe Completely removes build environment and exits. --no-init Skip initialization of build root and start with build - immediately. + immediately. Repeat to also keep previous build files. --no-checks Do not run checks (postbuild and %check) @@ -261,6 +264,14 @@ Known Parameters: the specified stage and all stages coming after it. With no suffix, stages up to and included the specified stage are run. + --noprep, --build-in-place + Passed to directly to rpmbuild + + --here + Usefor for building packages directly from a git + checkout in the current working directory. Shortcut + for --noprep --build-in-place --no-copy-sources + --target platform Set target platform for rpmbuild @@ -310,6 +321,10 @@ Known Parameters: This is useful if you are hacking in the buildroot. This must be set to the same value if the buildroot is re-used. + --no-source-copy + Mount source directory instead of copying. Only works + with chroot builds that are not on NFS. + --statistics monitor used resources during build inside VM @@ -1318,6 +1333,20 @@ while test -n "$1"; do -copy-sources-asis) COPY_SOURCES_ASIS=true ;; + -no-source-copy) + NO_SOURCE_COPY=true + ;; + -noprep) + NOPREP=true + ;; + -build-in-place) + BUILD_IN_PLACE=true + ;; + -here) + NOPREP=true + BUILD_IN_PLACE=true + NO_SOURCE_COPY=true + ;; ---noarg) cleanup_and_exit 1 "$ARG does not take an argument" ;; @@ -1536,8 +1565,16 @@ for RECIPEFILE in "${RECIPEFILES[@]}" ; do SRCDIR="${RECIPEFILE%/debian/control}" RECIPEFILE="debian/control" else - SRCDIR="${RECIPEFILE%/*}" - RECIPEFILE="${RECIPEFILE##*/}" + if test -z "$BUILD_IN_PLACE"; then + SRCDIR="${RECIPEFILE%/*}" + RECIPEFILE="${RECIPEFILE##*/}" + else + if test "${RECIPEFILE#../}" != "$RECIPEFILE" || \ + test "${RECIPEFILE#/}" != "$RECIPEFILE" ; then + cleanup_and_exit 1 "--build-in-place requires relative file path" + fi + SRCDIR="$PWD" + fi fi recipe_set_buildtype @@ -1603,7 +1640,7 @@ for RECIPEFILE in "${RECIPEFILES[@]}" ; do if recipe_needs_build_binaries "$MYSRCDIR/$RECIPEFILE" ; then CREATE_BUILD_BINARIES=--create-build-binaries fi - set -- init_buildsystem --configdir "$CONFIG_DIR" --cachedir "$CACHE_DIR" "${initbuildsysstuff[@]}" "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $DLNOSIGNATURE $USEUSEDFORBUILD $CREATE_BUILD_BINARIES $RPMLIST "$MYSRCDIR/$RECIPEFILE" $ADDITIONAL_PACKS + set -- init_buildsystem --configdir "$CONFIG_DIR" --cachedir "$CACHE_DIR" ${BUILD_IN_PLACE:+--build-in-place} "${initbuildsysstuff[@]}" "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $DLNOSIGNATURE $USEUSEDFORBUILD $CREATE_BUILD_BINARIES $RPMLIST "$MYSRCDIR/$RECIPEFILE" $ADDITIONAL_PACKS echo "$* ..." start_time=$SECONDS "$@" || cleanup_and_exit 1 diff --git a/build-recipe b/build-recipe index fb36c1893..59968260f 100644 --- a/build-recipe +++ b/build-recipe @@ -125,13 +125,17 @@ recipe_set_buildtype() { expand_recipe_directories() { local f t ff found types if test -z "$RECIPEFILES" ; then - set -- "`pwd`" + if test -z "$BUILD_IN_PLACE"; then + set -- "`pwd`" + else + set -- "./" + fi else set -- "${RECIPEFILES[@]}" fi RECIPEFILES=() for f in "$@" ; do - if test "$f" = "${f#/}" ; then + if test -z "$BUILD_IN_PLACE" && test "$f" = "${f#/}" ; then f="`pwd`/$f" fi if test -d "$f" ; then diff --git a/build-recipe-spec b/build-recipe-spec index cd649599b..da75c50f7 100644 --- a/build-recipe-spec +++ b/build-recipe-spec @@ -32,7 +32,13 @@ recipe_setup_spec() { mkdir -p $BUILD_ROOT$TOPDIR/$i done mkdir -p $BUILD_ROOT$TOPDIR/SOURCES - copy_sources "$MYSRCDIR" "$BUILD_ROOT$TOPDIR/SOURCES/" + if [ -n "$NO_SOURCE_COPY" ]; then + test -z "$VM_TYPE" || cleanup_and_exit 1 "VM not supported with --no-source-copy" + mkdir -p $BUILD_ROOT/.overlay + mount -t overlay overlay -o metacopy=on,lowerdir="${MYSRCDIR//:/\\:}",workdir="$BUILD_ROOT/.overlay",upperdir="$BUILD_ROOT$TOPDIR/SOURCES/" "$BUILD_ROOT$TOPDIR/SOURCES/" || cleanup_and_exit 1 + else + copy_sources "$MYSRCDIR" "$BUILD_ROOT$TOPDIR/SOURCES/" + fi chown -hR "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR" } @@ -122,7 +128,7 @@ spec_setup_stages() { test "$stage#-b[a-z]" != "$stage" && stage="${stage#-b}" # compat local xstage=pciba case $stage in - "") stage=pciba ;; + "") stage="${xstage%${BUILD_IN_PLACE:+a}}";; [lr]) ;; [pciba]) stage="${xstage%$stage*}$stage" ;; [pcibalr]=) stage="${stage%=}" ;; @@ -192,6 +198,12 @@ recipe_build_spec() { rpmbopts[${#rpmbopts[@]}]='--define' rpmbopts[${#rpmbopts[@]}]="RSYNCDONE 1" fi + if test -n "$NOPREP" ; then + rpmbopts[${#rpmbopts[@]}]='--noprep' + fi + if test -n "$BUILD_IN_PLACE" ; then + rpmbopts[${#rpmbopts[@]}]='--build-in-place' + fi buildrootoverride=$(queryconfig --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" buildflags rpm-buildroot-override) if test -n "$buildrootoverride" ; then @@ -211,7 +223,7 @@ recipe_build_spec() { "$TOPDIR/SOURCES/$RECIPEFILE" \ > $BUILD_ROOT/.build.command chmod 755 $BUILD_ROOT/.build.command - chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null + chroot $BUILD_ROOT su -c "cd $TOPDIR/SOURCES; /.build.command" - $BUILD_USER < /dev/null st=$? if test "$st" != 0 -a "$st" != 11 ; then return @@ -245,7 +257,7 @@ recipe_build_spec() { > $BUILD_ROOT/.build.command chmod 755 $BUILD_ROOT/.build.command check_exit - chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null + chroot $BUILD_ROOT su -c "cd $TOPDIR/SOURCES; /.build.command" - $BUILD_USER < /dev/null st=$? test "$st" = 0 || break done @@ -258,7 +270,10 @@ recipe_resultdirs_spec() { } recipe_cleanup_spec() { - : + if [ -n "$NO_SOURCE_COPY" ] && mountpoint -q "$BUILD_ROOT$TOPDIR/SOURCES/"; then + cd / + umount "$BUILD_ROOT$TOPDIR/SOURCES/" + fi } recipe_unpack_srcrpm() { @@ -343,3 +358,4 @@ recipe_create_deltarpms() { fi } +# vim: syntax=bash diff --git a/init_buildsystem b/init_buildsystem index 92ce0137e..e6bf4564e 100755 --- a/init_buildsystem +++ b/init_buildsystem @@ -127,6 +127,11 @@ while test -n "$1" ; do OBSURL="$2" shift 2 ;; + --build-in-place) + definesnstuff[${#definesnstuff[@]}]="--define"; + definesnstuff[${#definesnstuff[@]}]="_build_in_place 1"; + shift + ;; *) break ;;