]> git.ozlabs.org Git - next-scripts/blobdiff - common.sh
do_build: consolidate failure action
[next-scripts] / common.sh
index 31478c3909e1a6b3237db2de9158856cd840c76a..0bb8d69f5e7c0b4f364dc77718e200d5478f5ebd 100644 (file)
--- a/common.sh
+++ b/common.sh
 #
 
 # Just in case this gets included twice ...
-[ "$_next_common_included" ] && return 0
+if [ "$_next_common_included" ]; then
+       return 0
+fi
 _next_common_included=1
 
-bin_dir="$(dirname $0)"
+bin_dir=$(realpath "$(dirname "$0")")
+top_dir=$(dirname "$bin_dir")
 
-LOG_FILE="../merge.log"
-SHA1_FILE="../SHA1s"
-CTRL_FILE="../etc/control"
+if [ -z "$LOG_FILE" ]; then
+       LOG_FILE="$top_dir/merge.log"
+fi
+# "... appears unused"
+# shellcheck disable=SC2034
+SHA1_FILE="$top_dir/SHA1s"
+CTRL_FILE="$top_dir/etc/control"
 
-build_host="ka2"
-build_dir="/scratch/sfr/next"
+build_host="ash"
+build_dir="$HOME/next/next"
+gcc_version="4.9.0"
+j_factor=$(nproc)
+# "... appears unused"
+# shellcheck disable=SC2034
+gpg_key=89F91C0A41D5C07A
+# "... appears unused"
+# shellcheck disable=SC2034
+kup_gpg_key=015042F34957D06C
 
-[ "$NEXT_BUILD_HOST" ] && build_host="$NEXT_BUILD_HOST"
-[ "$NEXT_BUILD_DIR" ] && build_dir="$NEXT_BUILD_DIR"
+if [ "$NEXT_BUILD_HOST" ]; then
+       build_host="$NEXT_BUILD_HOST"
+       if [ "$build_host" = "none" ]; then
+               build_host=""
+       fi
+fi
+if [ "$NEXT_BUILD_DIR" ]; then
+       build_dir="$NEXT_BUILD_DIR"
+fi
+if [ "$NEXT_GCC_VERSION" ]; then
+       gcc_version="$NEXT_GCC_VERSION"
+fi
+gcc_ppc_version=$gcc_version
+if [ "$NEXT_GCC_PPC_VERSION" ]; then
+       gcc_ppc_version="$NEXT_GCC_PPC_VERSION"
+fi
+gcc_ppcle_version=$gcc_ppc_version
+if [ "$NEXT_GCC_PPCLE_VERSION" ]; then
+       gcc_ppcle_version="$NEXT_GCC_PPCLE_VERSION"
+fi
+if [ "$NEXT_J_FACTOR" ]; then
+       j_factor="$NEXT_J_FACTOR"
+fi
 
-[ -n "$1" ] && {
-       build_host="$1"
-       shift
+if [ -z "$_next_common_no_args" ]; then
+       if [ -n "$1" ]; then
+               build_host="$1"
+               shift
+       fi
+       if [ -n "$1" ]; then
+               build_dir="$1"
+               shift
+       fi
+fi
+
+export NEXT_BUILD_HOST="${build_host:-none}"
+export NEXT_BUILD_DIR="$build_dir"
+export NEXT_GCC_VERSION="$gcc_version"
+export NEXT_GCC_PPC_VERSION="$gcc_ppc_version"
+export NEXT_GCC_PPCLE_VERSION="$gcc_ppcle_version"
+export NEXT_J_FACTOR="$j_factor"
+
+# Support functions
+_TAB=$(printf '\t')
+
+get_control_field()
+{
+       awk -F "$_TAB" -v branch="$1" -v field="$2" '/^[^-#]/ && $3==branch { print $field; }' "$CTRL_FILE"
 }
-[ -n "$1" ] && {
-       build_dir="$1"
-       shift
+
+get_branches()
+{
+       awk -F "$_TAB" '/^[^-#]/ && $2=="git"{ print $3; }' "$CTRL_FILE"
 }
 
-export NEXT_BUILD_HOST="$build_host"
-export NEXT_BUILD_DIR="$build_dir"
+get_pending_branches()
+{
+       awk -F "$_TAB" '/^[^-#]/ && $2=="git"{ print $3; } $1=="pending-fixes" { exit; }' "$CTRL_FILE"
+}
+
+get_contacts()
+{
+       get_control_field "$1" 1
+}
+
+get_type()
+{
+       get_control_field "$1" 2
+}
+
+get_url()
+{
+       get_control_field "$1" 4
+}
+
+get_remote_branch()
+{
+       get_control_field "$1" 5
+}
+
+get_build_flag()
+{
+       get_control_field "$1" 6
+}
+
+check_unmerged_files()
+{
+       # "In POSIX sh, 'local' is undefined."
+       # shellcheck disable=SC3043
+       local tree="$1"
+       # shellcheck disable=SC3043
+       local um_files
+       # shellcheck disable=SC3043
+       local rm_files
+
+       um_files=$(git diff 2>&1 | sed -n 's/^\* Unmerged path //p')
+       if [ "$um_files" ] && [ -f "../merge-files/$tree" ]; then
+               rm_files=$(grep -F "$um_files" "../merge-files/$tree")
+               if [ "$rm_files" ]; then
+                       "$bin_dir/do_rm" "$rm_files"
+               fi
+       fi
+}
+
+check_dups()
+{
+       # "In POSIX sh, 'local' is undefined."
+       # shellcheck disable=SC3043
+       local name base sha dfile
+
+       name="$1"
+       base="$2"
+       sha="$3"
+       dlfile="$top_dir/duplicates/linus/$name"
+       if [ "$base" = "HEAD" ]; then
+               dfile="$top_dir/duplicates/next/$name"
+       else
+               dfile="$dlfile"
+       fi
+
+       # if there is anything in this tree, then check for duplicates
+       if [ "$(git rev-list --count --no-merges "$base".."$sha")" -eq 0 ]; then
+               rm -f "$dfile"
+               return;
+       fi
+
+       dups=$(git cherry "$base" "$sha" | sed -n 's/^- //p' |
+               xargs -r -n 1 "$tools_dir"/clog | sort)
+       if [ "$base" = "HEAD" ] && [ -f "$dlfile" ]; then
+               dups=$(printf '%s\n' "$dups" | comm -23 - "$dlfile")
+       fi
+       if [ -z "$dups" ]; then
+               rm -f "$dfile"
+       elif ! [ -f "$dfile" ]; then
+               printf '%s\n' "$dups" | tee "$dfile"
+       elif ! printf '%s\n' "$dups" | cmp -s - "$dfile"; then
+               printf '%s\n' "$dups" | comm -23 - "$dfile"
+               printf '%s\n' "$dups" >"$dfile"
+       fi
+}
 
 true