From 2fec02490259722815249fab319b976c0901aaf3 Mon Sep 17 00:00:00 2001 From: Vinnie Magro Date: Thu, 19 Dec 2024 14:52:14 -0800 Subject: [PATCH] [antlir2][rpm] allow prebuilt repodata Summary: Sometimes, building `repodata` is actually quite slow and bloats the critical path by potentially minutes. This diff allows the `repo` rule to accept a prebuilt repodata directory. Test Plan: testhard Reviewed By: justintrudell Differential Revision: D67404535 fbshipit-source-id: 3ef5b4f2856d00ef97e04e83f731c28eea6ae70b --- .../package_managers/dnf/rules/repo.bzl | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/antlir/antlir2/package_managers/dnf/rules/repo.bzl b/antlir/antlir2/package_managers/dnf/rules/repo.bzl index 02433bbf89..e886b21c2b 100644 --- a/antlir/antlir2/package_managers/dnf/rules/repo.bzl +++ b/antlir/antlir2/package_managers/dnf/rules/repo.bzl @@ -32,20 +32,23 @@ def _impl(ctx: AnalysisContext) -> list[Provider]: # First build a repodata directory that just contains repodata (this would # be suitable as a baseurl for dnf) - plain_repodata = ctx.actions.declare_output("repodata", dir = True) - ctx.actions.run( - cmd_args( - ctx.attrs.makerepo[RunInfo], - cmd_args(repo_id, format = "--repo-id={}"), - cmd_args(xml_dir, format = "--xml-dir={}"), - cmd_args(ctx.attrs.module_md, format = "--module-md={}") if ctx.attrs.module_md else cmd_args(), - cmd_args(plain_repodata.as_output(), format = "--out={}"), - "--compress={}".format(ctx.attrs.compress), - "--expected-rpm-count={}".format(len(ctx.attrs.rpms)), - optional_args, - ), - category = "repodata", - ) + if not ctx.attrs.repodata: + plain_repodata = ctx.actions.declare_output("repodata", dir = True) + ctx.actions.run( + cmd_args( + ctx.attrs.makerepo[RunInfo], + cmd_args(repo_id, format = "--repo-id={}"), + cmd_args(xml_dir, format = "--xml-dir={}"), + cmd_args(ctx.attrs.module_md, format = "--module-md={}") if ctx.attrs.module_md else cmd_args(), + cmd_args(plain_repodata.as_output(), format = "--out={}"), + "--compress={}".format(ctx.attrs.compress), + "--expected-rpm-count={}".format(len(ctx.attrs.rpms)), + optional_args, + ), + category = "repodata", + ) + else: + plain_repodata = ctx.attrs.repodata if is_facebook: # Pre-build .solv(x) files so that dnf installation is substantially faster @@ -113,6 +116,11 @@ repo_attrs = { "makecache": attrs.default_only(attrs.exec_dep(default = "antlir//antlir/antlir2/package_managers/dnf/rules/makecache:makecache")), "makerepo": attrs.default_only(attrs.exec_dep(default = "antlir//antlir/antlir2/package_managers/dnf/rules/makerepo:makerepo")), "module_md": attrs.option(attrs.source(), default = None), + "repodata": attrs.option( + attrs.source(allow_directory = True), + default = None, + doc = "Pre-built repodata, if available", + ), "rpms": attrs.list( attrs.dep(providers = [RpmInfo]), doc = "All RPMs that should be included in this repo",