Initial commit.
authorRichard W.M. Jones <rjones@redhat.com>
Mon, 6 Jan 2020 10:40:32 +0000 (10:40 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Tue, 7 Jan 2020 10:08:31 +0000 (10:08 +0000)
.gitignore [new file with mode: 0644]
Goalfile [new file with mode: 0644]
README [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..b25c15b
--- /dev/null
@@ -0,0 +1 @@
+*~
diff --git a/Goalfile b/Goalfile
new file mode 100644 (file)
index 0000000..1f7280c
--- /dev/null
+++ b/Goalfile
@@ -0,0 +1,132 @@
+# See README.
+
+let fedora-dir = "%HOME/d/fedora"
+
+let branch = "master"
+let side-tag = "f32-build-side-999999"
+
+# The magic string that must appear in %changelog when the
+# package has been rebuilt.
+let rebuild-name = "OCaml 4.10.0 (beta 1)"
+
+# Local repository that contains build dependencies.
+let yum-repo = "koji-rawhide"
+
+# Packages that are blocked.  Any dependent packages are also blocked
+# automatically.
+let blocked = [ "ocaml-camlp4" ]
+
+# Packages that are ignored, which means they are treated as if
+# they have been rebuilt.
+let ignored = [ "ocaml-srpm-macros", "ocaml" ]
+
+# All OCaml-related source package names
+let other-packages = [
+    "alt-ergo", "apron", "brltty", "coccinelle", "coq",
+    "frama-c", "gappalib-coq", "graphviz", "hevea", "hivex",
+    "libguestfs", "opam", "plplot", "virt-top", "virt-v2v",
+    "why3", "z3",
+    "flocq" # no OCaml code, but needs to be rebuilt after Coq
+]
+pure function get-source-packages () = {
+    cd %fedora-dir
+    echo '['
+    for f in ocaml* %other-packages; do
+        [ -f $f/%branch/$f.spec ] && echo "*built-in-koji(\"$f\"),"
+    done
+    echo ']'
+}
+let source-packages = get-source-packages ()
+
+# Main goal: Rebuild all packages.
+goal all = : source-packages ;
+
+# Check if the source package has been built in Koji.
+tactic *built-in-koji (pkg) = {
+    cd %fedora-dir/%pkg/%branch
+    specfile=%pkg.spec
+
+    # Packages which are ignored are treated as if they were rebuilt already.
+    for p in %ignored; do
+        if [ %pkg = "$p" ]; then exit 0; fi
+    done
+
+    # If the specfile doesn't have the magic string then the
+    # package definitely needs to be rebuilt.
+    grep -sq %rebuild-name $specfile || exit 99
+
+    # Else we must check Koji itself.
+    nvr=$(fedpkg verrel)
+    buildinfo=$(koji buildinfo $nvr)
+
+    # No build at all, needs rebuild.
+    echo "$buildinfo" | grep -sq "No such build" && exit 99
+
+    # Exists a build, find out what state it is in.
+    state=$(echo "$buildinfo" | grep ^State: | awk '{print $2}')
+    taskid=$(echo "$buildinfo" | grep ^Task: | awk '{print $2}')
+
+    case "$state" in
+    COMPLETE)
+        # Complete so we don't need to rebuild.
+        exit 0 ;;
+    FAILED)
+        # Failed builds must be examined and fixed manually.
+        exit 1 ;;
+    BUILDING)
+        # Cancel the build, we will resubmit it.
+        koji cancel $taskid
+        exit 99 ;;
+    CANCELED|DELETED)
+        # Do a rebuild.
+        exit 99 ;;
+    esac
+    # Don't know what happened there, so fail.
+    exit 1
+}
+
+goal rebuild (pkg) =
+*built-in-koji ("%pkg") : source-dependencies (pkg) {
+    cd %fedora-dir/%pkg/%branch
+    specfile=%pkg.spec
+
+    # If the specfile doesn't have the magic string then add
+    # that now.
+    if ! grep -sq %rebuild-name $specfile; then
+        rpmdev-bumpspec -c "- "%rebuild-name *.spec
+    else
+        rpmdev-bumpspec -c "- Bump release and rebuild." *.spec
+    fi
+    fedpkg commit -c
+    fedpkg push
+    fedpkg build
+}
+
+# Get the source package names for a particular package.
+# Note this is not merely the BuildRequires, since those are
+# the binary packages.  Also this will only find packages
+# which are in the list of source-packages.
+pure function source-dependencies (pkg) = @{
+    specfile=%fedora-dir/%pkg/%branch/%pkg.spec
+
+    echo -n Dependencies of %pkg: >&2
+
+    echo '['
+    for r 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 %source-packages; do
+            if [ "$p" != %pkg ] && \
+                 rpmspec -q --provides %fedora-dir/$p/%branch/$p.spec 2>/dev/null |
+                 awk '{print $1}' |
+                 grep -sq "^$r\$"
+             then
+                 echo "*built-in-koji(\"$p\"),"
+                 echo -n '' $p >&2
+            fi
+        done
+    done
+    echo ']'
+    echo >&2
+}
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..9ceeea0
--- /dev/null
+++ b/README
@@ -0,0 +1,5 @@
+Perform a complete Fedora OCaml rebuild, in build order.
+Requires the goals tool found here:
+http://git.annexia.org/?p=goals.git;a=summary
+
+DON'T RUN THIS without first reading the code.