From 1d7f9972151b0a52297880c8f9e5f28a1d7fe597 Mon Sep 17 00:00:00 2001
From: Levente Polyak <anthraxx@archlinux.org>
Date: Sat, 14 Jan 2023 18:20:29 +0100
Subject: build: command to build packages inside a clean chroot

---
 doc/man/pkgctl-build.1.asciidoc | 80 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100644 doc/man/pkgctl-build.1.asciidoc

(limited to 'doc/man/pkgctl-build.1.asciidoc')

diff --git a/doc/man/pkgctl-build.1.asciidoc b/doc/man/pkgctl-build.1.asciidoc
new file mode 100644
index 0000000..132c0a4
--- /dev/null
+++ b/doc/man/pkgctl-build.1.asciidoc
@@ -0,0 +1,80 @@
+pkgctl-build(1)
+===============
+
+Name
+----
+pkgctl-build - Build packages inside a clean chroot
+
+Synopsis
+--------
+pkgctl build [OPTIONS] [PATH...]
+
+Description
+-----------
+
+TODO
+
+Build Options
+-------------
+
+*--arch* 'ARCH'::
+	Specify architectures to build for (disables auto-detection)
+
+*--repo* 'REPO'::
+	Specify a target repository (disables auto-detection)
+
+*-s, --staging*::
+	Build against the staging counterpart of the auto-detected repo
+
+*-t, --testing*::
+	Build against the testing counterpart of the auto-detected repo
+
+*-o, --offload*::
+	Build on a remote server and transfer artifacts afterwards
+
+*-c, --clean*::
+	Recreate the chroot before building
+
+*-I, --install* 'FILE'::
+	Install a package into the working copy of the chroot
+
+PKGBUILD Options
+----------------
+
+*--pkgver*='PKGVER'::
+	Set pkgver, reset pkgrel and update checksums
+
+*--pkgrel*='PKGREL'::
+	Set pkgrel to a given value
+
+*--rebuild*::
+	Increment the current pkgrel variable
+
+*-e, --edit*::
+	Edit the PKGBUILD before building
+
+Release Options
+---------------
+
+*-r, --release*::
+	Automatically commit, tag and release after building
+
+*-m, --message* 'MSG'::
+	Use the given <msg> as the commit message
+
+*-u, --db-update*::
+	Automatically update the pacman database as last action
+
+Options
+-------
+
+*-h, --help*::
+	Show a help text
+
+See Also
+--------
+
+linkman:pkgctl-release[1]
+linkman:pkgctl-db-update[1]
+
+include::include/footer.asciidoc[]
-- 
cgit v1.2.3-70-g09d2


From f3518e248cc8be165009f2200ff3b6500bfc0476 Mon Sep 17 00:00:00 2001
From: Levente Polyak <anthraxx@archlinux.org>
Date: Sat, 1 Apr 2023 00:12:56 +0200
Subject: build: support nocheck for initial bootstrap builds

Output a warning when this option is used to remind packagers to rebuild
the packages with checks once the bootstrap cycle has been completed.
---
 contrib/completion/zsh/_devtools.in |  1 +
 doc/man/pkgctl-build.1.asciidoc     |  3 +++
 src/lib/build/build.sh              | 11 +++++++++--
 3 files changed, 13 insertions(+), 2 deletions(-)

(limited to 'doc/man/pkgctl-build.1.asciidoc')

diff --git a/contrib/completion/zsh/_devtools.in b/contrib/completion/zsh/_devtools.in
index 39e9ac0..e782fba 100644
--- a/contrib/completion/zsh/_devtools.in
+++ b/contrib/completion/zsh/_devtools.in
@@ -42,6 +42,7 @@ _pkgctl_build_args=(
 	'(-o --offload)'{-o,--offload}'[Build on a remote server and transfer artifacts afterwards]'
 	'(-c --clean)'{-c,--clean}'[Recreate the chroot before building]'
 	'(-I --install)'{-I,--install}'[Install a package into the working copy of the chroot]:target:_files -g "*.pkg.tar.*(.)"'
+	'--nocheck[Do not run the check() function in the PKGBUILD]'
 	'--pkgver=[Set pkgver, reset pkgrel and update checksums]:pkgver:'
 	'--pkgrel=[Set pkgrel to a given value]:pkgrel:'
 	'--rebuild[Increment the pkgrel variable]'
diff --git a/doc/man/pkgctl-build.1.asciidoc b/doc/man/pkgctl-build.1.asciidoc
index 132c0a4..6ae3872 100644
--- a/doc/man/pkgctl-build.1.asciidoc
+++ b/doc/man/pkgctl-build.1.asciidoc
@@ -38,6 +38,9 @@ Build Options
 *-I, --install* 'FILE'::
 	Install a package into the working copy of the chroot
 
+*--nocheck*::
+	Do not run the check() function in the PKGBUILD
+
 PKGBUILD Options
 ----------------
 
diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh
index 72ee4fb..fff8125 100644
--- a/src/lib/build/build.sh
+++ b/src/lib/build/build.sh
@@ -47,6 +47,7 @@ pkgctl_build_usage() {
 		    -o, --offload        Build on a remote server and transfer artifacts afterwards
 		    -c, --clean          Recreate the chroot before building
 		    -I, --install FILE   Install a package into the working copy of the chroot
+		    --nocheck            Do not run the check() function in the PKGBUILD
 
 		PKGBUILD OPTIONS
 		    --pkgver=PKGVER      Set pkgver, reset pkgrel and update checksums
@@ -120,6 +121,7 @@ pkgctl_build() {
 	local BUILD_OPTIONS=()
 	local MAKECHROOT_OPTIONS=()
 	local RELEASE_OPTIONS=()
+	local MAKEPKG_OPTIONS=()
 
 	local PTS
 	PTS="$(tty | sed 's|/dev/pts/||')"
@@ -201,6 +203,11 @@ pkgctl_build() {
 				warning 'installing packages into the chroot may break reproducible builds, use with caution!'
 				shift 2
 				;;
+			--nocheck)
+				MAKEPKG_OPTIONS+=("--nocheck")
+				warning 'not running checks is disallowed for official packages, except for bootstrapping. Please rebuild after bootstrapping is completed!'
+				shift
+				;;
 			-r|--release)
 				# shellcheck source=src/lib/release.sh
 				source "${_DEVTOOLS_LIBRARY_DIR}"/lib/release.sh
@@ -366,9 +373,9 @@ pkgctl_build() {
 			fi
 
 			if (( OFFLOAD )); then
-				offload-build --repo "${pkgrepo}" -- "${BUILD_OPTIONS[@]}" -- "${MAKECHROOT_OPTIONS[@]}" -l "${WORKER}"
+				offload-build --repo "${pkgrepo}" -- "${BUILD_OPTIONS[@]}" -- "${MAKECHROOT_OPTIONS[@]}" -l "${WORKER}" -- "${MAKEPKG_OPTIONS[@]}"
 			else
-				"${BUILDTOOL}" "${BUILD_OPTIONS[@]}" -- "${MAKECHROOT_OPTIONS[@]}" -l "${WORKER}"
+				"${BUILDTOOL}" "${BUILD_OPTIONS[@]}" -- "${MAKECHROOT_OPTIONS[@]}" -l "${WORKER}" -- "${MAKEPKG_OPTIONS[@]}"
 			fi
 		done
 
-- 
cgit v1.2.3-70-g09d2


From 4289be212b38cbd9a1676303224b6af5c00bd429 Mon Sep 17 00:00:00 2001
From: Christian Heusel <christian@heusel.eu>
Date: Tue, 18 Apr 2023 01:15:24 +0200
Subject: build: allow release options only in combination with --release

It leads to weird expectations when using --db-update or --message
without --release. Make the behavior more user friendly, by aborting the
operation and explaining that release options only work in conjunction
with the release option.

Fixes #131

Signed-off-by: Christian Heusel <christian@heusel.eu>
---
 doc/man/pkgctl-build.1.asciidoc |  4 +++-
 src/lib/build/build.sh          | 10 ++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

(limited to 'doc/man/pkgctl-build.1.asciidoc')

diff --git a/doc/man/pkgctl-build.1.asciidoc b/doc/man/pkgctl-build.1.asciidoc
index 6ae3872..489926e 100644
--- a/doc/man/pkgctl-build.1.asciidoc
+++ b/doc/man/pkgctl-build.1.asciidoc
@@ -60,7 +60,9 @@ Release Options
 ---------------
 
 *-r, --release*::
-	Automatically commit, tag and release after building
+	Automatically commit, tag and release after building +
+	Specifying this option is required when using any of the following options
+	in this section
 
 *-m, --message* 'MSG'::
 	Use the given <msg> as the commit message
diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh
index fff8125..2153200 100644
--- a/src/lib/build/build.sh
+++ b/src/lib/build/build.sh
@@ -238,6 +238,16 @@ pkgctl_build() {
 		esac
 	done
 
+	# check if any release specific options were specified without releasing
+	if (( ! RELEASE )); then
+		if (( DB_UPDATE )); then
+			die "cannot use --db-update without --release"
+		fi
+		if [[ -n "${MESSAGE}" ]]; then
+			die "cannot use --message without --release"
+		fi
+	fi
+
 	# check if invoked without any path from within a packaging repo
 	if (( ${#paths[@]} == 0 )); then
 		if [[ -f PKGBUILD ]]; then
-- 
cgit v1.2.3-70-g09d2


From 830dcde2d8353dbcce1e831adb7c7e8f538210a3 Mon Sep 17 00:00:00 2001
From: Levente Polyak <anthraxx@archlinux.org>
Date: Fri, 5 May 2023 20:21:38 +0200
Subject: pkgctl build: support worker slots for none tty builds

Allow overriding the worker slot with a dedicated option. Furthermore
detect if the current tty is no pts and fall back to choosing a random
worker slot between 1 and number of available processing units.

Fixes #137

Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
---
 contrib/completion/bash/devtools.in |  3 +++
 contrib/completion/zsh/_devtools.in |  1 +
 doc/man/pkgctl-build.1.asciidoc     |  6 ++++++
 src/lib/build/build.sh              | 23 ++++++++++++++++++-----
 4 files changed, 28 insertions(+), 5 deletions(-)

(limited to 'doc/man/pkgctl-build.1.asciidoc')

diff --git a/contrib/completion/bash/devtools.in b/contrib/completion/bash/devtools.in
index 31269dd..b0a90e5 100644
--- a/contrib/completion/bash/devtools.in
+++ b/contrib/completion/bash/devtools.in
@@ -168,6 +168,7 @@ _pkgctl_build_args=(
 	-t --testing
 	-o --offload
 	-c --clean
+	-w --worker
 
 	--pkgver
 	--pkgrel
@@ -182,6 +183,8 @@ _pkgctl_build_args=(
 )
 _pkgctl_build_args__arch_opts() { _devtools_completions_arch; }
 _pkgctl_build_args__repo_opts() { _devtools_completions_repo; }
+_pkgctl_build_args__worker_opts() { :; }
+_pkgctl_build_args_w_opts() { _pkgctl_build_args__worker_opts; }
 _pkgctl_build_args__pkgver_opts() { :; }
 _pkgctl_build_args__pkgrel_opts() { :; }
 _pkgctl_build_args__message_opts() { :; }
diff --git a/contrib/completion/zsh/_devtools.in b/contrib/completion/zsh/_devtools.in
index ed52a22..45ffde3 100644
--- a/contrib/completion/zsh/_devtools.in
+++ b/contrib/completion/zsh/_devtools.in
@@ -42,6 +42,7 @@ _pkgctl_build_args=(
 	'(-o --offload)'{-o,--offload}'[Build on a remote server and transfer artifacts afterwards]'
 	'(-c --clean)'{-c,--clean}'[Recreate the chroot before building]'
 	'(-I --install)'{-I,--install}'[Install a package into the working copy of the chroot]:target:_files -g "*.pkg.tar.*(.)"'
+	'(-w --worker)'{-w,--worker}'[Name of the worker slot, useful for concurrent builds (disables auto-detection)]:slot:'
 	'--nocheck[Do not run the check() function in the PKGBUILD]'
 	'--pkgver=[Set pkgver, reset pkgrel and update checksums]:pkgver:'
 	'--pkgrel=[Set pkgrel to a given value]:pkgrel:'
diff --git a/doc/man/pkgctl-build.1.asciidoc b/doc/man/pkgctl-build.1.asciidoc
index 489926e..f68e7cf 100644
--- a/doc/man/pkgctl-build.1.asciidoc
+++ b/doc/man/pkgctl-build.1.asciidoc
@@ -38,6 +38,12 @@ Build Options
 *-I, --install* 'FILE'::
 	Install a package into the working copy of the chroot
 
+*-w, --worker* 'SLOT'::
+	Name of the worker slot, useful for concurrent builds. By default the slot
+	is automatically assigned to the current tty pts number. In case the caller
+	is not a tty, choose a random slot between 1 and number of available
+	processing units.
+
 *--nocheck*::
 	Do not run the check() function in the PKGBUILD
 
diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh
index 2153200..191fded 100644
--- a/src/lib/build/build.sh
+++ b/src/lib/build/build.sh
@@ -25,6 +25,7 @@ source /usr/share/makepkg/util/config.sh
 source /usr/share/makepkg/util/message.sh
 
 set -e
+set -o pipefail
 
 
 pkgctl_build_usage() {
@@ -47,6 +48,7 @@ pkgctl_build_usage() {
 		    -o, --offload        Build on a remote server and transfer artifacts afterwards
 		    -c, --clean          Recreate the chroot before building
 		    -I, --install FILE   Install a package into the working copy of the chroot
+		    -w, --worker SLOT    Name of the worker slot, useful for concurrent builds (disables automatic names)
 		    --nocheck            Do not run the check() function in the PKGBUILD
 
 		PKGBUILD OPTIONS
@@ -123,9 +125,8 @@ pkgctl_build() {
 	local RELEASE_OPTIONS=()
 	local MAKEPKG_OPTIONS=()
 
-	local PTS
-	PTS="$(tty | sed 's|/dev/pts/||')"
-	local WORKER="${USER}-${PTS}"
+	local WORKER=
+	local WORKER_SLOT=
 
 	# variables
 	local path pkgbase pkgrepo source
@@ -224,6 +225,11 @@ pkgctl_build() {
 				DB_UPDATE=1
 				shift
 				;;
+			-w|--worker)
+				(( $# <= 1 )) && die "missing argument for %s" "$1"
+				WORKER_SLOT=$2
+				shift 2
+				;;
 			--)
 				shift
 				break
@@ -258,6 +264,12 @@ pkgctl_build() {
 		fi
 	fi
 
+	# assign default worker slot
+	if [[ -z ${WORKER_SLOT} ]] && ! WORKER_SLOT="$(tty | sed 's|/dev/pts/||')"; then
+		WORKER_SLOT=$(( RANDOM % $(nproc) + 1 ))
+	fi
+	WORKER="${USER}-${WORKER_SLOT}"
+
 	# Update pacman cache for auto-detection
 	if [[ -z ${REPO} ]]; then
 		update_pacman_repo_cache
@@ -311,8 +323,9 @@ pkgctl_build() {
 		fi
 
 		# print gathered build modes
-		msg2 "repo: ${pkgrepo}"
-		msg2 "arch: ${BUILD_ARCH[*]}"
+		msg2 "  repo: ${pkgrepo}"
+		msg2 "  arch: ${BUILD_ARCH[*]}"
+		msg2 "worker: ${WORKER}"
 
 		# increment pkgrel on rebuild
 		if (( REBUILD )); then
-- 
cgit v1.2.3-70-g09d2

