From: Paul Eggert Date: Mon, 15 Jul 2024 21:53:10 +0000 (-0700) Subject: Sync bootstrap from Gnulib X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=42d1143dd5557fbd6340bd9647caa2788750ca07;p=thirdparty%2Ftar.git Sync bootstrap from Gnulib --- diff --git a/bootstrap b/bootstrap index f52355b3..d78c8c30 100755 --- a/bootstrap +++ b/bootstrap @@ -3,7 +3,7 @@ # Bootstrap this package from checked-out sources. -scriptversion=2022-12-27.07; # UTC +scriptversion=2024-07-04.10; # UTC # Copyright (C) 2003-2024 Free Software Foundation, Inc. # @@ -37,7 +37,7 @@ medir=`dirname "$me"` # A library of shell functions for autopull.sh, autogen.sh, and bootstrap. -scriptlibversion=2023-06-06.21; # UTC +scriptlibversion=2024-06-29.23; # UTC # Copyright (C) 2003-2024 Free Software Foundation, Inc. # @@ -478,10 +478,9 @@ find_tool () # --------------------- Preparing GNULIB_SRCDIR for use. --------------------- # This is part of autopull.sh, but bootstrap needs it too, for self-upgrading. +# cleanup_gnulib fails, removing the directory $gnulib_path first. cleanup_gnulib() { status=$? - # XXX It's a bad idea to erase the submodule directory if it contains local - # modifications. rm -fr "$gnulib_path" exit $status } @@ -497,55 +496,63 @@ prepare_GNULIB_SRCDIR () # We already checked that $GNULIB_SRCDIR references a directory. # Verify that it contains a gnulib checkout. test -f "$GNULIB_SRCDIR/gnulib-tool" \ - || die "Error: --gnulib-srcdir or \$GNULIB_SRCDIR is specified, but does not contain gnulib-tool" - elif $use_git; then + || die "Error: --gnulib-srcdir or \$GNULIB_SRCDIR is specified," \ + "but does not contain gnulib-tool" + if test -n "$GNULIB_REVISION" && $use_git; then + # The 'git checkout "$GNULIB_REVISION"' command succeeds if the + # GNULIB_REVISION is a commit hash that exists locally, or if it is + # branch name that can be fetched from origin. It fails, however, + # if the GNULIB_REVISION is a commit hash that only exists in + # origin. In this case, we need a 'git fetch' and then retry + # 'git checkout "$GNULIB_REVISION"'. + (cd "$GNULIB_SRCDIR" \ + && { git checkout "$GNULIB_REVISION" 2>/dev/null \ + || { git fetch origin && git checkout "$GNULIB_REVISION"; } + } + ) || exit $? + fi + else + if ! $use_git; then + die "Error: --no-git is specified," \ + "but neither --gnulib-srcdir nor \$GNULIB_SRCDIR is specified" + fi + if git submodule -h | grep -- --reference > /dev/null; then + : + else + die "git version is too old, git >= 1.6.4 is required" + fi gnulib_path=$(git_modules_config submodule.gnulib.path) - test -z "$gnulib_path" && gnulib_path=gnulib - - # Get gnulib files. Populate $gnulib_path, possibly updating a - # submodule, for use in the rest of the script. - - if test -n "$GNULIB_REFDIR" && test -d "$GNULIB_REFDIR"/.git \ - && git_modules_config submodule.gnulib.url >/dev/null; then - # Use GNULIB_REFDIR as a reference. - echo "$0: getting gnulib files..." - if git submodule -h|grep -- --reference > /dev/null; then - # Prefer the one-liner available in git 1.6.4 or newer. - git submodule update --init --reference "$GNULIB_REFDIR" \ - "$gnulib_path" || exit $? + if test -n "$gnulib_path"; then + # A submodule 'gnulib' is configured. + # Get gnulib files. Populate $gnulib_path, updating the submodule. + if test -n "$GNULIB_REFDIR" && test -d "$GNULIB_REFDIR"/.git; then + # Use GNULIB_REFDIR as a reference. + echo "$0: getting gnulib files..." + git submodule update --init --reference "$GNULIB_REFDIR" "$gnulib_path"\ + || exit $? else - # This fallback allows at least git 1.5.5. - if test -f "$gnulib_path"/gnulib-tool; then - # Since file already exists, assume submodule init already complete. + # GNULIB_REFDIR is not set or not usable. Ignore it. + if git_modules_config submodule.gnulib.url >/dev/null; then + echo "$0: getting gnulib files..." + git submodule init -- "$gnulib_path" || exit $? git submodule update -- "$gnulib_path" || exit $? else - # Older git can't clone into an empty directory. - rmdir "$gnulib_path" 2>/dev/null - git clone --reference "$GNULIB_REFDIR" \ - "$(git_modules_config submodule.gnulib.url)" "$gnulib_path" \ - && git submodule init -- "$gnulib_path" \ - && git submodule update -- "$gnulib_path" \ - || exit $? + die "Error: submodule 'gnulib' has no configured url" fi fi else - # GNULIB_REFDIR is not set or not usable. Ignore it. - if git_modules_config submodule.gnulib.url >/dev/null; then - echo "$0: getting gnulib files..." - git submodule init -- "$gnulib_path" || exit $? - git submodule update -- "$gnulib_path" || exit $? - - elif [ ! -d "$gnulib_path" ]; then + gnulib_path='gnulib' + if test ! -d "$gnulib_path"; then + # The subdirectory 'gnulib' does not yet exist. Clone into it. echo "$0: getting gnulib files..." - trap cleanup_gnulib HUP INT PIPE TERM - + gnulib_url=${GNULIB_URL:-$default_gnulib_url} shallow= if test -z "$GNULIB_REVISION"; then if git clone -h 2>&1 | grep -- --depth > /dev/null; then shallow='--depth 2' fi - git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \ + git clone $shallow "$gnulib_url" "$gnulib_path" \ || cleanup_gnulib else if git fetch -h 2>&1 | grep -- --depth > /dev/null; then @@ -558,31 +565,46 @@ prepare_GNULIB_SRCDIR () # be processed, which can drastically reduce download and processing # time for checkout. If the fetch by commit fails, a shallow fetch can # not be performed because we do not know what the depth of the commit - # is without fetching all commits. So fallback to fetching all commits. + # is without fetching all commits. So fall back to fetching all + # commits. git -C "$gnulib_path" init - git -C "$gnulib_path" remote add origin \ - ${GNULIB_URL:-$default_gnulib_url} + git -C "$gnulib_path" remote add origin "$gnulib_url" git -C "$gnulib_path" fetch $shallow origin "$GNULIB_REVISION" \ || git -C "$gnulib_path" fetch origin \ || cleanup_gnulib git -C "$gnulib_path" reset --hard FETCH_HEAD + (cd "$gnulib_path" && git checkout "$GNULIB_REVISION") \ + || cleanup_gnulib fi - trap - HUP INT PIPE TERM + else + # The subdirectory 'gnulib' already exists. + if test -n "$GNULIB_REVISION"; then + if test -d "$gnulib_path/.git"; then + # The 'git checkout "$GNULIB_REVISION"' command succeeds if the + # GNULIB_REVISION is a commit hash that exists locally, or if it is + # branch name that can be fetched from origin. It fails, however, + # if the GNULIB_REVISION is a commit hash that only exists in + # origin. In this case, we need a 'git fetch' and then retry + # 'git checkout "$GNULIB_REVISION"'. + (cd "$gnulib_path" \ + && { git checkout "$GNULIB_REVISION" 2>/dev/null \ + || { git fetch origin && git checkout "$GNULIB_REVISION"; } + } + ) || exit $? + else + die "Error: GNULIB_REVISION is specified in bootstrap.conf," \ + "but '$gnulib_path' contains no git history" + fi + fi fi fi - GNULIB_SRCDIR=$gnulib_path - # Verify that the submodule contains a gnulib checkout. + # Verify that $gnulib_path contains a gnulib checkout. test -f "$gnulib_path/gnulib-tool" \ - || die "Error: $gnulib_path is supposed to contain a gnulib checkout, but does not contain gnulib-tool" - fi - - # XXX Should this be done if $use_git is false? - if test -d "$GNULIB_SRCDIR"/.git && test -n "$GNULIB_REVISION" \ - && ! git_modules_config submodule.gnulib.url >/dev/null; then - (cd "$GNULIB_SRCDIR" && git checkout "$GNULIB_REVISION") || cleanup_gnulib + || die "Error: '$gnulib_path' is supposed to contain a gnulib checkout," \ + "but does not contain gnulib-tool" + GNULIB_SRCDIR=$gnulib_path fi - # $GNULIB_SRCDIR now points to the version of gnulib to use, and # we no longer need to use git or $gnulib_path below here. } @@ -594,7 +616,8 @@ upgrade_bootstrap () if test -f "$medir"/bootstrap-funclib.sh; then update_lib=true { cmp -s "$medir"/bootstrap "$GNULIB_SRCDIR/top/bootstrap" \ - && cmp -s "$medir"/bootstrap-funclib.sh "$GNULIB_SRCDIR/top/bootstrap-funclib.sh" \ + && cmp -s "$medir"/bootstrap-funclib.sh \ + "$GNULIB_SRCDIR/top/bootstrap-funclib.sh" \ && cmp -s "$medir"/autopull.sh "$GNULIB_SRCDIR/top/autopull.sh" \ && cmp -s "$medir"/autogen.sh "$GNULIB_SRCDIR/top/autogen.sh"; \ } @@ -611,10 +634,18 @@ upgrade_bootstrap () a) ignored=--;; *) ignored=ignored;; esac + u=$update_lib exec sh -c \ - '{ if '$update_lib' && test -f "$1"; then cp "$1" "$3"; else cp "$2" "$3"; fi; } && { if '$update_lib' && test -f "$4"; then cp "$4" "$5"; else rm -f "$5"; fi; } && { if '$update_lib' && test -f "$6"; then cp "$6" "$7"; else rm -f "$7"; fi; } && { if '$update_lib' && test -f "$8"; then cp "$8" "$9"; else rm -f "$9"; fi; } && shift && shift && shift && shift && shift && shift && shift && shift && shift && exec "${CONFIG_SHELL-/bin/sh}" "$@"' \ + '{ if '$u' && test -f "$1"; then cp "$1" "$3"; else cp "$2" "$3"; fi; } && + { if '$u' && test -f "$4"; then cp "$4" "$5"; else rm -f "$5"; fi; } && + { if '$u' && test -f "$6"; then cp "$6" "$7"; else rm -f "$7"; fi; } && + { if '$u' && test -f "$8"; then cp "$8" "$9"; else rm -f "$9"; fi; } && + shift && shift && shift && shift && shift && + shift && shift && shift && shift && + exec "${CONFIG_SHELL-/bin/sh}" "$@"' \ $ignored \ - "$GNULIB_SRCDIR/top/bootstrap" "$GNULIB_SRCDIR/build-aux/bootstrap" "$medir/bootstrap" \ + "$GNULIB_SRCDIR/top/bootstrap" "$GNULIB_SRCDIR/build-aux/bootstrap" \ + "$medir/bootstrap" \ "$GNULIB_SRCDIR/top/bootstrap-funclib.sh" "$medir/bootstrap-funclib.sh" \ "$GNULIB_SRCDIR/top/autopull.sh" "$medir/autopull.sh" \ "$GNULIB_SRCDIR/top/autogen.sh" "$medir/autogen.sh" \ @@ -635,7 +666,8 @@ fi autopull_usage() { cat <