[pacman-dev] [PATCH 10/11] makepkg: provide mechanism for auto-updating pkgver
Now that VCS repos are provided in the source array, it becomes too complicated to have automatic updating pkgver as was the case with the old VCS PKGBUILDs (there can be multiple repos of different types in the source array, the VCS repo may not be the package primary source, etc). Instead provide an optional way for a PKGBUILD to update the pkgver value through the specifing of a pkgver() function that returns the new version string. This is run after all source files are downloaded so can access the VCS repo if needed. Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/makepkg.sh.in | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 0b282a5..5cc378d 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -471,9 +471,30 @@ download_sources() { esac done + if declare -f pkgver >/dev/null; then + update_pkgver + fi + popd &>/dev/null } +# Automatically update pkgver variable if a pkgver() function is provided +# Re-sources the PKGBUILD afterwards to allow for other variables that use $pkgver +update_pkgver() { + newpkgver=$(pkgver) + + if [[ -n $newpkgver && $newpkgver != "$pkgver" ]]; then + if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then + @SEDINPLACE@ "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "$BUILDFILE" + @SEDINPLACE@ "s/^pkgrel=[^ ]*/pkgrel=1/" "$BUILDFILE" + source "$BUILDFILE" + else + warning "$(gettext "%s is not writeable -- pkgver will not be updated")" \ + "$BUILDFILE" + fi + fi +} + # Print 'source not found' error message and exit makepkg missing_source_file() { error "$(gettext "Unable to find source file %s.")" "$(get_filename "$1")" -- 1.7.11.1
Allow SVN repo sources in the form: source=("<folder>::<repo>#<fragment>") where <repo> must start with svn (e.g svn+http://) and a <fragment> can specify a revision (e.g. revision=22). Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/makepkg.sh.in | 72 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 5cc378d..f113581 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -196,7 +196,7 @@ get_filepath() { local proto="$(get_protocol "$1")" case $proto in - git*) + git*|svn*) if [[ -d "$startdir/$file" ]]; then file="$startdir/$file" elif [[ -d "$SRCDEST/$file" ]]; then @@ -232,9 +232,11 @@ get_filename() { local proto=$(get_protocol "$netfile") case $proto in - git*) + git*|svn*) filename=${netfile##*/} filename=${filename%%#*} + ;;& + git*) filename=${filename%%.git*} ;; *) @@ -444,6 +446,67 @@ download_git() { popd &>/dev/null } +download_svn() { + local netfile=$1 + + local fragment=${netfile##*#} + if [[ $fragment = "$netfile" ]]; then + unset fragment + fi + + local folder=$(get_filepath "$netfile") + [[ -z "$folder" ]] && folder="$SRCDEST/$(get_filename "$netfile")" + + local repo=${netfile##*/} + repo=${repo%%#*} + + local url=$(get_url "$netfile") + if [[ $url != svn+ssh* ]]; then + url=${url##*svn+} + fi + url=${url%%#*} + + if [[ ! -d $folder ]]; then + msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "svn" + if ! svn checkout --config-dir $folder "$url" "$folder"; then + error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "svn" + plain "$(gettext "Aborting...")" + exit 1 + fi + else + msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "svn" + cd_safe "$folder" + if ! svn update; then + # only warn on failure to allow offline builds + warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "svn" + fi + fi + + msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "svn" + pushd "$srcdir" &>/dev/null + rm -rf ${folder##*/} + + local ref + if [[ -n $fragment ]]; then + case $fragment in + revision=*) + ref="-r ${fragment##*=}" + ;; + *) + error "$(gettext "Unrecognized reference: %s")" "${fragment}" + plain "$(gettext "Aborting...")" + exit 1 + esac + fi + + if ! svn export $ref $folder; then + error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "svn" + plain "$(gettext "Aborting...")" + fi + + popd &>/dev/null +} + download_sources() { msg "$(gettext "Retrieving Sources...")" @@ -463,6 +526,9 @@ download_sources() { git*) download_git "$netfile" ;; + svn*) + download_svn "$netfile" + ;; *) error "$(gettext "Unknown download protocol: %s")" "$proto" plain "$(gettext "Aborting...")" @@ -834,7 +900,7 @@ generate_checksums() { proto="$(get_protocol "$netfile")" case $proto in - git*) + git*|svn*) sum="SKIP" ;; *) -- 1.7.11.1
On Wed, Jun 27, 2012 at 09:18:54AM +1000, Allan McRae wrote:
Allow SVN repo sources in the form:
source=("<folder>::<repo>#<fragment>")
where <repo> must start with svn (e.g svn+http://) and a <fragment> can specify a revision (e.g. revision=22).
Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/makepkg.sh.in | 72 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 3 deletions(-)
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 5cc378d..f113581 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -196,7 +196,7 @@ get_filepath() { local proto="$(get_protocol "$1")"
case $proto in - git*) + git*|svn*) if [[ -d "$startdir/$file" ]]; then file="$startdir/$file" elif [[ -d "$SRCDEST/$file" ]]; then @@ -232,9 +232,11 @@ get_filename() { local proto=$(get_protocol "$netfile")
case $proto in - git*) + git*|svn*) filename=${netfile##*/} filename=${filename%%#*} + ;;&
a comment might be nice here just so people know that this is a deliberate fallthrough.
+ git*) filename=${filename%%.git*} ;; *) @@ -444,6 +446,67 @@ download_git() { popd &>/dev/null }
+download_svn() { + local netfile=$1 + + local fragment=${netfile##*#} + if [[ $fragment = "$netfile" ]]; then + unset fragment + fi + + local folder=$(get_filepath "$netfile") + [[ -z "$folder" ]] && folder="$SRCDEST/$(get_filename "$netfile")" + + local repo=${netfile##*/} + repo=${repo%%#*} + + local url=$(get_url "$netfile") + if [[ $url != svn+ssh* ]]; then + url=${url##*svn+} + fi + url=${url%%#*} + + if [[ ! -d $folder ]]; then + msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "svn" + if ! svn checkout --config-dir $folder "$url" "$folder"; then
quotes, please.
+ error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "svn" + plain "$(gettext "Aborting...")" + exit 1 + fi + else + msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "svn" + cd_safe "$folder" + if ! svn update; then + # only warn on failure to allow offline builds + warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "svn" + fi + fi + + msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "svn" + pushd "$srcdir" &>/dev/null + rm -rf ${folder##*/} + + local ref + if [[ -n $fragment ]]; then + case $fragment in + revision=*) + ref="-r ${fragment##*=}"
Could we make this an array so we aren't forced to avoid quoting it later?
+ ;; + *) + error "$(gettext "Unrecognized reference: %s")" "${fragment}" + plain "$(gettext "Aborting...")" + exit 1 + esac + fi + + if ! svn export $ref $folder; then + error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "svn" + plain "$(gettext "Aborting...")" + fi + + popd &>/dev/null +} + download_sources() { msg "$(gettext "Retrieving Sources...")"
@@ -463,6 +526,9 @@ download_sources() { git*) download_git "$netfile" ;; + svn*) + download_svn "$netfile" + ;; *) error "$(gettext "Unknown download protocol: %s")" "$proto" plain "$(gettext "Aborting...")" @@ -834,7 +900,7 @@ generate_checksums() { proto="$(get_protocol "$netfile")"
case $proto in - git*) + git*|svn*) sum="SKIP" ;; *) -- 1.7.11.1
On Wed, Jun 27, 2012 at 09:18:53AM +1000, Allan McRae wrote:
Now that VCS repos are provided in the source array, it becomes too complicated to have automatic updating pkgver as was the case with the old VCS PKGBUILDs (there can be multiple repos of different types in the source array, the VCS repo may not be the package primary source, etc).
Instead provide an optional way for a PKGBUILD to update the pkgver value through the specifing of a pkgver() function that returns the new version string. This is run after all source files are downloaded so can access the VCS repo if needed.
Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/makepkg.sh.in | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 0b282a5..5cc378d 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -471,9 +471,30 @@ download_sources() { esac done
+ if declare -f pkgver >/dev/null; then + update_pkgver + fi + popd &>/dev/null }
+# Automatically update pkgver variable if a pkgver() function is provided +# Re-sources the PKGBUILD afterwards to allow for other variables that use $pkgver +update_pkgver() { + newpkgver=$(pkgver)
This is arbitrary code from the user. Should we be wrapping this in the error trap?
+ + if [[ -n $newpkgver && $newpkgver != "$pkgver" ]]; then + if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then + @SEDINPLACE@ "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "$BUILDFILE" + @SEDINPLACE@ "s/^pkgrel=[^ ]*/pkgrel=1/" "$BUILDFILE" + source "$BUILDFILE" + else + warning "$(gettext "%s is not writeable -- pkgver will not be updated")" \ + "$BUILDFILE" + fi + fi
Hmmm, maybe a warning if $newpkgver is empty?
+} + # Print 'source not found' error message and exit makepkg missing_source_file() { error "$(gettext "Unable to find source file %s.")" "$(get_filename "$1")" -- 1.7.11.1
On 27/06/12 10:20, Dave Reisner wrote:
On Wed, Jun 27, 2012 at 09:18:53AM +1000, Allan McRae wrote:
Now that VCS repos are provided in the source array, it becomes too complicated to have automatic updating pkgver as was the case with the old VCS PKGBUILDs (there can be multiple repos of different types in the source array, the VCS repo may not be the package primary source, etc).
Instead provide an optional way for a PKGBUILD to update the pkgver value through the specifing of a pkgver() function that returns the new version string. This is run after all source files are downloaded so can access the VCS repo if needed.
Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/makepkg.sh.in | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 0b282a5..5cc378d 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -471,9 +471,30 @@ download_sources() { esac done
+ if declare -f pkgver >/dev/null; then + update_pkgver + fi + popd &>/dev/null }
+# Automatically update pkgver variable if a pkgver() function is provided +# Re-sources the PKGBUILD afterwards to allow for other variables that use $pkgver +update_pkgver() { + newpkgver=$(pkgver)
This is arbitrary code from the user. Should we be wrapping this in the error trap?
Done.
+ + if [[ -n $newpkgver && $newpkgver != "$pkgver" ]]; then + if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then + @SEDINPLACE@ "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "$BUILDFILE" + @SEDINPLACE@ "s/^pkgrel=[^ ]*/pkgrel=1/" "$BUILDFILE" + source "$BUILDFILE" + else + warning "$(gettext "%s is not writeable -- pkgver will not be updated")" \ + "$BUILDFILE" + fi + fi
Hmmm, maybe a warning if $newpkgver is empty?
We really need to run all the pkgver checks here to ensure it is valid (on the TODO list...). An empty pkgver will be caught there.
+} + # Print 'source not found' error message and exit makepkg missing_source_file() { error "$(gettext "Unable to find source file %s.")" "$(get_filename "$1")" -- 1.7.11.1
participants (2)
-
Allan McRae
-
Dave Reisner