Skip to content

Commit

Permalink
[antlir2] some genrule api shim fixes and fix rpmbuild
Browse files Browse the repository at this point in the history
Summary:
Make `image_rpmbuild` work in antlir2. This is going to be deleted in a
following diff in this stack, but I think there's a good chance we'll need to
bring it back in the future and I already did the work to fix it

Test Plan: Was able to build systemd rpmbuild on antlir2

Reviewed By: epilatow

Differential Revision: D51263725

fbshipit-source-id: 1cab6d96e0a76005b38a728cc4de3fed604b2381
  • Loading branch information
vmagro authored and facebook-github-bot committed Nov 13, 2023
1 parent c3d2a1e commit 5124e42
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 29 deletions.
93 changes: 64 additions & 29 deletions antlir/bzl/genrule/rpmbuild/rpmbuild.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ given image layer, and outputs a new layer with the resulting RPM(s)
available in a pre-determined location: `/rpmbuild/RPMS`.
"""

load("//antlir/antlir2/bzl:hoist.bzl?v2_only", antlir2_hoist = "hoist")
load("//antlir/antlir2/bzl/feature:defs.bzl?v2_only", antlir2_feature = "feature")
load("//antlir/antlir2/bzl/image:defs.bzl?v2_only", antlir2_image = "image")
load("//antlir/bzl:antlir2_shim.bzl", "antlir2_shim")
load("//antlir/bzl:build_defs.bzl", "buck_genrule", "get_visibility")
load("//antlir/bzl:flavor.shape.bzl", "flavor_t")
load("//antlir/bzl:flavor_helpers.bzl", "flavor_helpers")
Expand Down Expand Up @@ -135,6 +139,9 @@ def private_image_rpmbuild_impl(
feature.ensure_subdirs_exist("/rpmbuild", "SPECS"),
feature.tarball(":" + source_tarball, "/rpmbuild/SOURCES"),
] + (setup_features or []),
antlir2_features = [
"//antlir/facebook/image/build_appliance/common:etc_rpm_macros",
],
visibility = [],
antlir_rule = types.antlir_rule("user-internal"),
)
Expand All @@ -151,35 +158,62 @@ def private_image_rpmbuild_impl(
)

install_deps_layer = name + "-rpmbuild-install-deps"
image.genrule_layer(
name = install_deps_layer,
rule_type = "rpmbuild_install_deps_layer",
parent_layer = ":" + setup_layer,
flavor = flavor,
# Auto-installing RPM dependencies requires `root`.
user = "root",
cmd = [
installer,
"builddep", # Hack: our `yum` wrapper maps this to `yum-builddep`
# Define the build directory for this project
"--define=_topdir {}".format(rpmbuild_dir),
"--assumeyes",
specfile_path,
],
container_opts = struct(
# Serve default snapshots for the RPM installers that define
# one. So, we may start `repo-server`s for both `yum` and `dnf`
# -- this minor inefficiency is worth the simplicity.
#
# In the unlikely event we need support for a non-default snapshot,
# we can expose a flag that chooses between enabling shadowing, or
# serving a specific snapshot.
shadow_proxied_binaries = True,
),
antlir_rule = "user-internal",
visibility = [],
**image_layer_kwargs
)
if not antlir2_shim.should_shadow_layer(None) and not antlir2_shim.should_upgrade_layer():
image.genrule_layer(
name = install_deps_layer,
rule_type = "rpmbuild_install_deps_layer",
parent_layer = ":" + setup_layer,
flavor = flavor,
# Auto-installing RPM dependencies requires `root`.
user = "root",
cmd = [
installer,
"builddep", # Hack: our `yum` wrapper maps this to `yum-builddep`
# Define the build directory for this project
"--define=_topdir {}".format(rpmbuild_dir),
"--assumeyes",
specfile_path,
],
container_opts = struct(
# Serve default snapshots for the RPM installers that define
# one. So, we may start `repo-server`s for both `yum` and `dnf`
# -- this minor inefficiency is worth the simplicity.
#
# In the unlikely event we need support for a non-default snapshot,
# we can expose a flag that chooses between enabling shadowing, or
# serving a specific snapshot.
shadow_proxied_binaries = True,
),
antlir_rule = "user-internal",
visibility = [],
**image_layer_kwargs
)

else:
antlir2_image.layer(
name = name + "-rpmbuild-determine-builddeps",
parent_layer = ":" + setup_layer,
features = [antlir2_feature.genrule(user = "root", cmd = [
"/bin/bash",
"-c",
"rpmspec --define='_topdir /rpmbuild' -q --buildrequires /rpmbuild/SPECS/specfile.spec > /builddeps",
])],
)
antlir2_hoist(
name = name + "-rpmbuild-builddeps",
layer = ":{}-rpmbuild-determine-builddeps".format(name),
path = "/builddeps",
)
antlir2_layer_name = install_deps_layer
if not antlir2_shim.should_upgrade_layer():
antlir2_layer_name += ".antlir2"
antlir2_image.layer(
name = antlir2_layer_name,
parent_layer = ":" + setup_layer,
features = [
antlir2_feature.rpms_install(subjects_src = ":{}-rpmbuild-builddeps".format(name)),
],
)

build_layer = name + "-rpmbuild-build"
image.genrule_layer(
Expand All @@ -202,6 +236,7 @@ def private_image_rpmbuild_impl(
],
antlir_rule = "user-facing",
visibility = visibility,
antlir2_mount_platform = True,
**image_layer_kwargs
)

Expand Down
7 changes: 7 additions & 0 deletions antlir/bzl/image_genrule_layer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def image_genrule_layer(
container_opts = None,
bind_repo_ro = False,
boot = False,
antlir2_mount_platform = False,
**image_layer_kwargs):
"""
### Danger! Danger! Danger!
Expand Down Expand Up @@ -120,6 +121,9 @@ Optional arguments:
antlir2_feature.genrule(
cmd = cmd,
user = user,
mount_platform = antlir2_mount_platform,
bind_repo_ro = bind_repo_ro,
boot = boot,
) if is_buck2() else None,
],
implicit_antlir2 = True,
Expand Down Expand Up @@ -152,6 +156,9 @@ Optional arguments:
antlir2_feature = antlir2_feature.genrule(
cmd = cmd,
user = user,
mount_platform = antlir2_mount_platform,
bind_repo_ro = bind_repo_ro,
boot = boot,
) if is_buck2() else None,
)]

Expand Down

0 comments on commit 5124e42

Please sign in to comment.