1 # Goals stdlib Fedora module.
2 # Copyright (C) 2020 Richard W.M. Jones
3 # Copyright (C) 2020 Red Hat Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 # Goals for dealing with Fedora builds.
21 # For these to work you must set up your environment in
22 # a particular way as described below:
25 # Points to a directory containing Fedora packages checked out
26 # of dist git. You must use the fedpkg clone -B command to
27 # create separate branches.
29 # %fedora-branch: Working branch, eg. "rawhide".
30 # %fedora-tag: Build tag, eg. "f32-build".
32 # %fedora-rebuild-name:
33 # Magic string that identifies this rebuild. This is used to
34 # detect if a rebuild has been attempted before in this run.
35 # eg. "Perl 5.99 rebuild"
37 # %fedora-source-packages:
38 # List of source packages that will be rebuilt.
41 # List of source packages which will be ignored. These are treated
42 # as if they have been rebuilt.
45 # List of packages which are blocked. Any dependent packages are
46 # also blocked. XXX NOT IMPLEMENTED
48 # Check if the source package has been built in Koji.
50 predicate is-koji-built (pkg) = {
51 cd %fedora-dir/%pkg/%fedora-branch
54 # Packages which are ignored are treated as if they were rebuilt already.
55 for p in %fedora-ignored; do
56 if [ %pkg = "$p" ]; then exit 0; fi
59 # If the specfile doesn't have the magic string then the
60 # package definitely needs to be rebuilt.
61 grep -sq %fedora-rebuild-name $specfile || exit 99
63 # Else we must check Koji itself.
64 # Koji sends some messages to stderr.
66 buildinfo=$(koji buildinfo $nvr 2>&1 ||:)
68 # No build at all, needs rebuild.
69 echo "$buildinfo" | grep -sq "No such build" && exit 99
71 # Existing build, find out what state it is in.
72 state=$(echo "$buildinfo" | grep ^State: | awk '{print $2}')
73 taskid=$(echo "$buildinfo" | grep ^Task: | awk '{print $2}')
77 # Complete so we don't need to rebuild.
80 # Failed builds must be examined and fixed manually.
83 # Cancel the build, we will resubmit it.
84 koji cancel $taskid ||:
90 # Don't know what happened there, so fail.
94 # Rebuild a Fedora package. This rebuilds any dependencies first.
96 goal fedora-rebuild (pkg) =
97 is-koji-built ("%pkg") :
98 wrap ("is-koji-built", fedora-source-dependencies (pkg)) {
99 cd %fedora-dir/%pkg/%fedora-branch
102 # We have to wait for the dependencies to become available
103 # before we can start the new build.
105 nvr=$(koji --quiet latest-build %fedora-tag $p | awk '{print $1}')
106 while ! koji wait-repo --timeout=10000 %fedora-tag --build=$nvr; do sleep 1m; done
109 # Make sure the local directory is up to date.
110 # This should also fail if there are local changes, which
111 # would need to be corrected/integrated by hand.
114 # Add the new commit.
115 if ! grep -sq "^%%autochangelog" $specfile; then
116 # If we're not building for Rawhide then we must use the
117 # rpmdev-bumpspec rightmost (-r) flag so there's an upgrade
120 if test %fedora-branch != "rawhide"; then rightmost=-r; fi
122 # If the specfile doesn't have the magic string then add
124 if ! grep -sq %fedora-rebuild-name $specfile; then
125 rpmdev-bumpspec -c "- "%fedora-rebuild-name $rightmost *.spec
127 rpmdev-bumpspec -c "- Bump release and rebuild" $rightmost *.spec
132 # Using autochangelog.
133 if ! git log | grep -sq %fedora-rebuild-name; then
134 git commit --allow-empty -m %fedora-rebuild-name
136 git commit --allow-empty -m "Bump release and rebuild"
140 # Push the new commit.
143 # Do the Koji build in the side tag.
144 fedpkg build --target %fedora-tag
147 # Get the source package names for a particular package.
148 # Note this is not merely the BuildRequires, since those are
149 # the binary packages. Also this will only find packages
150 # which are in the list of fedora-source-packages.
151 pure function fedora-source-dependencies (pkg) returning strings = @{
152 echo Calculating dependencies of %pkg >&2
154 specfile=%fedora-dir/%pkg/%fedora-branch/%pkg.spec
156 # We will require the mapping of all source packages to the
157 # list of binary packages they build, so work this out in advance.
159 for p in %fedora-source-packages; do
160 p_specfile=%fedora-dir/$p/%fedora-branch/$p.spec
161 p_depcache=%fedora-dir/$p/%fedora-branch/.depcache
162 if ! test -f "$p_depcache" || test "$p_specfile" -nt "$p_depcache";
165 for b in $(rpmspec -q --provides $p_specfile 2>/dev/null | awk '{print $1}'); do
166 echo "bin2src['$b']='$p'" >> $p_depcache
172 for b in $(rpmspec -q --buildrequires $specfile 2>/dev/null |
173 awk '{print $1}'); do
174 # Find the source package that produces these binary requirements.
176 done | grep -v '^$' | sort -u