Skip to content

Commit

Permalink
[antlir2][rpm] simplify RpmInfo provider
Browse files Browse the repository at this point in the history
Summary:
`nevra` does not need to be structured, the only field that ever gets used
individually is `name`

Test Plan:
```
❯ buck2 test fbcode//antlir/antlir2/features/rpm/tests:
Buck UI: https://www.internalfb.com/buck2/49488e24-ea0e-45c5-a53a-b7f6a16985ad
Test UI: https://www.internalfb.com/intern/testinfra/testrun/18014398571955644
Tests finished: Pass 62. Fail 0. Fatal 0. Skip 0. Build failure 0
```

Reviewed By: justintrudell

Differential Revision: D67613413

fbshipit-source-id: 909202038abeb34640dbcdefab1334a1987d4786
  • Loading branch information
vmagro authored and facebook-github-bot committed Jan 2, 2025
1 parent a13540d commit d369932
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 34 deletions.
3 changes: 1 addition & 2 deletions antlir/antlir2/bzl/dnf/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ load("//antlir/antlir2/package_managers/dnf/rules:repo.bzl", "RepoInfo")
load(
"//antlir/antlir2/package_managers/dnf/rules:rpm.bzl",
"RpmInfo", # @unused Used as type
"nevra_to_string",
"package_href",
)

Expand Down Expand Up @@ -90,7 +89,7 @@ def compiler_plan_to_local_repos(
for repo_info in dnf_available_repos:
by_repo[repo_info.id] = {"nevras": {}, "repo_info": repo_info}
for rpm_info in repo_info.all_rpms:
by_repo[repo_info.id]["nevras"][nevra_to_string(rpm_info.nevra)] = rpm_info
by_repo[repo_info.id]["nevras"][rpm_info.nevra] = rpm_info

def _dyn(ctx, artifacts, outputs, tx = tx, by_repo = by_repo, dir = dir):
tx = artifacts[tx].read_json()
Expand Down
4 changes: 2 additions & 2 deletions antlir/antlir2/package_managers/dnf/rules/repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

load("//antlir/antlir2/bzl:platform.bzl", "rule_with_default_target_platform")
load("//antlir/bzl:internal_external.bzl", "is_facebook")
load(":rpm.bzl", "RpmInfo", "nevra_to_string", "package_href")
load(":rpm.bzl", "RpmInfo", "package_href")

RepoInfo = provider(fields = [
"all_rpms", # All RpmInfos contained in this repo
Expand All @@ -25,7 +25,7 @@ def _impl(ctx: AnalysisContext) -> list[Provider]:

# Construct repodata XML blobs from each individual RPM
xml_dir = ctx.actions.declare_output("xml", dir = True)
ctx.actions.copied_dir(xml_dir, {nevra_to_string(rpm.nevra): rpm.xml for rpm in rpm_infos})
ctx.actions.copied_dir(xml_dir, {rpm.nevra: rpm.xml for rpm in rpm_infos})
optional_args = []
if ctx.attrs.timestamp != None:
optional_args += ["--timestamp={}".format(ctx.attrs.timestamp)]
Expand Down
45 changes: 15 additions & 30 deletions antlir/antlir2/package_managers/dnf/rules/rpm.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,18 @@

load("//antlir/antlir2/bzl:platform.bzl", "rule_with_default_target_platform")
load("//antlir/antlir2/bzl/dnf:reflink.bzl", "REFLINK_FLAVORS", "rpm2extents")
load("//antlir/bzl:types.bzl", "types")

nevra = record(
name = str,
epoch = int,
version = str,
release = str,
arch = str,
)

def nevra_to_string(nevra: nevra | typing.Any) -> str:
return "{}-{}:{}-{}.{}".format(
nevra.name,
nevra.epoch,
nevra.version,
nevra.release,
nevra.arch,
)

def package_href(nevra: nevra | str, id: str) -> str:
def package_href(nevra: str, id: str) -> str:
"""
Make the location encode the pkgid. The last path component is the package
nevra so that dnf logs look nice, but the repo proxy only looks at the
middle path component that includes the pkgid.
"""
if not types.is_string(nevra):
nevra = nevra_to_string(nevra)
return "Packages/{id}/{nevra}.rpm".format(id = id, nevra = nevra)

RpmInfo = provider(fields = [
"extents", # .rpm transformed by rpm2extents
"name", # Name component of NEVRA
"nevra", # RPM NEVRA
"pkgid", # checksum (sha256 or sha1, usually sha256)
"raw_rpm", # .rpm file artifact
Expand Down Expand Up @@ -67,21 +48,23 @@ def _impl(ctx: AnalysisContext) -> list[Provider]:
rpm_file = ctx.actions.declare_output("rpm.rpm")
ctx.actions.download_file(rpm_file, ctx.attrs.url, sha256 = ctx.attrs.sha256, sha1 = ctx.attrs.sha1)

pkg_nevra = nevra(
name = ctx.attrs.rpm_name,
epoch = ctx.attrs.epoch,
version = ctx.attrs.version,
release = ctx.attrs.release,
arch = ctx.attrs.arch,
# TODO: move nevra directly into attrs.string()
nevra = "{}-{}:{}-{}.{}".format(
ctx.attrs.rpm_name,
ctx.attrs.epoch,
ctx.attrs.version,
ctx.attrs.release,
ctx.attrs.arch,
)
pkgid = ctx.attrs.sha256 or ctx.attrs.sha1
href = package_href(pkg_nevra, pkgid)
href = package_href(nevra, pkgid)

xml = ctx.attrs.xml or _make_xml(ctx, rpm_file, href)

return common_impl(
ctx = ctx,
nevra = pkg_nevra,
name = ctx.attrs.rpm_name,
nevra = nevra,
rpm = rpm_file,
xml = xml,
pkgid = ctx.attrs.sha256 or ctx.attrs.sha1,
Expand All @@ -90,7 +73,8 @@ def _impl(ctx: AnalysisContext) -> list[Provider]:

def common_impl(
ctx: AnalysisContext,
nevra: nevra,
name: str,
nevra: str,
rpm: Artifact,
xml: Artifact,
pkgid: str,
Expand Down Expand Up @@ -127,6 +111,7 @@ def common_impl(
"xml": [DefaultInfo(xml)],
}),
RpmInfo(
name = name,
nevra = nevra,
raw_rpm = rpm,
pkgid = pkgid,
Expand Down

0 comments on commit d369932

Please sign in to comment.