-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[antlir2][buck] new configuration settings for flavor/os
Summary: Add some buck2 configuration constraints for OS version. This diff by itself enables `select()` based on these constraints, but does not yet plumb it through the rest of the stack to make it consistent with `flavor`. See the next diff for that implementation, more Summary details and staticdocs. Test Plan: ``` ❯ buck2 test fbcode//antlir/antlir2/test_images/cfg/os: Buck UI: https://www.internalfb.com/buck2/ce167cd0-920b-4406-9ed1-49b6a64132cc Test UI: https://www.internalfb.com/intern/testinfra/testrun/8725724465341791 Network: Up: 0B Down: 101MiB (reSessionID-3ba4921a-dc3f-4354-82d8-12b813ff7e5a) Jobs completed: 604596. Time elapsed: 39.6s. Tests finished: Pass 18. Fail 0. Fatal 0. Skip 0. Build failure 0 ``` Reviewed By: epilatow Differential Revision: D49553996 fbshipit-source-id: c8d219a3e7897d8cecafc8b822ec7a001f28dff6
- Loading branch information
1 parent
f011fb8
commit b93764a
Showing
10 changed files
with
370 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
load("@prelude//:rules.bzl", "constraint_setting") | ||
load(":defs.bzl", "os_version") | ||
|
||
constraint_setting( | ||
name = "os", | ||
visibility = ["PUBLIC"], | ||
) | ||
|
||
os_version( | ||
name = "none", | ||
family = "//antlir/antlir2/os/family:none", | ||
) | ||
|
||
os_version( | ||
name = "centos8", | ||
family = "//antlir/antlir2/os/family:centos", | ||
) | ||
|
||
os_version( | ||
name = "centos9", | ||
family = "//antlir/antlir2/os/family:centos", | ||
) | ||
|
||
os_version( | ||
name = "eln", | ||
family = "//antlir/antlir2/os/family:fedora", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
load("@prelude//:rules.bzl", "config_setting", "constraint_value") | ||
|
||
OsVersionInfo = provider(fields = [ | ||
"constraint", | ||
"family", | ||
]) | ||
|
||
def _os_version_rule_impl(ctx: AnalysisContext) -> list[Provider]: | ||
return [ | ||
DefaultInfo(), | ||
ctx.attrs.config_setting[ConfigurationInfo], | ||
OsVersionInfo( | ||
constraint = ctx.attrs.constraint, | ||
family = ctx.attrs.family, | ||
), | ||
] | ||
|
||
_os_version_rule = rule( | ||
impl = _os_version_rule_impl, | ||
attrs = { | ||
"config_setting": attrs.dep(providers = [ConfigurationInfo]), | ||
"constraint": attrs.dep(providers = [ConstraintValueInfo]), | ||
"family": attrs.dep(providers = [ConstraintValueInfo]), | ||
}, | ||
) | ||
|
||
def os_version( | ||
name: str, | ||
family: str): | ||
constraint_value( | ||
name = name + ".constraint", | ||
constraint_setting = "//antlir/antlir2/os:os", | ||
visibility = [":" + name], | ||
) | ||
config_setting( | ||
name = name + ".config", | ||
constraint_values = [ | ||
":{}.constraint".format(name), | ||
family, | ||
], | ||
visibility = ["PUBLIC"], | ||
) | ||
_os_version_rule( | ||
name = name, | ||
family = family, | ||
constraint = ":{}.constraint".format(name), | ||
config_setting = ":{}.config".format(name), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
load("@prelude//:rules.bzl", "constraint_setting", "constraint_value") | ||
|
||
constraint_setting( | ||
name = "family", | ||
visibility = ["PUBLIC"], | ||
) | ||
|
||
constraint_value( | ||
name = "none", | ||
constraint_setting = ":family", | ||
visibility = ["PUBLIC"], | ||
) | ||
|
||
# Any version of CentOS. | ||
constraint_value( | ||
name = "centos", | ||
constraint_setting = ":family", | ||
visibility = ["PUBLIC"], | ||
) | ||
|
||
constraint_value( | ||
name = "fedora", | ||
constraint_setting = ":family", | ||
visibility = ["PUBLIC"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
def set_default_os_for_package(*, default_os: str): | ||
write_package_value( | ||
"antlir2.default_os", | ||
default_os, | ||
overwrite = True, | ||
) | ||
|
||
def get_default_os_for_package() -> str: | ||
return read_package_value("antlir2.default_os") | ||
|
||
def all_images_in_package_use_default_os(yes: bool = True): | ||
write_package_value( | ||
"antlir2.all_images_in_package_use_default_os", | ||
yes, | ||
overwrite = True, | ||
) | ||
|
||
def should_all_images_in_package_use_default_os() -> bool: | ||
return read_package_value( | ||
"antlir2.all_images_in_package_use_default_os", | ||
) or False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature") | ||
load("//antlir/antlir2/bzl/image:defs.bzl", "image") | ||
load("//antlir/antlir2/testing:image_test.bzl", "image_rust_test") | ||
load(":defs.bzl", "write_os") | ||
|
||
oncall("twimage") | ||
|
||
image.layer( | ||
name = "root", | ||
features = [ | ||
feature.rpms_install(rpms = [ | ||
"bash", | ||
"coreutils", | ||
# @oss-disable | ||
]), | ||
write_os("/root.os"), | ||
], | ||
flavor = "//antlir/antlir2/test_images:test-image-flavor", | ||
) | ||
|
||
image.layer( | ||
name = "intermediate", | ||
features = [ | ||
write_os("/intermediate.os"), | ||
], | ||
parent_layer = ":root", | ||
) | ||
|
||
image.layer( | ||
name = "leaf.generic", | ||
features = [ | ||
write_os("/leaf.os"), | ||
], | ||
parent_layer = ":intermediate", | ||
) | ||
|
||
[ | ||
[ | ||
image.layer( | ||
name = "leaf." + os, | ||
default_os = os, | ||
features = [ | ||
write_os("/leaf.os"), | ||
], | ||
parent_layer = ":intermediate", | ||
), | ||
image_rust_test( | ||
name = "test-leaf." + os, | ||
srcs = ["test.rs"], | ||
crate = "test_leaf_" + os, | ||
crate_root = "test.rs", | ||
env = { | ||
"OS": os, | ||
}, | ||
layer = ":leaf." + os, | ||
), | ||
image_rust_test( | ||
name = "test-leaf.generic." + os, | ||
srcs = ["test.rs"], | ||
crate = "test_leaf_generic_" + os, | ||
crate_root = "test.rs", | ||
default_os = os, | ||
env = { | ||
"OS": os, | ||
}, | ||
layer = ":leaf.generic", | ||
), | ||
] | ||
for os in [ | ||
"centos8", | ||
"centos9", | ||
"eln", | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature") | ||
|
||
def write_os(path: str): | ||
return feature.install_text( | ||
dst = path, | ||
text = select({ | ||
"//antlir/antlir2/os:centos8": "centos8", | ||
"//antlir/antlir2/os:centos9": "centos9", | ||
"//antlir/antlir2/os:eln": "eln", | ||
}), | ||
) |
Oops, something went wrong.