Skip to content

Commit

Permalink
Optionally don't copy sources around
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lnussel committed Jan 20, 2022
1 parent ea392f1 commit c91a5d6
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 11 deletions.
45 changes: 41 additions & 4 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
;;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions build-recipe
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 21 additions & 5 deletions build-recipe-spec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down Expand Up @@ -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%=}" ;;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -343,3 +358,4 @@ recipe_create_deltarpms() {
fi
}

# vim: syntax=bash
5 changes: 5 additions & 0 deletions init_buildsystem
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand Down

0 comments on commit c91a5d6

Please sign in to comment.