diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-10-01 17:01:02 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-10-01 17:01:02 +0200 |
commit | 8bb9d760b54f103fe1c6be67fde307666b81b789 (patch) | |
tree | 297da8f42c8aa0d377a2db677d29ee16be198908 | |
parent | 8253c613c49dd2c1aaac424ed932dffa52c494a9 (diff) |
Add rep-{update,test,publish} scripts
-rwxr-xr-x | rep-publish | 33 | ||||
-rwxr-xr-x | rep-test | 179 | ||||
-rwxr-xr-x | rep-update | 84 |
3 files changed, 296 insertions, 0 deletions
diff --git a/rep-publish b/rep-publish new file mode 100755 index 0000000..8db26e0 --- /dev/null +++ b/rep-publish @@ -0,0 +1,33 @@ +#! /usr/bin/env bash + +# Publish the repository. +# +# Usage: publish <dir> <host>:<dir> [<rsync-options>] +# +# Some commonly useful rsync options: +# +# --dry-run +# --progress +# +usage="$0 <dir> <host>:<dir> [<rsync-options>]" + +trap 'exit 1' ERR +set -o errtrace # Trap in functions. + +function info () { echo "$*" 1>&2; } +function error () { info "$*"; exit 1; } + +dir=${1%/} +if [ -z "$dir" ]; then + error $usage +fi +shift + +host=$1 +if [ -z "$host" ]; then + error $usage +fi +shift + +rsync -v -rlpt -c --exclude '.*' --copy-unsafe-links --prune-empty-dirs \ +--delete-after $* $dir/ $host diff --git a/rep-test b/rep-test new file mode 100755 index 0000000..2e45840 --- /dev/null +++ b/rep-test @@ -0,0 +1,179 @@ +#! /usr/bin/env bash + +# Test repository. +# +# Usage: update [options] <dir> +# +# First, the script determines the list of repositories/sections. If <dir> +# contains the 'repositories' file, then it is the only repository to be +# tested. Otherwise, every first-level subdirectory of <dir> that doesn't +# start with '.' and contains the 'repositories' file is to be tested. +# +# Then, it makes sure that every package in every repository can be built +# in a clean configuration. +# +# -n +# Only test new packages. For this to work, <dir> should be (part of) a +# git repository. Untracked (and changed) files are considered new. +# +# -e <subdir> +# Exclude the specified sub-directory. Currently only one directory can +# be excluded. +# +# -t <toolchain> +# Specify the build2 toolchain install/stage directory. The script will +# use <toolchain>/bin/b and <toolchain>/bin/bpkd instead of just b and +# bpkg. +# +# -c <option>|<module>|<var> +# Specify additional options, modules, or configuration variables to pass +# to the bpkg create command. For example: +# +# -c cxx -c config.cxx.loptions=-L/usr/local/lib +# +usage="usage: $0 [options] <dir>" + +trap 'exit 1' ERR +set -o errtrace # Trap in functions. + +function info () { echo "$*" 1>&2; } +function error () { info "$*"; exit 1; } + +dir= +cfg=/tmp/test-cfg +toolchain= +exclude= +co=() # Use a bash array to handle arguments with spaces (say "-Ifoo -Ibar"). +new=n + +while [ $# -gt 0 ]; do + case $1 in + -e) + shift + exclude=${1%/} + shift + ;; + -t) + shift + toolchain=${1%/} + shift + ;; + -c) + shift + co=("${co[@]}" "$1") + shift + ;; + -n) + new=y + shift + ;; + *) + dir=${1%/} + shift + break + ;; + esac +done + +if [ -z "$dir" ]; then + error $usage +fi + +if [ -z "$toolchain" ]; then + b="b" + bpkg="bpkg" +else + b="$toolchain/bin/b" + if [ ! -x $b ]; then + error "$b does not exist or is not executable" + fi + bo="--build $b" + + bpkg="$toolchain/bin/bpkg" + if [ ! -x $bpkg ]; then + error "$bpkg does not exist or is not executable" + fi +fi + +if [ "$new" = "y" ]; then + new=( `git -C $dir status --untracked-files=all --porcelain . | \ +sed -e 's%^\(??\| M\|M \) .*/\(.*\)$%\2%'` ) + if [ ${#new[@]} -eq 0 ]; then + info "no new packages in $dir" + exit 0 + fi + info "testing only ${new[@]}" +else + new=() +fi + +function check_new () # <pkg> <ver> +{ + if [ ${#new[@]} -eq 0 ]; then + return 0 + fi + + for f in ${new[@]}; do + if [[ $f == $1-$2.?* ]]; then + return 0 + fi + done + + return 1 +} + +# Determine the list of repositories. +# +rep= + +if [ -f "$dir/repositories" ]; then + rep=$dir +else + sub=`find $dir -mindepth 1 -maxdepth 1 -type d -name '[^.]*'` + if [ -z "$sub" ]; then + error "no subdirectories in $dir/" + fi + + for d in $sub; do + if [ `basename $d` = "$exclude" ]; then + info "skipping excluded $d/" + continue + fi + if [ -f "$d/repositories" ]; then + rep+=" $d" + else + info "no 'repositories' file in $d/, skipping" + fi + done + + if [ -z "$rep" ]; then + error "no repositories in $dir/" + fi +fi + +# Test repositories. +# +for r in $rep; do + info "testing $r" + + IFS=$'\n' + pkg=( `$bpkg rep-info --packages $r` ) + IFS=$' \t\n' + + for p in "${pkg[@]}"; do + nv=( $p ) + n=${nv[0]} + v=${nv[1]} + + if ! check_new $n $v; then + continue + fi + + info "testing $n $v" + + $bpkg $bo create -d $cfg --wipe "${co[@]}" + $bpkg add -d $cfg $r + $bpkg fetch -d $cfg + $bpkg $bo build -d $cfg --yes $n/$v + done +done diff --git a/rep-update b/rep-update new file mode 100755 index 0000000..cb40441 --- /dev/null +++ b/rep-update @@ -0,0 +1,84 @@ +#! /usr/bin/env bash + +# Update (or create) bpkg 'packages' files in repository. +# +# Usage: update [-t <toolchain>] [-e <subdir>] <dir> [<bpkg-options>] +# +# This script runs the rep-create command for every first-level subdirectory +# of <dir> that doesn't start with '.' and contains the 'repositories' file, +# unless <dir> itself contains 'repositories'. +# +# -e <subdir> +# Exclude the specified sub-directory. Currently only one directory can +# be excluded. +# +# -t <toolchain> +# Specify the build2 toolchain install/stage directory. The script will +# use <toolchain>/bin/bpkd instead of just bpkg. +# + +trap 'exit 1' ERR +set -o errtrace # Trap in functions. + +function info () { echo "$*" 1>&2; } +function error () { info "$*"; exit 1; } + +dir= +toolchain= +exclude= + +while [ $# -gt 0 ]; do + case $1 in + -e) + shift + exclude=${1%/} + shift + ;; + -t) + shift + toolchain=${1%/} + shift + ;; + *) + dir=${1%/} + shift + break + ;; + esac +done + +if [ -z "$dir" ]; then + error "usage: $0 [-t <toolchain>] <dir> [<bpkg-options>]" +fi + +if [ -z "$toolchain" ]; then + bpkg="bpkg" +else + bpkg="$toolchain/bin/bpkg" + if [ ! -x $bpkg ]; then + error "$bpkg does not exist or is not executable" + fi +fi + +if [ -f "$dir/repositories" ]; then + sub=$dir +else + sub=`find $dir -mindepth 1 -maxdepth 1 -type d -name '[^.]*'` + + if [ -z "$sub" ]; then + error "no 'repositories' file or subdirectories in $dir/" + fi +fi + +for d in $sub; do + if [ `basename $d` = "$exclude" ]; then + echo "skipping excluded $d/" 1>&2 + continue + fi + + if [ -f "$d/repositories" ]; then + $bpkg rep-create "$@" $d + else + echo "no 'repositories' file in $d/, skipping" 1>&2 + fi +done |