Skip to content

Commit

Permalink
Make the check for set_cfg_modifiers more repo friendly
Browse files Browse the repository at this point in the history
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 <module>
             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
  • Loading branch information
chatura-atapattu authored and facebook-github-bot committed Oct 31, 2024
1 parent f97b151 commit 552be02
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion prelude/cfg/modifier/set_cfg_modifiers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down

0 comments on commit 552be02

Please sign in to comment.