X-Git-Url: https://git.pld-linux.org/?a=blobdiff_plain;f=builder.sh;h=adfb34490dcfe30da8392fa7f506200a8229c8e1;hb=a9ded6014cf511533ed14864bb2969d77fdf3b23;hp=846e4e761dd0fbb2ea9f48883199ea681388d008;hpb=e0ddd96de2c3dacc1d5f1bcc731127f2459279c5;p=packages%2Frpm-build-tools.git diff --git a/builder.sh b/builder.sh index 846e4e7..adfb344 100755 --- a/builder.sh +++ b/builder.sh @@ -39,7 +39,7 @@ RCSID='$Id: builder,v 1.645 2011/02/13 17:54:10 glen Exp $' r=${RCSID#* * } rev= VERSION="v0.35/$rev" VERSIONSTRING="\ Build package utility from PLD Linux Packages repository -$VERSION (C) 1999-2012 Free Penguins". +$VERSION (C) 1999-2014 Free Penguins". CLEAN_PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin" @@ -77,11 +77,12 @@ DATE=`date +%Y-%m-%d_%H-%M-%S` # target arch, can also be used for log file naming TARGET=$(rpm -E %{_target}) +# Note the *single* quotes, this allows using shell variables expanded at build time # Example: LOGFILE='../log.$PACKAGE_NAME' # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE' # Example: LOGFILE='$PACKAGE_NAME/$PACKAGE_NAME.$DATE.log' # Example: LOGFILE='$PACKAGE_NAME.$DATE.log' -# Yes, you can use variable name! Note _single_ quotes! +# Example: LOGFILE='.log.$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE.$TARGET.$DATE' LOGFILE='' # use teeboth Perl wrapper @@ -468,13 +469,13 @@ insert_gitlog() { # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997' # otherwise i'd use --date=iso here # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1 - # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c#l31 + # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33 # NOTE: changelog date is always in UTC for rpmbuild # * 1265749244 +0000 Random Hacker 9370900 git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do local logfmt='%B%n' - git notes list $sha1 > /dev/null 2>&1 && logfmt=%N - git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n${logfmt}%n" --date=raw | sed '/^$/q' + git notes list $sha1 > /dev/null 2>&1 && logfmt='%N' + git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q' done > $gitlog # add link to full git logs @@ -581,10 +582,7 @@ set_spec_target() { # runs rpm with minimal macroset minirpm() { - # we reset macros not to contain macros.build as all the %() macros are - # executed here, while none of them are actually needed. - # at the time of this writing macros.build + macros contained 70 "%(...)" macros. - safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); gsub(/:.*macros.build:/, ":", $0); print $0 } ') + safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); print $0 } ') # TODO: move these to /usr/lib/rpm/macros cat > $BUILDER_MACROS <<'EOF' @@ -605,6 +603,7 @@ minirpm() { %releq_kernel_up(n:) ERROR %releq_kernel_smp(n:) ERROR %releq_kernel(n:) ERROR +%py_postclean(x:) ERROR %kgcc_package ERROR %_fontsdir ERROR %ruby_version ERROR @@ -850,8 +849,10 @@ init_builder() { PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME fi else - REPO_DIR="." - PACKAGE_DIR="." + TOP_DIR=$(pwd) + PACKAGE_DIR=$TOP_DIR + REPO_DIR=$PACKAGE_DIR + RPMBUILDOPTS="$RPMBUILDOPTS --define '_topdir $TOP_DIR' --define '_builddir %_topdir' --define '_rpmdir %_topdir' --define '_srcrpmdir %_topdir'" fi export GIT_WORK_TREE=$PACKAGE_DIR export GIT_DIR=$PACKAGE_DIR/.git @@ -1052,7 +1053,7 @@ src_md5() { # use "sources" file from package dir, like vim if [ -f sources ]; then md5=$(grep -s -v '^#' sources | \ - grep -E "[ ]$(basename "$1")([ ,]|\$)" | \ + grep -E "[ *]$(basename "$1")([ ,]|\$)" | \ sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \ grep -E '^[0-9a-f]{32}$') @@ -1510,50 +1511,61 @@ set_version() { " $specfile } +# try to upgrade .spec to new version +# if --upgrade-version is specified, use that as new version, otherwise invoke pldnotify to find new version +# +# return 1: if .spec was updated +# return 0: no changes to .spec +# exit 1 in case of error try_upgrade() { - if [ -n "$TRY_UPGRADE" ]; then - local TNOTIFY TNEWVER TOLDVER - update_shell_title "build_package: try_upgrade" + if [ -z "$TRY_UPGRADE" ]; then + return 0 + fi - cd "$PACKAGE_DIR" - - if [ "$UPGRADE_VERSION" ]; then - TNEWVER=$UPGRADE_VERSION - else - if [ -n "$FLOAT_VERSION" ]; then - TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1 - else - TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1 - fi + local TNOTIFY TNEWVER TOLDVER + update_shell_title "build_package: try_upgrade" - # pldnotify.awk does not set exit codes, but it has match for ERROR - # in output which means so. - if [[ "$TNOTIFY" = *ERROR* ]]; then - echo >&2 "$TNOTIFY" - exit 1 - fi + cd "$PACKAGE_DIR" - TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }') + if [ "$UPGRADE_VERSION" ]; then + TNEWVER=$UPGRADE_VERSION + echo "Updating spec file to version $TNEWVER" + else + if [ -n "$FLOAT_VERSION" ]; then + TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1 + else + TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1 fi - if [ -n "$TNEWVER" ]; then - TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'` - echo "New version found, updating spec file from $TOLDVER to version $TNEWVER" - if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then - cp -f $SPECFILE $SPECFILE.bak - fi - chmod +w $SPECFILE - set_release $SPECFILE $PACKAGE_RELEASE 1 - set_version $SPECFILE $PACKAGE_VERSION $TNEWVER - parse_spec - if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then - echo >&2 "Upgrading version failed, you need to update spec yourself" - exit 1 - fi - return 1 + # pldnotify.awk does not set exit codes, but it has match for ERROR + # in output which means so. + if [[ "$TNOTIFY" = *ERROR* ]]; then + echo >&2 "$TNOTIFY" + exit 1 fi + + TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'` + echo "New version found, updating spec file from $TOLDVER to version $TNEWVER" + + TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }') + fi + + if [ -z "$TNEWVER" ]; then + return 0 + fi + + if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then + cp -f $SPECFILE $SPECFILE.bak + fi + chmod +w $SPECFILE + set_version $SPECFILE $PACKAGE_VERSION $TNEWVER + set_release $SPECFILE $PACKAGE_RELEASE 1 + parse_spec + if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then + echo >&2 "Upgrading version failed, you need to update spec yourself" + exit 1 fi - return 0 + return 1 } build_package() { @@ -1599,7 +1611,7 @@ build_package() { local specdir=$(insert_gitlog $SPECFILE) # FIXME: eval here is exactly why? - PATH=$CLEAN_PATH eval teeboth "'$logfile'" ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $specdir/$SPECFILE + PATH=$CLEAN_PATH eval teeboth "'$logfile'" ${TIME_COMMAND} ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $specdir/$SPECFILE retval=$? rm -r $specdir @@ -1752,13 +1764,13 @@ run_sub_builder() { package_name="${1}" update_shell_title "run_sub_builder $package_name" # - # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego - # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do + # No i tutaj bym chciał zrobić sztuczną inteligencję, która spróbuje tego + # pakieta zbudować. Aktualnie niewiele dziala, bo generalnie nie widze do # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo # jakby nie bylo tego kawalka kodu. # - # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy. - # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach. + # Update: Poprawiłem parę rzeczy i zaczęło generować pakiety spoza zadanej listy. + # Jednym słowem budowanie niespoldkowanych zależności działa w paru przypadkach. # # # y0shi. @@ -2080,23 +2092,36 @@ fetch_build_requires() fi } +init_repository() { + local remoterepo=$1 + local localrepo=$2 + + if [ ! -e $localrepo ]; then + git clone -o $REMOTE_PLD ${GIT_SERVER}/$remoterepo $localrepo + git --git-dir=$localrepo/.git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/$remoterepo + fi +} + init_rpm_dir() { local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}') local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}') local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}') local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}') + local TEMPLATES=template-specs local tmp echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER" mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir cd "$TOP_DIR" - if [ ! -e ../rpm-build-tools ]; then - git clone ${GIT_SERVER}/${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools - fi - for a in adapter builder fetchsrc_request; do + init_repository ${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools + init_repository projects/$TEMPLATES ../$TEMPLATES + for a in adapter builder fetchsrc_request compile repackage; do ln -sf ../rpm-build-tools/${a}.sh $a done + for a in md5; do + ln -sf ../rpm-build-tools/${a} $a + done ln -sf ../rpm-build-tools/mirrors mirrors init_builder } @@ -2107,7 +2132,7 @@ mr_proper() { DONT_PRINT_REVISION="yes" # remove spec and sources - PATH=$CLEAN_PATH $RPMBUILD --clean --rmsource --rmspec --nodeps --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" --define "_builddir $builddir" $PACKAGE_DIR/$SPECFILE + PATH=$CLEAN_PATH $RPMBUILD --clean --rmsource --rmspec --nodeps --define "__urlgetfile() %nil" --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" --define "_builddir $builddir" $PACKAGE_DIR/$SPECFILE rm -rf $PACKAGE_DIR/{.git,.gitignore} rmdir --ignore-fail-on-non-empty $PACKAGE_DIR } @@ -2450,6 +2475,9 @@ else NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}" fi +# see time(1) for output format that could be used +TIME_COMMAND="time -p" + update_shell_title "$COMMAND" case "$COMMAND" in "show_bconds") @@ -2564,7 +2592,7 @@ case "$COMMAND" in case $? in 0) get_files $SOURCES $PATCHES - check_md5 $SOURCES + check_md5 $SOURCES $PATCHES ;; *) NODIST="yes" get_files $SOURCES $PATCHES