Skip to content

Commit

Permalink
Avoid calling cfg constructor in nested cells
Browse files Browse the repository at this point in the history
Summary:
PACKAGE values aren't shared across cells, but we can use
get_root_config() and get_config() to determine if we are in the root cell or
not.

Reviewed By: bigfootjon

Differential Revision: D64993387

fbshipit-source-id: 240929d4bc5f87ea7e8ce1460821e3243323da6a
  • Loading branch information
ckwalsh authored and facebook-github-bot committed Oct 28, 2024
1 parent 327b466 commit 19c8296
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 4 additions & 1 deletion shim/PACKAGE
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.

load(":cfg.bzl", "get_shim_modifiers")
load(":cfg.bzl", "SHIM_ALIASES", "set_cfg_constructor", "get_shim_modifiers")
load("@prelude//cfg/modifier:set_cfg_modifiers.bzl", "set_cfg_modifiers")

# Activate cfg modifiers from CLI / PACKAGE / targets
set_cfg_constructor(SHIM_ALIASES)

modifiers = get_shim_modifiers()
set_cfg_modifiers(modifiers)
8 changes: 3 additions & 5 deletions shim/cfg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ SHIM_ALIASES = {
"ubuntu": "shim//os/linux/distro/constraints:ubuntu",
}

CFG_CONSTRUCTOR_INITIALIZED_KEY = "buck.cfg_constructor_initialized"

def set_cfg_constructor(aliases = dict()):
if not read_parent_package_value(CFG_CONSTRUCTOR_INITIALIZED_KEY):
project_root_cell = read_root_config("cell_aliases", "root")
current_root_cell = read_config("cell_aliases", "root")
if project_root_cell == current_root_cell:
native.set_cfg_constructor(
stage0 = cfg_constructor_pre_constraint_analysis,
stage1 = cfg_constructor_post_constraint_analysis,
Expand All @@ -25,8 +25,6 @@ def set_cfg_constructor(aliases = dict()):
extra_data = struct(),
)

write_package_value(CFG_CONSTRUCTOR_INITIALIZED_KEY, True)

def get_shim_modifiers():
modifiers = []

Expand Down

0 comments on commit 19c8296

Please sign in to comment.