Fix fedpkg build so it uses --target option.
[fedora-ocaml-rebuild.git] / Goalfile
1 # See README.
2
3 let fedora-dir = "%HOME/d/fedora"
4
5 let branch = "master"
6 let side-tag = "f32-ocaml"
7 #let koji = "koji"
8 let koji = "koji -p riscv64"
9 #let fedpkg = "fedpkg"
10 let fedpkg = "fedpkg --user-config %HOME/d/fedora-ocaml-rebuild/fedpkg-user-config"
11
12 # The magic string that must appear in %changelog when the
13 # package has been rebuilt.
14 let rebuild-name = "OCaml 4.09.0 for riscv64"
15
16 # Packages that are blocked.  Any dependent packages are also blocked
17 # automatically.
18 let blocked = [ "ocaml-camlp4" ]
19
20 # Packages that are ignored, which means they are treated as if
21 # they have been rebuilt.
22 #let ignored = [ "ocaml-srpm-macros", "ocaml" ]
23 let ignored = [ "ocaml-srpm-macros" ]
24
25 # All OCaml-related source package names
26 let other-packages = [
27     "alt-ergo", "apron", "brltty", "coccinelle", "coq",
28     "frama-c", "gappalib-coq", "graphviz", "hevea", "hivex",
29     "libguestfs", "opam", "plplot", "virt-top", "virt-v2v",
30     "why3", "z3",
31     "flocq" # no OCaml code, but needs to be rebuilt after Coq
32 ]
33 pure function get-source-packages () = {
34     cd %fedora-dir
35     echo '['
36     for f in ocaml* %other-packages; do
37         [ -f $f/%branch/$f.spec ] && echo "*built-in-koji(\"$f\"),"
38     done
39     echo ']'
40 }
41 let source-packages = get-source-packages ()
42
43 # Main goal: Rebuild all packages.
44 goal all = : source-packages ;
45
46 # Check if the source package has been built in Koji.
47 tactic *built-in-koji (pkg) = {
48     cd %fedora-dir/%pkg/%branch
49     koji=%koji
50     specfile=%pkg.spec
51
52     # Packages which are ignored are treated as if they were rebuilt already.
53     for p in %ignored; do
54         if [ %pkg = "$p" ]; then exit 0; fi
55     done
56
57     # If the specfile doesn't have the magic string then the
58     # package definitely needs to be rebuilt.
59     grep -sq %rebuild-name $specfile || exit 99
60
61     # Else we must check Koji itself.
62     # Koji sends some messages to stderr.
63     nvr=$(fedpkg verrel)
64     buildinfo=$($koji buildinfo $nvr 2>&1)
65
66     # No build at all, needs rebuild.
67     echo "$buildinfo" | grep -sq "No such build" && exit 99
68
69     # Exists a build, find out what state it is in.
70     state=$(echo "$buildinfo" | grep ^State: | awk '{print $2}')
71     taskid=$(echo "$buildinfo" | grep ^Task: | awk '{print $2}')
72
73     case "$state" in
74     COMPLETE)
75         # Complete so we don't need to rebuild.
76         exit 0 ;;
77     FAILED)
78         # Failed builds must be examined and fixed manually.
79         exit 1 ;;
80     BUILDING)
81         # Cancel the build, we will resubmit it.
82         $koji cancel $taskid
83         exit 99 ;;
84     CANCELED|DELETED)
85         # Do a rebuild.
86         exit 99 ;;
87     esac
88     # Don't know what happened there, so fail.
89     exit 1
90 }
91
92 goal rebuild (pkg) =
93 *built-in-koji ("%pkg") : source-dependencies (pkg) {
94     cd %fedora-dir/%pkg/%branch
95     fedpkg=%fedpkg
96     koji=%koji
97     specfile=%pkg.spec
98
99     # We have to wait for the dependencies to become available
100     # before we can start the new build.
101     for p in %<; do
102         nvr=$($koji --quiet latest-build %side-tag $p | awk '{print $1}')
103         $koji wait-repo %side-tag $nvr
104     done
105
106     # If the specfile doesn't have the magic string then add
107     # that now.
108     if ! grep -sq %rebuild-name $specfile; then
109         rpmdev-bumpspec -c "- "%rebuild-name *.spec
110     else
111         rpmdev-bumpspec -c "- Bump release and rebuild." *.spec
112     fi
113     $fedpkg commit -c
114     $fedpkg push
115     $fedpkg build --target %side-tag
116 }
117
118 # Get the source package names for a particular package.
119 # Note this is not merely the BuildRequires, since those are
120 # the binary packages.  Also this will only find packages
121 # which are in the list of source-packages.
122 pure function source-dependencies (pkg) = @{
123     specfile=%fedora-dir/%pkg/%branch/%pkg.spec
124
125     echo -n Dependencies of %pkg: >&2
126
127     echo '['
128     for r in $(rpmspec -q --buildrequires $specfile 2>/dev/null |
129                awk '{print $1}'); do
130         # Now we examine each *other* source package to see
131         # if any will create this dependency when they build.
132         for p in %source-packages; do
133             if [ "$p" != %pkg ] && \
134                  rpmspec -q --provides %fedora-dir/$p/%branch/$p.spec 2>/dev/null |
135                  awk '{print $1}' |
136                  grep -sq "^$r\$"
137              then
138                  echo "*built-in-koji(\"$p\"),"
139                  echo -n '' $p >&2
140             fi
141         done
142     done
143     echo ']'
144     echo >&2
145 }