diff options
-rw-r--r-- | Makefile | 2 | ||||
-rwxr-xr-x | abuild.in | 88 | ||||
-rwxr-xr-x | ap.in | 62 | ||||
-rwxr-xr-x | aports.lua | 42 | ||||
-rwxr-xr-x | buildlab.in | 14 |
5 files changed, 136 insertions, 72 deletions
@@ -1,6 +1,6 @@ PACKAGE := abuild -VERSION := 2.7.5 +VERSION := 2.8.2 prefix ?= /usr sysconfdir ?= /etc @@ -360,7 +360,7 @@ cleanpkg() { for i in $(listpkgnames); do local p="${i%:*}-$pkgver-r$pkgrel" rm -f "$PKGDEST/$p.apk" "$PKGDEST/$p.src.tar.gz" \ - "$abuildrepo"/$p.apk + "$abuildrepo"/$p.apk "$abuildrepo"/*/$p.apk done # remove given packages from index } @@ -371,9 +371,11 @@ cleanoldpkg() { getpkgver || return 1 msg "Cleaning all packages except $pkgver-r$pkgrel..." for i in $(listpkgnames); do - for j in "$PKGDEST"/${i%:*}-[0-9]*.apk; do - [ "$j" != "$PKGDEST/${i%:*}-$pkgver-r$pkgrel.apk" ] \ - && rm -f "$j" + local pn=${i%:*} + for j in "$PKGDEST"/$pn-[0-9]*.apk ; do + [ "$j" = "$PKGDEST/$pn-$pkgver-r$pkgrel.apk" ] \ + && continue + rm -f "$j" "$abuildrepo"/*/${j##*/} done done return 0 @@ -771,41 +773,75 @@ create_apks() { done } -update_abuildrepo() { - if ! apk_up2date || [ -n "$force" ]; then - sanitycheck && builddeps && clean && fetch && unpack \ - && prepare && mkusers && rootpkg || return 1 - fi +# fish out the arch from an apk file +apk_arch_prefix() { + apk index -q "$1" | tar -zxO | awk -F: '$1 == "A" { print $2 }' +} +apk_arch_prefix_compat() { + tar -zxOf "$1" .PKGINFO | awk -F" = " '$1 == "arch" { print $2 }' +} + +clean_abuildrepo() { local apk - mkdir -p "$abuildrepo" || return 1 - cd "$abuildrepo" + cd "$abuildrepo" || return 1 + + # remove compat symlink + for d in "$abuildrepo/$CARCH" "$abuildrepo"/noarch; do + [ -L "$d" ] && rm "$d" + done - # remove broken links - for apk in *.apk; do + # remove broken links from abuildrepo + for apk in *.apk */*.apk; do if [ -L "$apk" ] && [ ! -f "$apk" ]; then rm -f "$apk" fi done +} +mklinks_abuildrepo() { + local apk get_prefix=apk_arch_prefix + local version=$($APK --version | awk '{print $2}') + if [ "$($APK version --test $version 2.1)" = '<' ]; then + get_prefix=apk_arch_prefix_compat + fi + mkdir -p "$abuildrepo"/$CARCH "$abuildrepo"/noarch + cd "$abuildrepo" || return 1 # create links for this package for apk in $(listpkg); do - ln -sf "$PKGDEST"/$apk "$abuildrepo"/$apk + [ -f "$PKGDEST"/$apk ] || continue + local prefix=$($get_prefix "$PKGDEST"/$apk) + mkdir -p "$abuildrepo"/$prefix + ln -sf "$PKGDEST"/$apk "$abuildrepo"/$prefix/$apk done +} + +update_abuildrepo() { + local d apk + if ! apk_up2date || [ -n "$force" ]; then + sanitycheck && builddeps && clean && fetch && unpack \ + && prepare && mkusers && rootpkg || return 1 + fi + + clean_abuildrepo + mklinks_abuildrepo + + cd "$abuildrepo" + local index=$CARCH/APKINDEX.tar.gz msg "Updating the cached abuild repository index..." local sign=".SIGN.RSA.${SIGN_PUBLIC_KEY##*/}" local oldindex= - if [ -f APKINDEX.tar.gz ]; then - oldindex="--index APKINDEX.tar.gz" + if [ -f "$index" ]; then + oldindex="--index $index" fi - $APK index $oldindex --output APKINDEX.tar.gz.unsigned \ + $APK index --quiet $oldindex --output "$index".unsigned \ --description "$repo $(cd $startdir && git describe)" \ - *.apk || exit 1 + noarch/*.apk $CARCH/*.apk || exit 1 msg "Signing the index..." - abuild-sign -q APKINDEX.tar.gz.unsigned || exit 1 - mv APKINDEX.tar.gz.unsigned APKINDEX.tar.gz - chmod 644 APKINDEX.tar.gz + abuild-sign -q "$index".unsigned || exit 1 + mv "$index".unsigned "$index" + chmod 644 "$index" } # predefined splitfunc doc @@ -971,11 +1007,17 @@ apk_up2date() { } abuildindex_up2date() { - local i apk + local i j apk getpkgver || return 1 for i in $pkgname $subpackages; do apk="${i%:*}-$pkgver-r$pkgrel.apk" - [ "$abuildrepo"/APKINDEX.tar.gz -nt "$abuildrepo"/$apk ] || return 1 + for j in "$abuildrepo"/*/$apk; do + [ -r "$j" ] || continue # ignore missing files + local idx="${j%/*}"/APKINDEX.tar.gz + if ! [ "$idx" -nt "$j" ]; then + return 1 + fi + done done return 0 } @@ -13,7 +13,7 @@ subcmd.revdep = { for i = 2, #opts do local pkg = opts[i] local _,p - for _,p in ipairs(rev[pkg] or {}) do + for _,p in pairs(rev[pkg] or {}) do print(p.pkgname) end end @@ -36,28 +36,11 @@ subcmd.recursdeps = { desc = "Recursively print all make dependencies for given packages", usage = "PKG...", run = function (opts) - local i - local visited = {} - local apkdb, rev = aports.init_apkdb(repodirs) - function recurs(pn) - if pn == nil or visited[pn] or apkdb[pn] == nil then - return - end - visited[pn] = true - local i,d, p - for i,p in ipairs(apkdb[pn]) do - local _, d - for _, d in ipairs(p.depends) do - recurs(d) - end - for _, d in ipairs(p.makedepends) do - recurs(d) - end - end - print(pn) - end + local db, rev = aports.init_apkdb(repodirs) for i = 2, #opts do - recurs(opts[i]) + aports.recurs_until(db, opts[i], function(pn) + print(pn) + end) end end } @@ -68,35 +51,23 @@ subcmd.builddirs = { run = function(opts) local i, p, _ local visited = {} - local apkdb, rev = aports.init_apkdb(repodirs) + local db, rev = aports.init_apkdb(repodirs) local to_print = {} - function recursdir(pn) - if pn == nil or visited[pn] or apkdb[pn] == nil then - return - end - visited[pn] = true - local i, p - for i,p in pairs(apkdb[pn]) do - local _, d - for _, d in pairs(p.depends) do - recursdir(d) - end - for _, d in pairs(p.makedepends) do - recursdir(d) - end - if to_print[p.dir] then - print(p.dir) - to_print[p.dir] = nil - end - end - end for i = 2, #opts do - for _,p in pairs(apkdb[opts[i]]) do + for _,p in pairs(db[opts[i]]) do to_print[p.dir] = true end end for i = 2, #opts do - recursdir(opts[i]) + aports.recurs_until(db, opts[i], function(pn) + local j,p + for j, p in pairs(db[pn]) do + if to_print[p.dir] then + print(p.dir) + to_print[p.dir] = nil + end + end + end) end end } @@ -130,6 +101,7 @@ while i <= #arg do i = i + 1 end + cmd = opts[1] if cmd == nil then @@ -103,3 +103,45 @@ function init_apkdb(repodirs) return pkgdb, revdeps end +-- return a key list with makedepends and depends +function all_deps(p) + local m = {} + local k,v + if p == nil then + return m + end + if type(p.depends) == "table" then + for k,v in pairs(p.depends) do + m[v] = true + end + end + if type(p.makedepends) == "table" then + for k,v in pairs(p.makedepends) do + m[v] = true + end + end + return m +end + + +function recurs_until(apkdb, pn, func) + local visited={} + function recurs(pn) + if pn == nil or visited[pn] or apkdb[pn] == nil then + return false + end + visited[pn] = true + local _, p + for _, p in pairs(apkdb[pn]) do + local d + for d in pairs(all_deps(p)) do + if recurs(d) then + return true + end + end + end + return func(pn) + end + return recurs(pn) +end + diff --git a/buildlab.in b/buildlab.in index 43ffb08..2ff21d3 100755 --- a/buildlab.in +++ b/buildlab.in @@ -88,6 +88,7 @@ prepare_chroot() { local version="$2" local mirror="$3" local arch="$4" + local enablecache="$5" msg "Setting up repositories for mirror $mirror with version $version at $path..." @@ -95,6 +96,11 @@ prepare_chroot() { echo "http://$mirror/alpine/$version/packages/$arch/main" >> "$path"/etc/apk/repositories echo "http://$mirror/alpine/$version/packages/$arch/testing" >> "$path"/etc/apk/repositories + if [ ! -z "$enablecache" ]; then + mkdir -p "$path"/var/cache/apk + ln -s /var/cache/apk "$path"/etc/apk/cache + fi + mkdir -p "$path"/var/lib/apk echo "alpine-base" > "$path"/var/lib/apk/world @@ -187,6 +193,7 @@ usage() { echo " -m APK repository mirror" echo " -v APK distribution version" echo " -a APK repository architecture" + echo " -k Enable APK caching" echo " " echo "Updating build roots (buildlab -u):" echo " " @@ -205,7 +212,7 @@ usage() { unset force unset recursive -while getopts "chqCp:v:m:a:b:u" opt; do +while getopts "chqCkp:v:m:a:b:u" opt; do case $opt in 'c') default_colors color_opt="-c";; @@ -215,7 +222,8 @@ while getopts "chqCp:v:m:a:b:u" opt; do 'p') buildpath="$OPTARG";; 'm') buildmirror="$OPTARG";; 'v') buildver="$OPTARG";; - 'a') buildarch="$OPTARG";; + 'a') buildarch="$OPTARG";; + 'k') enablecache=1;; 'b') buildpkg="$OPTARG";; 'u') update="-u";; esac @@ -224,7 +232,7 @@ shift $(( $OPTIND - 1 )) if [ ! -z "$create" ]; then msg "Creating new chroot at $buildpath..." - prepare_chroot $buildpath $buildver $buildmirror $buildarch + prepare_chroot $buildpath $buildver $buildmirror $buildarch $enablecache exit 0 fi |