From 183c5f61333bfbfb9d6be306c0bc1429b746c483 Mon Sep 17 00:00:00 2001 From: Vinnie Magro Date: Tue, 31 Oct 2023 11:14:51 -0700 Subject: [PATCH] [antlir2][buck] add constraints for rou MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- antlir/antlir2/bzl/compat.bzl | 13 ++++++++++ antlir/antlir2/bzl/configured_alias.bzl | 17 +++++++++---- antlir/antlir2/bzl/image/cfg.bzl | 34 ++++++++++++++++++++----- antlir/antlir2/bzl/image/layer.bzl | 6 +++++ antlir/antlir2/bzl/package/btrfs.bzl | 6 ++--- antlir/antlir2/bzl/package/cfg.bzl | 9 ++++--- antlir/antlir2/os/cfg.bzl | 3 +++ antlir/antlir2/test_images/cfg/os/BUCK | 10 +++++++- 8 files changed, 78 insertions(+), 20 deletions(-) diff --git a/antlir/antlir2/bzl/compat.bzl b/antlir/antlir2/bzl/compat.bzl index 11a3e0c2760..96c4b3370c6 100644 --- a/antlir/antlir2/bzl/compat.bzl +++ b/antlir/antlir2/bzl/compat.bzl @@ -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, ) diff --git a/antlir/antlir2/bzl/configured_alias.bzl b/antlir/antlir2/bzl/configured_alias.bzl index e6852482d1a..2247497255c 100644 --- a/antlir/antlir2/bzl/configured_alias.bzl +++ b/antlir/antlir2/bzl/configured_alias.bzl @@ -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") @@ -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, @@ -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( @@ -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]: @@ -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) diff --git a/antlir/antlir2/bzl/image/cfg.bzl b/antlir/antlir2/bzl/image/cfg.bzl index ff31267e336..054cdd32430 100644 --- a/antlir/antlir2/bzl/image/cfg.bzl +++ b/antlir/antlir2/bzl/image/cfg.bzl @@ -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") @@ -30,7 +30,10 @@ 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 { @@ -38,9 +41,24 @@ def attrs_selected_by_cfg(): "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 @@ -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 @@ -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 @@ -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 }, ) diff --git a/antlir/antlir2/bzl/image/layer.bzl b/antlir/antlir2/bzl/image/layer.bzl index 54853979833..a56f506327b 100644 --- a/antlir/antlir2/bzl/image/layer.bzl +++ b/antlir/antlir2/bzl/image/layer.bzl @@ -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, @@ -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() @@ -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 [] @@ -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 diff --git a/antlir/antlir2/bzl/package/btrfs.bzl b/antlir/antlir2/bzl/package/btrfs.bzl index a2941737b8c..4ee7f07ce89 100644 --- a/antlir/antlir2/bzl/package/btrfs.bzl +++ b/antlir/antlir2/bzl/package/btrfs.bzl @@ -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") @@ -83,9 +83,7 @@ _btrfs = rule( ), default = None, ), - # used by transition - "target_arch": attrs.option(attrs.string(), default = None), - }, + } | cfg_attrs(), cfg = package_cfg, ) diff --git a/antlir/antlir2/bzl/package/cfg.bzl b/antlir/antlir2/bzl/package/cfg.bzl index cff7fad217a..4743332c807 100644 --- a/antlir/antlir2/bzl/package/cfg.bzl +++ b/antlir/antlir2/bzl/package/cfg.bzl @@ -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]), @@ -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( @@ -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 diff --git a/antlir/antlir2/os/cfg.bzl b/antlir/antlir2/os/cfg.bzl index fd45b8515c5..27f03d8194e 100644 --- a/antlir/antlir2/os/cfg.bzl +++ b/antlir/antlir2/os/cfg.bzl @@ -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 = { @@ -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 diff --git a/antlir/antlir2/test_images/cfg/os/BUCK b/antlir/antlir2/test_images/cfg/os/BUCK index 28a9acc83ca..4f92948c392 100644 --- a/antlir/antlir2/test_images/cfg/os/BUCK +++ b/antlir/antlir2/test_images/cfg/os/BUCK @@ -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"], @@ -21,7 +29,7 @@ image.layer( "coreutils", "rpm", # @oss-disable - "test-rpm-root", + test_rpm_root, ]), write_os("/root.os"), ],