-
Notifications
You must be signed in to change notification settings - Fork 19
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. NOTE: this is a re-submit of D49553996 that includes some fixes for evaluation on buck1 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 ``` buck1 evals: ``` ❯ buck run fbcode//antlir/facebook/buck1:test-buck1-graph -- -x -v 126 passed in 129.32s (0:02:09) ``` Reviewed By: epilatow Differential Revision: D50603790 fbshipit-source-id: 2dcf0ec10231cf78cd70fbaa387049b66104b2c1
- Loading branch information
1 parent
5b6b44b
commit 82e52aa
Showing
10 changed files
with
378 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,34 @@ | ||
# 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. | ||
|
||
_DEFAULT_OS_KEY = "antlir2.default_os" | ||
_ALL_IMAGES_IN_PACKAGE_USE_DEFAULT_OS_KEY = "antlir2.all_images_in_package_use_default_os" | ||
|
||
def _write_package_value(*args, **kwargs): | ||
write_package_value = getattr(native, "write_package_value", None) | ||
if write_package_value != None: | ||
write_package_value(*args, **kwargs) | ||
|
||
def _read_package_value(*args, **kwargs): | ||
read_package_value = getattr(native, "read_package_value", None) | ||
if read_package_value != None: | ||
return read_package_value(*args, **kwargs) | ||
return None | ||
|
||
def set_default_os_for_package(*, default_os: str): | ||
_write_package_value(_DEFAULT_OS_KEY, default_os, overwrite = True) | ||
|
||
def get_default_os_for_package() -> str: | ||
return _read_package_value(_DEFAULT_OS_KEY) | ||
|
||
def all_images_in_package_use_default_os(yes: bool = True): | ||
_write_package_value( | ||
_ALL_IMAGES_IN_PACKAGE_USE_DEFAULT_OS_KEY, | ||
yes, | ||
overwrite = True, | ||
) | ||
|
||
def should_all_images_in_package_use_default_os() -> bool: | ||
return _read_package_value(_ALL_IMAGES_IN_PACKAGE_USE_DEFAULT_OS_KEY) 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", | ||
] | ||
] |
Oops, something went wrong.