diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileModule.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileModule.java index 567a01bbea2c17..2d588414dd86dd 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileModule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileModule.java @@ -122,7 +122,7 @@ public void afterCommand() throws AbruptExitException { // Add the new resolved extensions for (var event : extensionResolutionEventsMap.values()) { LockFileModuleExtension extension = event.getModuleExtension(); - if (!extension.shouldLockExtesnsion()) { + if (!extension.shouldLockExtension()) { continue; } @@ -169,7 +169,7 @@ private boolean shouldKeepExtension( // If there is a new event for this extension, compare it with the existing ones ModuleExtensionResolutionEvent extEvent = extensionResolutionEventsMap.get(extensionId); if (extEvent != null) { - boolean doNotLockExtension = !extEvent.getModuleExtension().shouldLockExtesnsion(); + boolean doNotLockExtension = !extEvent.getModuleExtension().shouldLockExtension(); boolean dependencyOnOsChanged = lockedExtensionKey.getOs().isEmpty() != extEvent.getExtensionFactors().getOs().isEmpty(); boolean dependencyOnArchChanged = diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/LockFileModuleExtension.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/LockFileModuleExtension.java index 88cdd5c2e7888d..1443189e389a42 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/LockFileModuleExtension.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/LockFileModuleExtension.java @@ -54,7 +54,7 @@ public static Builder builder() { public abstract Builder toBuilder(); - public boolean shouldLockExtesnsion() { + public boolean shouldLockExtension() { return getModuleExtensionMetadata().isEmpty() || !getModuleExtensionMetadata().get().getReproducible(); } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionMetadata.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionMetadata.java index 539d7db8b26eaf..2f18222a89686a 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionMetadata.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionMetadata.java @@ -55,6 +55,14 @@ @AutoValue @GenerateTypeAdapter public abstract class ModuleExtensionMetadata implements StarlarkValue { + + static final ModuleExtensionMetadata REPRODUCIBLE = + create( + /* explicitRootModuleDirectDeps= */ null, + /* explicitRootModuleDirectDevDeps= */ null, + UseAllRepos.NO, + /* reproducible= */ true); + @Nullable abstract ImmutableSet getExplicitRootModuleDirectDeps(); diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/SingleExtensionEvalFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/SingleExtensionEvalFunction.java index 7e016afe230519..73e033d3592de9 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/SingleExtensionEvalFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/SingleExtensionEvalFunction.java @@ -713,7 +713,7 @@ public RunModuleExtensionResult run( ModuleExtensionId extensionId) throws InterruptedException, SingleExtensionEvalFunctionException { var generatedRepoSpecs = ImmutableMap.builderWithExpectedSize(repos.size()); - // Instiantiate the repos one by one. + // Instantiate the repos one by one. for (InnateExtensionRepo repo : repos) { Object exported = repo.loadedBzl().getModule().getGlobal(repo.ruleName()); if (exported == null) { @@ -790,7 +790,7 @@ public RunModuleExtensionResult run( return RunModuleExtensionResult.create( ImmutableMap.of(), generatedRepoSpecs.buildOrThrow(), - Optional.empty(), + Optional.of(ModuleExtensionMetadata.REPRODUCIBLE), ImmutableTable.of()); } } diff --git a/src/test/py/bazel/bzlmod/bazel_lockfile_test.py b/src/test/py/bazel/bzlmod/bazel_lockfile_test.py index f8669910295f35..d94bd55675a8cc 100644 --- a/src/test/py/bazel/bzlmod/bazel_lockfile_test.py +++ b/src/test/py/bazel/bzlmod/bazel_lockfile_test.py @@ -1460,52 +1460,6 @@ def testExtensionEvaluationRerunsIfDepGraphOrderChanges(self): ]['attributes']['value'], ) - def testInnateModuleExtension(self): - # tests that the repo spec in the lockfile is invalidated when the attr type - # changes, even if the MODULE.bazel file hasn't changed - self.ScratchFile( - 'MODULE.bazel', - [ - 'r=use_repo_rule("//:bzl.bzl","r")', - 'r(name="hello",value="hello.txt")', - ], - ) - self.ScratchFile('BUILD.bazel') - self.ScratchFile( - 'bzl.bzl', - [ - 'def _impl(ctx):', - ' ctx.file("BUILD", "filegroup(name=\'lol\')")', - 'r = repository_rule(_impl,attrs={"value":attr.string()})', - ], - ) - - self.RunBazel(['build', '@hello//:lol']) - with open('MODULE.bazel.lock', 'r') as json_file: - lockfile = json.load(json_file) - hello_attrs = lockfile['moduleExtensions']['//:MODULE.bazel%_repo_rules'][ - 'general']['generatedRepoSpecs']['hello']['attributes'] - self.assertEqual(hello_attrs['value'], 'hello.txt') - - # Shutdown bazel to make sure we rely on the lockfile and not skyframe - self.RunBazel(['shutdown']) - - self.ScratchFile( - 'bzl.bzl', - [ - 'def _impl(ctx):', - ' ctx.file("BUILD", "filegroup(name=\'lol\')")', - 'r = repository_rule(_impl,attrs={"value":attr.label()})', - # changed attr type to label in the line above! - ], - ) - self.RunBazel(['build', '@hello//:lol']) - with open('MODULE.bazel.lock', 'r') as json_file: - lockfile = json.load(json_file) - hello_attrs = lockfile['moduleExtensions']['//:MODULE.bazel%_repo_rules'][ - 'general']['generatedRepoSpecs']['hello']['attributes'] - self.assertEqual(hello_attrs['value'], '@@//:hello.txt') - def testExtensionRepoMappingChange(self): # Regression test for #20721 self.main_registry.createCcModule('foo', '1.0')