-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[antlir2][toolchain] macro to discover rpm dependencies for a distro …
…binary Summary: `rpm-build` comes with a helpful tool `/usr/lib/rpm/rpmdeps` that will produce a list of all the rpm subjects that a binary requires. This diff packages that up into a few little macros so that distro-targetted binaries can be easily installed along with their dependencies, without having to package it up into an rpm first. Test Plan: ``` ❯ buck2 test fbcode//antlir/distro/toolchain/cxx/tests: Buck UI: https://www.internalfb.com/buck2/2b25ecba-b0ef-4413-bd84-4b3319f929f6 Test UI: https://www.internalfb.com/intern/testinfra/testrun/13510798946868876 Tests finished: Pass 56. Fail 0. Fatal 0. Skip 0. Build failure 0 ``` Reviewed By: epilatow Differential Revision: D68342695 fbshipit-source-id: f69166835d32d385a2bbfc6c42ab2c92d514b75b
- Loading branch information
1 parent
42f7032
commit d4ba038
Showing
5 changed files
with
224 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature") | ||
load("//antlir/antlir2/bzl/image:defs.bzl", "image") | ||
load("//antlir/antlir2/bzl/package:defs.bzl", "package") | ||
load("//antlir/antlir2/image_command_alias:image_command_alias.bzl", "image_command_alias") | ||
|
||
oncall("antlir") | ||
|
||
image.layer( | ||
name = "layer", | ||
features = [ | ||
feature.rpms_install(subjects = [ | ||
"/usr/lib/rpm/find-requires", | ||
]), | ||
feature.install( | ||
src = "find-requires", | ||
dst = "/usr/bin/find-requires", | ||
mode = "a+rx", | ||
), | ||
], | ||
rootless = True, | ||
visibility = [], | ||
) | ||
|
||
package.unprivileged_dir( | ||
name = "root", | ||
layer = ":layer", | ||
rootless = True, | ||
visibility = [], | ||
) | ||
|
||
image_command_alias( | ||
name = "find-requires", | ||
exe = "/usr/bin/find-requires", | ||
root = ":root", | ||
rootless = True, | ||
visibility = ["PUBLIC"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
set -ex | ||
|
||
out="$1" | ||
shift | ||
|
||
exec /usr/lib/rpm/rpmdeps --define="_use_internal_dependency_generator 1" --requires "$@" > "$out" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
load("//antlir/antlir2/bzl:platform.bzl", "rule_with_default_target_platform") | ||
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature") | ||
load("//antlir/bzl:build_defs.bzl", "buck_genrule") | ||
load("//antlir/bzl:target_helpers.bzl", "normalize_target") | ||
|
||
def rpm_requires(binary: str): | ||
name = "rpm-deps-for-" + binary.replace(":", "_") | ||
if not native.rule_exists(name): | ||
buck_genrule( | ||
name = name, | ||
out = "subjects.txt", | ||
bash = """ | ||
$(exe antlir//antlir/distro/rpm:find-requires) \ | ||
$OUT \ | ||
$(location {binary}) \ | ||
""".format(binary = binary), | ||
) | ||
return normalize_target(":" + name) | ||
|
||
def install_with_rpm_requires(*, src: str, **kwargs): | ||
req = rpm_requires(src) | ||
return [ | ||
feature.rpms_install(subjects_src = req), | ||
feature.install(src = src, **kwargs), | ||
] | ||
|
||
def _query_all_binary_requirements_impl(ctx: AnalysisContext) -> list[Provider]: | ||
requires = ctx.actions.declare_output("requires.txt") | ||
ctx.actions.run( | ||
cmd_args( | ||
ctx.attrs._find_requires[RunInfo], | ||
requires.as_output(), | ||
[binary[DefaultInfo].default_outputs[0] for binary in ctx.attrs.q], | ||
), | ||
category = "find_requires", | ||
) | ||
return [DefaultInfo(requires)] | ||
|
||
_query_all_binary_requirements_rule = rule( | ||
impl = _query_all_binary_requirements_impl, | ||
attrs = { | ||
"q": attrs.query(), | ||
"_find_requires": attrs.default_only(attrs.exec_dep(default = "antlir//antlir/distro/rpm:find-requires")), | ||
}, | ||
) | ||
|
||
_query_all_binary_requirements = rule_with_default_target_platform(_query_all_binary_requirements_rule) | ||
|
||
def install_all_binary_rpm_requirements(layer: str): | ||
name = "rpm-requires-{}".format(layer.replace(":", "_")) | ||
_query_all_binary_requirements( | ||
name = name, | ||
q = "kind(cxx_binary, deps({}, 10000, target_deps()))".format(layer), | ||
) | ||
return feature.rpms_install(subjects_src = normalize_target(":" + name)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters