Skip to content

Commit

Permalink
list of URLs
Browse files Browse the repository at this point in the history
something like a lock-file
  • Loading branch information
praiskup committed Jun 28, 2024
1 parent 5eeefbb commit 37564a9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions mock/py/mockbuild/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': {},
Expand Down
39 changes: 39 additions & 0 deletions mock/py/mockbuild/plugins/package_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# installed_pkgs.log

# our imports
import json
import os
import shlex
from mockbuild.trace_decorator import traceLog
import mockbuild.util

Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down

0 comments on commit 37564a9

Please sign in to comment.