Skip to content

Commit

Permalink
[antlir2][rpm] use strip from toolchain
Browse files Browse the repository at this point in the history
Summary:
Use the `strip` from the current toolchain, instead of the centos system
`strip`, which likely does not correctly handle fbcode-platform binaries.

In the GitHub release, this is still correct and will just continue to be the
system toolchain since there is no isolated platform like fbcode.

Test Plan:
```
❯ buck2 test fbcode//mode/opt fbcode//antlir/antlir2/test_images/package/rpm:test
Buck UI: https://www.internalfb.com/buck2/c3bc1aab-f97a-463b-bd92-c709f830b18e
Test UI: https://www.internalfb.com/intern/testinfra/testrun/844425320107576
Network: Up: 0B  Down: 0B  (reSessionID-75828795-7372-4538-abd6-1f01a82bd953)
Jobs completed: 7. Time elapsed: 2.6s.
Tests finished: Pass 1. Fail 0. Fatal 0. Skip 0. Build failure 0
```

Reviewed By: epilatow

Differential Revision: D65492078

fbshipit-source-id: a86e78170ade05a6799e58f22b3071d6c54ac0c3
  • Loading branch information
vmagro authored and facebook-github-bot committed Nov 6, 2024
1 parent 3913a8b commit eef4a76
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
17 changes: 17 additions & 0 deletions antlir/antlir2/antlir2_packager/src/rpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ pub struct Rpm {
binary_payload: Option<String>,
disable_strip: bool,
disable_build_id_links: bool,
#[serde(rename = "_strip")]
strip: Option<Vec<String>>,
}

impl PackageFormat for Rpm {
Expand Down Expand Up @@ -238,6 +240,17 @@ AutoProv: {autoprov}
}
if self.disable_strip {
spec.push_str("%define __strip /usr/bin/true\n");
} else if let Some(strip) = &self.strip {
spec.push_str("%define __strip ");
let mut strip = strip.iter();
let path = strip.next().context("strip command is empty")?;
spec.push_str("/__antlir2__/working_directory/");
spec.push_str(path);
for arg in strip {
spec.push_str(arg);
spec.push(' ');
}
spec.push('\n');
}
if self.disable_build_id_links {
spec.push_str("%define _build_id_links none\n");
Expand Down Expand Up @@ -342,6 +355,10 @@ AutoProv: {autoprov}
.tmpfs(Path::new("/tmp"))
.tmpfs(Path::new("/dev"))
.inputs(Path::new("/dev/null"));
#[cfg(facebook)]
isol_context
.platform(Path::new("/usr/local/fbcode"))
.platform(Path::new("/mnt/gvfs"));
let isol_context = isol_context.build();

run_cmd(
Expand Down
13 changes: 12 additions & 1 deletion antlir/antlir2/bzl/package/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load("//antlir/antlir2/bzl:platform.bzl", "arch_select", "os_select")
load("//antlir/antlir2/bzl:types.bzl", "BuildApplianceInfo", "LayerInfo")
load("//antlir/antlir2/bzl/image:cfg.bzl", "attrs_selected_by_cfg")
load("//antlir/buck2/bzl:ensure_single_output.bzl", "ensure_single_output")
load("//antlir/bzl:build_defs.bzl", "internal_external")
load(":btrfs.bzl", "btrfs")
load(":cfg.bzl", "layer_attrs", "package_cfg")
load(":gpt.bzl", "GptPartitionSource", "gpt")
Expand Down Expand Up @@ -56,7 +57,13 @@ def _generic_impl_with_layer(
if uses_build_appliance:
spec_opts["build_appliance"] = build_appliance[BuildApplianceInfo].dir
for key in rule_attr_keys:
spec_opts[key] = getattr(ctx.attrs, key)
val = getattr(ctx.attrs, key)
if type(val) == "dependency":
if RunInfo in val:
val = val[RunInfo]
else:
val = ensure_single_output(val)
spec_opts[key] = val

spec = ctx.actions.write_json(
"spec.json",
Expand Down Expand Up @@ -310,6 +317,10 @@ _rpm, _rpm_anon = _new_package_rule(
"summary": attrs.option(attrs.string(), default = None),
"supplements": attrs.list(attrs.string(), default = []),
"version": attrs.option(attrs.string(), default = None, doc = "If unset, defaults to current datetime HHMMSS"),
"_strip": internal_external(
fb = attrs.default_only(attrs.exec_dep(default = "fbsource//third-party/binutils:strip")),
oss = attrs.option(attrs.exec_dep(), default = None),
),
},
format = "rpm",
dot_meta = False,
Expand Down
1 change: 0 additions & 1 deletion antlir/antlir2/test_images/package/rpm/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ image.layer(
package.rpm(
name = "add.rpm",
# @oss-disable
disable_strip = True, # disable double stripping (fixed later in this stack to not be necessary)
layer = ":layer",
license = "none",
rpm_name = "add",
Expand Down

0 comments on commit eef4a76

Please sign in to comment.