Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dicts passed to set_cfg_constructor stage0 callback should not be sorted #780

Open
thetimmorland opened this issue Sep 20, 2024 · 0 comments

Comments

@thetimmorland
Copy link

thetimmorland commented Sep 20, 2024

The commands below show that the dict passed to the package_modifiers argument of the set_cfg_constructor stage0 was sorted. This reordering is a problem because it causes cfg.conditional modifiers to resolve in an unexpected manner.

For example: I would expect the below modifier to leave the configuration unchanged if "cfg//c:y" and "cfg//a:y" were both set, but the sorting behaviour breaks this.

set_cfg_modifers(modifiers = [
  modifiers.conditional({
    "cfg//c:y": None,
    "cfg//b:y": None,
    "cfg//a:y": "cfg//ftr_foo:y",
  })
])

Minimal example

timorland-local@DUS-MXL3312NDR:/tmp/modifiers-problem$ git format-patch -1 --stdout
 .buckconfig |  2 ++
 .buckroot   |  0
 .gitignore  |  1 +
 BUCK        |  3 +++
 PACKAGE     | 18 ++++++++++++++++++
 defs.bzl    | 28 ++++++++++++++++++++++++++++
 6 files changed, 52 insertions(+)
 create mode 100644 .buckconfig
 create mode 100644 .buckroot
 create mode 100644 .gitignore
 create mode 100644 BUCK
 create mode 100644 PACKAGE
 create mode 100644 defs.bzl

diff --git a/.buckconfig b/.buckconfig
new file mode 100644
index 0000000..82ff4e5
--- /dev/null
+++ b/.buckconfig
@@ -0,0 +1,2 @@
+[cells]
+  root = .
diff --git a/.buckroot b/.buckroot
new file mode 100644
index 0000000..e69de29
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d60c5d2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+buck-out
diff --git a/BUCK b/BUCK
new file mode 100644
index 0000000..3cf47b4
--- /dev/null
+++ b/BUCK
@@ -0,0 +1,3 @@
+load(":defs.bzl", "nothing")
+
+nothing(name = "top")
diff --git a/PACKAGE b/PACKAGE
new file mode 100644
index 0000000..975e8d0
--- /dev/null
+++ b/PACKAGE
@@ -0,0 +1,18 @@
+load(":defs.bzl", "stage0", "stage1")
+
+set_cfg_constructor(
+    stage0 = stage0,
+    stage1 = stage1,
+    key = "buck.modifiers",
+    aliases = struct(),
+)
+
+write_package_value(
+    "buck.modifiers",
+    [
+        {
+            "b": "This should be first",
+            "a": "This should be second",
+        },
+    ],
+)
diff --git a/defs.bzl b/defs.bzl
new file mode 100644
index 0000000..b1bf623
--- /dev/null
+++ b/defs.bzl
@@ -0,0 +1,28 @@
+nothing = rule(
+    impl = lambda ctx: [DefaultInfo()],
+    attrs = {},
+)
+
+def stage0(*, legacy_platform, package_modifiers, target_modifiers, cli_modifiers, rule_name, aliases, **_kwargs):
+    print(
+        "stage0_args =",
+        pstr({
+            "legacy_platform": legacy_platform,
+            "package_modifiers": package_modifiers,
+            "target_modifiers": target_modifiers,
+            "cli_modifiers": cli_modifiers,
+            "rule_name": rule_name,
+            "aliases": aliases,
+        }),
+    )
+
+    return ([], None)
+
+def stage1(*, refs, params) -> PlatformInfo:
+    return PlatformInfo(
+        label = "<empty>",
+        configuration = ConfigurationInfo(
+            constraints = {},
+            values = {},
+        ),
+    )
--
2.45.GIT

timorland-local@DUS-MXL3312NDR:/tmp/modifiers-problem$ buck2 build :
Could not connect to buck2 daemon (buck2 daemon is not running), starting a new one...
Connected to new buck2 daemon.
stage0_args = {
  "legacy_platform": None,
  "package_modifiers": [ {
    "a": "This should be second",
    "b": "This should be first"
  } ],
  "target_modifiers": None,
  "cli_modifiers": [],
  "rule_name": "nothing",
  "aliases": struct()
}
Build ID: 1db24b5a-121c-4d48-ac22-bfb6d3783b2d
Jobs completed: 5. Time elapsed: 0.0s.
BUILD SUCCEEDED
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant