X-Original-To: alpine-devel@lists.alpinelinux.org Received: from lithium.8pit.net (lithium.8pit.net [81.4.121.103]) by lists.alpinelinux.org (Postfix) with ESMTP id DF0715C41B4; Wed, 13 Jul 2016 14:02:41 +0000 (GMT) Received: from localhost (p3EE0E856.dip0.t-ipconnect.de [62.224.232.86]) by lithium.8pit.net (OpenSMTPD) with ESMTPSA id dbe5f210 TLS version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO; Wed, 13 Jul 2016 16:02:39 +0200 (CEST) From: =?UTF-8?q?S=C3=B6ren=20Tempel?= To: alpine-devel@lists.alpinelinux.org Subject: [alpine-devel] [PATCH 1/2] abuild: support cloning form multiple git/svn urls Date: Wed, 13 Jul 2016 16:02:26 +0200 Message-Id: <20160713140227.12362-1-soeren+git@soeren-tempel.net> X-Mailer: git-send-email 2.9.0 X-Mailinglist: alpine-devel Precedence: list List-Id: Alpine Development List-Unsubscribe: List-Post: List-Help: List-Subscribe: Instead of having multiple variables for different version control systems ($svnurl and $giturl) this unites all version control systems in one URL $vcsurls and also allows you to add more than one URL per APKBUILD. The syntax is as follows: (git|svn)+[#] This has various advantages over the old approach: The obvious one being that you can clone multiple repositories without defining your own snapshot function now. I needed this for the testing/android-tools APKBUILD. Additionally it is now much easier to add support for more version control systems (e.g. mercurial). The new code should be fully mostly[1] with APKBUILDs that are still using $giturl, $svnurl and/or $reporev. However, this backwards compatibility makes the code somewhat uglier and should probably be removed in a feature version (deprecation warnings are already emitted in this version). In general the snapshot function code could be cleaned up a bit by moving the git/svn clone code to a separate function et cetera. [1] Since the previous snapshot code assumed that only one repository would be cloned the tarballs contained a directory called '$pkgname-${verbase:-0}_git${_date}', however since we have multiple tarballs now we can't use this as a filename thus you need to update "$builddir" after creating a new snapshot for your APKBUILD. Besides stuff *will* break if you used command line flags in $giturl as instructed in the comment above the snapshot function. --- abuild.in | 127 ++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 82 insertions(+), 45 deletions(-) diff --git a/abuild.in b/abuild.in index d4614d1..a0637c9 100644 --- a/abuild.in +++ b/abuild.in @@ -2057,61 +2057,98 @@ all() { fi } -# This abuild hook will checkout an svn or git repository by specifying -# $svnurl or $giturl in APKBUILD. You can checkout a specific branch in -# git by adding -b $branch in $giturl. $reporev will select the correct -# commit, revision or tag for you. If you specify $disturl your distfile -# will automatically be uploaded with rsync to the url provided. +# This abuild hook will checkout a version control source tree. +# Currently svn and git are supported. To checkout a repository +# add the repository to the $vcsurls variable. The syntax for $vcsurls +# items is the following: +# +# (git|svn)+[#] +# +# Revision to checkout is optional but recommended. If you specify $disturl +# your distfile will automatically be uploaded with rsync to the url provided. # Base version defaults to 0 except if specified by $verbase. snapshot() { + # included for compatiblity with old APKBUILDs + [ -n "$svnurl" ] && [ -n "$giturl" ] && die "You can only use a single repository!" + if [ -n "$svnurl" ]; then + warning "The \$svnurl variable is deprecated, use \$vcsurls instead." + vcsurls="svn+$svnurl${reporev:+#$reporev}" + elif [ -n "$giturl" ]; then + warning "The \$giturl variable is deprecated, use \$vcsurls instead." + vcsurls="git+$giturl${reporev:+#$reporev}" + fi + # check if we setup vars correctly [ -z "$disturl" ] && warning "Missing disturl in APKBUILD, auto uploading disabled." - [ -z "$svnurl" ] && [ -z "$giturl" ] && die "Missding repository url in APKBUILD!" - [ -n "$svnurl" ] && [ -n "$giturl" ] && die "You can only use a single repository!" + [ -z "$vcsurls" ] && die "Missing repository url in APKBUILD!" + [ -n "$reporev" ] && warning "The \$reporev variable is deprecated." + local _date=$(date +%Y%m%d) local _format="tar.gz" # remove any repositories left in srcdir abuild clean mkdir -p "$srcdir" && cd "$srcdir" - # clone git repo and archive - if [ -n "$giturl" ]; then - local _version=${verbase:-0}_git${_date} - command -v git >/dev/null || \ - die "Missing git! Install git to support git clone." - local _rev="${reporev:-HEAD}" - [ "$_rev" = "HEAD" ] && local _depth="--depth=1" - msg "Creating git snapshot: $pkgname-$_version" - git clone $_depth --bare $giturl $pkgname-$_version || return 1 - git --git-dir $pkgname-$_version archive \ - --format=$_format \ - -o $pkgname-$_version.$_format \ - --prefix=$pkgname-$_version/ $_rev \ - || return 1 - fi - # export svn repo and archive - if [ -n "$svnurl" ]; then - local _version=${verbase:-0}_svn${_date} - command -v svn >/dev/null || \ - die "Missing svn! Install subverion to support svn export." - [ -n "$reporev" ] && local _rev="-r $reporev" - msg "Creating svn snapshot: $pkgname-$_version" - svn co $_rev $svnurl $pkgname-$_version || return 1 - tar zcf $pkgname-$_version.$_format $pkgname-$_version || return 1 - fi - # upload to defined distfiles url - if [ -n "$disturl" ]; then - command -v rsync >/dev/null || \ - die "Missing rsync! Install rsync to enable automatic uploads." - msg "Uploading to $disturl" - rsync --progress -La $pkgname-$_version.$_format \ - $disturl || return 1 - cd "$startdir" - # set the pkgver to current date and update checksum - sed -i -e "s/^pkgver=.*/pkgver=${_version}/" \ - APKBUILD || return 1 - abuild checksum - fi + + local scr= ver= url= rver= type= + for url in $vcsurls; do + echo "$url" | grep -q + 2>/dev/null || \ + die "VCS type for '$url' wasn't specified." + type="${url%+*}" + url="${url##*+}" + + ver="${url##*\#}" + url="${url%\#*}" + + [ -z "${ver}" ] && warning "Please specify a revision to checkout for '$url'." + + case "$type" in + svn) + rver=${verbase:-0}_svn${_date} + scr="$pkgname-${url##*/}-$rver" + + command -v svn >/dev/null || \ + die "Missing svn! Install subverion to support svn export." + + [ -n "$ver" ] && local _rev="-r $ver" + msg "Creating svn snapshot: $scr" + svn co $_rev "$url" $scr || return 1 + tar zcf $scr.$_format $scr || return 1 + ;; + git) + rver=${verbase:-0}_git${_date} + scr="$pkgname-${url##*/}-$rver" + + command -v git >/dev/null || \ + die "Missing git! Install git to support git clone." + + local _rev="${ver:-HEAD}" + [ "$_rev" = "HEAD" ] && local _depth="--depth=1" + msg "Creating git snapshot: $scr" + git clone $_depth --bare "$url" $scr || return 1 + git --git-dir $scr archive \ + -o $scr.$_format \ + --format=$_format \ + --prefix=$pkgname-$rver/ $_rev \ + || return 1 + ;; + *) die "Unsupported VCS type: '${type}'" ;; + esac + + # upload to defined distfiles url + if [ -n "$disturl" ]; then + command -v rsync >/dev/null || \ + die "Missing rsync! Install rsync to enable automatic uploads." + msg "Uploading to $disturl" + rsync --progress -La $scr $disturl || return 1 + fi + done + + cd "$startdir" + # set the pkgver to current date and update checksum + sed -i -e "s/^pkgver=.*/pkgver=${rver}/" \ + APKBUILD || return 1 + abuild checksum } usage() { -- 2.9.0 --- Unsubscribe: alpine-devel+unsubscribe@lists.alpinelinux.org Help: alpine-devel+help@lists.alpinelinux.org ---