]> Savannah Git Hosting - gnulib.git/commitdiff
bootstrap: Implement phase 1 as documented in the --help output.
authorBruno Haible <bruno@clisp.org>
Sat, 13 Apr 2024 23:38:42 +0000 (01:38 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 14 Apr 2024 00:00:15 +0000 (02:00 +0200)
Reported by Simon Josefsson as bug #1 in
<https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00152.html>.

* top/bootstrap: Correct indentation.
* top/bootstrap-funclib.sh (prepare_GNULIB_SRCDIR): Implement as
documented:
If GNULIB_SRCDIR and GNULIB_REVISION are set and there is a 'gnulib'
submodule, checkout the revision GNULIB_REVISION.
If GNULIB_SRCDIR and GNULIB_REVISION are set and --no-git is specified,
don't checkout the revision GNULIB_REVISION.

ChangeLog
build-aux/bootstrap
top/bootstrap
top/bootstrap-funclib.sh

index a6878807bab8bba26fe0bba2106902035cc27e75..f57cb59b812331b1d1ad89e5b886ad69d97aad8b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-04-13  Bruno Haible  <bruno@clisp.org>
+
+       bootstrap: Implement phase 1 as documented in the --help output.
+       Reported by Simon Josefsson as bug #1 in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00152.html>.
+       * top/bootstrap: Correct indentation.
+       * top/bootstrap-funclib.sh (prepare_GNULIB_SRCDIR): Implement as
+       documented:
+       If GNULIB_SRCDIR and GNULIB_REVISION are set and there is a 'gnulib'
+       submodule, checkout the revision GNULIB_REVISION.
+       If GNULIB_SRCDIR and GNULIB_REVISION are set and --no-git is specified,
+       don't checkout the revision GNULIB_REVISION.
+
 2024-04-13  Bruno Haible  <bruno@clisp.org>
 
        bootstrap: Simplify git submodule initialization.
index 70e567b2ad33867d1424b32861f4397d0cd8871f..20913180a640e388153a994408bc249b59baae7c 100755 (executable)
@@ -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
 }
@@ -499,37 +498,44 @@ prepare_GNULIB_SRCDIR ()
     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
+    if test -n "$GNULIB_REVISION" && $use_git; then
+      (cd "$GNULIB_SRCDIR" && 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..."
-      git submodule update --init --reference "$GNULIB_REFDIR" \
-        "$gnulib_path" || exit $?
-    else
-      # GNULIB_REFDIR is not set or not usable. Ignore it.
-      if git_modules_config submodule.gnulib.url >/dev/null; then
+    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 init -- "$gnulib_path" || exit $?
-        git submodule update -- "$gnulib_path" || exit $?
-
-      elif [ ! -d "$gnulib_path" ]; then
+        git submodule update --init --reference "$GNULIB_REFDIR" "$gnulib_path" \
+          || exit $?
+      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 $?
+        else
+          die "Error: submodule 'gnulib' has no configured url"
+        fi
+      fi
+    else
+      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
-
         shallow=
         if test -z "$GNULIB_REVISION"; then
           if git clone -h 2>&1 | grep -- --depth > /dev/null; then
@@ -551,30 +557,32 @@ prepare_GNULIB_SRCDIR ()
           # 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:-$default_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
+            (cd "$gnulib_path" && git checkout "$GNULIB_REVISION") || exit 1
+          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," \
+      || die "Error: '$gnulib_path' is supposed to contain a gnulib checkout," \
              "but does not contain gnulib-tool"
+    GNULIB_SRCDIR=$gnulib_path
   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
-  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.
 }
@@ -1523,10 +1531,10 @@ if $pull && { $use_git || test -z "$SKIP_PO"; }; then
 fi
 
 if $gen; then
- autogen \
-    `if $copy; then echo ' --copy'; fi` \
-    `if test -z "$checkout_only_file"; then echo ' --force'; fi` \
-  || die "could not generate auxiliary files"
 autogen \
+      `if $copy; then echo ' --copy'; fi` \
+      `if test -z "$checkout_only_file"; then echo ' --force'; fi` \
+    || die "could not generate auxiliary files"
 fi
 
 # ----------------------------------------------------------------------------
index b640bae83d2788ceb8d10796647e45b2e268daf9..4beae0e912625fa618d1fb4a785c3719d5e058be 100755 (executable)
@@ -228,10 +228,10 @@ if $pull && { $use_git || test -z "$SKIP_PO"; }; then
 fi
 
 if $gen; then
- autogen \
-    `if $copy; then echo ' --copy'; fi` \
-    `if test -z "$checkout_only_file"; then echo ' --force'; fi` \
-  || die "could not generate auxiliary files"
 autogen \
+      `if $copy; then echo ' --copy'; fi` \
+      `if test -z "$checkout_only_file"; then echo ' --force'; fi` \
+    || die "could not generate auxiliary files"
 fi
 
 # ----------------------------------------------------------------------------
index e0d3ab900df468e35de0fcc195eacf660ffd4d22..7511d62d9b853f8b6ef155510ab99e37fbae960d 100644 (file)
@@ -441,10 +441,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
 }
@@ -462,37 +461,44 @@ prepare_GNULIB_SRCDIR ()
     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
+    if test -n "$GNULIB_REVISION" && $use_git; then
+      (cd "$GNULIB_SRCDIR" && 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..."
-      git submodule update --init --reference "$GNULIB_REFDIR" \
-        "$gnulib_path" || exit $?
-    else
-      # GNULIB_REFDIR is not set or not usable. Ignore it.
-      if git_modules_config submodule.gnulib.url >/dev/null; then
+    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 init -- "$gnulib_path" || exit $?
-        git submodule update -- "$gnulib_path" || exit $?
-
-      elif [ ! -d "$gnulib_path" ]; then
+        git submodule update --init --reference "$GNULIB_REFDIR" "$gnulib_path" \
+          || exit $?
+      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 $?
+        else
+          die "Error: submodule 'gnulib' has no configured url"
+        fi
+      fi
+    else
+      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
-
         shallow=
         if test -z "$GNULIB_REVISION"; then
           if git clone -h 2>&1 | grep -- --depth > /dev/null; then
@@ -514,30 +520,32 @@ prepare_GNULIB_SRCDIR ()
           # 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:-$default_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
+            (cd "$gnulib_path" && git checkout "$GNULIB_REVISION") || exit 1
+          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," \
+      || die "Error: '$gnulib_path' is supposed to contain a gnulib checkout," \
              "but does not contain gnulib-tool"
+    GNULIB_SRCDIR=$gnulib_path
   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
-  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.
 }