From 552be02c9908b4d160e9fd4afd3d3a701f7c4052 Mon Sep 17 00:00:00 2001 From: Chatura Atapattu Date: Thu, 31 Oct 2024 15:35:25 -0700 Subject: [PATCH] Make the check for set_cfg_modifiers more repo friendly Summary: In other repos, this file is not guaranteed to be at `fbcode/buck2/cfg/experimental/set_cfg_modifiers.bzl`. For example, in WAIPhone, it is at `tools/buck2/fbcode/buck2/cfg/experimental/set_cfg_modifiers.bzl` and this fails the check. ``` 5: Traceback (most recent call last): * tools/buck2/prelude/PACKAGE:15, in set_cfg_modifiers(cfg_modifiers = [ * tools/buck2/fbcode/buck2/cfg/experimental/set_cfg_modifiers.bzl:34, in set_cfg_modifiers _set_cfg_modifiers(cfg_modifiers, extra_cfg_modifiers_per_rule) * tools/buck2/prelude/cfg/modifier/set_cfg_modifiers.bzl:42, in set_cfg_modifiers fail("set_cfg_modifiers is only allowed to be used from a PACKAGE or BUCK_TRE... error: fail: set_cfg_modifiers is only allowed to be used from a PACKAGE or BUCK_TREE file, not a bzl file. --> tools/buck2/prelude/cfg/modifier/set_cfg_modifiers.bzl:42:13 | 42 | fail("set_cfg_modifiers is only allowed to be used from a PACKAGE or BUCK_TREE file, not a bzl file.") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ``` Since this file must be in the `fbcode` cell (due to loads elsewhere), assume that the file path ends with the path. Reviewed By: JakobDegen Differential Revision: D65290874 fbshipit-source-id: 3dd64f27989a9789b30ae56a6492d1571c4ce9c0 --- prelude/cfg/modifier/set_cfg_modifiers.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prelude/cfg/modifier/set_cfg_modifiers.bzl b/prelude/cfg/modifier/set_cfg_modifiers.bzl index 453f4a1d6aa93..45063df1d1cca 100644 --- a/prelude/cfg/modifier/set_cfg_modifiers.bzl +++ b/prelude/cfg/modifier/set_cfg_modifiers.bzl @@ -36,7 +36,7 @@ def set_cfg_modifiers( if not _is_buck_tree_file(frame1.module_path): # Now check the old bzl file for `set_cfg_modifiers` in case it is invoked through that one. frame2 = call_stack_frame(2) - if not (frame2 and frame1.module_path == "fbcode/buck2/cfg/experimental/set_cfg_modifiers.bzl" and _is_buck_tree_file(frame2.module_path)): + if not (frame2 and frame1.module_path.endswith("fbcode/buck2/cfg/experimental/set_cfg_modifiers.bzl") and _is_buck_tree_file(frame2.module_path)): fail("set_cfg_modifiers is only allowed to be used from a PACKAGE or BUCK_TREE file, not a bzl file.") cfg_modifiers = cfg_modifiers or []