From 9d0fb924ecfdd0410a59c748a81e3baec109727c Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Mon, 28 Oct 2024 12:58:51 -0700 Subject: [PATCH] Avoid calling cfg constructor in nested cells 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 --- shim/PACKAGE | 5 ++++- shim/cfg.bzl | 8 +++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/shim/PACKAGE b/shim/PACKAGE index ea35fecd141..782e6f913ff 100644 --- a/shim/PACKAGE +++ b/shim/PACKAGE @@ -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) diff --git a/shim/cfg.bzl b/shim/cfg.bzl index 9c630dfa062..9b63ae110f2 100644 --- a/shim/cfg.bzl +++ b/shim/cfg.bzl @@ -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, @@ -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 = []