-
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] define a transition that completely strips all target…
… platform configuration Summary: Similar to D64136720, but take it even further and strip *all* target platform configuration. This is useful for rules that we know will always be 100% identical (eg `rpm` snapshot targets), but is dangerous for almost any other use case. Test Plan: ``` ❯ buck2 test fbcode//antlir/antlir2/cfg/strip_configuration/... Buck UI: https://www.internalfb.com/buck2/0b9cb2fa-90b5-431f-b467-896aab5ed8d1 Test UI: https://www.internalfb.com/intern/testinfra/testrun/2533275057090435 Tests finished: Pass 2. Fail 0. Fatal 0. Skip 0. Build failure 0 ``` Reviewed By: doon Differential Revision: D68527501 fbshipit-source-id: 9e69f7f1508765c3bfb1875b316950013ff119b4
- Loading branch information
1 parent
05176e0
commit 1c5b7c1
Showing
4 changed files
with
70 additions
and
68 deletions.
There are no files selected for viewing
51 changes: 0 additions & 51 deletions
51
antlir/antlir2/cfg/strip_antlir_config/strip_antlir_config.bzl
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
antlir/antlir2/cfg/strip_configuration/strip_configuration.bzl
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,52 @@ | ||
# 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. | ||
|
||
# WARNING: THAR BE DRAGONS | ||
# DO NOT USE THIS UNLESS YOU *REALLY* KNOW WHAT YOU ARE DOING. | ||
# | ||
# Define a transition that strips *ALL* platform configuration, which can be | ||
# used to reduce some duplicate actions where we know that certain rules will | ||
# never use `select`-ed attrs based on the target platform (exec platform | ||
# configuration is still preserved). | ||
# | ||
# This works because buck2 caches artifacts based on the hash of the *entire* | ||
# target platform configuration and does not know what parts are actually used. | ||
# | ||
# This is useful almost exclusively for antlir2 rules that exist very low in the | ||
# dependency chain where leaf rules will have often applied their own | ||
# configuration that we know will be irrelevant - prime example is the `rpm` | ||
# snapshot rules - the output of that rule is always 100% identical no matter | ||
# what the platform configuration may be, so that work should be shared. | ||
def _strip_configuration_transition_impl( | ||
platform: PlatformInfo, # @unused | ||
refs: struct) -> PlatformInfo: # @unused | ||
return PlatformInfo( | ||
label = "<stripped>", | ||
configuration = ConfigurationInfo(constraints = {}, values = {}), | ||
) | ||
|
||
_strip_configuration_transition = transition( | ||
impl = _strip_configuration_transition_impl, | ||
refs = {}, | ||
) | ||
|
||
def _strip_configuration_impl(ctx: AnalysisContext) -> list[Provider]: | ||
if ctx.label.package not in [ | ||
"antlir/antlir2/cfg/strip_configuration/tests", | ||
# @oss-disable | ||
]: | ||
fail(""" | ||
target is in {} which is not an allowed package. | ||
You MUST talk to twimage to get an exception to this rule | ||
""".format(ctx.label.package)) | ||
return ctx.attrs.actual.providers | ||
|
||
strip_configuration_alias = rule( | ||
impl = _strip_configuration_impl, | ||
attrs = { | ||
"actual": attrs.transition_dep(cfg = _strip_configuration_transition), | ||
"labels": attrs.list(attrs.string(), default = []), | ||
}, | ||
) |
23 changes: 12 additions & 11 deletions
23
...ntlir2/cfg/strip_antlir_config/tests/BUCK → ...ntlir2/cfg/strip_configuration/tests/BUCK
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