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

[6.3.2] Lockfile updates & fixes (for PR# 19068 and 19105) #19175

Merged
merged 1 commit into from
Aug 4, 2023
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 @@ -109,25 +109,34 @@ public ImmutableList<String> getModuleAndFlagsDiff(
return moduleDiff.build();
}

/** Returns the differences between an extension and its locked data */
public ImmutableList<String> getModuleExtensionDiff(
LockFileModuleExtension lockedExtension,
ImmutableMap<ModuleKey, ModuleExtensionUsage> lockedExtensionUsages,
ModuleExtensionId extensionId,
byte[] transitiveDigest,
ImmutableMap<ModuleKey, ModuleExtensionUsage> extensionUsages) {
boolean filesChanged,
ImmutableMap<String, String> envVariables,
ImmutableMap<ModuleKey, ModuleExtensionUsage> extensionUsages,
ImmutableMap<ModuleKey, ModuleExtensionUsage> lockedExtensionUsages) {
LockFileModuleExtension lockedExtension = getModuleExtensions().get(extensionId);

ImmutableList.Builder<String> extDiff = new ImmutableList.Builder<>();
if (lockedExtension == null) {
extDiff.add("The module extension '" + extensionId + "' does not exist in the lockfile");
} else {
if (!Arrays.equals(transitiveDigest, lockedExtension.getBzlTransitiveDigest())) {
if (!Arrays.equals(transitiveDigest, lockedExtension.getBzlTransitiveDigest())) {
extDiff.add(
"The implementation of the extension '"
+ extensionId
+ "' or one of its transitive .bzl files has changed");
}
if (!extensionUsages.equals(lockedExtensionUsages)) {
extDiff.add("The usages of the extension named '" + extensionId + "' has changed");
}
}
if (filesChanged) {
extDiff.add("One or more files the extension '" + extensionId + "' is using have changed");
}
if (!extensionUsages.equals(lockedExtensionUsages)) {
extDiff.add("The usages of the extension '" + extensionId + "' has changed");
}
if (!envVariables.equals(lockedExtension.getEnvVariables())) {
extDiff.add(
"The environment variables the extension '"
+ extensionId
+ "' depends on (or their values) have changed");
}
return extDiff.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ public ModuleKey read(JsonReader jsonReader) throws IOException {
}
};

public static final TypeAdapter<Label> LABEL_TYPE_ADAPTER =
new TypeAdapter<Label>() {
@Override
public void write(JsonWriter jsonWriter, Label label) throws IOException {
jsonWriter.value(label.getUnambiguousCanonicalForm());
}

@Override
public Label read(JsonReader jsonReader) throws IOException {
return Label.parseCanonicalUnchecked(jsonReader.nextString());
}
};

public static final TypeAdapter<ModuleExtensionId> MODULE_EXTENSION_ID_TYPE_ADAPTER =
new TypeAdapter<>() {
@Override
Expand Down Expand Up @@ -308,6 +321,7 @@ public static Gson createLockFileGson(Path moduleFilePath) {
.registerTypeAdapterFactory(IMMUTABLE_SET)
.registerTypeAdapterFactory(OPTIONAL)
.registerTypeAdapterFactory(new LocationTypeAdapterFactory(moduleFilePath))
.registerTypeAdapter(Label.class, LABEL_TYPE_ADAPTER)
.registerTypeAdapter(Version.class, VERSION_TYPE_ADAPTER)
.registerTypeAdapter(ModuleKey.class, MODULE_KEY_TYPE_ADAPTER)
.registerTypeAdapter(ModuleExtensionId.class, MODULE_EXTENSION_ID_TYPE_ADAPTER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.events.ExtendedEventHandler.Postable;
import com.ryanharter.auto.value.gson.GenerateTypeAdapter;

Expand All @@ -28,13 +29,36 @@
@GenerateTypeAdapter
public abstract class LockFileModuleExtension implements Postable {

public static Builder builder() {
return new AutoValue_LockFileModuleExtension.Builder()
// TODO(salmasamy) can be removed when updating lockfile version
.setEnvVariables(ImmutableMap.of())
.setAccumulatedFileDigests(ImmutableMap.of());
}

@SuppressWarnings("mutable")
public abstract byte[] getBzlTransitiveDigest();

public abstract ImmutableMap<Label, String> getAccumulatedFileDigests();

public abstract ImmutableMap<String, String> getEnvVariables();

public abstract ImmutableMap<String, RepoSpec> getGeneratedRepoSpecs();

public static LockFileModuleExtension create(
byte[] transitiveDigest, ImmutableMap<String, RepoSpec> generatedRepoSpecs) {
return new AutoValue_LockFileModuleExtension(transitiveDigest, generatedRepoSpecs);
public abstract Builder toBuilder();

/** Builder type for {@link LockFileModuleExtension}. */
@AutoValue.Builder
public abstract static class Builder {

public abstract Builder setBzlTransitiveDigest(byte[] digest);

public abstract Builder setAccumulatedFileDigests(ImmutableMap<Label, String> value);

public abstract Builder setEnvVariables(ImmutableMap<String, String> value);

public abstract Builder setGeneratedRepoSpecs(ImmutableMap<String, RepoSpec> value);

public abstract LockFileModuleExtension build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@

import com.google.auto.value.AutoValue;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.packages.StarlarkExportable;
import javax.annotation.Nullable;
import net.starlark.java.annot.StarlarkBuiltin;
import net.starlark.java.eval.StarlarkCallable;
import net.starlark.java.eval.StarlarkValue;
import net.starlark.java.syntax.Location;

/**
* A module extension object, which can be used to perform arbitrary logic in order to create repos
* or register toolchains and execution platforms.
*/
@AutoValue
public abstract class ModuleExtension {
public abstract class ModuleExtension implements StarlarkValue {
public abstract String getName();

public abstract StarlarkCallable getImplementation();
Expand All @@ -43,6 +45,8 @@ public abstract class ModuleExtension {

public abstract Location getLocation();

public abstract ImmutableList<String> getEnvVariables();

public static Builder builder() {
return new AutoValue_ModuleExtension.Builder();
}
Expand All @@ -63,6 +67,8 @@ public abstract static class Builder {

public abstract Builder setTagClasses(ImmutableMap<String, TagClass> value);

public abstract Builder setEnvVariables(ImmutableList<String> value);

public abstract ModuleExtension build();
}

Expand Down
Loading