From 544d5f35be05732e23481aa9eee77f03b57dac25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Thu, 19 Oct 2023 13:25:56 +0200 Subject: [PATCH] Only %prep once when running %generate_buildrequires multiple times This saves time and IO and I believe this is what was originally intended. While doing this I moved some code around. Namely: - moved the variables used only in the if dynamic_buildrequires block inside it - ensured the --nodeps for the final rpmbuild call is only added once --- mock/py/mockbuild/backend.py | 22 ++++++++++--------- .../generate_buildrequires_prep.feature | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 releng/release-notes-next/generate_buildrequires_prep.feature diff --git a/mock/py/mockbuild/backend.py b/mock/py/mockbuild/backend.py index 6a03aed34..a2b855b4d 100644 --- a/mock/py/mockbuild/backend.py +++ b/mock/py/mockbuild/backend.py @@ -747,17 +747,18 @@ def get_command(mode, checkdeps=False): return command bd_out = self.make_chroot_path(self.buildroot.builddir) - max_loops = int(self.config.get('dynamic_buildrequires_max_loops')) - success = False dynamic_buildrequires = dynamic_buildrequires and self.config.get('dynamic_buildrequires') if dynamic_buildrequires: + max_loops = int(self.config.get('dynamic_buildrequires_max_loops')) + success = False + br_mode = ['-br'] while not success and max_loops > 0: # run rpmbuild+installSrpmDeps until # * it fails # * installSrpmDeps does nothing # * or we run out of dynamic_buildrequires_max_loops tries packages_before = self.buildroot.all_chroot_packages() - command = get_command(['-br']) + command = get_command(br_mode) (output, returncode) = \ self.buildroot.doChroot(command, shell=False, logger=self.buildroot.build_log, timeout=timeout, @@ -781,13 +782,14 @@ def get_command(mode, checkdeps=False): success = True for f_buildreqs in buildreqs: os.remove(f_buildreqs) - if not sc: - # We want to (re-)write src.rpm with dynamic BuildRequires, - # but with short-circuit it doesn't matter - mode = ['-ba'] - # rpmbuild -br already does %prep, so we don't need waste time - # on re-doing it - mode += ['--noprep'] + # The first rpmbuild -br already did %prep, so we don't need waste time + if '--noprep' not in br_mode: + br_mode += ['--noprep'] + if not sc: + # We want to (re-)write src.rpm with dynamic BuildRequires, + # but with short-circuit it doesn't matter + mode = ['-ba'] + mode += ['--noprep'] # When we used dynamic buildrequires, we must let rpmbuild check deps. # The rpmbuild -ba call executes the %generate_buildrequires once again diff --git a/releng/release-notes-next/generate_buildrequires_prep.feature b/releng/release-notes-next/generate_buildrequires_prep.feature new file mode 100644 index 000000000..2a0aaf552 --- /dev/null +++ b/releng/release-notes-next/generate_buildrequires_prep.feature @@ -0,0 +1,22 @@ +Only run the `%prep` section once when running `%generate_buildrequires` +multiple times. +Previously Mock run `%prep` repeatedly before each `%generate_buildrequires` +round except for the last one. +This was inconsistent and unnecessary slow/wasteful. + +When the original support for `%generate_buildrequires` landed into Mock, +the intention was to only call `%prep` once. +However when Mock added support for multiple rounds of +`%generate_buildrequires`, `%prep` ended up only being skipped in the final +`rpmbuild` call. This was an oversight. +`%prep` is now only called once, as originally intended. + +Some RPM packages might be affected by the change, especially if a dirty +working directory after running `%generate_buildrequires` affects the results +of subsequent rounds of `%generate_buildrequires`. +However, such behavior was undefined and quite buggy even previously, +due to the lack of the `%prep` section in the final `rpmbuild` call. + +Packages that need to run commands before every round of +`%generate_buildrequires` should place those commands in +the `%generate_buildrequires` section itself rather than `%prep`.