Commit 376946a6 authored by Vitaly Lipatov's avatar Vitaly Lipatov

rewrite git repo using to support a few specs or git dirs as args

make rpmbsh install all built packages in one hasher make rpmbs create one task with all packages
parent a65443cc
#!/bin/sh
# load common functions, compatible with local and installed script
. `dirname $0`/../share/eterbuild/functions/common
load_mod git
set_girar_host $1 && shift
if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
echo "grpmbph - multi repo rpmbsh analogue (build packages in hasher)"
echo "Usage: grpmbph [GIRAR] package1... package2..."
# FIXME: concatenate grpmbsh and grpmbs
#echo "Options:"
#echo " -a - build all packages in one task"
#echo " -u - build packages separately (one package per task)"
#echo " -f - force set tags (see rpmbs)"
exit 1
fi
for i in "$@" ; do
docmd cd $i || fatal "Please run in dir with '$i' subdirectory."
docmd rpmbph $GIRARHOST || fatal
cd -
done
#!/bin/sh
# load common functions, compatible with local and installed script
. `dirname $0`/../share/eterbuild/functions/common
load_mod git
set_girar_host $1 && shift
if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
echog "grpmbs - multi repo rpmbs analogue (build packages via girar)"
echog "Run in dir contains subdirs"
echog "Usage: grpmbs [GIRAR] [-a|-u] [-f] package1... package2..."
echo
echog "Options:"
echog " -a build all packages in one task"
echog " -u build packages separately (one package per task)"
echog " -f force set tags (see rpmbs)"
exit 1
fi
TASKADD=
if [ "$1" = "-a" ] ; then
TASKADD="-a"
shift
fi
SINGLETASK=
if [ "$1" = "-u" ] ; then
SINGLETASK="-u"
shift
fi
if [ -z "$TASKADD$SINGLETASK" ] ; then
fatal "Missing arguments. Run with --help for help."
fi
FORCE=
if [ "$1" = "-f" ] ; then
FORCE="-f"
shift
fi
fatal()
{
echo $@
exit 1
}
if [ -n "TASKADD" ] ; then
TASK=$(ssh $GEARHOST task new | head -n1)
[ -n "$TASK" ] || fatal
RUNCOMMAND="rpmbs $GIRARHOST -a $TASK"
else
RUNCOMMAND="rpmbs $GIRARHOST -u"
fi
for i in "$@" ; do
docmd cd $i || fatal "Run in dir contains '$i' dir"
echo
echo "== Run $RUNCOMMAND in $(pwd)"
docmd $RUNCOMMAND $FORCE || fatal
cd -
done
if [ -n "TASKADD" ] ; then
docmd ssh $GEARHOST task run "$TASK"
fi
#!/bin/sh
# load common functions, compatible with local and installed script
. `dirname $0`/../share/eterbuild/functions/common
load_mod git
set_girar_host $1 && shift
if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
echo "grpmbsh - multi repo rpmbsh analogue (build packages in hasher)"
echo "Usage: grpmbsh [GIRAR] package1... package2..."
# FIXME: concatenate grpmbsh and grpmbs
#echo "Options:"
#echo " -a - build all packages in one task"
#echo " -u - build packages separately (one package per task)"
#echo " -f - force set tags (see rpmbs)"
exit 1
fi
OPTIONS=
if [ "$1" = "-i" ] ; then
OPTIONS="-i"
fi
for i in "$@" ; do
docmd cd $i || fatal "Please run in dir with '$i' subdirectory."
docmd rpmbsh $GIRARHOST $OPTIONS || fatal
cd -
done
......@@ -76,6 +76,9 @@ mygetopts $LISTARGS
# see functions/alt:set_binaryrepo() for BINARYREPONAME
set_binaryrepo $MENV
# assure we have only specs or src.rpm
LISTNAMES=$(repodirs_to_specs $LISTNAMES)
test -z "$LISTNAMES" && fatal "file not found in '$@'"
if [ "$PKGVENDOR" = "alt" ] ; then
......@@ -94,73 +97,81 @@ if [ -z "$BUILDCOMMAND" ] ; then
[ -n "$NOBUILD" ] && BUILDCOMMAND="$ETERBUILDBIN/rpmbs $GIRARHOST"
fi
# set SPECDIR from LISTNAMES if empty
# set SPECDIR from LISTNAMES if empty (need for is_gear below)
[ -n "$SPECDIR" ] || set_specdir $LISTNAMES
# if run for ALT inside gear repo, just create backported spec
if [ "$PKGVENDOR" = "alt" ] && is_gear $SPECDIR ; then
[ -f "$LISTNAMES" ] || fatal "Run with one spec inside gear repo"
# set branch name
USEBRANCH=$BINARYREPO
SPEC=$LISTNAMES
BPSPEC=$SPEC.$USEBRANCH
# support for obsoleted M?? names
OLDBRANCH=$MDISTR
if [ "$OLDBRANCH" != "$USEBRANCH" ] ; then
if is_exist_branch $OLDBRANCH ; then
echo "Exists $OLDBRANCH branch, will use it instead $USEBRANCH"
USEBRANCH=$OLDBRANCH
for SPEC in $LISTNAMES ; do
set_specdir $SPEC
cd $SPECDIR || fatal
# TODO: move branch detection to a separate function
#[ -f "$LISTNAMES" ] || fatal "Run with one spec inside gear repo"
USEBRANCH=$BINARYREPO
# support for obsoleted M?? names
OLDBRANCH=$MDISTR
if [ "$OLDBRANCH" != "$USEBRANCH" ] ; then
if is_exist_branch $OLDBRANCH ; then
echo "Exists $OLDBRANCH branch, will use it instead $USEBRANCH"
USEBRANCH=$OLDBRANCH
fi
# hack about p5, M50 -> p5
#if [ "$USEBRANCH" = "M50" ] && is_exist_branch p5 ; then
# USENUMBRANCH=p5
# echo "Exists $USENUMBRANCH branch, will use it instead $USEBRANCH"
# USEBRANCH=$USENUMBRANCH
#fi
fi
# set branch name
BPSPEC=$SPEC.$USEBRANCH
[ -f "$BPSPEC" ] && fatal "File $BPSPEC is already exists, check it and remove"
cp -f $SPEC $BPSPEC || fatal
CURBRANCH=$(get_current_branch)
# TODO: move to a separate function
if [ "$CURBRANCH" = "$USEBRANCH" ] || [ "$CURBRANCH" = "$OLDBRANCH" ] ; then
fatal "You are already in backported branch $CURBRANCH. Run rpmbph in sisyphus or master branch only."
fi
# Create branch if not exist yet
if ! is_exist_branch $USEBRANCH ; then
docmd git branch $USEBRANCH
fi
docmd $ETERBUILDBIN/rpmbps -b $BINARYREPO $BPSPEC || fatal
docmd git checkout $USEBRANCH || fatal "Can't checkout branch $USEBRANCH. Use $BPSPEC manually or remove it."
# TODO: check result message for merge?
# Use heads/ against warning: refname 'branch-name' is ambiguous
docmd git merge --no-ff heads/$CURBRANCH
mv -f $BPSPEC $SPEC || fatal
# FIXME: Ctrl-\ and q will cancelled less with return error code
if [ -z "$QUIET" ] && tty -s && ! ( echo "etersoft-build-utils INFO: Please check diff for backported spec:" ; echo "# etersoft-build-utils NOTE: You can press Ctrl-\ before quit for cancel process."; echo ; git diff $USEBRANCH ) | less; then
#git checkout $SPEC $MDISTR
#git checkout $CURBRANCH
fatal "Cancelled by user. You are still in $USEBRANCH branch with modified spec."
fi
docmd git add $SPEC
if ! git_commit_ignore_nothing -a -m "backported to $USEBRANCH as $(get_version $SPEC)-$(get_release $SPEC) (with rpmbph script)" ; then
#git checkout $CURBRANCH
fatal "Commit error. You are still in $CURBRANCH branch with modified and uncommitted spec file."
fi
# hack about p5, M50 -> p5
#if [ "$USEBRANCH" = "M50" ] && is_exist_branch p5 ; then
# USENUMBRANCH=p5
# echo "Exists $USENUMBRANCH branch, will use it instead $USEBRANCH"
# USEBRANCH=$USENUMBRANCH
#fi
fi
[ -f "$BPSPEC" ] && fatal "File $BPSPEC is already exists, check it and remove"
CURBRANCH=$(get_current_branch)
if [ "$CURBRANCH" = "$USEBRANCH" ] || [ "$CURBRANCH" = "$OLDBRANCH" ] ; then
fatal "You are already in backported branch $CURBRANCH. Run rpmbph in sisyphus or master branch only."
fi
# Create branch if not exist yet
if ! is_exist_branch $USEBRANCH ; then
docmd git branch $USEBRANCH
fi
# Only one spec supported
cp -f $LISTNAMES $BPSPEC || fatal
docmd $ETERBUILDBIN/rpmbps -b $BINARYREPO $BPSPEC || fatal
docmd git checkout $USEBRANCH || fatal "Can't checkout branch $USEBRANCH. Use $BPSPEC manually or remove it."
# TODO: check result message for merge?
# Use heads/ against warning: refname 'branch-name' is ambiguous
docmd git merge --no-ff heads/$CURBRANCH
mv -f $BPSPEC $SPEC || fatal
# FIXME: Ctrl-\ and q will cancelled less with return error code
if [ -z "$QUIET" ] && tty -s && ! ( echo "etersoft-build-utils INFO: Please check diff for backported spec:" ; echo "# etersoft-build-utils NOTE: You can press Ctrl-\ before quit for cancel process."; echo ; git diff $USEBRANCH ) | less; then
#git checkout $SPEC $MDISTR
#git checkout $CURBRANCH
fatal "Cancelled by user. You are still in $USEBRANCH branch with modified spec."
fi
docmd git add $SPEC
if ! git_commit_ignore_nothing -a -m "backported to $USEBRANCH as $(get_version $SPEC)-$(get_release $SPEC) (with rpmbph script)" ; then
#git checkout $CURBRANCH
fatal "Commit error. You are still in $CURBRANCH branch with modified and uncommitted spec file."
fi
docmd $BUILDCOMMAND $MENVARG $LISTRPMARGS $UPLOADARG $SPEC || { git checkout $CURBRANCH ; fatal "Can't build" ; }
docmd git checkout $CURBRANCH
docmd $BUILDCOMMAND $MENVARG $LISTRPMARGS $UPLOADARG $SPEC || { git checkout $CURBRANCH ; fatal "Can't build" ; }
docmd git checkout $CURBRANCH
cd - >/dev/null
done
exit $?
fi
# handle src.rpm and spec both, LISTBUILT - result with full paths to src.rpms
pack_src_rpm $LISTNAMES
pack_src_rpm
export RPMTOPDIR=$(mktemp -d || fatal "can't create tmp dir")
mark_file_to_remove $RPMTOPDIR
......
......@@ -218,6 +218,7 @@ if [ -n "$NOSOURCE" ] ; then
exit $?
fi
# FIXME: need we it later?
# set SPECDIR from LISTNAMES if empty
[ -n "$SPECDIR" ] || set_specdir $LISTNAMES
......@@ -226,36 +227,62 @@ set_binaryrepo $MENV
# If we build from gear repo, run task
if [ -n "$UPLOADNOW" ] && is_gear $SPECDIR ; then
[ -n "$VERBOSE" ] && echo "Run with gear repo..."
echo "Prepare to publish to $GIRARHOST..."
# assure we have only specs or src.rpm
LISTNAMES=$(repodirs_to_specs $LISTNAMES)
# check release
build_rpms_name "$LISTNAMES"
pkg_release_check $RELEASE
NUMSPECS=$(estrlist count $LISTNAMES)
# if more then one spec, use common task
if [ $NUMSPECS -gt 1 ] && [ -z "$PREPARETASK" ] ; then
PREPARETASK=internal
showcmd ssh $GEARHOST task new
TASKNUMBER=$(ssh $GEARHOST task new | head -n1) || fatal
[ -n "$TASKNUMBER" ] || fatal "Can't get task number from $GEARHOST"
fi
PROJECTNAME=$(get_repo_name)
for ln in $LISTNAMES ; do
# force SPECDIR
set_specdir $ln
check_gear_and_tag || fatal "Can't make tag"
TAG=$(get_last_tag)
[ -n "$VERBOSE" ] && echo "Run with gear repo in dir $SPECDIR..."
# TODO: add check for repo (as in rpmgp) and run ginit if needed
docmd gpush $GIRARHOST $FORCE || fatal "gpush failed. It is possible you need run '\$ ginit $GIRARHOST' to create remote repo."
echo
echo "Run build $PROJECTNAME at $GEARHOST"
if [ -n "$PREPARETASK" ] ; then
docmd ssh $GEARHOST task add $TASKNUMBER repo $PROJECTNAME $TAG 2>&1 | tee $RPMDIR/uploaded.log.tmp
else
docmd ssh $GEARHOST build $(usearg -b $BINARYREPO sisyphus) $(usearg -p $POCKET) $PROJECTNAME $TAG 2>&1 | tee $RPMDIR/uploaded.log.tmp
echo "Prepare to publish to $GIRARHOST..."
cd $SPECDIR || fatal
# check release
build_rpms_name "$ln"
pkg_release_check $RELEASE
PROJECTNAME=$(get_repo_name)
check_gear_and_tag || fatal "Can't make tag"
TAG=$(get_last_tag)
# TODO: add check for repo (as in rpmgp) and run ginit if needed
docmd gpush $GIRARHOST $FORCE || fatal "gpush failed. It is possible you need run '\$ ginit $GIRARHOST' to create remote repo."
echo
echo "Run build $PROJECTNAME at $GEARHOST"
if [ -n "$PREPARETASK" ] ; then
docmd ssh $GEARHOST task add $TASKNUMBER repo $PROJECTNAME $TAG 2>&1 | tee $RPMDIR/uploaded.log.tmp
else
docmd ssh $GEARHOST build $(usearg -b $BINARYREPO sisyphus) $(usearg -p $POCKET) $PROJECTNAME $TAG 2>&1 | tee $RPMDIR/uploaded.log.tmp
fi
# FIXME: incorporate
cat $RPMDIR/uploaded.log.tmp | grep task | head -n2 | tail -n1 >> $RPMDIR/uploaded.log
echo " run $TASKNUMBER task $PROJECTNAME with tag $TAG at $GEARHOST (in $BINARYREPO) at `date "+%c"`" >>$RPMDIR/uploaded.log
rm -f $RPMDIR/uploaded.log.tmp
cd - >/dev/null
done
# if more then one spec, use common task
if [ "$PREPARETASK" = "internal" ] ; then
docmd ssh $GEARHOST task run $TASKNUMBER
fi
# FIXME: incorporate
cat $RPMDIR/uploaded.log.tmp | grep task | head -n2 | tail -n1 >> $RPMDIR/uploaded.log
echo " run $TASKNUMBER task $PROJECTNAME with tag $TAG at $GEARHOST (in $BINARYREPO) at `date "+%c"`" >>$RPMDIR/uploaded.log
rm -f $RPMDIR/uploaded.log.tmp
exit
fi
pack_src_rpm ${LISTRPMARGS}
pack_src_rpm $LISTRPMARGS
if [ -n "${DELETENOW}" ]; then
fatal "Removing did not realized yet"
......
......@@ -71,6 +71,9 @@ set_binaryrepo $MENV
[ -n "$LISTNAMES" ] || fatal "Run with exists specs as arg"
# assure we have only specs or src.rpm
LISTNAMES=$(repodirs_to_specs $LISTNAMES)
# Skip for prev. packed src.rpm
if estrlist has spec "$LISTNAMES" ; then
# If fail, we already has correct changelog
......@@ -83,9 +86,9 @@ pack_src_rpm $COMMIT $(drop_args "$LISTRPMARGS" s u c l f a A)
# TODO: use gear --hasher directly, drop myhsh
if rhas "$LISTNAMES" spec ; then
set_specdir $LISTNAMES
fi
#if rhas "$LISTNAMES" spec ; then
# set_specdir $LISTNAMES
#fi
# build in hasher
docmd time $ETERBUILDBIN/myhsh $MENVARG $(drop_args "$LISTRPMARGS" f u a A) $LISTBUILT
......
......@@ -7,10 +7,12 @@
get_gear_rules_by_spec()
{
local SPECNAME="$1"
local SPECDIR
set_specdir
# FIXME: move get rules file to separate function
local BASESPECNAME=$(basename "$SPECNAME")
local ALTGEARRULESFILE=.gear/rules-${BASESPECNAME/.spec/}
local ALTGEARRULES=$(get_root_git_dir)/$ALTGEARRULESFILE
local ALTGEARRULES=$(get_root_git_dir $SPECDIR)/$ALTGEARRULESFILE
local GEARRULES=
if [ -r "$ALTGEARRULES" ] ; then
#echo "Build with alternate rules $ALTGEARRULESFILE"
......@@ -113,7 +115,7 @@ uni_rpminstall()
#if is_gear $SPECDIR ; then
# $NICE $GEARBUILDREQ --commit -- $@ || RET=$?
#else
echo -n "Install package "
# echog "Install package "
docmd mkdir -p $RPMTOPDIR/SOURCES $RPMTOPDIR/SRPMS $RPMTOPDIR/RPMS
docmd rpm -iv "$TWOPARAM" "$@" || RET=$?
#fi
......
......@@ -19,7 +19,9 @@ uni_rpmbuildsrpm()
fi
local SPECNAME="$1"
local SPECDIR=`dirname $SPECNAME`
local SPECDIR
set_specdir $SPECNAME || fatal "Dir for $SPECNAME does not exists"
local GEAR=gear
local ONEPARAM="--quiet"
......@@ -31,6 +33,8 @@ uni_rpmbuildsrpm()
local THRPARAM="--quiet"
[ -n "$USE_VENDOR" ] && THRPARAM="--define=_vendor $USE_VENDOR"
cd $SPECDIR || fatal
if is_gear $SPECDIR ; then
[ -f "$SPECNAME" ] || fatal "run uni_rpmbuild with spec as 2nd parameter"
shift # skip spec name
......@@ -53,6 +57,8 @@ uni_rpmbuildsrpm()
docmd $NICE $RPMBUILD "$ONEPARAM" "$TWOPARAM" "$THRPARAM" "$@" || RET=$?
fi
cd - >/dev/null
return $RET
}
......@@ -70,9 +76,15 @@ fi
ARGS=$@
[ -n "$VERBOSE" ] && echo "LISTNAMES=$LISTNAMES ARGS=$ARGS" || :
ARGS="$ARGS --nodeps"
# i is a spec or src.rpm
for i in $LISTNAMES
do
# transform dir to spec if it is dir
if [ -d "$i" ] ; then
i=$(get_gear_spec $i)
fi
if [ -z ${i/*rpm/} ] ; then
# if rpm not spec, guess it is src.rpm
#NAMESRPMIN=$(basename $i)
......
......@@ -260,8 +260,20 @@ prepare_rpmdir()
get_root_git_dir()
{
local DIR=$(git rev-parse --git-dir 2>/dev/null)/../ || return
local DIR=
local LOCDIR="$1"
if [ -n "$LOCDIR" ] ; then
cd "$LOCDIR" || fatal "Only dir arg allowed for get_root_git_dir"
fi
DIR=$(git rev-parse --git-dir 2>/dev/null)/../ || DIR=
readlink -f "$DIR" 2>/dev/null || realpath "$DIR"
if [ -n "$LOCDIR" ] ; then
cd - >/dev/null
fi
# FIXME: 1) can return / with good status 2) no one check status later
}
......@@ -272,9 +284,7 @@ get_gear_rules()
local DIR="$1"
[ -z "$IGNOREGEAR" ] || return 1
[ -f "$DIR" ] && DIR=$(dirname "$DIR")
[ -n "$DIR" ] && cd "$DIR"
local GITDIR=$(get_root_git_dir)
[ -n "$DIR" ] && cd - >/dev/null
local GITDIR=$(get_root_git_dir $DIR)
local rules="$GITDIR/.gear/rules"
[ -r "$rules" ] || rules="$GITDIR/.gear-rules"
[ -r "$rules" ] || return
......@@ -420,8 +430,8 @@ LISTARGS=
OPTINDEX=1
for i in "$@"
do
# Если файл существует, то добавляем, иначе считаем аргумент параметром.
if [ -f "$i" ]; then
# Если файл или каталог существует, то добавляем, иначе считаем аргумент параметром.
if [ -e "$i" ]; then
# echo is workaround for missed readlink
LISTNAMES="$LISTNAMES $(readlink -f "$i" 2>/dev/null || realpath "$i" || echo "$i")"
else
......@@ -443,7 +453,7 @@ parse_cmd_pre_spec()
parse_cmd_pre "$@"
else
local SPEC=$(get_gear_spec)
[ -f "$SPEC" ] && info "Using autodetected spec $SPEC..."
[ -f "$SPEC" ] && info "Using autodetected spec $SPEC ..."
# it is possible in some command we need only possibility for spec
# || fatal "Run in dir with spec or in gear repo"
parse_cmd_pre "$SPEC" "$@"
......
......@@ -240,6 +240,12 @@ add_changelog_helper()
# set specdir by spec (run with full path to spec only or in spec dir)
set_specdir()
{
# support for use git dir instead spec
if [ -d "$1" ] ; then
SPECDIR="$1"
return 0
fi
SPECDIR=.
# get dir from the first spec
if [ -r "$1" ] ; then
......@@ -249,24 +255,25 @@ set_specdir()
if [ "$SPECDIR" = "." ] ; then
SPECDIR=`pwd`
fi
[ -d "$SPECDIR" ]
}
# internal func
get_gear_rule_spec()
{
local rules=$(get_gear_rules)
local rules=$(get_gear_rules $@)
[ -r "$rules" ] || return
local SPEC="$(grep "^spec:" $rules 2>/dev/null | sed -e "s/spec:[ ]*//g")"
test -r "$(get_root_git_dir)/$SPEC" && echo $(get_root_git_dir)/$SPEC
test -r "$(get_root_git_dir $@)/$SPEC" && echo $(get_root_git_dir $@)/$SPEC
}
# search for gear spec
get_gear_spec()
{
local trySpec
trySpec=$(get_gear_rule_spec)
trySpec=$(get_gear_rule_spec $@)
# check spec in git root dir (by default)
[ -f "$trySpec" ] || trySpec=`echo $(get_root_git_dir)/*.spec` || return
[ -f "$trySpec" ] || trySpec=`echo $(get_root_git_dir $@)/*.spec` || return
# check locally only if in gear repo
#is_gear && trySpec=$(echo *.spec)
# printout nothing if can't get spec
......@@ -275,6 +282,18 @@ get_gear_spec()
test -f "$trySpec"
}
# transform dir to spec if it is dir
repodirs_to_specs()
{
local i
for i in "$@" ; do
if [ -d "$i" ] ; then
i=$(get_gear_spec "$i") || continue
fi
echo "$i"
done
}
separate_changelog()
{
local SPEC="$1"
......
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