diff --git a/mock/py/mockbuild/config.py b/mock/py/mockbuild/config.py index 72eb1f47c..e109e3f9b 100644 --- a/mock/py/mockbuild/config.py +++ b/mock/py/mockbuild/config.py @@ -168,6 +168,7 @@ def setup_default_config_opts(): 'package_state_opts': { 'available_pkgs': False, 'installed_pkgs': True, + 'buildroot_info': True, }, 'pm_request_enable': False, 'pm_request_opts': {}, diff --git a/mock/py/mockbuild/plugins/package_state.py b/mock/py/mockbuild/plugins/package_state.py index 23184a2f3..3fcbb1bef 100644 --- a/mock/py/mockbuild/plugins/package_state.py +++ b/mock/py/mockbuild/plugins/package_state.py @@ -12,6 +12,9 @@ # installed_pkgs.log # our imports +import json +import os +import shlex from mockbuild.trace_decorator import traceLog import mockbuild.util @@ -44,6 +47,8 @@ def __init__(self, plugins, conf, buildroot): self.online = self.buildroot.config['online'] plugins.add_hook("postyum", self._availablePostYumHook) plugins.add_hook("postdeps", self._installedPreBuildHook) + if self.conf.get("buildroot_info", False): + plugins.add_hook("postdeps", self._installedPreBuildHook2) @traceLog() def _availablePostYumHook(self): @@ -62,6 +67,40 @@ def _availablePostYumHook(self): self.avail_done = True self.state.finish("Outputting list of available packages") + @traceLog() + def _installedPreBuildHook2(self): + filename = "mock-build-environment.json" + statename = "Outputting the file " + filename + try: + with self.buildroot.uid_manager: + self.state.start(statename) + out_file = os.path.join(self.buildroot.resultdir, filename) + chrootpath = self.buildroot.make_chroot_path() + + package_list_cmd = "rpm --root {0} -qa".format(shlex.quote(chrootpath)) + out, _ = self.buildroot.doOutChroot(package_list_cmd, returnOutput=True, shell=True) + packages = out.splitlines() + + cmd = "dnf -q --installroot={0} repoquery --location".format(shlex.quote(chrootpath)) + cmd += " " + " ".join(shlex.quote(p) for p in packages) + out, _ = self.buildroot.doOutChroot(cmd, returnOutput=True, shell=True) + + self.avail_done = True + data = { + "version": "0", + "buildroot": { + "packages": [] + } + } + data["version"] = "0" + for pkg in out.splitlines(): + data["buildroot"]["packages"].append({"url": pkg}) + + with open(out_file, "w", encoding="utf-8") as fdlist: + fdlist.write(json.dumps(data, indent=4) + "\n") + finally: + self.state.finish(statename) + @traceLog() def _installedPreBuildHook(self): if self.inst_done or not self.installed_pkgs_enabled: