diff options
author | Joshua Ismael Haase Hernández <hahj87@gmail.com> | 2011-06-13 21:28:07 -0500 |
---|---|---|
committer | Joshua Ismael Haase Hernández <hahj87@gmail.com> | 2011-06-13 21:28:07 -0500 |
commit | e4b46b5534ff31194bd960c5541c6f3cb7f1baf5 (patch) | |
tree | 1ed01e4e06585649418901edc9a06d2f7f46a5b7 /fullpkg | |
parent | 6e075397e14d65a039ed954ff0a6ab6400e4f02c (diff) | |
parent | e8724e43c334dfe57882dbe2b5d8a83f37c25af0 (diff) |
Merge branch 'master' of vparabola:~/projects/libretools
Conflicts:
fullpkg
Diffstat (limited to 'fullpkg')
-rwxr-xr-x | fullpkg | 199 |
1 files changed, 131 insertions, 68 deletions
@@ -7,8 +7,17 @@ source /etc/abs.conf source /etc/libretools.conf source /usr/bin/libremessages -[ -r $XDG_CONFIG_HOME/libretools/libretools.conf ] && \ - source $XDG_CONFIG_HOME/libretools/libretools.conf +# Avoid /libretools dir doesn't exist errors +if [ -z $XDG_CONFIG_HOME ]; then + error "There's no XDG_CONFIG_HOME var set" + OFLINE=true +elif [ -r $XDG_CONFIG_HOME/libretools/libretools.conf ]; +# set queue_file and ban_file + source $XDG_CONFIG_HOME/libretools/libretools.conf + queue_file=$XDG_CONFIG_HOME/libretools/queue + ban_file=$XDG_CONFIG_HOME/libretools/ban +fi + ##### START FUNCTIONS ##### @@ -27,6 +36,7 @@ function usage { echo " -n : don't update pacman db." echo " -m max_level : check deps until this level" echo " -r \"command\" : use this instead of \"$FULLBUILDCMD\"" + echo " -o : work offline (avoid queuing)" # printf " -f pkgname : build even when a package has been built. " # printf " Use it as many times as needed\n" echo @@ -37,11 +47,10 @@ function usage { # * Add/Remove from queue # * Check if a package is listed -# TODO -# * Check for concurrence # @ fauno: What do you mean? - # Get the queue list from the server get_queue() { + [[ "$OFFLINE" -eq true ]] && return 0 + rsync -e ssh -aq $PARABOLAHOST:mips64el/queue $queue_file >/dev/null 2>&1 || { error "Failed to retrieve queue list" return 1 @@ -50,6 +59,8 @@ get_queue() { # Put the queue list on the server put_queue() { + [[ "$OFFLINE" = true ]] && return 0 + rsync -e ssh -aq $queue_file $PARABOLAHOST:mips64el/queue >/dev/null 2>&1 || { error "Failed to put queue list" return 1 @@ -65,16 +76,20 @@ update_queue() { # Remove a package from the queue remove_queue() { + [[ "$OFFLINE" -eq true ]] && return 0 + get_queue - grep -Evw "^$(basename $PWD)" $queue_file > $queue_file.2 - mv $queue_file.2 $queue_file + grep -Evw "^$(basename $PWD)" ${queue_file} > ${queue_file}2 + mv ${queue_file}2 ${queue_file} put_queue && return 0 || return $? } # Checks if a package is listed check_queue() { + [[ "$OFFLINE" = "true" ]] && return 0 + get_queue local packager=$(grep -w "$(basename $PWD)" ${queue_file} | cut -d ':' -f2) @@ -89,15 +104,41 @@ check_queue() { # END Queue Management # +## Build order management ## + +# Removes a package from the buildorder +# $1 package name +# $2 buildorder file +remove_buildorder() { + grep -Evw "${1}" ${2} > ${2}2 + mv ${2}2 ${2} +} + +# Guesses the repo name according to the parent dir of the current package +# assuming the form repo/package/PKGBUILD guess_repo() { basename $(dirname $(pwd)) } +## +# usage : get_full_version( $epoch, $pkgver, $pkgrel ) +# return : full version spec, including epoch (if necessary), pkgver, pkgrel +## +get_full_version() { + if [[ $1 -eq 0 ]]; then + # zero epoch case, don't include it in version + echo $2-$3 + else + echo $1:$2-$3 + fi +} + # Usage: cleanup [ $(basename $PWD) ] from PKGBUILD dir # cleans the build_dir function cleanup { +# Already clean if [ ! -d $build_dir ]; then - return 1 + return 0 elif [ -d $build_dir -a ${#@} -gt 0 ]; then for _dir in $@; do @@ -105,7 +146,8 @@ function cleanup { done else - rm -rf $build_dir/* +# Only do full cleanup on level 0 + [ $level -eq 0 ] && rm -rf $build_dir/* fi } @@ -115,27 +157,31 @@ function find_deps { ## Check this level. source PKGBUILD local repo=${repo:-$(guess_repo)} + local pkgbase=${pkgbase:-${pkgname[0]}} + local fullver=$(get_full_version ${epoch} ${pkgver} ${pkgrel}) -# If package is built exit +# If package and correct ${fullver} is built exit # TODO?: If this package is in force_build: skip this step - if is_built "${pkgbase:-${pkgname[0]}}>=${pkgver}-${pkgrel}"; then + if is_built "${pkgbase}=${fullver}"; then exit 0 fi # Tell which packages are deeper in deps (even if they are on build_dir) # so we can build them first. - echo "${level}:$(basename $PWD)" >> "${build_dir}/BUILDORDER" + echo "${level}:${pkgbase}" >> "${build_dir}/BUILDORDER" # if pkgbuild directory is on build_dir, do not copy and exit - if [ -d "${build_dir}/$(basename $PWD)" ]; then + if [ -d "${build_dir}/${pkgbase}" ]; then exit 0 else - cp -r ../$(basename $PWD) ${build_dir}/ +# Copy dir to build_dir + cp -r ../${pkgbase}/ ${build_dir}/ # Info to eval later - echo "repo=$repo" > "${build_dir}/$(basename $PWD)/.INFO" + echo "repo=$repo" > "${build_dir}/${pkgbase}/.INFO" fi - msg2 "${pkgbase:-${pkgname[0]}}>=${pkgver}-${pkgrel}" +# Inform the current package + msg2 "${pkgbase}-${fullver}" ## Check next levels # Clean version checking @@ -150,8 +196,8 @@ function find_deps { for _dep in ${deps[@]}; do for _repo in ${REPOS[@]}; do # try to find $_dep on each repo from dirname - if [ -e "$ABSROOT/${_repo}/$_dep/PKGBUILD" ]; then - pushd "$ABSROOT/${_repo}/$_dep" > /dev/null + if [ -e "${ABSROOT}/${_repo}/${_dep}/PKGBUILD" ]; then + pushd "${ABSROOT}/${_repo}/${_dep}" > /dev/null $0 -c -d ${build_dir} -l ${next_level} # Circular deps must fail @@ -175,7 +221,6 @@ function find_deps { else echo "dep_not_found:$_dep:$_repo" >> $build_dir/log - fi done done @@ -198,18 +243,13 @@ function _pkg_build () { source PKGBUILD msg2 "${pkgbase:-${pkgname[0]}} $pkgver-$pkgrel" -# Add mips64el - if ! grep mips64el PKGBUILD >/dev/null; then - plain "Adding mips64el arch" - sed -i "s/^\(arch=([^)anym]\+\))/\1 'mips64el')/" "PKGBUILD" - fi # Check if pkg is being built msg2 "Checking build queue" check_queue || { echo "someone_is_building:$(basename $PWD)" >> $build_dir/log - grep -vwh "$(basename $PWD)" $buildorder > $buildorder.2 - mv $buildorder.2 $buildorder + + remove_buildorder "$(basename $PWD)" $buildorder continue } @@ -225,12 +265,11 @@ function _pkg_build () { # fails with something else if blacklist can't be retrieved if [ $? -eq 15 ]; then # log they have nonfree deps and so didn't build - echo "nonfree:$(basename $PWD)" >> $build_dir/log + echo "nonfree:$(basename $PWD)" >> $build_dir/log # take out package from $buildorder - grep -vwh "$(basename $PWD)" $buildorder > $buildorder.2 - mv $buildorder.2 $buildorder + remove_buildorder "$(basename $PWD)" $buildorder # continue building next package - continue + continue fi } @@ -242,8 +281,10 @@ function _pkg_build () { 0) plain "The build was succesful." source .INFO && [ -n $repo ] && { -# Release locally - mipsrelease *.pkg.tar.?z + +# Calls a local release script if it's used + [ -z $HOOKLOCALRELEASE ] || \ + $HOOKLOCALRELEASE $repo *.pkg.tar.?z # Stage for releasing librestage $repo || { @@ -253,6 +294,7 @@ function _pkg_build () { msg "Updating pacman db and packages" sudo pacman -Syu --noconfirm } + echo "built:$(basename $PWD)" >> $build_dir/log cleanup "$(basename $PWD)" ;; @@ -264,8 +306,7 @@ function _pkg_build () { esac # Package was built or failed: take it out of $buildorder - grep -vwh "${build_packages[0]}" $buildorder > $buildorder.2 - mv $buildorder.2 $buildorder + remove_buildorder "${build_packages[0]}" $buildorder # Take package out from queue remove_queue @@ -275,29 +316,48 @@ function _pkg_build () { popd > /dev/null done - pkgs=$(cat $build_dir/log | grep "nonfree:") && { + pkgs=($(grep "nonfree:" $build_dir/log)) && { error "Those packages contain nonfree deps:" echo ${pkgs[@]} | tr " " "\n" | cut -d: -f2 } - pkgs=$(cat $build_dir/log | tr " " "\n" | grep "built:") && { - msg "Those packages were built and installed:" + pkgs=($(grep "built:" $build_dir/log)) && { + msg "Those packages were built and staged:" echo ${pkgs[@]} | tr " " "\n" | cut -d: -f2 } - pkgs=$(cat $build_dir/log | tr " " "\n" | grep "failed:") && { + pkgs=($(grep "failed:" $build_dir/log) && { error "Those packages failed to build:" echo ${pkgs[@]} | tr " " "\n" | cut -d: -f2 } - pkgs=$(cat $build_dir/log | tr " " "\n" | grep "unstaged:") && { + pkgs=($(grep "unstaged:" $build_dir/log) && { error "Those packages couldn't be staged because of missing reponame:" echo ${pkgs[@]} | tr " " "\n" | cut -d: -f2 } popd > /dev/null } -###### END FUNCTIONS ###### + +# End inmediately but print a useful message +trap_exit() { + remove_queue + + error "$@" + warning "Leftover files left on $build_dir" + + exit 1 +} + +## END FUNCTIONS ## + +## Trap signals +# From makepkg +set -E +trap 'cleanup' 0 +trap 'trap_exit "TERM signal caught. Exiting..."' TERM HUP QUIT +trap 'trap_exit "Aborted by user! Exiting..."' INT +trap 'trap_exit "An unknown error has occurred. Exiting..."' ERR force_build="" level=0 @@ -306,7 +366,8 @@ build_only='n' check_deps_only='n' do_cleanup='n' max_level=21 -while getopts 'ha:bcCd:l:nm:r:' arg; do +OFFLINE=false +while getopts 'ha:bcCd:l:nm:r:o' arg; do case $arg in h) usage; exit 0 ;; a) ABSROOT="$OPTARG" ;; @@ -321,6 +382,7 @@ while getopts 'ha:bcCd:l:nm:r:' arg; do n) noupdate='y';; m) max_level=$OPTARG ;; r) FULLBUILDCMD="$OPTARG" ;; + o) OFFLINE=true ;; esac done @@ -329,14 +391,10 @@ done usage && exit 1 } -## if $level = 20 there is highly likely there are circular deps -[ $level -eq $max_level -o $level -gt $max_level ] && exit 20 - # Only on level 0 -[ $level -eq 0 ] && { +if [ $level -eq 0 ]; then # if build_dir exist use it, else make a build_dir build_dir=${build_dir:-$(mktemp -d /tmp/fullpkg.XXXXXX)} - mkdir -p $build_dir # cleanup if the option was used. [ $do_cleanup == 'y' ] && { @@ -344,11 +402,6 @@ done [ $build_only == 'y' ] && exit 0 } -# set queue_file and ban_file - mkdir -p $XDG_CONFIG_HOME/libretools - queue_file=$XDG_CONFIG_HOME/libretools/queue - ban_file=$XDG_CONFIG_HOME/libretools/ban - # make files for log and buildorder touch $build_dir/{log,BUILDORDER} buildorder=$build_dir/BUILDORDER @@ -360,16 +413,15 @@ done # Build only [ $build_only == 'y' ] && { -# Exit loop on Ctrl+C - trap "break" INT -# Remove from queue package being built on error - trap "remove_queue" EXIT INT QUIT TERM KILL _pkg_build exit 0 } msg "Checking dependencies" -} +fi + +## if $level = 20 it's highly likely there are circular deps +[ $level -ge $max_level ] && exit 20 find_deps || { # if find_deps finds circular deps @@ -386,19 +438,22 @@ find_deps || { # check BUILDORDER to not include banned deps and [ $level -eq 0 -a -d $build_dir ] && { - # Check for banned deps +# Check for banned deps if [ -w $ban_file -a -r $ban_file ]; then chmod o+rw $ban_file || error "Ban file is not readable/writable ($ban_file)" else rsync -e ssh -aq $PARABOLAHOST:mips64el/ban >/dev/null 2>&1 || { warning "Failed to get ban list" && [ -r $ban_file ] && { - # continue if download failed but local copy - search=$(cat $ban_file | tr "\n" "|") - echo ${@} | tr " " "\n" | egrep -w "$search" $buildorder >> $build_dir/banned - echo ${@} | tr " " "\n" | egrep -vw "$search" $buildorder > $buildorder.2 - mv $buildorder.2 $buildorder - unset search + +# Use local copy of ban file if it is avaliable and continue. + search=$(cat ${ban_file} | tr "\n" "|") +# Keep track of banned files + egrep -w "$search" ${buildorder} >> ${build_dir}/banned +# Take banned packages out from buildorder + egrep -vw "$search" ${buildorder} > ${buildorder}2 + mv ${buildorder}2 ${buildorder} + unset search } } fi @@ -407,11 +462,19 @@ find_deps || { ## START Building msg "Building packages:" -[ ! -w $queue_file ] && error "can't write queue file" -# Exit loop on Ctrl+C -trap "break" INT -# Remove from queue package being built on error -trap "remove_queue" EXIT INT QUIT TERM KILL +# If the queue file isn't writable go into offline mode +[ ! -w $queue_file ] && { + error "Can't write queue file" + OFFLINE=true +} + +# Add mips64el if missing from arch=() and it isn't an 'any' package +if ! grep mips64el PKGBUILD >/dev/null; then + plain "Adding mips64el arch" + sed -i "s/^\(arch=([^)anym]\+\))/\1 'mips64el')/" "PKGBUILD" +fi + +# Build the package _pkg_build echo |