Support rpmautospec / %autochangelog
[goals.git] / stdlib / fedora.gl
index 2bcaec1..5dca4d9 100644 (file)
@@ -26,7 +26,7 @@
 # of dist git.  You must use the fedpkg clone -B command to
 # create separate branches.
 #
-# %fedora-branch:   Working branch, eg. "master".
+# %fedora-branch:   Working branch, eg. "rawhide".
 # %fedora-tag:      Build tag, eg. "f32-build".
 #
 # %fedora-rebuild-name:
@@ -103,7 +103,7 @@ is-koji-built ("%pkg") :
     # before we can start the new build.
     for p in %<; do
         nvr=$(koji --quiet latest-build %fedora-tag $p | awk '{print $1}')
-        koji wait-repo %fedora-tag --build=$nvr
+        while ! koji wait-repo --timeout=10000 %fedora-tag --build=$nvr; do sleep 1m; done
     done
 
     # Make sure the local directory is up to date.
@@ -111,21 +111,33 @@ is-koji-built ("%pkg") :
     # would need to be corrected/integrated by hand.
     git pull
 
-    # If we're not building for Rawhide then we must use the rightmost
-    # (-r) flag so there's an upgrade path to Rawhide.
-    rightmost=
-    if test %fedora-branch != "master"; then rightmost=-r; fi
-
-    # If the specfile doesn't have the magic string then add
-    # that now.
-    if ! grep -sq %fedora-rebuild-name $specfile; then
-        rpmdev-bumpspec -c "- "%fedora-rebuild-name $rightmost *.spec
+    # Add the new commit.
+    if ! grep -sq "^%%autochangelog" $specfile; then
+        # If we're not building for Rawhide then we must use the
+        # rpmdev-bumpspec rightmost (-r) flag so there's an upgrade
+        # path to Rawhide.
+        rightmost=
+        if test %fedora-branch != "rawhide"; then rightmost=-r; fi
+
+        # If the specfile doesn't have the magic string then add
+        # that now.
+        if ! grep -sq %fedora-rebuild-name $specfile; then
+            rpmdev-bumpspec -c "- "%fedora-rebuild-name $rightmost *.spec
+        else
+            rpmdev-bumpspec -c "- Bump release and rebuild" $rightmost *.spec
+        fi
+
+        fedpkg commit -c
     else
-        rpmdev-bumpspec -c "- Bump release and rebuild." $rightmost *.spec
+        # Using autochangelog.
+        if ! git log | grep -sq %fedora-rebuild-name; then
+            git commit --allow-empty -m %fedora-rebuild-name
+        else
+            git commit --allow-empty -m "Bump release and rebuild"
+        fi
     fi
 
-    # Commit and push the change.
-    fedpkg commit -c
+    # Push the new commit.
     fedpkg push
 
     # Do the Koji build in the side tag.
@@ -143,26 +155,23 @@ pure function fedora-source-dependencies (pkg) returning strings = @{
 
     # We will require the mapping of all source packages to the
     # list of binary packages they build, so work this out in advance.
-    declare -A binpkgs
+    declare -A bin2src
     for p in %fedora-source-packages; do
-        binpkgs[$p]="$(
-            rpmspec -q --provides %fedora-dir/$p/%fedora-branch/$p.spec 2>/dev/null |
-            awk '{print $1}'
-        )"
+        p_specfile=%fedora-dir/$p/%fedora-branch/$p.spec
+        p_depcache=%fedora-dir/$p/%fedora-branch/.depcache
+        if ! test -f "$p_depcache" || test "$p_specfile" -nt "$p_depcache";
+        then
+            rm -f $p_depcache
+            for b in $(rpmspec -q --provides $p_specfile 2>/dev/null | awk '{print $1}'); do
+                echo "bin2src['$b']='$p'" >> $p_depcache
+            done
+        fi
+        source $p_depcache
     done
 
-    for r in $(rpmspec -q --buildrequires $specfile 2>/dev/null |
+    for b in $(rpmspec -q --buildrequires $specfile 2>/dev/null |
                awk '{print $1}'); do
-        # Now we examine each *other* source package to see
-        # if any will create this dependency when they build.
-        for p in %fedora-source-packages; do
-            if [ "$p" != %pkg ]; then
-                for f in ${binpkgs[$p]}; do
-                    if [ "$f" = "$r" ]; then
-                        echo "$p"
-                    fi
-                done
-            fi
-        done
-    done | sort -u
+        # Find the source package that produces these binary requirements.
+        echo ${bin2src[$b]}
+    done | grep -v '^$' | sort -u
 }