Skip to content

Commit

Permalink
[antlir2][buck] add constraints for rou
Browse files Browse the repository at this point in the history
Summary:
Instead of just the OS version, we also have ROU internally that updates those
OS versions in a rolling manner. Apply the same treatment to ROU.

Test Plan:
```
❯ buck2 test fbcode//antlir/antlir2/test_images/cfg/os:
Buck UI: https://www.internalfb.com/buck2/5895be5d-f4c9-4c3d-9158-c556ba9199ed
Test UI: https://www.internalfb.com/intern/testinfra/testrun/12666373954568127
Tests finished: Pass 48. Fail 0. Fatal 0. Skip 0. Build failure 0

❯ buck test fbcode//antlir/antlir2/test_images/cfg/facebook/rou:unittest-{centos{8,9},eln}
❯ buck2 test fbcode//antlir/antlir2/test_images/cfg/facebook/rou:unittest-centos8 fbcode//antlir/antlir2/test_images/cfg/facebook/rou:unittest-centos9 fbcode//antlir/antlir2/test_images/cfg/facebook/rou:unittest-eln
Buck UI: https://www.internalfb.com/buck2/5da69383-97f4-43ce-95cb-0853f2e8e4e8
Test UI: https://www.internalfb.com/intern/testinfra/testrun/9570149216939393
Jobs completed: 18. Time elapsed: 2.1s.
Tests finished: Pass 3. Fail 0. Fatal 0. Skip 0. Build failure 0
```

Reviewed By: epilatow

Differential Revision: D49350914

fbshipit-source-id: a189492caa58c35b4f45a1790ac19fa6234cfc14
  • Loading branch information
vmagro authored and facebook-github-bot committed Oct 31, 2023
1 parent bc7c45a commit 183c5f6
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 20 deletions.
13 changes: 13 additions & 0 deletions antlir/antlir2/bzl/compat.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,20 @@ def _flavor_config_override_to_versionlock_extend(flavor_config_override):
)
return versionlock_extend

def _default_rou_from_antlir1_flavor(flavor: str | typing.Any) -> str:
if not types.is_string(flavor):
flavor = flavor.unaliased_name
parts = flavor.split("-")
if len(parts) >= 2:
if parts[-2] == "rou":
phase = parts[-1]
if phase == "testing" or phase == "untested":
return "test"
return phase
return "stable"

compat = struct(
from_antlir1_flavor = _from_antlir1_flavor,
flavor_config_override_to_versionlock_extend = _flavor_config_override_to_versionlock_extend,
default_rou_from_antlir1_flavor = _default_rou_from_antlir1_flavor,
)
17 changes: 12 additions & 5 deletions antlir/antlir2/bzl/configured_alias.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# 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/image/facebook:fb_cfg.bzl", "fbcode_platform_refs", "transition_fbcode_platform")
# @oss-disable
load("//antlir/antlir2/os:cfg.bzl", "os_transition", "os_transition_refs")
load("//antlir/bzl:build_defs.bzl", "is_facebook")

Expand All @@ -14,8 +14,6 @@ def _transition_impl(platform: PlatformInfo, refs: struct, attrs: struct) -> Pla
if attrs.target_arch:
target_arch = getattr(refs, "arch." + attrs.target_arch)[ConstraintValueInfo]
constraints[target_arch.setting.label] = target_arch
if is_facebook:
constraints = transition_fbcode_platform(refs, attrs, constraints)

constraints = os_transition(
default_os = attrs.default_os,
Expand All @@ -24,6 +22,9 @@ def _transition_impl(platform: PlatformInfo, refs: struct, attrs: struct) -> Pla
overwrite = True,
)

if is_facebook:
constraints = fb_transition(refs, attrs, constraints)

return PlatformInfo(
label = platform.label,
configuration = ConfigurationInfo(
Expand All @@ -41,7 +42,10 @@ _transition = transition(
# @oss-disable
# @oss-enable {}
) | os_transition_refs(),
attrs = ["default_os", "target_arch"],
attrs = ["default_os", "target_arch"] + (
# @oss-disable
[] # @oss-enable
),
)

def _configured_alias_impl(ctx: AnalysisContext) -> list[Provider]:
Expand All @@ -57,7 +61,10 @@ _configured_alias = rule(
default = None,
doc = "Build for a specific target arch without using `buck -c`",
),
},
} | (
# @oss-disable
# @oss-enable {}
),
)

antlir2_configured_alias = rule_with_default_target_platform(_configured_alias)
34 changes: 27 additions & 7 deletions antlir/antlir2/bzl/image/cfg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Currently this supports reconfiguring the target cpu architecture.
"""

load("//antlir/antlir2/bzl:types.bzl", "FlavorInfo")
load("//antlir/antlir2/bzl/image/facebook:fb_cfg.bzl", "fbcode_platform_refs", "transition_fbcode_platform")
# @oss-disable
load("//antlir/antlir2/os:cfg.bzl", "os_transition", "os_transition_refs", "remove_os_constraints")
load("//antlir/bzl:build_defs.bzl", "is_facebook")

Expand All @@ -30,17 +30,35 @@ def cfg_attrs():
default = None,
doc = "Build this image for a specific target arch without using `buck -c`",
),
}
} | (
# @oss-disable
# @oss-enable {}
)

def attrs_selected_by_cfg():
return {
# only attrs.option because it cannot be set on build appliance layers
"flavor": attrs.option(
attrs.dep(providers = [FlavorInfo]),
default = select({
"//antlir/antlir2/os:centos8": "//antlir/antlir2/facebook/flavor/centos8:centos8",
"//antlir/antlir2/os:centos9": "//antlir/antlir2/facebook/flavor/centos9:centos9",
"//antlir/antlir2/os:eln": "//antlir/antlir2/facebook/flavor/eln:eln",
"//antlir/antlir2/os:centos8": select({
"//antlir/antlir2/os/facebook:rou-preparation": "//antlir/antlir2/facebook/flavor/centos8-rou-preparation:centos8-rou-preparation",
"//antlir/antlir2/os/facebook:rou-rolling": "//antlir/antlir2/facebook/flavor/centos8-rou-rolling:centos8-rou-rolling",
"//antlir/antlir2/os/facebook:rou-stable": "//antlir/antlir2/facebook/flavor/centos8:centos8",
"//antlir/antlir2/os/facebook:rou-test": "//antlir/antlir2/facebook/flavor/centos8-rou-untested:centos8-rou-untested",
}),
"//antlir/antlir2/os:centos9": select({
"//antlir/antlir2/os/facebook:rou-preparation": "//antlir/antlir2/facebook/flavor/centos9-rou-preparation:centos9-rou-preparation",
"//antlir/antlir2/os/facebook:rou-rolling": "//antlir/antlir2/facebook/flavor/centos9-rou-rolling:centos9-rou-rolling",
"//antlir/antlir2/os/facebook:rou-stable": "//antlir/antlir2/facebook/flavor/centos9:centos9",
"//antlir/antlir2/os/facebook:rou-test": "//antlir/antlir2/facebook/flavor/centos9-rou-untested:centos9-rou-untested",
}),
"//antlir/antlir2/os:eln": select({
"//antlir/antlir2/os/facebook:rou-preparation": "//antlir/antlir2/facebook/flavor/eln-rou-preparation:eln-rou-preparation",
"//antlir/antlir2/os/facebook:rou-rolling": "//antlir/antlir2/facebook/flavor/eln-rou-rolling:eln-rou-rolling",
"//antlir/antlir2/os/facebook:rou-stable": "//antlir/antlir2/facebook/flavor/eln:eln",
"//antlir/antlir2/os/facebook:rou-test": "//antlir/antlir2/facebook/flavor/eln-rou-untested:eln-rou-untested",
}),
"//antlir/antlir2/os:none": "//antlir/antlir2/flavor:none",
# TODO: in D49383768 this will be disallowed so that we can
# guarantee that we'll never end up building a layer without
Expand All @@ -56,8 +74,6 @@ def _impl(platform: PlatformInfo, refs: struct, attrs: struct) -> PlatformInfo:
if attrs.target_arch:
target_arch = getattr(refs, "arch." + attrs.target_arch)[ConstraintValueInfo]
constraints[target_arch.setting.label] = target_arch
if is_facebook:
constraints = transition_fbcode_platform(refs, attrs, constraints)

if attrs.default_os:
# The rule transition to set the default antlir2 OS only happens if the
Expand All @@ -83,6 +99,9 @@ def _impl(platform: PlatformInfo, refs: struct, attrs: struct) -> PlatformInfo:
if attrs.antlir_internal_build_appliance:
constraints = remove_os_constraints(refs = refs, constraints = constraints)

if is_facebook:
constraints = fb_transition(refs, attrs, constraints)

label = platform.label

# if we made any changes, change the label
Expand Down Expand Up @@ -134,5 +153,6 @@ remove_os_constraint = transition(
"os_constraint": "//antlir/antlir2/os:os",
"os_family_constraint": "//antlir/antlir2/os/family:family",
"package_manager_constraint": "//antlir/antlir2/os/package_manager:package_manager",
# @oss-disable
},
)
6 changes: 6 additions & 0 deletions antlir/antlir2/bzl/image/layer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ def layer(
default_os: str | None = None,
# TODO: remove this flag when all images are using this new mechanism
use_default_os_from_package: bool | None = None,
default_rou: str | None = None,
# We'll implicitly forward some users to antlir2, so any hacks for them
# should be confined behind this flag
implicit_antlir2: bool = False,
Expand All @@ -554,6 +555,8 @@ def layer(
if implicit_antlir2:
flavor = kwargs.pop("flavor", None)
kwargs["flavor"] = compat.from_antlir1_flavor(flavor) if flavor else None
if is_facebook:
default_rou = compat.default_rou_from_antlir1_flavor(flavor) if flavor else None

if use_default_os_from_package == None:
use_default_os_from_package = should_all_images_in_package_use_default_os()
Expand All @@ -563,6 +566,8 @@ def layer(
# TODO(vmagro): codemod existing callsites to use default_os directly
if "flavor" in kwargs and default_os:
fail("default_os= is preferred, stop setting flavor=")
if kwargs.get("flavor", None) and not default_rou:
default_rou = compat.default_rou_from_antlir1_flavor(kwargs["flavor"])

kwargs.update({"_feature_" + key: val for key, val in feature_attrs(features).items()})
compatible_with = kwargs.pop("compatible_with", []) or []
Expand Down Expand Up @@ -596,6 +601,7 @@ def layer(
return layer_rule(
name = name,
default_os = default_os,
default_rou = default_rou,
visibility = get_visibility(visibility),
_implicit_image_test = "//antlir/antlir2/testing/implicit_image_test:implicit_image_test",
**kwargs
Expand Down
6 changes: 2 additions & 4 deletions antlir/antlir2/bzl/package/btrfs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

load("//antlir/antlir2/bzl:platform.bzl", "rule_with_default_target_platform")
load("//antlir/antlir2/bzl:types.bzl", "LayerInfo")
load("//antlir/antlir2/bzl/package:cfg.bzl", "package_cfg")
load("//antlir/antlir2/bzl/package:cfg.bzl", "cfg_attrs", "package_cfg")
load(":gpt.bzl", "GptPartitionSource")
load(":sendstream.bzl", "anon_v1_sendstream")

Expand Down Expand Up @@ -83,9 +83,7 @@ _btrfs = rule(
),
default = None,
),
# used by transition
"target_arch": attrs.option(attrs.string(), default = None),
},
} | cfg_attrs(),
cfg = package_cfg,
)

Expand Down
9 changes: 6 additions & 3 deletions antlir/antlir2/bzl/package/cfg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
# LICENSE file in the root directory of this source tree.

load("//antlir/antlir2/bzl:types.bzl", "LayerInfo")
load("//antlir/antlir2/bzl/image:cfg.bzl", "cfg_attrs")
load("//antlir/antlir2/bzl/image:cfg.bzl", _cfg_attrs = "cfg_attrs")
# @oss-disable
load("//antlir/antlir2/os:cfg.bzl", "os_transition", "os_transition_refs")
load("//antlir/bzl:build_defs.bzl", "is_facebook")

cfg_attrs = _cfg_attrs

# Let the layer be configured by the same configuration attrs in image.layer
layer_attrs = {
"layer": attrs.dep(providers = [LayerInfo]),
Expand All @@ -20,8 +22,6 @@ def _package_cfg_impl(platform: PlatformInfo, refs: struct, attrs: struct) -> Pl
if attrs.target_arch:
target_arch = getattr(refs, "arch." + attrs.target_arch)[ConstraintValueInfo]
constraints[target_arch.setting.label] = target_arch
if is_facebook:
constraints = transition_fbcode_platform(refs, attrs, constraints)

if attrs.default_os:
constraints = os_transition(
Expand All @@ -33,6 +33,9 @@ def _package_cfg_impl(platform: PlatformInfo, refs: struct, attrs: struct) -> Pl
overwrite = True,
)

if is_facebook:
constraints = fb_transition(refs, attrs, constraints)

label = platform.label

# if we made any changes, change the label
Expand Down
3 changes: 3 additions & 0 deletions antlir/antlir2/os/cfg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

load("//antlir/bzl:build_defs.bzl", "is_facebook")
load(":defs.bzl", "OsVersionInfo")

_OS_REFS = {
Expand Down Expand Up @@ -39,4 +40,6 @@ def remove_os_constraints(*, constraints, refs):
constraints.pop(refs.os_constraint[ConstraintSettingInfo].label, None)
constraints.pop(refs.os_family_constraint[ConstraintSettingInfo].label, None)
constraints.pop(refs.package_manager_constraint[ConstraintSettingInfo].label, None)
if is_facebook:
constraints.pop(refs.rou_constraint[ConstraintSettingInfo].label, None)
return constraints
10 changes: 9 additions & 1 deletion antlir/antlir2/test_images/cfg/os/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ 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/testing:image_test.bzl", "image_rust_test")
load("//antlir/bzl:build_defs.bzl", "is_facebook")
load("//antlir/rpm/dnf2buck:repo.bzl", "repo")
load("//antlir/rpm/dnf2buck:rpm.bzl", "rpm")
load(":defs.bzl", "write_os")

oncall("antlir")

# This single-constraint select is useful to ensure that we can select on an ROU
# and that the default of stable is actually configured and we don't need to
# rely on DEFAULT
test_rpm_root = select({
"//antlir/antlir2/os/facebook:rou-stable": "test-rpm-root",
}) if is_facebook else "test-rpm-root"

image.layer(
name = "root",
dnf_additional_repos = [":repo"],
Expand All @@ -21,7 +29,7 @@ image.layer(
"coreutils",
"rpm",
# @oss-disable
"test-rpm-root",
test_rpm_root,
]),
write_os("/root.os"),
],
Expand Down

0 comments on commit 183c5f6

Please sign in to comment.