From 27419e33dc8c48fb5ca6d97f5d6788f9aca2032f Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 26 Jan 2024 11:36:52 -0800 Subject: [PATCH] Fix inconsistent dep graph stubs in Bzlmod tests These cause failures when relying on `depGraph` containing `ModuleKey`s for all modules, which is the case in production. Work towards #20997 Closes #21037. PiperOrigin-RevId: 601822357 Change-Id: Ifcad9d7b73835491c1f1fca975e05834057a6825 --- .../bzlmod/BazelDepGraphFunctionTest.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelDepGraphFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelDepGraphFunctionTest.java index 38b058339926aa..31aacbcbe3da8d 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelDepGraphFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelDepGraphFunctionTest.java @@ -226,11 +226,13 @@ private static ModuleExtensionUsage createModuleExtensionUsage( @Test public void createValue_moduleExtensions() throws Exception { + ModuleKey rjeKey = createModuleKey("rules_jvm_external", "1.0"); + ModuleKey rpyKey = createModuleKey("rules_python", "2.0"); Module root = buildModule("root", "1.0") .setKey(ModuleKey.ROOT) - .addDep("rje", createModuleKey("rules_jvm_external", "1.0")) - .addDep("rpy", createModuleKey("rules_python", "2.0")) + .addDep("rje", rjeKey) + .addDep("rpy", rpyKey) .addExtensionUsage( createModuleExtensionUsage("@rje//:defs.bzl", "maven", "av", "autovalue")) .addExtensionUsage( @@ -240,7 +242,7 @@ public void createValue_moduleExtensions() throws Exception { Module dep = buildModule("dep", "2.0") .setKey(depKey) - .addDep("rules_python", createModuleKey("rules_python", "2.0")) + .addDep("rules_python", rpyKey) .addExtensionUsage( createModuleExtensionUsage("@rules_python//:defs.bzl", "pip", "np", "numpy")) .addExtensionUsage( @@ -248,7 +250,16 @@ public void createValue_moduleExtensions() throws Exception { .addExtensionUsage( createModuleExtensionUsage("//incredible:conflict.bzl", "myext", "twoext", "myext")) .build(); - ImmutableMap depGraph = ImmutableMap.of(ModuleKey.ROOT, root, depKey, dep); + ImmutableMap depGraph = + ImmutableMap.of( + ModuleKey.ROOT, + root, + depKey, + dep, + rjeKey, + buildModule("rules_jvm_external", "1.0").setKey(rjeKey).build(), + rpyKey, + buildModule("rules_python", "2.0").setKey(rpyKey).build()); ModuleExtensionId maven = ModuleExtensionId.create( @@ -326,6 +337,7 @@ public void createValue_moduleExtensions() throws Exception { public void useExtensionBadLabelFails() throws Exception { Module root = buildModule("module", "1.0") + .setKey(ModuleKey.ROOT) .addExtensionUsage(createModuleExtensionUsage("@foo//:defs.bzl", "bar")) .build(); ImmutableMap depGraph = ImmutableMap.of(ModuleKey.ROOT, root);