From d220266566780795b2cad867253ac75b99c59604 Mon Sep 17 00:00:00 2001 From: Nicolas Reynolds Date: Wed, 17 Aug 2011 12:13:58 -0300 Subject: Toru stores PKGBUILD paths. Fullpkg consults toru path cache to know where to find them. Removed package path guessing altogether Usage: (on abs root) toru -u [repo] Do that for every repo, then you can use fullpkg safely --- fullpkg | 130 +++++++++++++++++++++++++++++++++++----------------------------- toru | 56 ++++++++++++++++------------ 2 files changed, 105 insertions(+), 81 deletions(-) diff --git a/fullpkg b/fullpkg index 6fb580c..bda55e7 100755 --- a/fullpkg +++ b/fullpkg @@ -19,7 +19,6 @@ elif [ -e $XDG_CONFIG_HOME/libretools/libretools.conf ]; then fi - usage() { echo "cd to a dir containing a PKGBUILD and run:" @@ -41,6 +40,23 @@ usage() { } +# Finds a PKGBUILD on toru's path cache +# Look in all caches but pick the first one +# TODO move to a toru flag (-p?) +where_is() { + local _repo + local _path + for _repo in ${REPOS[@]}; do + _path=$(grep "^${1}:" "${TORUPATH}/${_repo}.paths.cache" 2>/dev/null| \ + cut -d: -f2 2>/dev/null) + + [ -n "${_path}" ] && break + done + + echo ${_path} + +} + # Removes a package from the buildorder # $1 package name # $2 buildorder file @@ -84,27 +100,33 @@ find_deps() { # Check this level source PKGBUILD +# unset PKGBUILD variables + unset pkgdesc url license groups optdepends provides conflicts replaces \ + backup options install changelog source noextract md5sums build \ + check package + for _pkg in ${pkgname[@]}; do + unset package_${_pkg} >/dev/null 2>&1 + done + local repo=${repo:-$(guess_repo)} local pkgbase=${pkgbase:-${pkgname[0]}} # Provide a default 0 to epoch local epoch=${epoch:-0} local fullver=$(get_fullver ${epoch} ${pkgver} ${pkgrel}) +# Check if the package is already built if is_built "${pkgbase}>=${fullver}"; then # pkg is built and updated exit 0 fi # greater levels are built first - echo "${level}:${pkgbase}" >> "${build_dir}/BUILDORDER" + echo "${level}:${pkgbase}" >>"${build_dir}/BUILDORDER" # PKGBUILD is already there if [ -d "${build_dir}/${pkgbase}" ]; then - exit 0 - # Copy dir to build_dir else - cp -r ../${pkgbase}/ ${build_dir}/ # to identify repo later @@ -118,40 +140,30 @@ find_deps() { declare -i next_level=$level+1 # All deps in separate line, only once, without version. - deps=$(echo "${depends[@]} ${makedepends[@]}" | \ + deps=($(echo "${depends[@]} ${makedepends[@]}" | \ sed "s/[=<>]\+[^ ]\+//g" | \ tr ' ' "\n" | \ - sort -u) + sort -u)) for _dep in ${deps[@]}; do local found=false + local pkgdir=$(where_is ${_dep}) -# TODO ask toru where the pkgbuild is - for _repo in ${REPOS[@]}; do + if [ -d "${pkgdir}" ]; then + found=true -# ABSROOT/repo/package - if [ -e "${ABSROOT}/${_repo}/${_dep}/PKGBUILD" ]; then + pushd "${pkgdir}" > /dev/null +# runs itself on dep's PKGBUILD dir + $0 -c -d ${build_dir} -l ${next_level} - pushd "${ABSROOT}/${_repo}/${_dep}" > /dev/null -# run this cmd on dep's PKGBUILD dir - $0 -c -d ${build_dir} -l ${next_level} # probable circular deps - [ $? -eq 20 ] && return 20 - popd > /dev/null - local found=true -# found, end cycle - break 1 - fi - - done - + [ $? -eq 20 ] && return 20 + popd > /dev/null + fi - if ( ${found} ); then -# go to next dep - continue 1 - else - echo "dep_not_found:$_dep" >> $build_dir/log + if ! (( found )); then + echo "dep_not_found:$_dep" >>$build_dir/log fi done @@ -159,20 +171,16 @@ find_deps() { ## End variable block unset next_level dir -# unset PKGBUILD variables - unset pkgname pkgver pkgrel epoch pkgdesc arch url license groups depends \ - makedepens checkdepends optdepends provides conflicts replaces backup \ - options install changelog source noextract md5sums build check package } __build() { - pushd ${build_dir} > /dev/null + pushd ${build_dir} >/dev/null # greater levels must be built first build_packages=($(sort -gr $buildorder | cut -d: -f2)) while [ ${#build_packages[@]} -ge 1 ]; do - pushd $build_dir/${build_packages[0]} > /dev/null + pushd $build_dir/${build_packages[0]} >/dev/null source PKGBUILD msg2 "${pkgbase:-${pkgname[0]}} $pkgver-$pkgrel" @@ -182,7 +190,7 @@ __build() { # this error means nonfree others means fail. if [ $? -eq 15 ]; then - echo "nonfree:$(basename $PWD)" >> $build_dir/log + echo "nonfree:$(basename $PWD)" >>$build_dir/log # take out package from $buildorder remove_buildorder "$(basename $PWD)" $buildorder @@ -210,20 +218,20 @@ __build() { find -name "*.pkg.tar.?z" -print0 | xargs -0 $HOOKLOCALRELEASE $repo fi - librestage $repo || echo "unstaged:$(basename $PWD)" >> $build_dir/log + librestage $repo || echo "unstaged:$(basename $PWD)" >>$build_dir/log msg "Updating pacman db and packages" sudo pacman -Sy || true fi - echo "built:$(basename $PWD)" >> $build_dir/log + echo "built:$(basename $PWD)" >>$build_dir/log ;; ## Build failed *) error "There were errors while trying to build the package." - echo "failed:$(basename $PWD)" >> $build_dir/log + echo "failed:$(basename $PWD)" >>$build_dir/log ;; esac @@ -254,12 +262,11 @@ __build() { echo ${pkgs[@]} | tr " " "\n" | cut -d: -f2 } - popd > /dev/null + popd >/dev/null } # End inmediately but print a useful message trap_exit() { - error "$@" warning "Leftover files left on $build_dir" @@ -273,7 +280,6 @@ trap 'trap_exit "(prfullpkg:${level}) TERM signal caught. Exiting..."' TERM HUP trap 'trap_exit "(prfullpkg:${level}) Aborted by user! Exiting..."' INT trap 'trap_exit "(prfullpkg:${level}) An unknown error has occurred. Exiting..."' ERR -ban_file=$XDG_CONFIG_HOME/libretools/ban force_build="" level=0 noupdate=false @@ -288,13 +294,17 @@ while getopts 'ha:b:cCd:l:nm:r:' arg; do a) ABSROOT="$OPTARG" ;; b) build_only=true build_dir="$OPTARG" - if [ -z ${build_dir} ]; then + + if [ -z "${build_dir}" ]; then usage fi - if [ ! -r ${build_dir}/BUILDORDER ] ; then + + if [ ! -r "${build_dir}/BUILDORDER" ] ; then error "${build_dir}/BUILDORDER doesn't exist." exit 1 - fi;; + fi + + ;; c) check_deps_only=true ;; C) do_cleanup=true;; d) build_dir="$OPTARG" ;; @@ -306,7 +316,7 @@ while getopts 'ha:b:cCd:l:nm:r:' arg; do esac done -if [[ ! ${build_only} ]]; then +if ! (( build_only )); then # Check if we are actually on a build directory. Do this early. if [ ! -r PKGBUILD ]; then @@ -314,31 +324,33 @@ if [[ ! ${build_only} ]]; then usage fi - if [ ! -z "$HOOKPKGBUILDMOD" ]; then - "$HOOKPKGBUILDMOD" +# Run the pre build hook + if [ ! -z "${HOOKPKGBUILDMOD}" ]; then + ${HOOKPKGBUILDMOD} fi fi -if [ $level -eq 0 ]; then +if [ ${level} -eq 0 ]; then # use -d option or else mktemp - build_dir=${build_dir:-$(mktemp -d /tmp/fullpkg.XXXXXX)} + build_dir="${build_dir:-$(mktemp -d /tmp/fullpkg.XXXXXX)}" # in case of custom -d option - if [ ! -d ${build_dir} ]; then - mkdir -p ${build_dir} + if [ ! -d "${build_dir}" ]; then + mkdir -p "${build_dir}" else # files already there can screw find_deps cleanup fi # make files for log and buildorder - touch ${build_dir}/{log,BUILDORDER} ${ban_file} - buildorder=${build_dir}/BUILDORDER + touch "${build_dir}"/{log,BUILDORDER} + buildorder="${build_dir}/BUILDORDER" if ! (( noupdate )); then +# Always return true msg "Updating pacman db and packages" sudo pacman -Syu --noconfirm || true @@ -346,7 +358,7 @@ if [ $level -eq 0 ]; then if (( build_only )); then - msg "Build Packages" + msg "Building Packages" __build @@ -360,6 +372,7 @@ fi # Probable circular deps [ $level -ge $max_level ] && exit 20 +# Find the dependencies on the ABS itself find_deps || { # Probable circular deps @@ -376,14 +389,15 @@ find_deps || { } # only build on level 0 -$( (( check_deps_only )) || [ $level -gt 0 ] ) && exit 0 - -msg "Building packages:" +if (( check_deps_only )) || [ $level -gt 0 ]; then + exit 0 +fi # Build the packages +msg "Building packages:" __build echo -msg2 "Check if your system works fine and librerelease if it does" +msg2 "Check if your system works fine and librerelease if it does." exit 0 diff --git a/toru b/toru index a9f0be7..d622510 100755 --- a/toru +++ b/toru @@ -21,15 +21,18 @@ if [ ! -w "$TORUPATH" ]; then fi # TODO move to common functions -function in_array { # usage : in_array( $needle, $haystack ) - - [[ $2 ]] || return 1 # Not found - local needle=$1; shift - local item - for item in "$@"; do - [[ ${item#@} = $needle ]] && return 0 # Found - done - return 1 # Not Found +# usage : in_array( $needle, $haystack ) +function in_array { + [[ $2 ]] || return 1 # Not found + + local needle=$1; shift + local item + + for item in "$@"; do + [[ ${item#@} = $needle ]] && return 0 # Found + done + + return 1 # Not Found } # Stores the lastsync date @@ -146,21 +149,32 @@ update() { # Check if the repo is set as such, otherwise skip is_repo ${_repo} || continue +# Fullpath of the repo + _repopath=$(readlink -f ${_repo}) + # This is the syncfile, stores the last date as content and mtime local lastsyncfile=${TORUPATH}/${_repo}.lastsync # Find all the PKGBUILDs newer than the last update # Update newer, otherwise everything if [[ $force = true || ! -e ${lastsyncfile} ]]; then + $quiet || warning "Forcing upgrade" - pkgbuilds=($(find ${_repo} -maxdepth 2 -type f -name 'PKGBUILD')) +# Get all PKGBUILDs + pkgbuilds=($(find ${_repopath} -maxdepth 2 -type f -name 'PKGBUILD')) + else - pkgbuilds=($(find ${_repo} -maxdepth 2 -type f -name 'PKGBUILD' -newer ${lastsyncfile})) + +# Only find newer than lastsyncfile and read everything else from cache + pkgbuilds=($(find ${_repopath} -maxdepth 2 -type f -name 'PKGBUILD' -newer ${lastsyncfile})) packages_in_abs=($(read_cache ${_repo})) - package_paths=($(read_cache paths)) + $quiet || msg2 "Getting ${#packages_in_abs[@]} packages from cache" + fi + package_paths=($(read_cache ${_repo}.paths)) + # Inform how many PKGBUILDS were found and quit immediately if none $quiet || msg "Found $((${#pkgbuilds[*]}-1)) PKGBUILDs to update" @@ -169,13 +183,13 @@ update() { # Update the sync file because there are pkgbuilds to update update_sync_file=true -# Guess pkgbase from PKGBUILD's basedir - _pkgpath=$(dirname "${_pkgbuild}") - _pkgbase=$(basename "${_pkgpath}") - # Load PKGBUILD's metadata source ${_pkgbuild} +# Guess pkgbase from PKGBUILD's basedir + _pkgpath=$(dirname "${_pkgbuild}") + _pkgbase=${pkgbase:-${pkgname[0]}} + # We won't need this (all unsets are for memory efficiency) unset build package url md5sums install pkgdesc backup options # TODO fill a license list @@ -199,9 +213,9 @@ update() { # Sync! (Only if there was an actual sync) ${update_sync_file} && lastsync ${lastsyncfile} - if [ "${lastsyncfile}" -nt "${TORUPATH}/paths.cache" ]; then + if [ "${lastsyncfile}" -nt "${TORUPATH}/${_repo}.paths.cache" ]; then print_package_array "${package_paths[@]}" > $TMPDIR/paths - store_cache paths $TMPDIR/paths + store_cache ${_repo}.paths $TMPDIR/paths fi # If there isn't an update cache or it's older than the last update, we check @@ -256,7 +270,7 @@ update() { store_cache ${_repo}.updates ${TMPDIR}/updates else - msg "Reading updates from cache..." + $quiet || msg "Reading updates from cache..." read_cache ${_repo}.updates fi @@ -292,10 +306,6 @@ TMPDIR=$(mktemp -d) [[ -z ${TMPDIR} ]] && exit 1 -# TODO this is all for debugging -msg2 "force: $force quiet: $quiet repos: $@ commands: ${commands[@]}" -msg2 "read lastsync: $([ -e $lastsyncfile ])" - ${commands[0]} ${@} #rm -rf ${TMPDIR} -- cgit v1.2.2