From 0ea7e9e0e586d092bcc991789dbf23b5981204a3 Mon Sep 17 00:00:00 2001 From: Christian Heusel Date: Mon, 12 Jun 2023 19:14:24 +0200 Subject: chore(doc): fix spelling typo in pkgrel detection Signed-off-by: Christian Heusel Signed-off-by: Levente Polyak --- src/lib/build/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib/build') diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index 3394395..aa2293c 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -329,7 +329,7 @@ pkgctl_build() { # increment pkgrel on rebuild if (( REBUILD )); then - # try to figure out of pkgrel has been changed + # try to figure out if pkgrel has been changed if ! old_pkgrel=$(git_diff_tree HEAD PKGBUILD | grep --perl-regexp --only-matching --max-count=1 '^-pkgrel=\K\w+'); then old_pkgrel=${pkgrel} fi -- cgit v1.2.3-54-g00ecf From 720b7c9b0524fd2dfb8b811985b55237ffe2de69 Mon Sep 17 00:00:00 2001 From: Christian Heusel Date: Thu, 15 Jun 2023 11:05:12 +0200 Subject: chore(build): skip invalid architectures on autodetection This is done so that pkgctl can be better used to build aur packages which can have arch=(...) settings for which we do not have a clean chroot builder. Signed-off-by: Christian Heusel --- src/lib/build/build.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/lib/build') diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index aa2293c..ecdeaad 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -129,7 +129,7 @@ pkgctl_build() { local WORKER_SLOT= # variables - local path pkgbase pkgrepo source + local loop_arch path pkgbase pkgrepo source while (( $# )); do case $1 in @@ -318,7 +318,13 @@ pkgctl_build() { if in_array any "${arch[@]}"; then BUILD_ARCH=("${_arch[0]}") else - BUILD_ARCH+=("${arch[@]}") + for loop_arch in "${arch[@]}"; do + if in_array "${loop_arch}" "${_arch[@]}"; then + BUILD_ARCH+=("$loop_arch") + else + warning 'invalid architecture, not building for: %s' "${loop_arch}" + fi + done fi fi -- cgit v1.2.3-54-g00ecf From 9f7808c26e4270370bb878de56004ddda49b7ce9 Mon Sep 17 00:00:00 2001 From: Christian Heusel Date: Thu, 27 Jul 2023 11:53:11 +0200 Subject: fix(build): installing packages into the chroot fails for relative links As the relative links are relative to the pkgctl invocations PWD and not necessarily relative to the location where makechrootpkg is invoked from this fails unexpectedly. This commit fixes this by just using the full path when passing the location to makechrootpkg. Fixes https://gitlab.archlinux.org/archlinux/devtools/-/issues/181 Signed-off-by: Christian Heusel --- src/lib/build/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib/build') diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index ecdeaad..a5a272d 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -200,7 +200,7 @@ pkgctl_build() { ;; -I|--install) (( $# <= 1 )) && die "missing argument for %s" "$1" - MAKECHROOT_OPTIONS+=("-I" "$2") + MAKECHROOT_OPTIONS+=("-I" "$(realpath "$2")") warning 'installing packages into the chroot may break reproducible builds, use with caution!' shift 2 ;; -- cgit v1.2.3-54-g00ecf From 0669315821ea0af00fcc2c6271eb474174173e0a Mon Sep 17 00:00:00 2001 From: Christian Heusel Date: Fri, 21 Jul 2023 11:04:13 +0200 Subject: chore: refactor variable names in valid-{tags,repos}.sh Even though the variables in these files are globablly used they have a weirdly local sounding name. This commit fixes this by refactoring all usages throughout our codebase. Signed-off-by: Christian Heusel --- contrib/completion/bash/devtools.in | 8 ++++---- contrib/completion/zsh/_devtools.in | 20 ++++++++++---------- src/archrelease.in | 2 +- src/lib/build/build.sh | 2 +- src/lib/release.sh | 2 +- src/lib/valid-repos.sh | 4 ++-- src/lib/valid-tags.sh | 4 ++-- src/sogrep.in | 8 ++++---- 8 files changed, 25 insertions(+), 25 deletions(-) (limited to 'src/lib/build') diff --git a/contrib/completion/bash/devtools.in b/contrib/completion/bash/devtools.in index 3faad27..b28258f 100644 --- a/contrib/completion/bash/devtools.in +++ b/contrib/completion/bash/devtools.in @@ -8,7 +8,7 @@ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-tags.sh # shellcheck source=src/lib/valid-repos.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-repos.sh -_binary_arch=${_arch[*]:0:-1} +_binary_arch=${DEVTOOLS_VALID_ARCHES[*]:0:-1} _colors=(never always auto) @@ -355,14 +355,14 @@ _devtools_completions_color() { mapfile -t COMPREPLY < <(compgen -W "${_colors[*]}" -- "$cur") } _devtools_completions_arch() { - mapfile -t COMPREPLY < <(compgen -W "${_arch[*]}" -- "$cur") + mapfile -t COMPREPLY < <(compgen -W "${DEVTOOLS_VALID_ARCHES[*]}" -- "$cur") } _devtools_completions_repo() { local optional=${1:-} - mapfile -t COMPREPLY < <(compgen -W "${optional} ${_repos[*]}" -- "$cur") + mapfile -t COMPREPLY < <(compgen -W "${optional} ${DEVTOOLS_VALID_REPOS[*]}" -- "$cur") } _devtools_completions_build_repo() { - mapfile -t COMPREPLY < <(compgen -W "${_build_repos[*]}" -- "$cur") + mapfile -t COMPREPLY < <(compgen -W "${DEVTOOLS_VALID_BUILDREPOS[*]}" -- "$cur") } _devtools_completions_all_packages() { mapfile -t COMPREPLY < <(compgen -W "$(pacman -Sql)" -- "$cur") diff --git a/contrib/completion/zsh/_devtools.in b/contrib/completion/zsh/_devtools.in index bd17466..49c4113 100644 --- a/contrib/completion/zsh/_devtools.in +++ b/contrib/completion/zsh/_devtools.in @@ -8,7 +8,7 @@ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-tags.sh # shellcheck source=src/lib/valid-repos.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-repos.sh -_binary_arch=${_arch[*]:0:-1} +_binary_arch=${DEVTOOLS_VALID_ARCHES[*]:0:-1} _colors=(never always auto) _archbuild_args=( @@ -36,7 +36,7 @@ _pkgctl_auth_status_args=( _pkgctl_build_args=( "--arch=[Specify architectures to build for (disables auto-detection)]:arch:($_arch[*])" - "--repo=[Specify a target repository (disables auto-detection)]:repo:($_repos[*])" + "--repo=[Specify a target repository (disables auto-detection)]:repo:($DEVTOOLS_VALID_REPOS[*])" '(-s --staging)'{-s,--staging}'[Build against the staging counterpart of the auto-detected repo]' '(-t --testing)'{-t,--testing}'[Build against the testing counterpart of the auto-detected repo]' '(-o --offload)'{-o,--offload}'[Build on a remote server and transfer artifacts afterwards]' @@ -64,15 +64,15 @@ _pkgctl_db_cmds=( _pkgctl_db_move_args=( '(-h --help)'{-h,--help}'[Display usage]' - "1:src-repo:($_repos[*])" - "2:target-repo:($_repos[*])" + "1:src-repo:($DEVTOOLS_VALID_REPOS[*])" + "2:target-repo:($DEVTOOLS_VALID_REPOS[*])" '*:pkgbase:_devtools_completions_all_packages' ) _pkgctl_db_remove_args=( '(-a --arch=)'{-a,--arch=}"[Override the architecture (disables auto-detection)]:arch:($_arch[*])" '(-h --help)'{-h,--help}'[Display usage]' - "1:repo:($_repos[*])" + "1:repo:($DEVTOOLS_VALID_REPOS[*])" '*:pkgbase:_devtools_completions_all_packages' ) @@ -82,7 +82,7 @@ _pkgctl_db_update_args=( _pkgctl_release_args=( '(-m --message=)'{-m,--message=}"[Use the given as the commit message]:message:" - '(-r --repo=)'{-r,--repo=}"[Specify a target repository (disables auto-detection)]:repo:($_repos[*])" + '(-r --repo=)'{-r,--repo=}"[Specify a target repository (disables auto-detection)]:repo:($DEVTOOLS_VALID_REPOS[*])" '(-s --staging)'{-s,--staging}'[Release to the staging counterpart of the auto-detected repo]' '(-t --testing)'{-t,--testing}'[Release to the testing counterpart of the auto-detected repo]' '(-u --db-update)'{-u,--db-update}'[Automatically update the pacman database after uploading]' @@ -146,14 +146,14 @@ _arch_nspawn_args=( _archrelease_args=( '-f[Force release without checks]' - "*:arch:($_tags[*])" + "*:arch:($DEVTOOLS_VALID_TAGS[*])" ) _commitpkg_args=( '-f[Force release without checks]' '-s[Target repo server]' '-l[Set bandwidth limit]:limit' - "-a[Release to a specific architecture only]:arch:($_arch[*])" + "-a[Release to a specific architecture only]:arch:($DEVTOOLS_VALID_ARCHES[*])" '1:commit_msg' ) @@ -212,12 +212,12 @@ _sogrep_args=( '(-v --verbose)'{-v,--verbose}'[Show matched links in addition to pkgname]' '(-r --refresh)'{-r,--refresh}'[Refresh the links databases]' '(-h --help)'{-h,--help}'[Display usage]' - '1:repo:(all $_repos[*])' + '1:repo:(all $DEVTOOLS_VALID_REPOS[*])' '2:libname' ) _offload_build_args=( - '(-r --repo)'{-r,--repo}'[Build against a specific repository]:repo:($_build_repos[*])' + '(-r --repo)'{-r,--repo}'[Build against a specific repository]:repo:($DEVTOOLS_VALID_BUILDREPOS[*])' '(-a --arch)'{-a,--arch}'[Build against a specific architecture]:arch:(${_binary_arch[*]})' '(-s --server)'{-s,--server}'[Offload to a specific Build server]:server:' '(-h --help)'{-h,--help}'[Display usage]' diff --git a/src/archrelease.in b/src/archrelease.in index 818b0ca..84aed28 100644 --- a/src/archrelease.in +++ b/src/archrelease.in @@ -35,7 +35,7 @@ fi # validate repo is really repo-arch if [[ -z $FORCE ]]; then for tag in "$@"; do - if ! in_array "$tag" "${_tags[@]}"; then + if ! in_array "$tag" "${DEVTOOLS_VALID_TAGS[@]}"; then die "archrelease: Invalid tag: '%s' (use -f to force release)" "$tag" fi done diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index a5a272d..f2549f2 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -274,7 +274,7 @@ pkgctl_build() { if [[ -z ${REPO} ]]; then update_pacman_repo_cache # Check valid repos if not resolved dynamically - elif ! in_array "${REPO}" "${_repos[@]}"; then + elif ! in_array "${REPO}" "${DEVTOOLS_VALID_REPOS[@]}"; then die "Invalid repository target: %s" "${REPO}" fi diff --git a/src/lib/release.sh b/src/lib/release.sh index aabbd35..028d92e 100644 --- a/src/lib/release.sh +++ b/src/lib/release.sh @@ -126,7 +126,7 @@ pkgctl_release() { if [[ -z ${REPO} ]]; then update_pacman_repo_cache # Check valid repos if not resolved dynamically - elif ! in_array "${REPO}" "${_repos[@]}"; then + elif ! in_array "${REPO}" "${DEVTOOLS_VALID_REPOS[@]}"; then die "Invalid repository target: %s" "${REPO}" fi diff --git a/src/lib/valid-repos.sh b/src/lib/valid-repos.sh index 14f90ce..af8a552 100644 --- a/src/lib/valid-repos.sh +++ b/src/lib/valid-repos.sh @@ -4,7 +4,7 @@ : # shellcheck disable=2034 -_repos=( +DEVTOOLS_VALID_REPOS=( core core-staging core-testing extra extra-staging extra-testing multilib multilib-staging multilib-testing @@ -13,7 +13,7 @@ _repos=( ) # shellcheck disable=2034 -_build_repos=( +DEVTOOLS_VALID_BUILDREPOS=( core-staging core-testing extra extra-staging extra-testing multilib multilib-staging multilib-testing diff --git a/src/lib/valid-tags.sh b/src/lib/valid-tags.sh index ca8d7d7..cef0cc6 100644 --- a/src/lib/valid-tags.sh +++ b/src/lib/valid-tags.sh @@ -4,13 +4,13 @@ : # shellcheck disable=2034 -_arch=( +DEVTOOLS_VALID_ARCHES=( x86_64 any ) # shellcheck disable=2034 -_tags=( +DEVTOOLS_VALID_TAGS=( core-x86_64 core-any core-staging-x86_64 core-staging-any core-testing-x86_64 core-testing-any diff --git a/src/sogrep.in b/src/sogrep.in index 0ee05cc..9f51e53 100644 --- a/src/sogrep.in +++ b/src/sogrep.in @@ -31,7 +31,7 @@ recache() { (( VERBOSE )) && verbosity=--progress-bar - for repo in "${_repos[@]}"; do + for repo in "${DEVTOOLS_VALID_REPOS[@]}"; do if [[ -n "$SOLINKS_MIRROR" ]]; then mirror="$SOLINKS_MIRROR" elif ! mirror="$(set -o pipefail; pacman-conf --repo "$repo" Server 2>/dev/null | head -n1)"; then @@ -72,7 +72,7 @@ is_outdated_cache() { # links databases are generated at about the same time every day; we should # attempt to check for new database files if any of them are over a day old - for repo in "${_repos[@]}"; do + for repo in "${DEVTOOLS_VALID_REPOS[@]}"; do for arch in "${arches[@]}"; do local dbpath=${SOCACHE_DIR}/${arch}/${repo}.links.tar.gz if [[ ! -f ${dbpath} ]] || [[ $(find "${dbpath}" -mtime +0) ]]; then @@ -85,10 +85,10 @@ is_outdated_cache() { } search() { - local repo=$1 arch lib=$2 srepos=("${_repos[@]}") + local repo=$1 arch lib=$2 srepos=("${DEVTOOLS_VALID_REPOS[@]}") if [[ $repo != all ]]; then - if ! in_array "${repo}" "${_repos[@]}"; then + if ! in_array "${repo}" "${DEVTOOLS_VALID_REPOS[@]}"; then echo "${BASH_SOURCE[0]##*/}: unrecognized repo '$repo'" echo "Try '${BASH_SOURCE[0]##*/} --help' for more information." exit 1 -- cgit v1.2.3-54-g00ecf From 6f106e7cd6c19d8666d25676afc8dcc5975d124b Mon Sep 17 00:00:00 2001 From: Christian Heusel Date: Fri, 21 Jul 2023 11:37:27 +0200 Subject: chore: refactor loop variable name Component: pkgctl build Signed-off-by: Christian Heusel --- src/lib/build/build.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/lib/build') diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index f2549f2..d6b530d 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -129,7 +129,7 @@ pkgctl_build() { local WORKER_SLOT= # variables - local loop_arch path pkgbase pkgrepo source + local _arch path pkgbase pkgrepo source while (( $# )); do case $1 in @@ -318,11 +318,11 @@ pkgctl_build() { if in_array any "${arch[@]}"; then BUILD_ARCH=("${_arch[0]}") else - for loop_arch in "${arch[@]}"; do - if in_array "${loop_arch}" "${_arch[@]}"; then - BUILD_ARCH+=("$loop_arch") + for _arch in "${arch[@]}"; do + if in_array "${_arch}" "${_arch[@]}"; then + BUILD_ARCH+=("$_arch") else - warning 'invalid architecture, not building for: %s' "${loop_arch}" + warning 'invalid architecture, not building for: %s' "${_arch}" fi done fi -- cgit v1.2.3-54-g00ecf From 5cbe9ad61296c91251299bcb0f32aa2e0b3dd5ea Mon Sep 17 00:00:00 2001 From: Antonio Rojas Date: Fri, 13 Oct 2023 20:13:31 +0000 Subject: fix(build): allow using --install and --offload simultaneously Don't take the full (local) path of the package to install when using --offload. Fixes #194 Component: pkgctl build --- src/lib/build/build.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/lib/build') diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index d6b530d..bf6339a 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -200,7 +200,11 @@ pkgctl_build() { ;; -I|--install) (( $# <= 1 )) && die "missing argument for %s" "$1" - MAKECHROOT_OPTIONS+=("-I" "$(realpath "$2")") + if (( OFFLOAD )); then + MAKECHROOT_OPTIONS+=("-I" "$2") + else + MAKECHROOT_OPTIONS+=("-I" "$(realpath "$2")") + fi warning 'installing packages into the chroot may break reproducible builds, use with caution!' shift 2 ;; -- cgit v1.2.3-54-g00ecf From e0ab20d05c7cf1807194d40b222970700f9f92fc Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Tue, 17 Oct 2023 23:23:36 +0200 Subject: fix(build): use correct variable to reference available architectures The referenced places were missing in a previous refactoring commit and hence broke the build command in multiple ways. Fixes 0669315821ea0af00fcc2c6271eb474174173e0a --- src/lib/build/build.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/lib/build') diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index bf6339a..455f38a 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -146,11 +146,11 @@ pkgctl_build() { --arch) (( $# <= 1 )) && die "missing argument for %s" "$1" if [[ ${2} == all ]]; then - BUILD_ARCH=("${_arch[@]::${#_arch[@]}-1}") + BUILD_ARCH=("${DEVTOOLS_VALID_ARCHES[@]::${#DEVTOOLS_VALID_ARCHES[@]}-1}") elif [[ ${2} == any ]]; then - BUILD_ARCH=("${_arch[0]}") + BUILD_ARCH=("${DEVTOOLS_VALID_ARCHES[0]}") elif ! in_array "${2}" "${BUILD_ARCH[@]}"; then - if ! in_array "${2}" "${_arch[@]}"; then + if ! in_array "${2}" "${DEVTOOLS_VALID_ARCHES[@]}"; then die 'invalid architecture: %s' "${2}" fi BUILD_ARCH+=("${2}") @@ -320,10 +320,10 @@ pkgctl_build() { BUILD_ARCH=("") elif (( ${#BUILD_ARCH[@]} == 0 )); then if in_array any "${arch[@]}"; then - BUILD_ARCH=("${_arch[0]}") + BUILD_ARCH=("${DEVTOOLS_VALID_ARCHES[0]}") else for _arch in "${arch[@]}"; do - if in_array "${_arch}" "${_arch[@]}"; then + if in_array "${_arch}" "${DEVTOOLS_VALID_ARCHES[@]}"; then BUILD_ARCH+=("$_arch") else warning 'invalid architecture, not building for: %s' "${_arch}" -- cgit v1.2.3-54-g00ecf From e7b82f36ef586127453e8c68660e0ef7826d0127 Mon Sep 17 00:00:00 2001 From: Christian Heusel Date: Tue, 25 Jul 2023 11:19:11 +0200 Subject: feat(build): add --updpkgsums option This is useful so people who update patches etc. can update their checksums on building. The functionality itself was already implemented for --pkgver, but was not available separately. Fixes #168 Component: pkgctl build Signed-off-by: Christian Heusel --- contrib/completion/bash/devtools.in | 1 + contrib/completion/zsh/_devtools.in | 1 + doc/man/pkgctl-build.1.asciidoc | 3 +++ src/lib/build/build.sh | 5 +++++ 4 files changed, 10 insertions(+) (limited to 'src/lib/build') diff --git a/contrib/completion/bash/devtools.in b/contrib/completion/bash/devtools.in index b28258f..e0fca51 100644 --- a/contrib/completion/bash/devtools.in +++ b/contrib/completion/bash/devtools.in @@ -173,6 +173,7 @@ _pkgctl_build_args=( --pkgver --pkgrel --rebuild + --updpkgsums -e --edit -r --release diff --git a/contrib/completion/zsh/_devtools.in b/contrib/completion/zsh/_devtools.in index 49c4113..d3d6df0 100644 --- a/contrib/completion/zsh/_devtools.in +++ b/contrib/completion/zsh/_devtools.in @@ -47,6 +47,7 @@ _pkgctl_build_args=( '--pkgver=[Set pkgver, reset pkgrel and update checksums]:pkgver:' '--pkgrel=[Set pkgrel to a given value]:pkgrel:' '--rebuild[Increment the pkgrel variable]' + '--updpkgsums[Regenerate the checksums]' '(-e --edit)'{-e,--edit}'[Edit the PKGBUILD before building]' '(-r --release)'{-r,--release}'[Automatically commit, tag and release after building]' '(-m --message=)'{-m,--message=}"[Use the given as the commit message]:message:" diff --git a/doc/man/pkgctl-build.1.asciidoc b/doc/man/pkgctl-build.1.asciidoc index f68e7cf..2637ebc 100644 --- a/doc/man/pkgctl-build.1.asciidoc +++ b/doc/man/pkgctl-build.1.asciidoc @@ -59,6 +59,9 @@ PKGBUILD Options *--rebuild*:: Increment the current pkgrel variable +*--updpkgsums*:: + Regenerate the checksums + *-e, --edit*:: Edit the PKGBUILD before building diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index 455f38a..8d58b63 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -55,6 +55,7 @@ pkgctl_build_usage() { --pkgver=PKGVER Set pkgver, reset pkgrel and update checksums --pkgrel=PKGREL Set pkgrel to a given value --rebuild Increment the current pkgrel variable + --updpkgsums Regenerate the checksums -e, --edit Edit the PKGBUILD before building RELEASE OPTIONS @@ -169,6 +170,10 @@ pkgctl_build() { PKGREL="${1#*=}" shift ;; + --updpkgsums) + UPDPKGSUMS=1 + shift + ;; --rebuild) # shellcheck source=src/lib/util/git.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/git.sh -- cgit v1.2.3-54-g00ecf From cc369e86d2e060d8b65c7dbbb0c933d18f8aa6b0 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Thu, 23 Mar 2023 23:38:29 +0100 Subject: feat(makechrootpkg): add option to interactively inspect the chroot Implement the -x option for makechrootpkg which allows to get an interactive shell in the chroot after building the package. Useful to ease the debugging of a package build. Depending on the argument, the interactive shell is either always spawned or only when an error occurred during build. This option is also forwarded from `pkgctl build` via the `--inspect` flag. Component: pkgctl build Component: makechrootpkg Signed-off-by: Levente Polyak --- contrib/completion/bash/devtools.in | 9 +++++++++ contrib/completion/zsh/_devtools.in | 4 ++++ doc/man/makechrootpkg.1.asciidoc | 4 ++++ doc/man/pkgctl-build.1.asciidoc | 4 ++++ src/lib/build/build.sh | 11 +++++++++++ src/lib/valid-inspect.sh | 10 ++++++++++ src/makechrootpkg.in | 38 ++++++++++++++++++++++++++++++++----- 7 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 src/lib/valid-inspect.sh (limited to 'src/lib/build') diff --git a/contrib/completion/bash/devtools.in b/contrib/completion/bash/devtools.in index e0fca51..b347b31 100644 --- a/contrib/completion/bash/devtools.in +++ b/contrib/completion/bash/devtools.in @@ -7,6 +7,8 @@ _DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-tags.sh # shellcheck source=src/lib/valid-repos.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-repos.sh +# shellcheck source=src/lib/valid-inspect.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-inspect.sh _binary_arch=${DEVTOOLS_VALID_ARCHES[*]:0:-1} _colors=(never always auto) @@ -24,6 +26,7 @@ _makechrootpkg_args=( -n -T -U + -x ) _makechrootpkg_args_d_opts() { _filedir -d; } _makechrootpkg_args_D_opts() { _filedir -d; } @@ -31,6 +34,7 @@ _makechrootpkg_args_r_opts() { _filedir -d; } _makechrootpkg_args_I_opts() { _filedir '*.pkg.tar.*'; } _makechrootpkg_args_l_opts() { _filedir -d; } _makechrootpkg_args_U_opts() { :; } +_makechrootpkg_args_x_opts() { _devtools_completions_inspect; } _makechrootpkg() { __devtools_complete _makechrootpkg; } complete -F _makechrootpkg makechrootpkg @@ -169,6 +173,7 @@ _pkgctl_build_args=( -o --offload -c --clean -w --worker + --inspect --pkgver --pkgrel @@ -186,6 +191,7 @@ _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__inspect_opts() { _devtools_completions_inspect; } _pkgctl_build_args__pkgver_opts() { :; } _pkgctl_build_args__pkgrel_opts() { :; } _pkgctl_build_args__message_opts() { :; } @@ -371,6 +377,9 @@ _devtools_completions_all_packages() { _devtools_completions_protocol() { mapfile -t COMPREPLY < <(compgen -W "https" -- "$cur") } +_devtools_completions_inspect() { + mapfile -t COMPREPLY < <(compgen -W "${DEVTOOLS_VALID_INSPECT_MODES[*]}" -- "$cur") +} __devtools_complete() { local service=$1 diff --git a/contrib/completion/zsh/_devtools.in b/contrib/completion/zsh/_devtools.in index d3d6df0..feeb2c2 100644 --- a/contrib/completion/zsh/_devtools.in +++ b/contrib/completion/zsh/_devtools.in @@ -7,6 +7,8 @@ _DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-tags.sh # shellcheck source=src/lib/valid-repos.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-repos.sh +# shellcheck source=src/lib/valid-inspect.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-inspect.sh _binary_arch=${DEVTOOLS_VALID_ARCHES[*]:0:-1} _colors=(never always auto) @@ -42,6 +44,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.*(.)"' + "--inspect[Spawn an interactive shell to inspect the chroot (never, always, failure)]:inspect:($DEVTOOLS_VALID_INSPECT_MODES[*])" '(-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:' @@ -190,6 +193,7 @@ _makechrootpkg_args=( '-n[Run namcap on the package]' '-T[Build in a temporary directory]' '-U[Run makepkg as a specified user]:makepkg_user' + "-x[Spawn an interactive shell to inspect the chroot (never, always, failure)]:inspect:($DEVTOOLS_VALID_INSPECT_MODES[*])" ) _mkarchroot_args=( diff --git a/doc/man/makechrootpkg.1.asciidoc b/doc/man/makechrootpkg.1.asciidoc index 12d32f1..3aa1be5 100644 --- a/doc/man/makechrootpkg.1.asciidoc +++ b/doc/man/makechrootpkg.1.asciidoc @@ -73,4 +73,8 @@ Options *-U*:: Run makepkg as a specified user +*-x* :: + Inspect chroot after build, possible modes are 'never' (default), 'always' or 'failure' + + include::include/footer.asciidoc[] diff --git a/doc/man/pkgctl-build.1.asciidoc b/doc/man/pkgctl-build.1.asciidoc index 2637ebc..3f2d44e 100644 --- a/doc/man/pkgctl-build.1.asciidoc +++ b/doc/man/pkgctl-build.1.asciidoc @@ -38,6 +38,10 @@ Build Options *-I, --install* 'FILE':: Install a package into the working copy of the chroot +*--inspect* 'WHEN':: + Spawn an interactive shell to inspect the chroot after building. Useful to ease the debugging of a package build. + + Possible values for 'WHEN' are `'never'`, `'always'` or `'failure'` + *-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 diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index 8d58b63..2b9d4cf 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -20,6 +20,8 @@ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/pacman.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-repos.sh # shellcheck source=src/lib/valid-tags.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-tags.sh +# shellcheck source=src/lib/valid-inspect.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-inspect.sh source /usr/share/makepkg/util/config.sh source /usr/share/makepkg/util/message.sh @@ -48,6 +50,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 + --inspect WHEN Spawn an interactive shell to inspect the chroot (never, always, failure) -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 @@ -218,6 +221,14 @@ pkgctl_build() { warning 'not running checks is disallowed for official packages, except for bootstrapping. Please rebuild after bootstrapping is completed!' shift ;; + --inspect) + (( $# <= 1 )) && die "missing argument for %s" "$1" + if ! in_array "${2}" "${DEVTOOLS_VALID_INSPECT_MODES[@]}"; then + die "Invalid inspect mode: %s" "${2}" + fi + MAKECHROOT_OPTIONS+=("-x" "${2}") + shift 2 + ;; -r|--release) # shellcheck source=src/lib/release.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/release.sh diff --git a/src/lib/valid-inspect.sh b/src/lib/valid-inspect.sh new file mode 100644 index 0000000..3b5dcad --- /dev/null +++ b/src/lib/valid-inspect.sh @@ -0,0 +1,10 @@ +#!/hint/bash +# +# SPDX-License-Identifier: GPL-3.0-or-later + +# shellcheck disable=2034 +DEVTOOLS_VALID_INSPECT_MODES=( + never + always + failure +) diff --git a/src/makechrootpkg.in b/src/makechrootpkg.in index 2cfd849..14b8f11 100644 --- a/src/makechrootpkg.in +++ b/src/makechrootpkg.in @@ -8,9 +8,12 @@ _DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh # shellcheck source=src/lib/archroot.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/archroot.sh +# shellcheck source=src/lib/valid-inspect.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-inspect.sh source /usr/share/makepkg/util/config.sh +source /usr/share/makepkg/util/util.sh shopt -s nullglob @@ -31,6 +34,8 @@ run_checkpkg=0 temp_chroot=0 tmp_opts="nosuid,nodev,size=50%,nr_inodes=2m" +inspect=never + bindmounts_ro=() bindmounts_rw=() @@ -76,6 +81,7 @@ usage() { echo '-C Run checkpkg on the package' echo '-T Build in a temporary directory' echo '-U Run makepkg as a specified user' + echo '-x Inspect chroot after build (never, always, failure)' exit 1 } @@ -280,7 +286,7 @@ move_products() { } # }}} -while getopts 'hcur:I:l:nCTD:d:U:' arg; do +while getopts 'hcur:I:l:nCTD:d:U:x:' arg; do case "$arg" in c) clean_first=1 ;; D) bindmounts_ro+=("--bind-ro=$OPTARG") ;; @@ -293,6 +299,7 @@ while getopts 'hcur:I:l:nCTD:d:U:' arg; do C) run_checkpkg=1 ;; T) temp_chroot=1; copy+="-$$" ;; U) makepkg_user="$OPTARG" ;; + x) inspect="$OPTARG" ;; h|*) usage ;; esac done @@ -314,6 +321,10 @@ else copydir="$chrootdir/$copy" fi +if ! in_array "${inspect}" "${DEVTOOLS_VALID_INSPECT_MODES[@]}"; then + die "Invalid inspect mode: %s" "${inspect}" +fi + # Pass all arguments after -- right to makepkg makepkg_args+=("${@:$OPTIND}") @@ -368,11 +379,16 @@ download_sources prepare_chroot +nspawn_build_args=( + --bind="${PWD//:/\\:}:/startdir" + --bind="${SRCDEST//:/\\:}:/srcdest" + --tmpfs="/tmp:${tmp_opts}" + "${bindmounts_ro[@]}" + "${bindmounts_rw[@]}" +) + if arch-nspawn "$copydir" \ - --bind="${PWD//:/\\:}:/startdir" \ - --bind="${SRCDEST//:/\\:}:/srcdest" \ - --tmpfs="/tmp:${tmp_opts}" \ - "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ + "${nspawn_build_args[@]}" \ /chrootbuild "${makepkg_args[@]}" then mapfile -t pkgnames < <(sudo -u "$makepkg_user" bash -c 'source PKGBUILD; printf "%s\n" "${pkgname[@]}"') @@ -382,6 +398,18 @@ else move_logfiles fi +if [[ $inspect == always ]] || ( [[ $inspect == failure ]] && (( ret != 0 )) ); then + if (( ret == 0 )); then + msg "Build succeeded, inspecting %s" "$copydir" + else + error "Build failed, inspecting %s" "$copydir" + fi + arch-nspawn "$copydir" \ + "${nspawn_build_args[@]}" \ + --user=builduser \ + --chdir=/build +fi + (( temp_chroot )) && delete_chroot "$copydir" "$copy" if (( ret != 0 )); then -- cgit v1.2.3-54-g00ecf From 4425913e4f3bfd3cb346c38e13a10f0002615a55 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Thu, 21 Dec 2023 21:40:57 +0100 Subject: chore(build): use more intuitive update-checksums option for humans The philosophy of our CLI is to provide options that better match human expectations in an intuitive way rather than mimic wording of previous tools with abbreviation. Component: pkgctl build Signed-off-by: Levente Polyak --- contrib/completion/bash/devtools.in | 2 +- contrib/completion/zsh/_devtools.in | 2 +- doc/man/pkgctl-build.1.asciidoc | 8 ++++++-- src/lib/build/build.sh | 12 ++++++------ 4 files changed, 14 insertions(+), 10 deletions(-) (limited to 'src/lib/build') diff --git a/contrib/completion/bash/devtools.in b/contrib/completion/bash/devtools.in index 83264ce..b974257 100644 --- a/contrib/completion/bash/devtools.in +++ b/contrib/completion/bash/devtools.in @@ -179,7 +179,7 @@ _pkgctl_build_args=( --pkgver --pkgrel --rebuild - --updpkgsums + --update-checksums -e --edit -r --release diff --git a/contrib/completion/zsh/_devtools.in b/contrib/completion/zsh/_devtools.in index b82ece4..35ab2dc 100644 --- a/contrib/completion/zsh/_devtools.in +++ b/contrib/completion/zsh/_devtools.in @@ -50,7 +50,7 @@ _pkgctl_build_args=( '--pkgver=[Set pkgver, reset pkgrel and update checksums]:pkgver:' '--pkgrel=[Set pkgrel to a given value]:pkgrel:' '--rebuild[Increment the pkgrel variable]' - '--updpkgsums[Regenerate the checksums]' + '--update-checksums[Force computation and update of the checksums (disables auto-detection)]' '(-e --edit)'{-e,--edit}'[Edit the PKGBUILD before building]' '(-r --release)'{-r,--release}'[Automatically commit, tag and release after building]' '(-m --message=)'{-m,--message=}"[Use the given as the commit message]:message:" diff --git a/doc/man/pkgctl-build.1.asciidoc b/doc/man/pkgctl-build.1.asciidoc index 3f2d44e..12deaaa 100644 --- a/doc/man/pkgctl-build.1.asciidoc +++ b/doc/man/pkgctl-build.1.asciidoc @@ -63,8 +63,12 @@ PKGBUILD Options *--rebuild*:: Increment the current pkgrel variable -*--updpkgsums*:: - Regenerate the checksums +*--update-checksums*:: + Force computation and update of the checksums by disabling auto-detection. + + Should only be used in special circumstances, like when adding new patch + files to the source array. During regular packaging operations, checksums + are either automatically updated when upgrading a package using `--pkgver` + or should remain immutable during rebuilds. *-e, --edit*:: Edit the PKGBUILD before building diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index 2b9d4cf..e0982e4 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -58,7 +58,7 @@ pkgctl_build_usage() { --pkgver=PKGVER Set pkgver, reset pkgrel and update checksums --pkgrel=PKGREL Set pkgrel to a given value --rebuild Increment the current pkgrel variable - --updpkgsums Regenerate the checksums + --update-checksums Force computation and update of the checksums (disables auto-detection) -e, --edit Edit the PKGBUILD before building RELEASE OPTIONS @@ -108,7 +108,7 @@ pkgctl_build() { exit 1 fi - local UPDPKGSUMS=0 + local UPDATE_CHECKSUMS=0 local EDIT=0 local REBUILD=0 local OFFLOAD=0 @@ -165,7 +165,7 @@ pkgctl_build() { pkgctl_build_check_option_group_ver '--pkgver' "${PKGVER}" "${PKGREL}" "${REBUILD}" PKGVER="${1#*=}" PKGREL=1 - UPDPKGSUMS=1 + UPDATE_CHECKSUMS=1 shift ;; --pkgrel=*) @@ -173,8 +173,8 @@ pkgctl_build() { PKGREL="${1#*=}" shift ;; - --updpkgsums) - UPDPKGSUMS=1 + --update-checksums) + UPDATE_CHECKSUMS=1 shift ;; --rebuild) @@ -407,7 +407,7 @@ pkgctl_build() { # update checksums if any sources are declared - if (( UPDPKGSUMS )) && (( ${#source[@]} >= 1 )); then + if (( UPDATE_CHECKSUMS )) && (( ${#source[@]} >= 1 )); then updpkgsums fi -- cgit v1.2.3-54-g00ecf From b264c7f1c771790c53561f5d3f4de589e0000c05 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Sun, 10 Sep 2023 00:00:27 +0200 Subject: feat(util): parallelize srcinfo generation Heavily improve the runtime of huge split packages, by creating an own parallelized high level implementation of the makepkg low level building blocks for srcinfo generation. This reduces the runtine to generate the srcinfo file for thunderbird from 24 seconds down to 1 second. --- src/commitpkg.in | 10 ++++--- src/lib/build/build.sh | 5 ++-- src/lib/util/srcinfo.sh | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 src/lib/util/srcinfo.sh (limited to 'src/lib/build') diff --git a/src/commitpkg.in b/src/commitpkg.in index 016ab22..e17b270 100644 --- a/src/commitpkg.in +++ b/src/commitpkg.in @@ -5,9 +5,12 @@ _DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} # shellcheck source=src/lib/common.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh +# shellcheck source=src/lib/util/srcinfo.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/srcinfo.sh source /usr/share/makepkg/util/util.sh -source /usr/share/makepkg/srcinfo.sh + +set -eo pipefail check_pkgbuild_validity() { @@ -185,10 +188,9 @@ done check_pkgbuild_validity # auto generate .SRCINFO -stat_busy 'Generating .SRCINFO' -write_srcinfo_content > .SRCINFO +# shellcheck disable=SC2119 +write_srcinfo_file git add --force .SRCINFO -stat_done if [[ -n $(git status --porcelain --untracked-files=no) ]]; then stat_busy 'Staging files' diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index e0982e4..8b4240c 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -14,6 +14,8 @@ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/db/update.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/release.sh # shellcheck source=src/lib/util/git.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/git.sh +# shellcheck source=src/lib/util/srcinfo.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/srcinfo.sh # shellcheck source=src/lib/util/pacman.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/pacman.sh # shellcheck source=src/lib/valid-repos.sh @@ -26,8 +28,7 @@ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-inspect.sh source /usr/share/makepkg/util/config.sh source /usr/share/makepkg/util/message.sh -set -e -set -o pipefail +set -eo pipefail pkgctl_build_usage() { diff --git a/src/lib/util/srcinfo.sh b/src/lib/util/srcinfo.sh new file mode 100644 index 0000000..b646dc3 --- /dev/null +++ b/src/lib/util/srcinfo.sh @@ -0,0 +1,69 @@ +#!/hint/bash +# +# SPDX-License-Identifier: GPL-3.0-or-later + +[[ -z ${DEVTOOLS_INCLUDE_UTIL_SRCINFO_SH:-} ]] || return 0 +DEVTOOLS_INCLUDE_UTIL_SRCINFO_SH=1 + +_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} +# shellcheck source=src/lib/common.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh + +source /usr/share/makepkg/util/util.sh +source /usr/share/makepkg/srcinfo.sh + +set -eo pipefail + + +print_srcinfo() { + local pkgpath=${1:-.} + local outdir pkg pid + local pids=() + + # source the PKGBUILD + # shellcheck source=contrib/makepkg/PKGBUILD.proto + . "${pkgpath}"/PKGBUILD + + # run without parallelization for single packages + if (( ${#pkgname[@]} == 1 )); then + write_srcinfo_content + return 0 + fi + + [[ -z ${WORKDIR:-} ]] && setup_workdir + outdir=$(mktemp --directory --tmpdir="${WORKDIR}" pkgctl-srcinfo.XXXXXXXXXX) + + # fork workload for each split pkgname + for pkg in "${pkgname[@]}"; do + ( + # deactivate errexit to avoid makepkg abort on grep_function + set +e + srcinfo_write_package "$pkg" > "${outdir}/${pkg}" + )& + pids+=($!) + done + + # join workload + for pid in "${pids[@]}"; do + if ! wait "${pid}"; then + return 1 + fi + done + + # collect output + srcinfo_write_global + for pkg in "${pkgname[@]}"; do + srcinfo_separate_section + cat "${outdir}/${pkg}" + done +} + +write_srcinfo_file() { + local pkgpath=${1:-.} + stat_busy 'Generating .SRCINFO' + if ! print_srcinfo "${pkgpath}" > "${pkgpath}"/.SRCINFO; then + error 'Failed to write .SRCINFO file' + return 1 + fi + stat_done +} -- cgit v1.2.3-54-g00ecf From ef04960b98595de8f9405d0069324b6b1fddb5ba Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Sat, 23 Dec 2023 23:49:07 +0100 Subject: feat(build): update srcinfo file after build The srcinfo file is essentially a representation of the current build recipes, hence generate an up to date version by adding it as secondary build artifact to the build process. Signed-off-by: Levente Polyak --- src/lib/build/build.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/lib/build') diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index 8b4240c..a19dd37 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -429,6 +429,10 @@ pkgctl_build() { fi done + # auto generate .SRCINFO + # shellcheck disable=SC2119 + write_srcinfo_file + # release the build if (( RELEASE )); then pkgctl_release --repo "${pkgrepo}" "${RELEASE_OPTIONS[@]}" -- cgit v1.2.3-54-g00ecf From e413b65df3dcddeb94da2defb53ab17ef2a8558d Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Wed, 3 Jan 2024 16:21:40 +0100 Subject: fix(build): re-source the PKGBUILD to update changed values During certain operations like --edit, --pkgver etc the PKGBUILD may change since last sourced. If a modified checksum of the PKGBUILD is detected, re-source it before processing. Signed-off-by: Levente Polyak --- src/lib/build/build.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/lib/build') diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index a19dd37..5276653 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -134,7 +134,7 @@ pkgctl_build() { local WORKER_SLOT= # variables - local _arch path pkgbase pkgrepo source + local _arch path pkgbase pkgrepo source pkgbuild_checksum while (( $# )); do case $1 in @@ -311,6 +311,7 @@ pkgctl_build() { . ./PKGBUILD pkgbase=${pkgbase:-$pkgname} pkgrepo=${REPO} + pkgbuild_checksum=$(b2sum PKGBUILD | awk '{print $1}') msg "Building ${pkgbase}" # auto-detection of build target @@ -412,6 +413,12 @@ pkgctl_build() { updpkgsums fi + # re-source the PKGBUILD if it changed + if [[ ${pkgbuild_checksum} != "$(b2sum PKGBUILD | awk '{print $1}')" ]]; then + # shellcheck source=contrib/makepkg/PKGBUILD.proto + . ./PKGBUILD + fi + # execute build for arch in "${BUILD_ARCH[@]}"; do if [[ -n $arch ]]; then -- cgit v1.2.3-54-g00ecf From db8c157eeaac98d23247dac1236642c79a1d257f Mon Sep 17 00:00:00 2001 From: Christian Heusel Date: Fri, 5 Jan 2024 17:43:34 +0100 Subject: chore(build): factor out functions to modify PKGBUILDs Component: pkgctl build Signed-off-by: Christian Heusel --- src/lib/build/build.sh | 12 ++++-------- src/lib/util/pkgbuild.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 src/lib/util/pkgbuild.sh (limited to 'src/lib/build') diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index 5276653..712be22 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -18,6 +18,8 @@ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/git.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/srcinfo.sh # shellcheck source=src/lib/util/pacman.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/pacman.sh +# shellcheck source=src/lib/util/pkgbuild.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/pkgbuild.sh # shellcheck source=src/lib/valid-repos.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-repos.sh # shellcheck source=src/lib/valid-tags.sh @@ -374,20 +376,14 @@ pkgctl_build() { # update pkgver if [[ -n ${PKGVER} ]]; then - if [[ $(type -t pkgver) == function ]]; then - # TODO: check if die or warn, if we provide _commit _gitcommit setter maybe? - warning 'setting pkgver variable has no effect if the PKGBUILD has a pkgver() function' - fi msg "Bumping pkgver to ${PKGVER}" - grep --extended-regexp --quiet --max-count=1 "^pkgver=${pkgver}$" PKGBUILD || die "Non-standard pkgver declaration" - sed --regexp-extended "s|^(pkgver=)${pkgver}$|\1${PKGVER}|g" -i PKGBUILD + pkgbuild_set_pkgver "${PKGVER}" fi # update pkgrel if [[ -n ${PKGREL} ]]; then msg "Bumping pkgrel to ${PKGREL}" - grep --extended-regexp --quiet --max-count=1 "^pkgrel=${pkgrel}$" PKGBUILD || die "Non-standard pkgrel declaration" - sed --regexp-extended "s|^(pkgrel=)${pkgrel}$|\1${PKGREL}|g" -i PKGBUILD + pkgbuild_set_pkgrel "${PKGREL}" fi # edit PKGBUILD diff --git a/src/lib/util/pkgbuild.sh b/src/lib/util/pkgbuild.sh new file mode 100644 index 0000000..ebf8e5f --- /dev/null +++ b/src/lib/util/pkgbuild.sh @@ -0,0 +1,43 @@ +#!/hint/bash +# +# SPDX-License-Identifier: GPL-3.0-or-later + +[[ -z ${DEVTOOLS_INCLUDE_UTIL_PKGBUILD_SH:-} ]] || return 0 +DEVTOOLS_INCLUDE_UTIL_PKGBUILD_SH=1 + +_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} + +source /usr/share/makepkg/util/message.sh + +set -e + + +# set the pkgver variable in a PKGBUILD +# assumes that the pkgbuild is sourced to detect the presence of a pkgver function +pkgbuild_set_pkgver() { + local new_pkgver=$1 + local pkgver=${pkgver} + + if [[ $(type -t pkgver) == function ]]; then + # TODO: check if die or warn, if we provide _commit _gitcommit setter maybe? + warning 'setting pkgver variable has no effect if the PKGBUILD has a pkgver() function' + fi + + if ! grep --extended-regexp --quiet --max-count=1 "^pkgver=${pkgver}$" PKGBUILD; then + die "Non-standard pkgver declaration" + fi + sed --regexp-extended "s|^(pkgver=)${pkgver}$|\1${new_pkgver}|g" --in-place PKGBUILD +} + +# set the pkgrel variable in a PKGBUILD +# assumes that the pkgbuild is sourced so pkgrel is present +pkgbuild_set_pkgrel() { + local new_pkgrel=$1 + local pkgrel=${pkgrel} + + if ! grep --extended-regexp --quiet --max-count=1 "^pkgrel=${pkgrel}$" PKGBUILD; then + die "Non-standard pkgrel declaration" + fi + sed --regexp-extended "s|^(pkgrel=)${pkgrel}$|\1${new_pkgrel}|g" --in-place PKGBUILD +} + -- cgit v1.2.3-54-g00ecf From 5042dcaeb4916e199b30ecf21048a4234da43499 Mon Sep 17 00:00:00 2001 From: Christian Heusel Date: Thu, 15 Jun 2023 16:30:41 +0200 Subject: feat(build): allow to test-install the built packages This change introduces the new --install-to-host flag to pkgctl build, which can be used with one of the modes 'all' or 'auto'. Depending on the mode either all or just already installed packages are installed to the host system. BREAKING CHANGE: the --install flag is renamed to --install-to-chroot to avoid confusion with the newly introduced flag. Component: pkgctl build Signed-off-by: Christian Heusel Signed-off-by: Levente Polyak --- contrib/completion/bash/devtools.in | 11 +++++++ contrib/completion/zsh/_devtools.in | 5 ++- doc/man/pkgctl-build.1.asciidoc | 14 +++++++-- src/lib/build/build.sh | 61 ++++++++++++++++++++++++++++++++++--- src/lib/valid-build-install.sh | 11 +++++++ 5 files changed, 93 insertions(+), 9 deletions(-) create mode 100644 src/lib/valid-build-install.sh (limited to 'src/lib/build') diff --git a/contrib/completion/bash/devtools.in b/contrib/completion/bash/devtools.in index f8b1c9f..11fa234 100644 --- a/contrib/completion/bash/devtools.in +++ b/contrib/completion/bash/devtools.in @@ -3,6 +3,8 @@ # SPDX-License-Identifier: GPL-3.0-or-later _DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} +# shellcheck source=src/lib/valid-build-install.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-build-install.sh # shellcheck source=src/lib/valid-tags.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-tags.sh # shellcheck source=src/lib/valid-repos.sh @@ -179,6 +181,8 @@ _pkgctl_build_args=( -c --clean -w --worker --inspect + -I --install-to-chroot + -i --install-to-host --pkgver --pkgrel @@ -199,9 +203,16 @@ _pkgctl_build_args_w_opts() { _pkgctl_build_args__worker_opts; } _pkgctl_build_args__inspect_opts() { _devtools_completions_inspect; } _pkgctl_build_args__pkgver_opts() { :; } _pkgctl_build_args__pkgrel_opts() { :; } +_pkgctl_build_args__install_to_host_opts() { _pkgctl_build_completions_install_mode; } +_pkgctl_build_args_i_opts() { _pkgctl_build_args__install_to_host_opts; } +_pkgctl_build_args__install_to_chroot_opts() { _makechrootpkg_args_I_opts; } +_pkgctl_build_args_I_opts() { _pkgctl_build_args__install_to_chroot_opts; } _pkgctl_build_args__message_opts() { :; } _pkgctl_build_args_m_opts() { _pkgctl_build_args__message_opts; } _pkgctl_build_opts() { _filedir -d; } +_pkgctl_build_completions_install_mode() { + mapfile -t COMPREPLY < <(compgen -W "${DEVTOOLS_VALID_BUILD_INSTALL[*]}" -- "$cur") +} _pkgctl_db_cmds=( diff --git a/contrib/completion/zsh/_devtools.in b/contrib/completion/zsh/_devtools.in index 34f90c6..24e57bf 100644 --- a/contrib/completion/zsh/_devtools.in +++ b/contrib/completion/zsh/_devtools.in @@ -3,6 +3,8 @@ # SPDX-License-Identifier: GPL-3.0-or-later _DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} +# shellcheck source=src/lib/valid-build-install.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-build-install.sh # shellcheck source=src/lib/valid-tags.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-tags.sh # shellcheck source=src/lib/valid-repos.sh @@ -45,8 +47,9 @@ _pkgctl_build_args=( '(-t --testing)'{-t,--testing}'[Build against the testing counterpart of the auto-detected repo]' '(-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.*(.)"' "--inspect[Spawn an interactive shell to inspect the chroot (never, always, failure)]:inspect:($DEVTOOLS_VALID_INSPECT_MODES[*])" + '(-I --install-to-chroot)'{-I,--install-to-chroot}'[Install a package to the working copy of the chroot]:target:_files -g "*.pkg.tar.*(.)"' + '(-i --install-to-host)'{-i,--install-to-host}"[Install the built packages to the host system]:mode:($DEVTOOLS_VALID_BUILD_INSTALL[*])" '(-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:' diff --git a/doc/man/pkgctl-build.1.asciidoc b/doc/man/pkgctl-build.1.asciidoc index 12deaaa..e7ec714 100644 --- a/doc/man/pkgctl-build.1.asciidoc +++ b/doc/man/pkgctl-build.1.asciidoc @@ -35,9 +35,6 @@ Build Options *-c, --clean*:: Recreate the chroot before building -*-I, --install* 'FILE':: - Install a package into the working copy of the chroot - *--inspect* 'WHEN':: Spawn an interactive shell to inspect the chroot after building. Useful to ease the debugging of a package build. + Possible values for 'WHEN' are `'never'`, `'always'` or `'failure'` @@ -51,6 +48,17 @@ Build Options *--nocheck*:: Do not run the check() function in the PKGBUILD +Install Options +--------------- + +*-I, --install-to-chroot* 'FILE':: + Install a package to the working copy of the chroot + +*-i, --install-to-host* 'MODE':: + Install the built packages to the host system. Useful when one wants to verify that the package works as intended. + * When 'MODE' is 'all', this installs all built packages + * When 'MODE' is 'auto', this installs all built packages which are currently installed + PKGBUILD Options ---------------- diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index 712be22..64a6ce3 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -20,6 +20,8 @@ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/srcinfo.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/pacman.sh # shellcheck source=src/lib/util/pkgbuild.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/pkgbuild.sh +# shellcheck source=src/lib/valid-build-install.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-build-install.sh # shellcheck source=src/lib/valid-repos.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-repos.sh # shellcheck source=src/lib/valid-tags.sh @@ -52,11 +54,14 @@ pkgctl_build_usage() { -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 --inspect WHEN Spawn an interactive shell to inspect the chroot (never, always, failure) -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 + INSTALL OPTIONS + -I, --install-to-chroot FILE Install a package to the working copy of the chroot + -i, --install-to-host MODE Install the built package to the host system, possible modes are 'all' and 'auto' + PKGBUILD OPTIONS --pkgver=PKGVER Set pkgver, reset pkgrel and update checksums --pkgrel=PKGREL Set pkgrel to a given value @@ -119,6 +124,7 @@ pkgctl_build() { local TESTING=0 local RELEASE=0 local DB_UPDATE=0 + local INSTALL_TO_HOST=none local REPO= local PKGVER= @@ -131,12 +137,13 @@ pkgctl_build() { local MAKECHROOT_OPTIONS=() local RELEASE_OPTIONS=() local MAKEPKG_OPTIONS=() + local INSTALL_HOST_PACKAGES=() local WORKER= local WORKER_SLOT= # variables - local _arch path pkgbase pkgrepo source pkgbuild_checksum + local _arch path pkgbase pkgrepo source pkgbuild_checksum current_checksum while (( $# )); do case $1 in @@ -209,14 +216,22 @@ pkgctl_build() { BUILD_OPTIONS+=("-c") shift ;; - -I|--install) + -I|--install-to-chroot) (( $# <= 1 )) && die "missing argument for %s" "$1" if (( OFFLOAD )); then MAKECHROOT_OPTIONS+=("-I" "$2") else MAKECHROOT_OPTIONS+=("-I" "$(realpath "$2")") fi - warning 'installing packages into the chroot may break reproducible builds, use with caution!' + warning 'installing packages to the chroot may break reproducible builds, use with caution!' + shift 2 + ;; + -i|--install-to-host) + (( $# <= 1 )) && die "missing argument for %s" "$1" + if ! in_array "$2" "${DEVTOOLS_VALID_BUILD_INSTALL[@]}"; then + die 'invalid install mode: %s' "${2}" + fi + INSTALL_TO_HOST=$2 shift 2 ;; --nocheck) @@ -410,7 +425,9 @@ pkgctl_build() { fi # re-source the PKGBUILD if it changed - if [[ ${pkgbuild_checksum} != "$(b2sum PKGBUILD | awk '{print $1}')" ]]; then + current_checksum="$(b2sum PKGBUILD | awk '{print $1}')" + if [[ ${pkgbuild_checksum} != "${current_checksum}" ]]; then + pkgbuild_checksum=${current_checksum} # shellcheck source=contrib/makepkg/PKGBUILD.proto . ./PKGBUILD fi @@ -432,10 +449,38 @@ pkgctl_build() { fi done + # re-source the PKGBUILD if it changed + current_checksum="$(b2sum PKGBUILD | awk '{print $1}')" + if [[ ${pkgbuild_checksum} != "${current_checksum}" ]]; then + pkgbuild_checksum=${current_checksum} + # shellcheck source=contrib/makepkg/PKGBUILD.proto + . ./PKGBUILD + fi + # auto generate .SRCINFO # shellcheck disable=SC2119 write_srcinfo_file + # test-install (some of) the produced packages + if [[ ${INSTALL_TO_HOST} == auto ]] || [[ ${INSTALL_TO_HOST} == all ]]; then + # shellcheck disable=2119 + load_makepkg_config + + # this is inspired by print_all_package_names from libmakepkg + local version pkg_architecture pkg pkgfile + version=$(get_full_version) + + for pkg in "${pkgname[@]}"; do + pkg_architecture=$(get_pkg_arch "$pkg") + pkgfile=$(realpath "$(printf "%s/%s-%s-%s%s\n" "${PKGDEST:-.}" "$pkg" "$version" "$pkg_architecture" "$PKGEXT")") + + # check if we install all packages or if the (split-)package is already installed + if [[ ${INSTALL_TO_HOST} == all ]] || ( [[ ${INSTALL_TO_HOST} == auto ]] && pacman -Qq -- "$pkg" &>/dev/null ); then + INSTALL_HOST_PACKAGES+=("$pkgfile") + fi + done + fi + # release the build if (( RELEASE )); then pkgctl_release --repo "${pkgrepo}" "${RELEASE_OPTIONS[@]}" @@ -446,6 +491,12 @@ pkgctl_build() { popd >/dev/null done + # install all collected packages to the host system + if (( ${#INSTALL_HOST_PACKAGES[@]} )); then + msg "Installing built packages to the host system" + sudo pacman -U -- "${INSTALL_HOST_PACKAGES[@]}" + fi + # update the binary package repo db as last action if (( RELEASE )) && (( DB_UPDATE )); then # shellcheck disable=2119 diff --git a/src/lib/valid-build-install.sh b/src/lib/valid-build-install.sh new file mode 100644 index 0000000..9e98be2 --- /dev/null +++ b/src/lib/valid-build-install.sh @@ -0,0 +1,11 @@ +#!/hint/bash +# +# SPDX-License-Identifier: GPL-3.0-or-later +: + +# shellcheck disable=2034 +DEVTOOLS_VALID_BUILD_INSTALL=( + none + auto + all +) -- cgit v1.2.3-54-g00ecf From 3ecba314fc3a7508d80c5450aaae4b5fc507d62b Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Tue, 6 Feb 2024 21:59:11 +0100 Subject: feat(build): consolidate repo flags in build and release subcommand Previously the behavior was inconsistent and not fully fulfilling its purpose of only using --repo once when initially pushing a new and unknown package to the official repositories. Consolidate the behavior by only allowing to use --repo during the initial packaging and disallow any subsequent usage. The expected user experience is to subsequently use --testing or --staging to influence the auto-detection of the build target. This avoids any kind of human error which leads to releasing core packages to extra-testing by accident. Furthermore, allow the build subcommand to automatically fallback to extra as the default stable repository target which greatly improves the usability for AUR or local override builds. Fixes #193 Fixes #191 Component: pkgctl build Component: pkgctl release Signed-off-by: Levente Polyak --- contrib/completion/zsh/_devtools.in | 2 +- doc/man/pkgctl-build.1.asciidoc | 5 ++++- doc/man/pkgctl-release.1.asciidoc | 4 +++- src/lib/build/build.sh | 35 +++++++++++++++++++++-------------- src/lib/release.sh | 29 ++++++++++++++++++----------- src/lib/util/pacman.sh | 7 ++++++- 6 files changed, 53 insertions(+), 29 deletions(-) (limited to 'src/lib/build') diff --git a/contrib/completion/zsh/_devtools.in b/contrib/completion/zsh/_devtools.in index 24e57bf..3aa0f96 100644 --- a/contrib/completion/zsh/_devtools.in +++ b/contrib/completion/zsh/_devtools.in @@ -91,7 +91,7 @@ _pkgctl_db_update_args=( _pkgctl_release_args=( '(-m --message=)'{-m,--message=}"[Use the given as the commit message]:message:" - '(-r --repo=)'{-r,--repo=}"[Specify a target repository (disables auto-detection)]:repo:($DEVTOOLS_VALID_REPOS[*])" + '(-r --repo=)'{-r,--repo=}"[Specify a target repository for new packages]:repo:($DEVTOOLS_VALID_REPOS[*])" '(-s --staging)'{-s,--staging}'[Release to the staging counterpart of the auto-detected repo]' '(-t --testing)'{-t,--testing}'[Release to the testing counterpart of the auto-detected repo]' '(-u --db-update)'{-u,--db-update}'[Automatically update the pacman database after uploading]' diff --git a/doc/man/pkgctl-build.1.asciidoc b/doc/man/pkgctl-build.1.asciidoc index e7ec714..f7abdeb 100644 --- a/doc/man/pkgctl-build.1.asciidoc +++ b/doc/man/pkgctl-build.1.asciidoc @@ -21,7 +21,10 @@ Build Options Specify architectures to build for (disables auto-detection) *--repo* 'REPO':: - Specify a target repository (disables auto-detection) + Specify target repository for new packages not in any official repo. + Fallback to `'extra'` when building packages that are not present in any + official repository yet. Using this option is disallowed if the package is + already released, as it would circumvent the auto-detection safeguard. *-s, --staging*:: Build against the staging counterpart of the auto-detected repo diff --git a/doc/man/pkgctl-release.1.asciidoc b/doc/man/pkgctl-release.1.asciidoc index c991db4..01a0c9e 100644 --- a/doc/man/pkgctl-release.1.asciidoc +++ b/doc/man/pkgctl-release.1.asciidoc @@ -27,7 +27,9 @@ Options Use the given as the commit message *-r, --repo* 'REPO':: - Specify a target repository (disables auto-detection) + Specify target repository for new packages not in any official repo. + Using this option is disallowed if the package is already released, as it + would circumvent the auto-detection safeguard. *-s, --staging*:: Build against the staging counterpart of the auto-detected repo diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index 64a6ce3..8e9a3bb 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -49,7 +49,7 @@ pkgctl_build_usage() { BUILD OPTIONS --arch ARCH Specify architectures to build for (disables auto-detection) - --repo REPO Specify a target repository (disables auto-detection) + --repo REPO Specify target repository for new packages not in any official repo -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 @@ -89,8 +89,7 @@ pkgctl_build_check_option_group_repo() { local repo=$2 local testing=$3 local staging=$4 - if ( (( testing )) && (( staging )) ) || - ( [[ $repo =~ ^.*-(staging|testing)$ ]] && ( (( testing )) || (( staging )) )); then + if [[ -n "${repo}" ]] || (( testing )) || (( staging )); then die "The argument '%s' cannot be used with one or more of the other specified arguments" "${option}" exit 1 fi @@ -153,8 +152,8 @@ pkgctl_build() { ;; --repo) (( $# <= 1 )) && die "missing argument for %s" "$1" - REPO="${2}" pkgctl_build_check_option_group_repo '--repo' "${REPO}" "${TESTING}" "${STAGING}" + REPO="${2}" shift 2 ;; --arch) @@ -203,13 +202,13 @@ pkgctl_build() { shift ;; -s|--staging) - STAGING=1 pkgctl_build_check_option_group_repo '--staging' "${REPO}" "${TESTING}" "${STAGING}" + STAGING=1 shift ;; -t|--testing) - TESTING=1 pkgctl_build_check_option_group_repo '--testing' "${REPO}" "${TESTING}" "${STAGING}" + TESTING=1 shift ;; -c|--clean) @@ -331,14 +330,22 @@ pkgctl_build() { pkgbuild_checksum=$(b2sum PKGBUILD | awk '{print $1}') msg "Building ${pkgbase}" - # auto-detection of build target - if [[ -z ${pkgrepo} ]]; then - if ! pkgrepo=$(get_pacman_repo_from_pkgbuild PKGBUILD); then - die 'failed to get pacman repo' - fi - if [[ -z "${pkgrepo}" ]]; then - die 'unknown repo, specify --repo for packages not currently in any official repo' - fi + # auto-detect target repository + if ! repo=$(get_pacman_repo_from_pkgbuild PKGBUILD); then + die 'Failed to query pacman repo' + fi + + # fail if an existing package specifies --repo + if [[ -n "${repo}" ]] && [[ -n ${pkgrepo} ]]; then + die 'Using --repo for packages that exist in official repositories is disallowed' + fi + + # assign auto-detected target repository + if [[ -n ${repo} ]]; then + pkgrepo=${repo} + # fallback to extra for unreleased packages + elif [[ -z ${pkgrepo} ]]; then + pkgrepo=extra fi # special cases to resolve final build target diff --git a/src/lib/release.sh b/src/lib/release.sh index 028d92e..700b2b0 100644 --- a/src/lib/release.sh +++ b/src/lib/release.sh @@ -35,7 +35,7 @@ pkgctl_release_usage() { OPTIONS -m, --message MSG Use the given as the commit message - -r, --repo REPO Specify a target repository (disables auto-detection) + -r, --repo REPO Specify target repository for new packages not in any official repo -s, --staging Release to the staging counterpart of the auto-detected repo -t, --testing Release to the testing counterpart of the auto-detected repo -u, --db-update Automatically update the pacman database after uploading @@ -43,8 +43,8 @@ pkgctl_release_usage() { EXAMPLES $ ${COMMAND} - $ ${COMMAND} --repo core-testing --message 'libyay 0.42 rebuild' libfoo libbar - $ ${COMMAND} --staging --db-update libfoo + $ ${COMMAND} --staging --message 'libyay 0.42 rebuild' libfoo libbar + $ ${COMMAND} --repo extra --db-update new-package _EOF_ } @@ -134,15 +134,22 @@ pkgctl_release() { pushd "${path}" >/dev/null pkgbase=$(basename "${path}") - if [[ -n ${REPO} ]]; then - repo=${REPO} - else - if ! repo=$(get_pacman_repo_from_pkgbuild PKGBUILD); then - die 'Failed to get pacman repo' - fi - if [[ -z "${repo}" ]]; then - die 'Unknown repo, please specify --repo for new packages' + # auto-detect target repository + if ! repo=$(get_pacman_repo_from_pkgbuild PKGBUILD); then + die 'Failed to query pacman repo' + fi + + # fail if an existing package specifies --repo + if [[ -n "${repo}" ]] && [[ -n ${REPO} ]]; then + die 'Using --repo for packages that exist in official repositories is disallowed' + fi + + # fail if a new package does not specify --repo + if [[ -z "${repo}" ]]; then + if [[ -z ${REPO} ]]; then + die 'Specify --repo for packages that do not yet exist in official repositories' fi + repo=${REPO} fi if (( TESTING )); then diff --git a/src/lib/util/pacman.sh b/src/lib/util/pacman.sh index 82a227b..620e1a8 100644 --- a/src/lib/util/pacman.sh +++ b/src/lib/util/pacman.sh @@ -38,6 +38,11 @@ get_pacman_repo_from_pkgbuild() { return fi + # update the pacman repo cache if it doesn't exist yet + if [[ ! -d "${_DEVTOOLS_PACMAN_CACHE_DIR}" ]]; then + update_pacman_repo_cache + fi + slock 10 "${_DEVTOOLS_PACMAN_CACHE_DIR}.lock" "Locking pacman database cache" # query repo of passed pkgname, specify --nodeps twice to skip all dependency checks mapfile -t repos < <(pacman --config "${_DEVTOOLS_PACMAN_CONF_DIR}/multilib.conf" \ @@ -47,7 +52,7 @@ get_pacman_repo_from_pkgbuild() { --nodeps \ --print \ --print-format '%n %r' \ - "${pkgnames[0]}" | awk '$1=="'"${pkgnames[0]}"'"{print $2}' + "${pkgnames[0]}" 2>/dev/null | awk '$1=="'"${pkgnames[0]}"'"{print $2}' ) lock_close 10 -- cgit v1.2.3-54-g00ecf From fc05ea19d9005cffaa461cf4f86131a001f88ca9 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Thu, 8 Feb 2024 01:15:48 +0100 Subject: fix(build): allow unstable repositories to override repo target This works around the fact that we are currently not auto detecting unstable repository targets while providing a stability layer option on the subcommand. Soften the --repo option rules by allowing unstable repositories to use that flag for building and releasing against the unstable repositories. This will be replaced in the near future by proper integration of target repository auto-detection that in aware of unstable repositories while providing a unstable stability layer options. Component: pkgctl build Component: pkgctl release Signed-off-by: Levente Polyak --- src/lib/build/build.sh | 7 ++++++- src/lib/release.sh | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src/lib/build') diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index 8e9a3bb..9bd1e5d 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -337,7 +337,12 @@ pkgctl_build() { # fail if an existing package specifies --repo if [[ -n "${repo}" ]] && [[ -n ${pkgrepo} ]]; then - die 'Using --repo for packages that exist in official repositories is disallowed' + # allow unstable to use --repo + if [[ ${pkgrepo} == *unstable ]]; then + repo=${pkgrepo} + else + die 'Using --repo for packages that exist in official repositories is disallowed' + fi fi # assign auto-detected target repository diff --git a/src/lib/release.sh b/src/lib/release.sh index 700b2b0..acb3b54 100644 --- a/src/lib/release.sh +++ b/src/lib/release.sh @@ -141,7 +141,12 @@ pkgctl_release() { # fail if an existing package specifies --repo if [[ -n "${repo}" ]] && [[ -n ${REPO} ]]; then - die 'Using --repo for packages that exist in official repositories is disallowed' + # allow unstable to use --repo + if [[ ${REPO} == *unstable ]]; then + repo=${REPO} + else + die 'Using --repo for packages that exist in official repositories is disallowed' + fi fi # fail if a new package does not specify --repo -- cgit v1.2.3-54-g00ecf From 1cf402eae9d4b98f839ce9d116f807531cda7862 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Fri, 9 Feb 2024 20:18:30 +0100 Subject: fix(build): forward target repo options to the release subcommand The adequate target repo options are not appropriately forwarded to the release subcommand if the auto-release options is activated. Previously we did not restrict the --repo option, which the build option has used as a shortcut. Since last release, this option is restricted to new packages that are not in any official repository yet. Fix this issue by forwarding the same target repo options that have been used during the build command and not forcefully the --repo options. Fixes #209 Component: pkgctl build Signed-off-by: Levente Polyak --- src/lib/build/build.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/lib/build') diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh index 9bd1e5d..171bb9a 100644 --- a/src/lib/build/build.sh +++ b/src/lib/build/build.sh @@ -154,6 +154,7 @@ pkgctl_build() { (( $# <= 1 )) && die "missing argument for %s" "$1" pkgctl_build_check_option_group_repo '--repo' "${REPO}" "${TESTING}" "${STAGING}" REPO="${2}" + RELEASE_OPTIONS+=("--repo" "${REPO}") shift 2 ;; --arch) @@ -204,11 +205,13 @@ pkgctl_build() { -s|--staging) pkgctl_build_check_option_group_repo '--staging' "${REPO}" "${TESTING}" "${STAGING}" STAGING=1 + RELEASE_OPTIONS+=("--staging") shift ;; -t|--testing) pkgctl_build_check_option_group_repo '--testing' "${REPO}" "${TESTING}" "${STAGING}" TESTING=1 + RELEASE_OPTIONS+=("--testing") shift ;; -c|--clean) @@ -495,7 +498,7 @@ pkgctl_build() { # release the build if (( RELEASE )); then - pkgctl_release --repo "${pkgrepo}" "${RELEASE_OPTIONS[@]}" + pkgctl_release "${RELEASE_OPTIONS[@]}" fi # reset common PKGBUILD variables -- cgit v1.2.3-54-g00ecf