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

[7.1.0] Mark use_repo_rule extension as reproducible #21335

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading