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