From nobody Tue Apr 30 08:54:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1492710894760749.9359604391042; Thu, 20 Apr 2017 10:54:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8759475EC5; Thu, 20 Apr 2017 17:54:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C05737DE25; Thu, 20 Apr 2017 17:54:50 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0A45618523CC; Thu, 20 Apr 2017 17:54:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3KHskDM031993 for ; Thu, 20 Apr 2017 13:54:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8AAC217ADC; Thu, 20 Apr 2017 17:54:46 +0000 (UTC) Received: from inaba.usersys.redhat.com (dhcp129-166.brq.redhat.com [10.34.129.166]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE48417AF5 for ; Thu, 20 Apr 2017 17:54:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8759475EC5 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8759475EC5 From: Andrea Bolognani To: libvir-list@redhat.com Date: Thu, 20 Apr 2017 19:54:39 +0200 Message-Id: <1492710879-27184-1-git-send-email-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2] autogen.sh: Improve and generalize X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 20 Apr 2017 17:54:53 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The goal is twofold: firstly, we want to extend the script so that it can deal with more than a single git submodule, and secondly we'd like to reduce the amount of duplicated code. Moreover, since we're making heavy changes to the code anyway, we might as well make sure it follows a somewhat consistent coding style too. To reduce code duplication, we introduce a new --dry-run option, which can be used by third parties to figure out whether calling autogen.sh is necessary or not: this allows us to get rid of the reimplementation of part of the logic in cfg.mk and guarantee they'll never get out of sync. Other changes include: making dirty submodules checking and cleaning entirely independent of other operations; removing the use of 'set -e' and handling errors explicitly instead; better parsing of command line arguments. --- Changes from [v1]: * drop the generic submodule update framework and simply update all submodules unconditionally, *then* perform any required gnulib-specific step; * handle "autogen not required" and "dry run error" differently in cfg.mk; * improve comments. [v1] https://www.redhat.com/archives/libvir-list/2017-April/msg00816.html autogen.sh | 253 ++++++++++++++++++++++++++++++++++++++++-----------------= ---- cfg.mk | 53 ++++++------- 2 files changed, 193 insertions(+), 113 deletions(-) diff --git a/autogen.sh b/autogen.sh index d1c319d..d5d836a 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,117 +1,196 @@ #!/bin/sh # Run this to generate all the initial makefiles, etc. =20 -set -e +die() +{ + echo "error: $1" >&2 + exit 1 +} =20 -srcdir=3D`dirname "$0"` -test -z "$srcdir" && srcdir=3D. +starting_point=3D$(pwd) =20 -THEDIR=3D`pwd` -cd "$srcdir" +srcdir=3D$(dirname "$0") +test "$srcdir" || srcdir=3D. =20 -test -f src/libvirt.c || { - echo "You must run this script in the top-level libvirt directory" - exit 1 +cd "$srcdir" || { + die "Failed to cd into $srcdir" } =20 +test -f src/libvirt.c || { + die "$0 must live in the top-level libvirt directory" +} =20 -EXTRA_ARGS=3D +dry_run=3D no_git=3D -if test "x$1" =3D "x--no-git"; then - no_git=3D" $1" - shift - case "$1 $2" in - --gnulib-srcdir=3D*) no_git=3D"$no_git $1"; shift ;; - --gnulib-srcdir\ *) no_git=3D"$no_git $1=3D$2"; shift; shift;; - esac -fi -if test -z "$NOCONFIGURE" ; then - if test "x$1" =3D "x--system"; then - shift - prefix=3D/usr - libdir=3D$prefix/lib - sysconfdir=3D/etc - localstatedir=3D/var - if [ -d /usr/lib64 ]; then - libdir=3D$prefix/lib64 - fi - EXTRA_ARGS=3D"--prefix=3D$prefix --sysconfdir=3D$sysconfdir --localsta= tedir=3D$localstatedir --libdir=3D$libdir" - echo "Running ./configure with $EXTRA_ARGS $@" - else - if test -z "$*" && test ! -f "$THEDIR/config.status"; then - echo "I am going to run ./configure with no arguments - if you wis= h" - echo "to pass any to it, please specify them on the $0 command lin= e." - fi - fi -fi +gnulib_srcdir=3D +extra_args=3D +while test "$#" -gt 0; do + case "$1" in + --dry-run) + # This variable will serve both as an indicator of the fact that + # a dry run has been requested, and to store the result of the + # dry run. It will be ultimately used as return code for the + # script: 0 means no action is necessary, 2 means that autogen.sh + # needs to be executed, and 1 is reserved for failures + dry_run=3D0 + shift + ;; + --no-git) + no_git=3D" $1" + shift + ;; + --gnulib-srcdir=3D*) + gnulib_srcdir=3D" $1" + shift + ;; + --gnulib-srcdir) + gnulib_srcdir=3D" $1=3D$2" + shift + shift + ;; + --system) + prefix=3D/usr + sysconfdir=3D/etc + localstatedir=3D/var + if test -d $prefix/lib64; then + libdir=3D$prefix/lib64 + else + libdir=3D$prefix/lib + fi + extra_args=3D"--prefix=3D$prefix --localstatedir=3D$localstatedir" + extra_args=3D"$extra_args --sysconfdir=3D$sysconfdir --libdir=3D$l= ibdir" + shift + ;; + *) + # All remaining arguments will be passed to configure verbatim + break + ;; + esac +done +no_git=3D"$no_git$gnulib_srcdir" =20 -# Compute the hash we'll use to determine whether rerunning bootstrap -# is required. The first is just the SHA1 that selects a gnulib snapshot. -# The second ensures that whenever we change the set of gnulib modules used -# by this package, we rerun bootstrap to pull in the matching set of files. -# The third ensures that whenever we change the set of local gnulib diffs, -# we rerun bootstrap to pull in those diffs. -bootstrap_hash() +gnulib_hash() { + local no_git=3D$1 + if test "$no_git"; then - echo no-git + echo "no-git" return fi - git submodule status | sed 's/^[ +-]//;s/ .*//' + + # Compute the hash we'll use to determine whether rerunning bootstrap + # is required. The first is just the SHA1 that selects a gnulib snapsh= ot. + # The second ensures that whenever we change the set of gnulib modules= used + # by this package, we rerun bootstrap to pull in the matching set of f= iles. + # The third ensures that whenever we change the set of local gnulib di= ffs, + # we rerun bootstrap to pull in those diffs. + git submodule status .gnulib | awk '{ print $1 }' git hash-object bootstrap.conf - git ls-tree -d HEAD gnulib/local | awk '{print $3}' + git ls-tree -d HEAD gnulib/local | awk '{ print $3 }' } =20 -# Ensure that whenever we pull in a gnulib update or otherwise change to a -# different version (i.e., when switching branches), we also rerun ./boots= trap. -# Also, running 'make rpm' tends to litter the po/ directory, and some peo= ple -# like to run 'git clean -x -f po' to fix it; but only ./bootstrap regener= ates -# the required file po/Makevars. -# Only run bootstrap from a git checkout, never from a tarball. +# Only look into git submodules if we're in a git checkout if test -d .git || test -f .git; then - curr_status=3D.git-module-status t=3D - if test "$no_git"; then - t=3Dno-git - elif test -d .gnulib; then - t=3D$(bootstrap_hash; git diff .gnulib) + + # Check for dirty submodules + if test -z "$CLEAN_SUBMODULE"; then + for path in $(git submodule status | awk '{ print $2 }'); do + case "$(git diff "$path")" in + *-dirty*) + echo "error: $path is dirty, please investigate" >&2 + echo "set CLEAN_SUBMODULE to discard submodule changes= " >&2 + exit 1 + ;; + esac + done fi - case $t:${CLEAN_SUBMODULE+set} in - *:set) ;; - *-dirty*) - echo "error: gnulib submodule is dirty, please investigate" 2>= &1 - echo "set env-var CLEAN_SUBMODULE to discard gnulib changes" 2= >&1 - exit 1 ;; - esac - # Keep this test in sync with cfg.mk:_update_required - if test "$t" =3D "$(cat $curr_status 2>/dev/null)" \ - && test -f "po/Makevars" && test -f AUTHORS; then - # good, it's up to date, all we need is autoreconf - autoreconf -if + if test "$CLEAN_SUBMODULE" && test -z "$no_git"; then + if test -z "$dry_run"; then + echo "Cleaning up submodules..." + git submodule foreach 'git clean -dfqx && git reset --hard' ||= { + die "Cleaning up submodules failed" + } + fi + fi + + # Update all submodules. If any of the submodules has not been + # initialized yet, it will be initialized now; moreover, any submodule + # with uncommitted changes will be returned to the expected state + echo "Updating submodules..." + git submodule update --init || { + die "Updating submodules failed" + } + + # The expected hash, eg. the one computed after the last + # successful bootstrap run, is stored on disk + state_file=3D.git-module-status + expected_hash=3D$(cat "$state_file" 2>/dev/null) + actual_hash=3D$(gnulib_hash "$no_git") + + if test "$actual_hash" =3D "$expected_hash" && \ + test -f po/Makevars && test -f AUTHORS; then + # The gnulib hash matches our expectations, and all the files + # that can only be generated through bootstrap are present: + # we just need to run autoreconf. Unless we're performing a + # dry run, of course... + if test -z "$dry_run"; then + echo "Running autoreconf..." + autoreconf -if || { + die "autoreconf failed" + } + fi else - if test -z "$no_git" && test ${CLEAN_SUBMODULE+set}; then - echo cleaning up submodules... - git submodule foreach 'git clean -dfqx && git reset --hard' + # Whenever the gnulib submodule or any of the related bits + # has been changed in some way (see gnulib_hash) we need to + # run bootstrap again. If we're performing a dry run, we + # change the return code instead to signal our caller + if test "$dry_run"; then + dry_run=3D2 + else + echo "Running bootstrap..." + ./bootstrap$no_git --bootstrap-sync || { + die "bootstrap failed" + } + gnulib_hash >"$state_file" fi - echo running bootstrap$no_git... - ./bootstrap$no_git --bootstrap-sync && bootstrap_hash > $curr_stat= us \ - || { echo "Failed to bootstrap, please investigate."; exit 1; } fi fi =20 -test -n "$NOCONFIGURE" && exit 0 +# When performing a dry run, we can stop here +test "$dry_run" && exit "$dry_run" =20 -cd "$THEDIR" +# If asked not to run configure, we can stop here +test "$NOCONFIGURE" && exit 0 =20 -if test "x$OBJ_DIR" !=3D x; then - mkdir -p "$OBJ_DIR" - cd "$OBJ_DIR" +cd "$starting_point" || { + die "Failed to cd into $starting_point" +} + +if test "$OBJ_DIR"; then + mkdir -p "$OBJ_DIR" || { + die "Failed to create $OBJ_DIR" + } + cd "$OBJ_DIR" || { + die "Failed to cd into $OBJ_DIR" + } fi =20 -if test -z "$*" && test -z "$EXTRA_ARGS" && test -f config.status; then - ./config.status --recheck +if test -z "$*" && test -z "$extra_args" && test -f config.status; then + echo "Running config.status..." + ./config.status --recheck || { + die "config.status failed" + } else - $srcdir/configure $EXTRA_ARGS "$@" -fi && { - echo - echo "Now type 'make' to compile libvirt." -} + if test -z "$*" && test -z "$extra_args"; then + echo "I am going to run configure with no arguments - if you wish" + echo "to pass any to it, please specify them on the $0 command lin= e." + else + echo "Running configure with $extra_args $@" + fi + "$srcdir/configure" $extra_args "$@" || { + die "configure failed" + } +fi + +echo +echo "Now type 'make' to compile libvirt." diff --git a/cfg.mk b/cfg.mk index 09548fe..c04a991 100644 --- a/cfg.mk +++ b/cfg.mk @@ -1026,33 +1026,30 @@ prev_version_file =3D /dev/null =20 ifneq ($(_gl-Makefile),) ifeq (0,$(MAKELEVEL)) - _curr_status =3D .git-module-status - # The sed filter accommodates those who check out on a commit from which - # no tag is reachable. In that case, git submodule status prints a "-" - # in column 1 and does not print a "git describe"-style string after the - # submodule name. Contrast these: - # -b653eda3ac4864de205419d9f41eec267cb89eeb .gnulib - # b653eda3ac4864de205419d9f41eec267cb89eeb .gnulib (v0.0-2286-gb653eda) - # $ cat .git-module-status - # b653eda3ac4864de205419d9f41eec267cb89eeb - # - # Keep this logic in sync with autogen.sh. - _submodule_hash =3D $(SED) 's/^[ +-]//;s/ .*//' - _update_required :=3D $(shell \ - cd '$(srcdir)'; \ - test -d .git || { echo 0; exit; }; \ - test -f po/Makevars || { echo 1; exit; }; \ - test -f AUTHORS || { echo 1; exit; }; \ - test "no-git" =3D "$$(cat $(_curr_status))" && { echo 0; exit; }; \ - actual=3D$$(git submodule status | $(_submodule_hash); \ - git hash-object bootstrap.conf; \ - git ls-tree -d HEAD gnulib/local | awk '{print $$3}'; \ - git diff .gnulib); \ - stamp=3D"$$($(_submodule_hash) $(_curr_status) 2>/dev/null)"; \ - test "$$stamp" =3D "$$actual"; echo $$?) + _dry_run_result :=3D $(shell \ + cd '$(srcdir)'; \ + test -d .git || test -f .git || { echo 0; exit; }; \ + $(srcdir)/autogen.sh --dry-run >/dev/null 2>&1; \ + echo $$?; \ + ) _clean_requested =3D $(filter %clean,$(MAKECMDGOALS)) - ifeq (1,$(_update_required)$(_clean_requested)) - $(info INFO: gnulib update required; running ./autogen.sh first) + + # A return value of 0 means no action is required + + # A return value of 1 means a genuine error has occurred while + # performing the dry run, and it should be reported so it can + # be investigated + ifeq (1,$(_dry_run_result)) + $(info INFO: autogen.sh error, running again to show details) +maint.mk Makefile: _autogen_error + endif + + # A return value of 2 means that autogen.sh needs to be executed + # in earnest before building, probably because of gnulib updates. + # We don't run autogen.sh if the clean target has been invoked, + # though, as it would be quite pointless + ifeq (2,$(_dry_run_result)$(_clean_requested)) + $(info INFO: running autogen.sh is required, running it now...) $(shell touch $(srcdir)/AUTHORS $(srcdir)/ChangeLog) maint.mk Makefile: _autogen endif @@ -1066,6 +1063,10 @@ _autogen: $(srcdir)/autogen.sh ./config.status =20 +.PHONY: _autogen_error +_autogen_error: + $(srcdir)/autogen.sh --dry-run + # regenerate HACKING as part of the syntax-check ifneq ($(_gl-Makefile),) syntax-check: $(top_srcdir)/HACKING spacing-check test-wrap-argv \ --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list