Skip to content

Commit

Permalink
Delete unused native Java serialization code.
Browse files Browse the repository at this point in the history
`JavaSerializableCodec` was deleted in bazelbuild@1e2ac68 and had been unused for years prior. The only use case for implementing `Serializable` in bazel code is for lambdas and their `@FunctionalInterface` (see `LambdaCodec`).

PiperOrigin-RevId: 408426802
  • Loading branch information
justinhorvitz authored and copybara-github committed Nov 8, 2021
1 parent a9206eb commit 5149408
Show file tree
Hide file tree
Showing 54 changed files with 304 additions and 910 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Root;
import java.io.Serializable;
import java.util.Objects;
import net.starlark.java.eval.Printer;

Expand All @@ -46,7 +45,7 @@
*/
@AutoCodec
@Immutable
public final class ArtifactRoot implements Comparable<ArtifactRoot>, Serializable, FileRootApi {
public final class ArtifactRoot implements Comparable<ArtifactRoot>, FileRootApi {
private static final Interner<ArtifactRoot> INTERNER = Interners.newWeakInterner();
/**
* Do not use except in tests and in {@link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
import java.io.Serializable;

/** A marker interface for objects which can return a byte[] digest. */
@FunctionalInterface
public interface HasDigest extends Serializable {
byte[] getDigest();

public static final HasDigest EMPTY = new ByteStringDigest(new byte[] {});
HasDigest EMPTY = new ByteStringDigest(new byte[] {});

/** An immutable wrapper around a byte[] digest. */
public static class ByteStringDigest implements HasDigest {
/** An immutable wrapper around a {@code byte[]} digest. */
final class ByteStringDigest implements HasDigest {
private final ByteString bytes;

public ByteStringDigest(byte[] bytes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import com.google.devtools.build.lib.actions.ArtifactRoot;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.io.Serializable;

/**
* A factory for language-specific build-info files. Use this to translate the build-info into
* target-independent language-specific files. The generated actions are registered into the action
* graph on every build, but only executed if anything depends on them.
*/
public interface BuildInfoFactory extends Serializable {
public interface BuildInfoFactory {
/**
* Type of the build-data artifact.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.devtools.common.options.OptionDefinition;
import com.google.devtools.common.options.OptionMetadataTag;
import com.google.devtools.common.options.OptionsParser;
import java.io.Serializable;
import java.util.Map;
import javax.annotation.Nullable;

Expand All @@ -40,8 +39,8 @@
* <li>whether it is selectable, i.e., allowed to appear in a {@code config_setting}
* </ul>
*
* <p>For Starlark options (defined in a Starlark {@code build_setting)}, this tracks their value
* in built-in Starlark-object form (post-parse, pre-implementation function form).
* <p>For Starlark options (defined in a Starlark {@code build_setting}), this tracks their value in
* built-in Starlark-object form (post-parse, pre-implementation function form).
*/
public final class BuildOptionDetails {

Expand Down Expand Up @@ -90,7 +89,7 @@ static BuildOptionDetails forOptions(
return new BuildOptionDetails(map.build(), ImmutableMap.copyOf(starlarkOptions));
}

private static final class OptionDetails implements Serializable {
private static final class OptionDetails {

private OptionDetails(
Class<? extends FragmentOptions> optionsClass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import com.google.protobuf.CodedInputStream;
import com.google.protobuf.CodedOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
Expand All @@ -63,7 +62,7 @@
/** Stores the command-line options from a set of configuration fragments. */
// TODO(janakr): If overhead of FragmentOptions class names is too high, add constructor that just
// takes fragments and gets names from them.
public final class BuildOptions implements Cloneable, Serializable {
public final class BuildOptions implements Cloneable {

@SerializationConstant
static final Comparator<Class<? extends FragmentOptions>> LEXICAL_FRAGMENT_OPTIONS_COMPARATOR =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
import com.google.devtools.common.options.OptionDefinition;
import com.google.devtools.common.options.Options;
import com.google.devtools.common.options.OptionsBase;
import java.io.Serializable;
import java.util.Map;
import javax.annotation.Nullable;

/** Command-line build options for a Blaze module. */
public abstract class FragmentOptions extends OptionsBase implements Cloneable, Serializable {
public abstract class FragmentOptions extends OptionsBase implements Cloneable {

@Override
public FragmentOptions clone() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.devtools.build.lib.util.RegexFilter.RegexFilterConverter;
import com.google.devtools.common.options.Converter;
import com.google.devtools.common.options.OptionsParsingException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand All @@ -30,7 +29,7 @@
* Models options that can be added to a command line when a label matches a given {@link
* RegexFilter}.
*/
public class PerLabelOptions implements Serializable {
public final class PerLabelOptions {
/** The filter used to match labels */
private final RegexFilter regexFilter;

Expand All @@ -53,7 +52,7 @@ public PerLabelOptions convert(String input) throws OptionsParsingException {
int atIndex = input.indexOf('@');
RegexFilterConverter converter = new RegexFilter.RegexFilterConverter();
if (atIndex < 0) {
return new PerLabelOptions(converter.convert(input), ImmutableList.<String> of());
return new PerLabelOptions(converter.convert(input), ImmutableList.of());
} else {
String filterPiece = input.substring(0, atIndex);
String optionsPiece = input.substring(atIndex + 1);
Expand Down Expand Up @@ -109,16 +108,20 @@ RegexFilter getRegexFilter() {
public String toString() {
return regexFilter + " Options: " + optionsList;
}

@Override
public boolean equals(Object other) {
PerLabelOptions otherOptions =
other instanceof PerLabelOptions ? (PerLabelOptions) other : null;
return this == other || (otherOptions != null &&
this.regexFilter.equals(otherOptions.regexFilter) &&
this.optionsList.equals(otherOptions.optionsList));
if (this == other) {
return true;
}
if (!(other instanceof PerLabelOptions)) {
return false;
}
PerLabelOptions otherOptions = (PerLabelOptions) other;
return this.regexFilter.equals(otherOptions.regexFilter)
&& this.optionsList.equals(otherOptions.optionsList);
}

@Override
public int hashCode() {
return Objects.hash(regexFilter, optionsList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
package com.google.devtools.build.lib.analysis.config;

import com.google.devtools.build.lib.cmdline.Label;
import java.io.Serializable;
import java.util.List;

/** Components of --run_under option. */
public interface RunUnder extends Serializable {
/** Components of the {@code --run_under} option. */
public interface RunUnder {
/**
* @return the whole value passed to --run_under option.
*/
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/google/devtools/build/lib/cmdline/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ java_library(
srcs = [
"Label.java",
"LabelConstants.java",
"LabelSerializationProxy.java",
"ResolvedTargets.java",
"SignedTargetPattern.java",
"TargetParsingException.java",
Expand Down
14 changes: 1 addition & 13 deletions src/main/java/com/google/devtools/build/lib/cmdline/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.skyframe.SkyFunctionName;
import com.google.devtools.build.skyframe.SkyKey;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.Arrays;
import javax.annotation.Nullable;
import net.starlark.java.annot.Param;
Expand All @@ -55,8 +52,7 @@
@AutoCodec
@Immutable
@ThreadSafe
public final class Label
implements Comparable<Label>, Serializable, StarlarkValue, SkyKey, CommandLineItem {
public final class Label implements Comparable<Label>, StarlarkValue, SkyKey, CommandLineItem {

// Intern "__pkg__" and "__subpackages__" pseudo-targets, which appears in labels used for
// visibility specifications. This saves a couple tenths of a percent of RAM off the loading
Expand Down Expand Up @@ -342,14 +338,6 @@ private Label(PackageIdentifier packageIdentifier, String name) {
this.name = name;
}

private Object writeReplace() {
return new LabelSerializationProxy(getUnambiguousCanonicalForm());
}

private void readObject(ObjectInputStream unusedStream) throws InvalidObjectException {
throw new InvalidObjectException("Serialization is allowed only by proxy");
}

public PackageIdentifier getPackageIdentifier() {
return packageIdentifier;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.devtools.build.lib.concurrent.BlazeInterners;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.io.Serializable;
import java.util.Objects;
import javax.annotation.concurrent.Immutable;

Expand All @@ -33,7 +32,7 @@
*/
@AutoCodec
@Immutable
public final class PackageIdentifier implements Comparable<PackageIdentifier>, Serializable {
public final class PackageIdentifier implements Comparable<PackageIdentifier> {
private static final Interner<PackageIdentifier> INTERNER = BlazeInterners.newWeakInterner();

public static PackageIdentifier create(String repository, PathFragment pkgName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
import com.google.devtools.build.lib.util.StringUtilities;
import com.google.devtools.build.lib.vfs.OsPathPolicy;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.io.Serializable;
import java.util.Objects;
import java.util.concurrent.CompletionException;
import java.util.regex.Pattern;
import javax.annotation.Nullable;

/** The name of an external repository. */
public final class RepositoryName implements Serializable {
public final class RepositoryName {

static final String DEFAULT_REPOSITORY = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.errorprone.annotations.CheckReturnValue;
import com.google.errorprone.annotations.CompileTimeConstant;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand All @@ -46,9 +45,9 @@
import javax.annotation.concurrent.Immutable;

/**
* Represents a target pattern. Target patterns are a generalization of labels to include
* wildcards for finding all packages recursively beneath some root, and for finding all targets
* within a package.
* Represents a target pattern. Target patterns are a generalization of labels to include wildcards
* for finding all packages recursively beneath some root, and for finding all targets within a
* package.
*
* <p>Note that this class does not handle negative patterns ("-//foo/bar"); these must be handled
* one level up. In particular, the query language comes with built-in support for negative
Expand All @@ -59,7 +58,7 @@
*
* <p>See lib/blaze/commands/target-syntax.txt for details.
*/
public abstract class TargetPattern implements Serializable {
public abstract class TargetPattern {

private static final Splitter SLASH_SPLITTER = Splitter.on('/');
private static final Joiner SLASH_JOINER = Joiner.on('/');
Expand All @@ -86,25 +85,17 @@ public static Parser mainRepoParser(PathFragment offset) {
return new Parser(offset, RepositoryName.MAIN, RepositoryMapping.ALWAYS_FALLBACK);
}

private static String removeSuffix(String s, String suffix) {
if (s.endsWith(suffix)) {
return s.substring(0, s.length() - suffix.length());
} else {
throw new IllegalArgumentException(s + ", " + suffix);
}
}

/**
* Normalizes the given relative path by resolving {@code //}, {@code /./} and {@code x/../}
* pieces. Note that leading {@code ".."} segments are not removed, so the returned string can
* have leading {@code ".."} segments.
*
* @throws IllegalArgumentException if the path is absolute, i.e. starts with a @{code '/'}
* @throws IllegalArgumentException if the path is absolute, i.e. starts with {@code /}
*/
@VisibleForTesting
static String normalize(String path) {
Preconditions.checkArgument(!path.startsWith("/"));
Preconditions.checkArgument(!path.startsWith("@"));
Preconditions.checkArgument(!path.startsWith("/"), path);
Preconditions.checkArgument(!path.startsWith("@"), path);
Iterator<String> it = SLASH_SPLITTER.split(path).iterator();
List<String> pieces = new ArrayList<>();
while (it.hasNext()) {
Expand Down Expand Up @@ -641,7 +632,7 @@ public IgnoredPathFragmentsInScopeOrFilteringIgnorer getAllIgnoredSubdirectories
ignoredPackagePrefix);
}
PackageIdentifier pkgIdForIgnoredDirectorPrefix =
PackageIdentifier.create(this.getDirectory().getRepository(), ignoredPackagePrefix);
PackageIdentifier.create(directory.getRepository(), ignoredPackagePrefix);
if (this.containsAllTransitiveSubdirectories(pkgIdForIgnoredDirectorPrefix)) {
ignoredPathsBuilder.add(ignoredPackagePrefix);
}
Expand Down Expand Up @@ -747,8 +738,8 @@ public boolean containsAllTransitiveSubdirectories(PackageIdentifier containedDi
* the given {@code containedPattern} from this one.
*/
public ContainsResult contains(TargetsBelowDirectory containedPattern) {
if (containsAllTransitiveSubdirectories(containedPattern.getDirectory())) {
return !getRulesOnly() && containedPattern.getRulesOnly()
if (containsAllTransitiveSubdirectories(containedPattern.directory)) {
return !rulesOnly && containedPattern.rulesOnly
? ContainsResult.DIRECTORY_EXCLUSION_WOULD_BE_TOO_BROAD
: ContainsResult.DIRECTORY_EXCLUSION_WOULD_BE_EXACT;
} else {
Expand Down Expand Up @@ -957,7 +948,7 @@ public TargetPattern parse(String pattern) throws TargetParsingException {
}

if (packagePart.endsWith("/...")) {
String realPackagePart = removeSuffix(packagePart, "/...");
String realPackagePart = packagePart.substring(0, packagePart.length() - "/...".length());
PackageIdentifier packageIdentifier;
try {
packageIdentifier = PackageIdentifier.parse(
Expand Down Expand Up @@ -1097,6 +1088,6 @@ public enum Type {
/** Targets below a directory, eg "foo/...". */
TARGETS_BELOW_DIRECTORY,
/** Target in a package, eg "foo:all". */
TARGETS_IN_PACKAGE;
TARGETS_IN_PACKAGE
}
}
Loading

0 comments on commit 5149408

Please sign in to comment.