Skip to content

Commit

Permalink
[7.1.0] Mark use_repo_rule extension as reproducible (#21335)
Browse files Browse the repository at this point in the history
This ensures that the attributes of repo rules used with `use_repo_rule`
are not duplicated in the locked extension entry in the lockfile. They
are still duplicated in the usages section of the lockfile.

Also fix two typos.

Closes #21304.

Commit
0523461

PiperOrigin-RevId: 606660953
Change-Id: I5f7fa50dbacfafae22e4ea3fdb92e6bfb2beffc6

Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
  • Loading branch information
bazel-io and fmeum authored Feb 13, 2024
1 parent b49ee4b commit 2ce2960
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static Builder builder() {

public abstract Builder toBuilder();

public boolean shouldLockExtesnsion() {
public boolean shouldLockExtension() {
return getModuleExtensionMetadata().isEmpty()
|| !getModuleExtensionMetadata().get().getReproducible();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> getExplicitRootModuleDirectDeps();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ public RunModuleExtensionResult run(
ModuleExtensionId extensionId)
throws InterruptedException, SingleExtensionEvalFunctionException {
var generatedRepoSpecs = ImmutableMap.<String, RepoSpec>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) {
Expand Down Expand Up @@ -790,7 +790,7 @@ public RunModuleExtensionResult run(
return RunModuleExtensionResult.create(
ImmutableMap.of(),
generatedRepoSpecs.buildOrThrow(),
Optional.empty(),
Optional.of(ModuleExtensionMetadata.REPRODUCIBLE),
ImmutableTable.of());
}
}
Expand Down
46 changes: 0 additions & 46 deletions src/test/py/bazel/bzlmod/bazel_lockfile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 2ce2960

Please sign in to comment.