From nobody Mon Apr 29 09:37:41 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 1492525906027820.9191113263837; Tue, 18 Apr 2017 07:31:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EEF25BB9D1; Tue, 18 Apr 2017 14:31:43 +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 87ADEFB1A7; Tue, 18 Apr 2017 14:31:43 +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 F0C5318523C7; Tue, 18 Apr 2017 14:31:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3IEVepC005219 for ; Tue, 18 Apr 2017 10:31:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 389D383283; Tue, 18 Apr 2017 14:31:40 +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 6C6D6832B2 for ; Tue, 18 Apr 2017 14:31:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EEF25BB9D1 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.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 EEF25BB9D1 From: Andrea Bolognani To: libvir-list@redhat.com Date: Tue, 18 Apr 2017 16:31:17 +0200 Message-Id: <1492525878-21819-2-git-send-email-abologna@redhat.com> In-Reply-To: <1492525878-21819-1-git-send-email-abologna@redhat.com> References: <1492525878-21819-1-git-send-email-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/2] autogen.sh: Rewrite 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 18 Apr 2017 14:31:44 +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 be able to make parts of it into reusable modules, 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. In order to be able to move forward with modularization down the line, we extract the gnulib-specific part of the submodule logic into three functions which adhere to a fairly generic API that's not tied to gnulib. Other changes include: removing assumptions about gnulib being the only submodule, both in actual logic and in messages to the user; making dirty submodules checking and cleaning entirely independent of whether or not updating submodules is needed; removing the use of 'set -e' and handling errors explicitly instead. --- I originally intended to proceed with this rewrite through a series of small, incremental changes; however, I soon realized it would take a lot more time and energy, and the result will be in some case quite frankly silly, so I've decided to go with a single commit that includes an extensive explanation of goals and changes. Basically: the diff is useless, just look at the two scripts side by side ;) The shell code is probably not 100% portable to all weird platforms out there (the use of 'local' comes to mind), but it should be portable enough to work on all those we target with libvirt. I've tested it on Fedora 24, CentOS 6 and FreeBSD 11 without running into any issue. autogen.sh | 269 +++++++++++++++++++++++++++++++++++++++++----------------= ---- cfg.mk | 34 ++------ 2 files changed, 189 insertions(+), 114 deletions(-) diff --git a/autogen.sh b/autogen.sh index d1c319d..98baab7 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,117 +1,210 @@ #!/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 r= un. + # It will be ultimately used as return code for the script, so a + # value of 1 means "running autogen.sh is not needed at this time" + dry_run=3D1 + 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. -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) +gnulib_update_required() +{ + local expected=3D$1 + local actual=3D$2 + local no_git=3D$3 + + local ret=3D0 + + # Whenever the gnulib submodule or any of the related bits has been + # changed in some way (see gnulib_hash) we need to update the submodul= e, + # eg. run bootstrap again; updating is also needed if any of the files + # that can only be generated through bootstrap has gone missing + if test "$actual" =3D "$expected" && \ + test -f po/Makevars && test -f AUTHORS; then + ret=3D1 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 + + return "$ret" +} + +gnulib_update() +{ + local expected=3D$1 + local actual=3D$2 + local no_git=3D$3 + + local ret=3D0 + + # Depending on whether or not an update is required, we might be able = to + # get away with simply running autoreconf, or we might have to go thro= ugh + # the bootstrap process + if gnulib_update_required "$expected" "$actual" "$no_git"; then + echo "Running bootstrap..." + ./bootstrap$no_git --bootstrap-sync + ret=3D$? else - if test -z "$no_git" && test ${CLEAN_SUBMODULE+set}; then - echo cleaning up submodules... - git submodule foreach 'git clean -dfqx && git reset --hard' + echo "Running autoreconf..." + autoreconf -if + ret=3D$? + fi + + return "$ret" +} + +if test -d .git || test -f .git; then + + if test -z "$CLEAN_SUBMODULE"; then + git submodule status | while read _ path _; do + dirty=3D$(git diff "$path") + case "$dirty" in + *-dirty*) + echo "error: $path is dirty, please investigate" >&2 + echo "set CLEAN_SUBMODULE to discard submodule changes= " >&2 + exit 1 + ;; + esac + done + fi + 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 + + curr_status=3D.git-module-status + expected=3D$(cat "$curr_status" 2>/dev/null) + actual=3D$(gnulib_hash "$no_git") + + if test "$dry_run"; then + if gnulib_update_required "$expected" "$actual" "$no_git"; then + dry_run=3D0 fi - echo running bootstrap$no_git... - ./bootstrap$no_git --bootstrap-sync && bootstrap_hash > $curr_stat= us \ - || { echo "Failed to bootstrap, please investigate."; exit 1; } + else + gnulib_update "$expected" "$actual" "$no_git" || { + die "submodule update failed" + } + gnulib_hash >"$curr_status" 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 + ./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 wis= h" + 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 4c22195..c40e7b4 100644 --- a/cfg.mk +++ b/cfg.mk @@ -1026,33 +1026,15 @@ 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 $$?) + _autogen_required :=3D $(shell \ + cd '$(srcdir)'; \ + test -d .git || test -f .git || { echo 0; exit; }; \ + $(srcdir)/autogen.sh --dry-run >/dev/null 2>&1 || { echo 0; exit; };= \ + echo 1; \ + ) _clean_requested =3D $(filter %clean,$(MAKECMDGOALS)) - ifeq (1,$(_update_required)$(_clean_requested)) - $(info INFO: gnulib update required; running ./autogen.sh first) + ifeq (1,$(_autogen_required)$(_clean_requested)) + $(info INFO: running autogen.sh is required, running it now...) $(shell touch $(srcdir)/AUTHORS $(srcdir)/ChangeLog) maint.mk Makefile: _autogen endif --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 09:37:41 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 1492525964755235.93509153985633; Tue, 18 Apr 2017 07:32:44 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E6608A4641; Tue, 18 Apr 2017 14:32:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 91BE29A869; Tue, 18 Apr 2017 14:32:42 +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 2A9E1B31B0; Tue, 18 Apr 2017 14:31:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3IEVkMU005238 for ; Tue, 18 Apr 2017 10:31:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id E657983295; Tue, 18 Apr 2017 14:31:45 +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 6E58E8328A for ; Tue, 18 Apr 2017 14:31:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E6608A4641 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.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 E6608A4641 From: Andrea Bolognani To: libvir-list@redhat.com Date: Tue, 18 Apr 2017 16:31:18 +0200 Message-Id: <1492525878-21819-3-git-send-email-abologna@redhat.com> In-Reply-To: <1492525878-21819-1-git-send-email-abologna@redhat.com> References: <1492525878-21819-1-git-send-email-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/2] autogen.sh: Modularize 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 18 Apr 2017 14:32:43 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This sets up a generic framework for dealing with git submodules, removing the assumption that gnulib is going to be the only git submodule libvirt uses and making it relatively easy for more to be added without sacrificing the convenience we've gotten used to, eg. automatic updates. --- .gitignore | 2 +- .submodules/gnulib.functions | 65 ++++++++++++++++++ autogen.sh | 155 ++++++++++++++++++++++-----------------= ---- 3 files changed, 145 insertions(+), 77 deletions(-) create mode 100644 .submodules/gnulib.functions diff --git a/.gitignore b/.gitignore index d7927e1..f1ca602 100644 --- a/.gitignore +++ b/.gitignore @@ -30,11 +30,11 @@ .dirstamp .gdb_history .git -.git-module-status .libs .lvimrc .memdump .sc-start-sc_* +.submodules/*.status /ABOUT-NLS /AUTHORS /ChangeLog diff --git a/.submodules/gnulib.functions b/.submodules/gnulib.functions new file mode 100644 index 0000000..ec89b37 --- /dev/null +++ b/.submodules/gnulib.functions @@ -0,0 +1,65 @@ +gnulib_hash() +{ + local no_git=3D$1 + + if test "$no_git"; then + echo "no-git" + return + fi + + # 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 }' +} + +gnulib_update_required() +{ + local expected=3D$1 + local actual=3D$2 + local no_git=3D$3 + + local ret=3D0 + + # Whenever the gnulib submodule or any of the related bits has been + # changed in some way (see gnulib_hash) we need to update the submodul= e, + # eg. run bootstrap again; updating is also needed if any of the files + # that can only be generated through bootstrap has gone missing + if test "$actual" =3D "$expected" && \ + test -f po/Makevars && test -f AUTHORS; then + ret=3D1 + fi + + return "$ret" +} + +gnulib_update() +{ + local expected=3D$1 + local actual=3D$2 + local no_git=3D$3 + + local ret=3D0 + + # Depending on whether or not an update is required, we might be able = to + # get away with simply running autoreconf, or we might have to go thro= ugh + # the bootstrap process + if gnulib_update_required "$expected" "$actual" "$no_git"; then + echo "Running bootstrap..." + ./bootstrap$no_git --bootstrap-sync + ret=3D$? + else + echo "Running autoreconf..." + autoreconf -if + ret=3D$? + fi + + return "$ret" +} + +# vim: set syntax=3Dsh: diff --git a/autogen.sh b/autogen.sh index 98baab7..38b3476 100755 --- a/autogen.sh +++ b/autogen.sh @@ -7,6 +7,19 @@ die() exit 1 } =20 +git_submodules() +{ + # Print the list of known submodules. Parse the .gitmodules file becau= se + # we want the submodule's alias rather than its path (as we're going to + # use it for building eg. function names) and the 'git submodule' comm= and + # doesn't provide us with that information + grep -E '^\[submodule ' .gitmodules | while read _ name; do + name=3D${name#\"} + name=3D${name%%\"*} + echo "$name" + done +} + starting_point=3D$(pwd) =20 srcdir=3D$(dirname "$0") @@ -68,70 +81,6 @@ while test "$#" -gt 0; do done no_git=3D"$no_git$gnulib_srcdir" =20 -gnulib_hash() -{ - local no_git=3D$1 - - if test "$no_git"; then - echo "no-git" - return - fi - - # 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 }' -} - -gnulib_update_required() -{ - local expected=3D$1 - local actual=3D$2 - local no_git=3D$3 - - local ret=3D0 - - # Whenever the gnulib submodule or any of the related bits has been - # changed in some way (see gnulib_hash) we need to update the submodul= e, - # eg. run bootstrap again; updating is also needed if any of the files - # that can only be generated through bootstrap has gone missing - if test "$actual" =3D "$expected" && \ - test -f po/Makevars && test -f AUTHORS; then - ret=3D1 - fi - - return "$ret" -} - -gnulib_update() -{ - local expected=3D$1 - local actual=3D$2 - local no_git=3D$3 - - local ret=3D0 - - # Depending on whether or not an update is required, we might be able = to - # get away with simply running autoreconf, or we might have to go thro= ugh - # the bootstrap process - if gnulib_update_required "$expected" "$actual" "$no_git"; then - echo "Running bootstrap..." - ./bootstrap$no_git --bootstrap-sync - ret=3D$? - else - echo "Running autoreconf..." - autoreconf -if - ret=3D$? - fi - - return "$ret" -} - if test -d .git || test -f .git; then =20 if test -z "$CLEAN_SUBMODULE"; then @@ -155,20 +104,74 @@ if test -d .git || test -f .git; then fi fi =20 - curr_status=3D.git-module-status - expected=3D$(cat "$curr_status" 2>/dev/null) - actual=3D$(gnulib_hash "$no_git") + for submodule in $(git_submodules); do + functions_file=3D".submodules/$submodule.functions" + status_file=3D".submodules/$submodule.status" + + # No need to check for the file's existence: the script will + # abort if it's not present + . "$functions_file" + + # hash_function(no_git): + # @no_git: whether to avoid using git for updates + # + # This function must print a hash encompassing the entire submodule + # status. The hash will be remembered between runs and will be used + # to determine whether a submodule update is required. + # + # Output: submodule hash + # Return value: ignored + hash_function=3D"${submodule}_hash" + type "$hash_function" >/dev/null 2>&1 || { + die "required function $hash_function missing" + } =20 - if test "$dry_run"; then - if gnulib_update_required "$expected" "$actual" "$no_git"; then - dry_run=3D0 - fi - else - gnulib_update "$expected" "$actual" "$no_git" || { - die "submodule update failed" + # update_required_function(expected, actual, no_git): + # @expected: expected hash (from previous run) + # @actual: actual hash (from current run) + # @no_git: whether to avoid using git for updates + # + # This function is used to determine whether a submodule update is + # required. It must perform no action, regardless of the outcome: + # it's mostly intended for use with --dry-run. + # + # Output: ignored + # Return value: 0 if update is required, 1 otherwise + update_required_function=3D"${submodule}_update_required" + type "$update_required_function" >/dev/null 2>&1 || { + die "required function $update_required_function missing" } - gnulib_hash >"$curr_status" - fi + + # update_function(expected, actual, no_git): + # @expected: expected hash (from previous run) + # @actual: actual hash (from current run) + # @no_git: whether to avoid using git for updates + # + # This function must perform the submodule update; if no update + # is required, it can decide to skip it, but it will be called + # regardless. + # + # Output: ignored + # Return value: 0 if update was successful, 1 otherwise + update_function=3D"${submodule}_update" + type "$update_function" >/dev/null 2>&1 || { + die "required function $update_function missing" + } + + expected=3D$(cat "$status_file" 2>/dev/null) + actual=3D$("$hash_function" "$no_git") + + if test "$dry_run"; then + if "$update_required_function" "$expected" "$actual" "$no_git"= ; then + dry_run=3D0 + fi + else + "$update_function" "$expected" "$actual" "$no_git" || { + die "submodule update failed" + } + "$hash_function" >"$status_file" + fi + done fi =20 # When performing a dry run, we can stop here --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list