Skip to content

Commit

Permalink
[antlir][third-party] install srcs with feature.tarball
Browse files Browse the repository at this point in the history
Summary:
Don't need to extract this as part of the build every time, we can just install
it into the image with the native antlir `feature.tarball`.

Test Plan:
```
❯ buck2 test fbcode//antlir/third-party/...
Buck UI: https://www.internalfb.com/buck2/3e1bac02-8b6f-4658-bc21-e809022131fc
Test UI: https://www.internalfb.com/intern/testinfra/testrun/6473924689049367
Network: Up: 0B  Down: 39KiB  (reSessionID-59f08fa0-bdb1-45e4-8bbc-1732cda9aa9b)
Jobs completed: 152. Time elapsed: 2:18.6s.
Cache hits: 11%. Commands: 46 (cached: 5, remote: 0, local: 41)
Tests finished: Pass 27. Fail 0. Fatal 0. Skip 0. Build failure 0
```

Reviewed By: justintrudell

Differential Revision: D59702344

fbshipit-source-id: 1c8ef488e1c087378e325a07b2e44cbd2d518b52
  • Loading branch information
vmagro authored and facebook-github-bot committed Nov 6, 2024
1 parent b8b00de commit 14693d3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
18 changes: 5 additions & 13 deletions antlir/bzl/third_party.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ load(":build_defs.bzl", "buck_genrule", "internal_external", third_party_shim =
load(":third_party.shape.bzl", "dep_t", "script_t")

PREFIX = "/third-party-build"
SRC_TGZ = paths.join(PREFIX, "source.tar.gz")
PATCHES_DIR = paths.join(PREFIX, "patches")
SRC_DIR = paths.join(PREFIX, "src")
DEPS_DIR = paths.join(PREFIX, "deps")
OUTPUT_DIR = "/output"

def _build(name, features, script, src, deps = None, dnf_additional_repos = None, **kwargs):
def _build(name, features, script, src, deps = None, **kwargs):
deps = deps or []
OUTPUT_DIR = paths.join(DEPS_DIR, name)

Expand All @@ -35,9 +34,7 @@ cat > $TMP/out << 'EOF'
set -uex
set -o pipefail
# unpack the source in build dir
cd "{src_dir}"
tar xzf {src} --strip-components=1
cd {src_dir}
# Patch sources
for p in \\$(ls -A {patches_dir}); do
Expand All @@ -56,7 +53,6 @@ EOF
mv $TMP/out $OUT
chmod +x $OUT
""").format(
src = SRC_TGZ,
prepare = sels.script_prepare if sels.script_prepare else "",
build = sels.script_build,
install = sels.script_install,
Expand All @@ -73,24 +69,20 @@ chmod +x $OUT
fb = "antlir//antlir/third-party:build-base",
oss = "//third-party/antlir:build-base",
),
dnf_additional_repos = dnf_additional_repos,
features = features + [
feature.ensure_dirs_exist(dirs = DEPS_DIR),
feature.ensure_dirs_exist(dirs = OUTPUT_DIR),
feature.ensure_dirs_exist(dirs = PATCHES_DIR),
feature.ensure_dirs_exist(dirs = SRC_DIR),
feature.install(
feature.tarball(
src = src,
dst = SRC_TGZ,
into_dir = SRC_DIR,
strip_components = 1,
),
feature.install(
src = ":" + name + "__build_script",
dst = "/build.sh",
mode = "a+x",
),
feature.rpms_install(rpms = [
"tar",
]),
] + [
[
feature.ensure_dirs_exist(
Expand Down
6 changes: 3 additions & 3 deletions third-party/antlir/tests/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ oncall("antlir")
]]

buck_genrule(
name = "hello_world.tgz",
out = "hello_world.tgz",
name = "hello_world.tar",
out = "hello_world.tar",
cmd = """
OUT_DIR=\\$(dirname $OUT)
mkdir -p "$OUT_DIR/hello_world"
cp "$(location {})" "$OUT_DIR/hello_world/"
tar -czf "$OUT" -C "$OUT_DIR" hello_world/hello_world.c
tar -cf "$OUT" -C "$OUT_DIR" hello_world/hello_world.c
rm -rf hello_world/
""".format(":hello_world.c"),
)
Expand Down
2 changes: 1 addition & 1 deletion third-party/antlir/tests/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ load("//antlir/bzl:third_party.bzl", "third_party")
def hello_world_build_test(ver, msg, patches = None):
third_party.build(
name = "hello_world.{}.build".format(ver),
src = ":hello_world.tgz",
src = ":hello_world.tar",
features = [feature.rpms_install(rpms = ["gcc", "patch"])],
script = third_party.script(
build = "gcc -o hello_world hello_world.c",
Expand Down

0 comments on commit 14693d3

Please sign in to comment.