Skip to content

Commit

Permalink
Revert D50194750: [antlir2][migration] add antlir2 only mode to PACKA…
Browse files Browse the repository at this point in the history
…GE files

Test Plan: revert-hammer

Differential Revision:
D50194750

Original commit changeset: e5c73064bc69

Original Phabricator Diff: D50194750

fbshipit-source-id: 29837f455ea5587ed0a3785fe53e87963201f1e8
  • Loading branch information
tutchiio authored and facebook-github-bot committed Oct 13, 2023
1 parent 7ca66de commit 8aad22d
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 257 deletions.
11 changes: 1 addition & 10 deletions antlir/bzl/antlir2_migration.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@

load("//antlir/bzl:types.bzl", "types")

mode_t = enum(
# no antlir2 shadowing by default
"none",
# shadow all layers, features, packages and tests with antlir2 definitions by default
"shadow",
# transparently upgrade all targets to antlir2.
# antlir1 feature rules are kept around since they don't have conflicting
# names with the porcelain antlir2 targets
"upgrade",
)
mode_t = enum("none", "shadow")

def _configure_package(*, mode: str | mode_t):
if types.is_string(mode):
Expand Down
58 changes: 3 additions & 55 deletions antlir/bzl/antlir2_shim.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ load("//antlir/bzl:build_defs.bzl", "export_file")
load(":antlir2_migration.bzl?v2_only", "antlir2_migration")
load(":build_defs.bzl", "is_buck2", "python_unittest")
load(":flavor.shape.bzl", "flavor_t")
load(":structs.bzl", "structs")
load(":target_helpers.bzl", "antlir_dep")
load(":types.bzl", "types")

Expand Down Expand Up @@ -44,18 +43,6 @@ def _should_shadow(antlir2: str | bool | None) -> bool:

return antlir2 == antlir2_setting("yes")

def _should_upgrade() -> bool:
if not is_buck2():
return False
package_mode = antlir2_migration.get_mode()
return package_mode == antlir2_migration.mode_t("upgrade")

# features are currently left with an antlir1 definition because it does not
# conflict and features often have cross-package dependencies.
# when migration closer to complete, this can use the same logic as above
def _should_upgrade_feature(*args, **kwargs):
return False

def _fake_buck1_layer(name):
# export a target of the same name to make td happy
_fake_buck1_target(name = name + ".antlir2")
Expand All @@ -80,52 +67,13 @@ def _fake_buck1_target(name):
antlir_rule = "user-internal",
)

def _upgrade_or_shadow(
*,
name: str,
antlir2: str | bool | None,
fn,
fake_buck1: struct,
**kwargs) -> str | None:
if _should_upgrade():
fn(name = name, **kwargs)
return "upgrade"
if _should_shadow(antlir2 = antlir2):
fn(name = name + ".antlir2", **kwargs)
if not is_buck2():
fake = structs.to_dict(fake_buck1)
fake_fn = fake.pop("fn")
fake_fn(**fake)
return None

def _upgrade_or_shadow_feature(
*,
name: str,
antlir2: str | bool | None,
fn,
**kwargs) -> str | None:
if _should_upgrade():
fn(name = name, **kwargs)
if _should_shadow(antlir2 = antlir2):
fn(name = name, **kwargs)
return None

def _getattr_buck2(val, attr):
if is_buck2():
return getattr(val, attr)
else:
return None

antlir2_shim = struct(
fake_buck1_layer = _fake_buck1_layer,
fake_buck1_feature = _fake_buck1_target,
fake_buck1_target = _fake_buck1_target,
fake_buck1_test = _fake_buck1_test,
should_upgrade_layer = _should_upgrade,
should_shadow_feature = _should_shadow,
should_shadow_layer = _should_shadow,
upgrade_or_shadow_layer = _upgrade_or_shadow,
upgrade_or_shadow_feature = _upgrade_or_shadow_feature,
upgrade_or_shadow_test = _upgrade_or_shadow,
upgrade_or_shadow_package = _upgrade_or_shadow,
getattr_buck2 = _getattr_buck2,
should_shadow_test = _should_shadow,
should_shadow_package = _should_shadow,
)
35 changes: 16 additions & 19 deletions antlir/bzl/genrule/extractor/extract.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ exported by a parent layer which also includes an extract.extract feature.
load("@bazel_skylib//lib:paths.bzl", "paths")
load("//antlir/antlir2/bzl/feature:defs.bzl?v2_only", antlir2_feature = "feature")
load("//antlir/bzl:antlir2_shim.bzl", "antlir2_shim")
load("//antlir/bzl:build_defs.bzl", "is_buck2")
load("//antlir/bzl:constants.bzl", "REPO_CFG")
load("//antlir/bzl:image.bzl", "image")
load("//antlir/bzl:sha256.bzl", "sha256_b64")
Expand All @@ -88,25 +89,6 @@ def _extract(
binaries = binaries or []
normalized_source = normalize_target(source)
name = sha256_b64(normalized_source + " ".join(binaries) + dest)

if antlir2_shim.upgrade_or_shadow_feature(
name = name,
antlir2 = antlir2,
fn = antlir2_feature.new,
features = [
antlir2_feature.extract_from_layer(
binaries = binaries,
layer = source + ".antlir2",
),
],
visibility = [],
fake_buck1 = struct(
fn = antlir2_shim.fake_buck1_feature,
name = name,
),
) == "upgrade":
return normalize_target(":" + name)

base_extract_layer = "image-extract-setup--{}".format(name)
image.layer(
name = base_extract_layer,
Expand Down Expand Up @@ -169,6 +151,21 @@ cp "${{source_layer_path}}{output_dir}/feature.json" "$OUT"
deps = ["//antlir/bzl/genrule/extractor:extract"],
)

if antlir2_shim.should_shadow_feature(antlir2):
if is_buck2():
antlir2_feature.new(
name = name,
features = [
antlir2_feature.extract_from_layer(
binaries = binaries,
layer = source + ".antlir2",
),
],
visibility = [],
)
else:
antlir2_shim.fake_buck1_feature(name)

return normalize_target(":" + name)

# Helper to create a layer to use as 'source' for 'extract.extract', that
Expand Down
20 changes: 9 additions & 11 deletions antlir/bzl/image/feature/new.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,12 @@ def feature_new(
# If we're on buck2, instantiate an antlir2 feature rule. This does not
# conflict with the feature above, since antlir1 adds a "private" suffix to
# all feature targets
antlir2_shim.upgrade_or_shadow_feature(
antlir2 = antlir2,
name = name,
fn = antlir2_feature.new,
features = [f if types.is_string(f) else f.antlir2_feature for f in flatten.flatten(features)],
visibility = get_visibility(visibility),
fake_buck1 = struct(
fn = antlir2_shim.fake_buck1_feature,
name = name,
),
)
if antlir2_shim.should_shadow_layer(antlir2):
if is_buck2():
antlir2_feature.new(
name,
features = [f if types.is_string(f) else f.antlir2_feature for f in flatten.flatten(features)],
visibility = get_visibility(visibility),
)
else:
antlir2_shim.fake_buck1_feature(name)
40 changes: 18 additions & 22 deletions antlir/bzl/image/package/new.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ load("@bazel_skylib//lib:shell.bzl", "shell")
load("//antlir/antlir2/bzl/package:defs.bzl?v2_only", antlir2_package = "package")
load("//antlir/bzl:antlir2_shim.bzl", "antlir2_shim")
load("//antlir/bzl:bash.bzl", "wrap_bash_build_in_common_boilerplate")
load("//antlir/bzl:build_defs.bzl", "buck_genrule", "get_visibility")
load("//antlir/bzl:build_defs.bzl", "buck_genrule", "get_visibility", "is_buck2")
load("//antlir/bzl:loopback_opts.bzl", "normalize_loopback_opts")
load("//antlir/bzl:query.bzl", "layer_deps_query")
load("//antlir/bzl:shape.bzl", "shape")
load("//antlir/bzl:structs.bzl", "structs")
load("//antlir/bzl:target_helpers.bzl", "antlir_dep", "targets_and_outputs_arg_list")

_IMAGE_PACKAGE = "image_package"
Expand Down Expand Up @@ -56,27 +55,24 @@ def package_new(
if format in _SENDSTREAM_FORMATS and not subvol_name:
subvol_name = "volume"

if shape.is_any_instance(loopback_opts):
opts_kwargs = shape.as_dict_shallow(loopback_opts)
elif loopback_opts:
opts_kwargs = structs.to_dict(loopback_opts)
else:
opts_kwargs = {}
if antlir2_shim.should_shadow_package(antlir2 = antlir2):
if is_buck2():
antlir2_opts = shape.as_dict_shallow(loopback_opts) if loopback_opts else None
opts_kwargs = {
"opts": antlir2_opts,
} if antlir2_opts else {}

if antlir2_shim.upgrade_or_shadow_package(
antlir2 = antlir2,
name = name,
fn = antlir2_package.backward_compatible_new,
layer = layer + ".antlir2",
format = format,
visibility = visibility,
fake_buck1 = struct(
fn = antlir2_shim.fake_buck1_target,
name = name + ".antlir2",
),
**opts_kwargs
) == "upgrade":
return
antlir2_package.backward_compatible_new(
name = name + ".antlir2",
layer = layer + ".antlir2",
format = format,
visibility = visibility,
**opts_kwargs
)
else:
antlir2_shim.fake_buck1_target(
name = name + ".antlir2",
)

loopback_opts = normalize_loopback_opts(loopback_opts)

Expand Down
33 changes: 14 additions & 19 deletions antlir/bzl/image_cpp_unittest.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

load("//antlir/antlir2/testing:image_test.bzl?v2_only", antlir2_image_cpp_test = "image_cpp_test")
load(":antlir2_shim.bzl", "antlir2_shim")
load(":build_defs.bzl", "buck_sh_test", "cpp_unittest", "python_binary")
load(":container_opts.bzl", "normalize_container_opts")
load(":build_defs.bzl", "buck_sh_test", "cpp_unittest", "is_buck2", "python_binary")
load(":image_unittest_helpers.bzl", helpers = "image_unittest_helpers")

def image_cpp_unittest(
Expand All @@ -20,23 +19,6 @@ def image_cpp_unittest(
antlir2 = None,
**cpp_unittest_kwargs):
visibility = visibility or []
container_opts = normalize_container_opts(container_opts)

if antlir2_shim.upgrade_or_shadow_test(
antlir2 = antlir2,
fn = antlir2_image_cpp_test,
name = name,
layer = layer + ".antlir2",
boot = boot,
run_as_user = run_as_user,
boot_requires_units = ["dbus.socket"] if (boot and container_opts and container_opts.boot_await_dbus) else [],
fake_buck1 = struct(
fn = antlir2_shim.fake_buck1_test,
name = name,
),
**cpp_unittest_kwargs
) == "upgrade":
return

supports_static_listing = cpp_unittest_kwargs.pop("supports_static_listing", False)
wrapper_props = helpers.nspawn_wrapper_properties(
Expand Down Expand Up @@ -102,3 +84,16 @@ def image_cpp_unittest(
visibility = visibility,
**wrapper_props.outer_test_kwargs
)

if antlir2_shim.should_shadow_test(antlir2):
if is_buck2():
antlir2_image_cpp_test(
name = name + ".antlir2",
layer = layer + ".antlir2",
boot = boot,
run_as_user = run_as_user,
boot_requires_units = ["dbus.socket"] if (boot and wrapper_props.container_opts.boot_await_dbus) else [],
**cpp_unittest_kwargs
)
else:
antlir2_shim.fake_buck1_test(name = name)
36 changes: 16 additions & 20 deletions antlir/bzl/image_genrule_layer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,22 @@ Optional arguments:
- See the `_image_layer_impl` signature (in `image_layer_utils.bzl`)
for supported, but less commonly used, kwargs.
"""
antlir2 = image_layer_kwargs.pop("antlir2", None)
if antlir2_shim.upgrade_or_shadow_layer(
antlir2 = antlir2,
name = name,
fn = antlir2_shim.getattr_buck2(antlir2_image, "layer"),
parent_layer = parent_layer + ".antlir2" if parent_layer else None,
flavor = flavor,
features = [
antlir2_feature.genrule(
cmd = cmd,
user = user,
),
],
implicit_antlir2 = True,
fake_buck1 = struct(
fn = antlir2_shim.fake_buck1_layer,
name = name,
),
) == "upgrade":
return
if antlir2_shim.should_shadow_layer(image_layer_kwargs.pop("antlir2", None)):
if is_buck2():
antlir2_image.layer(
name = name + ".antlir2",
parent_layer = parent_layer + ".antlir2" if parent_layer else None,
flavor = flavor,
features = [
antlir2_feature.genrule(
cmd = cmd,
user = user,
),
],
implicit_antlir2 = True,
)
else:
antlir2_shim.fake_buck1_layer(name = name)

flavor = flavor_to_struct(flavor)
container_opts = normalize_container_opts(container_opts)
Expand Down
38 changes: 19 additions & 19 deletions antlir/bzl/image_layer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,25 @@ def image_layer(
[docs](/docs/tutorials/helper-buck-targets#imagelayer) for the list of
possible helpers, their respective behaviours, and how to invoke them.
"""
if antlir2_shim.upgrade_or_shadow_layer(
name = name,
antlir2 = image_layer_kwargs.pop("antlir2", None),
fn = antlir2_shim.getattr_buck2(antlir2_image, "layer"),
flavor = flavor,
parent_layer = parent_layer + ".antlir2" if parent_layer else None,
features = (features or []) + antlir2_features,
implicit_antlir2 = True,
compatible_with = antlir2_compatible_with,
visibility = get_visibility(image_layer_kwargs.get("visibility")),
# Antlir1 provisioning images explicitly install package-devel stub, we need to allow them here.
dnf_excluded_rpms = ["aziot-identity-service"],
default_mountpoint = antlir2_default_mountpoint,
fake_buck1 = struct(
fn = antlir2_shim.fake_buck1_layer,
name = name,
),
) == "upgrade":
return
if antlir2_shim.should_shadow_layer(image_layer_kwargs.pop("antlir2", None)):
if is_buck2():
if not antlir2_allow_ignored_flavor_config_override and flavor_config_override:
fail("antlir2 does not support flavor_config_override: {}".format(flavor_config_override))

antlir2_image.layer(
name = name + ".antlir2",
flavor = flavor,
parent_layer = parent_layer + ".antlir2" if parent_layer else None,
features = (features or []) + antlir2_features,
implicit_antlir2 = True,
compatible_with = antlir2_compatible_with,
visibility = get_visibility(image_layer_kwargs.get("visibility")),
# Antlir1 provisioning images explicitly install package-devel stub, we need to allow them here.
dnf_excluded_rpms = ["aziot-identity-service"],
default_mountpoint = antlir2_default_mountpoint,
)
else:
antlir2_shim.fake_buck1_layer(name = name)

flavor = flavor_to_struct(flavor)
if not flavor and parent_layer:
Expand Down
Loading

0 comments on commit 8aad22d

Please sign in to comment.