Commit 014754b3 authored by Natanael Copa's avatar Natanael Copa

abuild: reworked dependency handling

- Added option -i, to install a given build target after successful build.

- Parse all APKBUILDs and use awk to calculate a dependency graph. Then
  build the package and use -i to install the needed dependency.

- Uninstall all build dependencies after package is built (unless -i given)

- Automatically add binutils gcc make patch uclibc-dev as deps
parent e48c520d
...@@ -36,6 +36,7 @@ pkgrel=0 ...@@ -36,6 +36,7 @@ pkgrel=0
# defaults # defaults
SRCDEST=${SRCDEST:-$startdir} SRCDEST=${SRCDEST:-$startdir}
PKGDEST=${PKGDEST:-$startdir} PKGDEST=${PKGDEST:-$startdir}
BUILD_BASE="binutils gcc make patch uclibc-dev"
default_cmds="sanitycheck builddeps clean fetch md5check unpack rootpkg" default_cmds="sanitycheck builddeps clean fetch md5check unpack rootpkg"
...@@ -47,6 +48,9 @@ set_xterm_title() { ...@@ -47,6 +48,9 @@ set_xterm_title() {
cleanup() { cleanup() {
set_xterm_title "" set_xterm_title ""
if [ -z "$install_after" ] && [ -n "$uninstall_after" ]; then
sudo apk_delete $uninstall_after
fi
} }
die() { die() {
...@@ -394,42 +398,86 @@ up2date() { ...@@ -394,42 +398,86 @@ up2date() {
return 0 return 0
} }
# note: this must run in a subshell # source all APKBUILDs and output:
find_aport() { # 1) origin of package
local i # 2) all dependencies
msg "Searching for $1 in aports tree..." # the output is i in a format easy parseable for awk
cd ../.. depparse_aports() {
for i in */*/APKBUILD; do # lets run this in a subshell since we source all APKBUILD here
pkgrel= (
aportsdir=$(realpath ${APKBUILD%/APKBUILD}/../..)
for i in $aportsdir/*/*/APKBUILD; do
pkgname=
subpackages=
depends=
makedepends=
. $i . $i
local j dir=${i%/APKBUILD}
for j in $pkgname $subpackages; do for j in $pkgname $subpackages; do
if [ "${j%%:*}" = "$1" ]; then echo "o ${j%%:*} $dir"
echo "$PWD/${i%/APKBUILD}/$1-$pkgver-r$pkgrel.apk" set -- $depends $makedepends
return 0 echo -n "d ${j%%:*} $1"
fi shift
while [ $# -gt 0 ]; do
echo -n ",$1"
shift
done
echo
done done
done done
return 1 )
} }
# recursively build and install dependencies deptrace() {
builddeps() { ( depparse_aports
local dep pkg if [ -z "$upgrade" ]; then
for dep in $depends $makedepends; do # list installed pkgs and prefix with 'i '
[ -z "$upgrade" ] && apk_info -e $dep && continue apk_info | sed 's/-[0-9].*//; s/^/i /'
[ -z "$recursive" ] && die "Missing dependency $dep. Use -r or -u to build recursively"
pkg=$(find_aport $dep)
if [ -z "$pkg" ]; then
# try install from system repo as fallback
apk_add ${upgrade:+-u} $dep && continue
die "Failed to find dependency $dep"
fi fi
# recursively build deps ) | awk -v pkgs="$BUILD_BASE $depends $makedepends" '
msg "Entering ${pkg%/*}"
cd ${pkg%/*} function depgraph(pkg, a, i) {
$0 -r ${upgrade:+-u} || return 1 if (visited[pkg])
sudo apk_add ${upgrade:+-u} $pkg return 0;
visited[pkg] = 1;
split(deps[pkg], a, ",");
for (i in a)
depgraph(a[i]);
print pkg ":" origin[pkg];
}
$1 == "i" { visited[$2] = 1 }
$1 == "o" { origin[$2] = $3 }
$1 == "d" { deps[$2] = $3 }
END {
split(pkgs, pkgarray);
for (i in pkgarray)
depgraph(pkgarray[i]);
}
'
}
# build and install dependencies
builddeps() {
local deps alldeps pkg i dir ver
msg "Building dependencies..."
deps="$BUILD_BASE $depends $makedepends"
if [ -z "$recursive" ]; then
for i in $deps; do
apk_info -e $i || die "Missing dependency $i. Use -r to build recursively"
done
return 0
fi
for i in $(deptrace); do
# i = pkg:dir
local dir=${i#*:}
local pkg=${i%:*}
msg "Entering $dir"
cd "$dir" || return 1
$0 -i $pkg || return 1
uninstall_after="$pkg $uninstall_after"
done done
} }
...@@ -469,10 +517,11 @@ listpkg() { ...@@ -469,10 +517,11 @@ listpkg() {
usage() { usage() {
echo "$(basename $0) $abuild_ver" echo "$(basename $0) $abuild_ver"
echo "usage: $0 [options] [cmd] ..." echo "usage: $0 [options] [-i PKG] [cmd] ..."
echo "Options:" echo "Options:"
echo " -h Show this help"
echo " -f Force specified cmd, even if they are already done" echo " -f Force specified cmd, even if they are already done"
echo " -h Show this help"
echo " -i Install PKG after successul build"
echo " -q Quiet" echo " -q Quiet"
echo " -r Recursively build and install missing dependencies (using sudo)" echo " -r Recursively build and install missing dependencies (using sudo)"
echo " -u Recursively build and upgrade dependencies (using sudo)" echo " -u Recursively build and upgrade dependencies (using sudo)"
...@@ -499,10 +548,13 @@ usage() { ...@@ -499,10 +548,13 @@ usage() {
APKBUILD="${APKBUILD:-./APKBUILD}" APKBUILD="${APKBUILD:-./APKBUILD}"
while getopts "hfqru" opt; do unset force
unset recursive
while getopts "fhi:qru" opt; do
case $opt in case $opt in
'h') usage;;
'f') force=1;; 'f') force=1;;
'h') usage;;
'i') install_after="$install_after $OPTARG";;
'q') quiet=1;; 'q') quiet=1;;
'r') recursive=1;; 'r') recursive=1;;
'u') upgrade=1 'u') upgrade=1
...@@ -536,5 +588,11 @@ while [ $# -gt 0 ]; do ...@@ -536,5 +588,11 @@ while [ $# -gt 0 ]; do
runpart $1 runpart $1
shift shift
done done
for i in $install_after; do
sudo apk_add -s -u $PKGDEST/$i-$pkgver-r$pkgrel.apk \
|| die "Failed to install $i"
done
cleanup cleanup
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment