diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD index 716b26c448a046..482444d51669dd 100644 --- a/src/main/java/com/google/devtools/build/lib/BUILD +++ b/src/main/java/com/google/devtools/build/lib/BUILD @@ -383,6 +383,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/profiler/memory:allocationtracker", "//src/main/java/com/google/devtools/build/lib/query2", "//src/main/java/com/google/devtools/build/lib/query2:aquery-utils", + "//src/main/java/com/google/devtools/build/lib/query2/common:cquery-node", "//src/main/java/com/google/devtools/build/lib/query2/engine", "//src/main/java/com/google/devtools/build/lib/query2/query/output", "//src/main/java/com/google/devtools/build/lib/runtime/events", diff --git a/src/main/java/com/google/devtools/build/lib/actions/Artifact.java b/src/main/java/com/google/devtools/build/lib/actions/Artifact.java index 1a0b1ba55483cb..c5e79a90ee5962 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/Artifact.java +++ b/src/main/java/com/google/devtools/build/lib/actions/Artifact.java @@ -39,7 +39,7 @@ import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec; import com.google.devtools.build.lib.skyframe.serialization.SerializationContext; import com.google.devtools.build.lib.skyframe.serialization.SerializationException; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.lib.starlarkbuildapi.FileApi; import com.google.devtools.build.lib.util.FileType; diff --git a/src/main/java/com/google/devtools/build/lib/actions/ArtifactRoot.java b/src/main/java/com/google/devtools/build/lib/actions/ArtifactRoot.java index ca1a6e6e01db68..26dc193d3bb332 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ArtifactRoot.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ArtifactRoot.java @@ -21,6 +21,7 @@ import com.google.devtools.build.lib.actions.Artifact.SourceArtifact; import com.google.devtools.build.lib.cmdline.LabelConstants; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.starlarkbuildapi.FileRootApi; import com.google.devtools.build.lib.vfs.Path; @@ -164,7 +165,7 @@ public static ArtifactRoot asDerivedRoot( return INTERNER.intern(new ArtifactRoot(Root.fromPath(root), execPath, rootType)); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static ArtifactRoot createForSerialization( Root rootForSerialization, PathFragment execPath, RootType rootType) { diff --git a/src/main/java/com/google/devtools/build/lib/actions/BUILD b/src/main/java/com/google/devtools/build/lib/actions/BUILD index c8c6e19ef72c22..71ea06e1a77b6f 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/BUILD +++ b/src/main/java/com/google/devtools/build/lib/actions/BUILD @@ -179,6 +179,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/skyframe:sane_analysis_exception", "//src/main/java/com/google/devtools/build/lib/skyframe:skyframe_aware_action", "//src/main/java/com/google/devtools/build/lib/skyframe:tree_artifact_value", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant", "//src/main/java/com/google/devtools/build/lib/starlarkbuildapi", @@ -319,6 +320,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/skyframe:detailed_exceptions", "//src/main/java/com/google/devtools/build/lib/skyframe:sky_functions", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant", "//src/main/java/com/google/devtools/build/lib/starlarkbuildapi", @@ -399,6 +401,7 @@ java_library( ":has_digest", "//src/main/java/com/google/devtools/build/lib/concurrent", "//src/main/java/com/google/devtools/build/lib/io:inconsistent_filesystem_exception", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant", "//src/main/java/com/google/devtools/build/lib/util", diff --git a/src/main/java/com/google/devtools/build/lib/actions/FileValue.java b/src/main/java/com/google/devtools/build/lib/actions/FileValue.java index 3d26ea98043b97..1453b49d300056 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/FileValue.java +++ b/src/main/java/com/google/devtools/build/lib/actions/FileValue.java @@ -19,6 +19,7 @@ import com.google.common.collect.Iterables; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.vfs.RootedPath; @@ -150,7 +151,7 @@ public static Key key(RootedPath rootedPath) { } /** Key type for FileValue. */ - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec public static class Key extends AbstractSkyKey { private static final SkyKeyInterner interner = SkyKey.newInterner(); @@ -159,7 +160,7 @@ private Key(RootedPath arg) { super(arg); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static Key create(RootedPath arg) { return interner.intern(new Key(arg)); diff --git a/src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParams.java b/src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParams.java index ec9dcde9b5049d..a82b60e1cdcbba 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParams.java +++ b/src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParams.java @@ -17,8 +17,8 @@ import com.google.auto.value.extension.memoized.Memoized; import com.google.common.collect.ImmutableSortedSet; import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.Instantiator; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; import com.google.devtools.build.lib.util.Fingerprint; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BUILD b/src/main/java/com/google/devtools/build/lib/analysis/BUILD index a8c437f0b0eb42..8fd7dfb1c3992c 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BUILD +++ b/src/main/java/com/google/devtools/build/lib/analysis/BUILD @@ -407,6 +407,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/profiler", "//src/main/java/com/google/devtools/build/lib/profiler:google-auto-profiler-utils", "//src/main/java/com/google/devtools/build/lib/profiler/memory:current_rule_tracker", + "//src/main/java/com/google/devtools/build/lib/query2/common:cquery-node", "//src/main/java/com/google/devtools/build/lib/shell", "//src/main/java/com/google/devtools/build/lib/skyframe:aspect_key_creator", "//src/main/java/com/google/devtools/build/lib/skyframe:build_info_collection_value", @@ -416,6 +417,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/skyframe:starlark_builtins_value", "//src/main/java/com/google/devtools/build/lib/skyframe:workspace_status_value", "//src/main/java/com/google/devtools/build/lib/skyframe/config", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant", "//src/main/java/com/google/devtools/build/lib/starlarkbuildapi", @@ -691,6 +693,7 @@ java_library( ":transitive_info_collection", "//src/main/java/com/google/devtools/build/lib/actions:action_lookup_key", "//src/main/java/com/google/devtools/build/lib/cmdline", + "//src/main/java/com/google/devtools/build/lib/query2/common:cquery-node", "//src/main/java/com/google/devtools/build/lib/skyframe/config", "//src/main/java/net/starlark/java/eval", "//third_party:guava", @@ -1225,6 +1228,7 @@ java_library( ":transitive_info_provider_map", "//src/main/java/com/google/devtools/build/lib/collect", "//src/main/java/com/google/devtools/build/lib/packages", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//third_party:guava", "//third_party:jsr305", @@ -1380,6 +1384,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/collect/nestedset", "//src/main/java/com/google/devtools/build/lib/concurrent", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant", "//src/main/java/com/google/devtools/build/lib/util", @@ -2491,12 +2496,14 @@ java_library( "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/collect/nestedset", "//src/main/java/com/google/devtools/build/lib/concurrent", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/starlarkbuildapi", "//src/main/java/com/google/devtools/build/lib/util", "//src/main/java/com/google/devtools/build/lib/vfs:pathfragment", "//src/main/java/net/starlark/java/eval", "//src/main/java/net/starlark/java/syntax", + "//third_party:error_prone_annotations", "//third_party:guava", "//third_party:jsr305", ], diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java b/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java index 2a48c40ae4a5e2..aafa9ae4790c5e 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java @@ -50,7 +50,7 @@ import com.google.devtools.build.lib.packages.TestSize; import com.google.devtools.build.lib.packages.Type; import com.google.devtools.build.lib.packages.Type.ConversionException; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.lib.util.FileTypeSet; import javax.annotation.Nullable; @@ -63,7 +63,7 @@ public class BaseRuleClasses { private BaseRuleClasses() {} - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final Attribute.ComputedDefault testonlyDefault = new Attribute.ComputedDefault() { @Override @@ -77,7 +77,7 @@ public boolean resolvableWithRawAttributes() { } }; - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final Attribute.ComputedDefault deprecationDefault = new Attribute.ComputedDefault() { @Override @@ -91,7 +91,7 @@ public boolean resolvableWithRawAttributes() { } }; - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization public static final Attribute.ComputedDefault TIMEOUT_DEFAULT = new Attribute.ComputedDefault() { @Override @@ -112,7 +112,7 @@ public boolean resolvableWithRawAttributes() { } }; - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization public static final Attribute.ComputedDefault packageMetadataDefault = new Attribute.ComputedDefault() { @Override @@ -135,7 +135,7 @@ public boolean resolvableWithRawAttributes() { * they only run on the target configuration and should not operate on action_listeners and * extra_actions themselves (to avoid cycles). */ - @SerializationConstant @AutoCodec.VisibleForSerialization @VisibleForTesting + @SerializationConstant @VisibleForSerialization @VisibleForTesting static final LabelListLateBoundDefault ACTION_LISTENER = LabelListLateBoundDefault.fromTargetConfiguration( BuildConfigurationValue.class, @@ -143,7 +143,7 @@ public boolean resolvableWithRawAttributes() { public static final String DEFAULT_COVERAGE_SUPPORT_VALUE = "//tools/test:coverage_support"; - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final Resolver COVERAGE_SUPPORT_CONFIGURATION_RESOLVER = (rule, attributes, configuration) -> configuration.getCoverageSupport(); @@ -156,7 +156,7 @@ public static LabelLateBoundDefault coverageSupportAttribute( public static final String DEFAULT_COVERAGE_REPORT_GENERATOR_VALUE = "//tools/test:coverage_report_generator"; - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final Resolver COVERAGE_REPORT_GENERATOR_CONFIGURATION_RESOLVER = (rule, attributes, configuration) -> configuration.reportGenerator(); @@ -174,13 +174,13 @@ public static LabelLateBoundDefault getCoverageOutputGene CoverageConfiguration.class, null, COVERAGE_OUTPUT_GENERATOR_RESOLVER); } - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final Resolver COVERAGE_OUTPUT_GENERATOR_RESOLVER = (rule, attributes, configuration) -> configuration.outputGenerator(); // TODO(b/65746853): provide a way to do this without passing the entire configuration /** Implementation for the :run_under attribute. */ - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization public static final LabelLateBoundDefault RUN_UNDER = LabelLateBoundDefault.fromTargetConfiguration( BuildConfigurationValue.class, diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTarget.java b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTarget.java index 3db2decc9ae279..af72a3058b8f38 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTarget.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTarget.java @@ -19,6 +19,7 @@ import com.google.devtools.build.lib.actions.ActionLookupKey; import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider; import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.skyframe.config.BuildConfigurationKey; import javax.annotation.Nullable; import net.starlark.java.eval.Dict; @@ -35,7 +36,7 @@ * their direct dependencies, only the corresponding {@link TransitiveInfoCollection}s. Also, {@link * ConfiguredTarget} objects should not be accessible from the action graph. */ -public interface ConfiguredTarget extends TransitiveInfoCollection, Structure { +public interface ConfiguredTarget extends TransitiveInfoCollection, Structure, CqueryNode { /** All ConfiguredTargets have a "label" field. */ String LABEL_FIELD = "label"; @@ -44,6 +45,7 @@ public interface ConfiguredTarget extends TransitiveInfoCollection, Structure { String FILES_FIELD = "files"; /** Returns a key that may be used to lookup this {@link ConfiguredTarget}. */ + @Override ActionLookupKey getLookupKey(); @Override @@ -51,6 +53,7 @@ default Label getLabel() { return getLookupKey().getLabel(); } + @Override @Nullable default String getConfigurationChecksum() { return getConfigurationKey() == null ? null : getConfigurationKey().getOptions().checksum(); @@ -65,8 +68,9 @@ default String getConfigurationChecksum() { * com.google.devtools.build.lib.analysis.configuredtargets.PackageGroupConfiguredTarget} for * which it is always null. * - *

If this changes, {@link AspectResolver#aspecMatchesConfiguredTarget} should be updated. + *

If this changes, {@link AspectResolver#aspectMatchesConfiguredTarget} should be updated. */ + @Override @Nullable default BuildConfigurationKey getConfigurationKey() { return getLookupKey().getConfigurationKey(); @@ -89,6 +93,7 @@ default BuildConfigurationKey getConfigurationKey() { * If the configured target is an alias, return the actual target, otherwise return the current * target. This follows alias chains. */ + @Override default ConfiguredTarget getActual() { return this; } @@ -98,6 +103,7 @@ default ConfiguredTarget getActual() { * label. This is not the same as {@code getActual().getLabel()}, because it does not follow alias * chains. */ + @Override default Label getOriginalLabel() { return getLabel(); } @@ -106,10 +112,12 @@ default Label getOriginalLabel() { * The configuration conditions that trigger this configured target's configurable attributes. For * targets that do not support configurable attributes, this will be an empty map. */ + @Override default ImmutableMap getConfigConditions() { return ImmutableMap.of(); } + @Override default boolean isRuleConfiguredTarget() { return false; } @@ -119,6 +127,7 @@ default boolean isRuleConfiguredTarget() { * *

Unwrapping is recursive if there are multiple layers. */ + @Override default ConfiguredTarget unwrapIfMerged() { return this; } @@ -128,6 +137,7 @@ default ConfiguredTarget unwrapIfMerged() { * * @return a map of provider names to their values, or null if there are no providers */ + @Override @Nullable default Dict getProvidersDictForQuery() { return null; diff --git a/src/main/java/com/google/devtools/build/lib/analysis/PseudoAction.java b/src/main/java/com/google/devtools/build/lib/analysis/PseudoAction.java index 7499663a951b8f..a3458a560eb783 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/PseudoAction.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/PseudoAction.java @@ -27,7 +27,7 @@ import com.google.devtools.build.lib.server.FailureDetails.Execution; import com.google.devtools.build.lib.server.FailureDetails.Execution.Code; import com.google.devtools.build.lib.server.FailureDetails.FailureDetail; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.util.DetailedExitCode; import com.google.devtools.build.lib.util.Fingerprint; import com.google.protobuf.Extension; @@ -41,11 +41,10 @@ * about rules to extra_actions. */ public class PseudoAction extends AbstractAction { - @AutoCodec.VisibleForSerialization protected final UUID uuid; + @VisibleForSerialization protected final UUID uuid; private final String mnemonic; - @AutoCodec.VisibleForSerialization - protected final Extension infoExtension; + @VisibleForSerialization protected final Extension infoExtension; private final InfoType info; diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java index 91fcc2724fa9dc..04854ed8317c0c 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java @@ -38,7 +38,7 @@ import com.google.devtools.build.lib.events.EventKind; import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.lib.starlarkbuildapi.RunfilesApi; import com.google.devtools.build.lib.util.Fingerprint; @@ -88,7 +88,7 @@ public void fingerprint(Fingerprint fp) { } } - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final EmptyFilesSupplier DUMMY_EMPTY_FILES_SUPPLIER = new DummyEmptyFilesSupplier(); // It is important to declare this *after* the DUMMY_SYMLINK_EXPANDER to avoid NPEs diff --git a/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactHelper.java b/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactHelper.java index cbe7eb522cbd7b..9560b21a856fc2 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactHelper.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactHelper.java @@ -30,6 +30,7 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.profiler.AutoProfiler; import com.google.devtools.build.lib.profiler.GoogleAutoProfilerUtils; +import com.google.devtools.build.lib.query2.common.CqueryNode; import java.time.Duration; import java.util.ArrayList; import java.util.HashMap; @@ -243,7 +244,7 @@ static ArtifactsToBuild getAllArtifactsToBuild( * *

Always returns false for hidden rules and source file targets. */ - public static boolean shouldConsiderForDisplay(ConfiguredTarget configuredTarget) { + public static boolean shouldConsiderForDisplay(CqueryNode configuredTarget) { // TODO(bazel-team): this is quite ugly. Add a marker provider for this check. if (configuredTarget instanceof InputFileConfiguredTarget) { // Suppress display of source files (because we do no work to build them). diff --git a/src/main/java/com/google/devtools/build/lib/analysis/TransitiveInfoProviderMapImpl.java b/src/main/java/com/google/devtools/build/lib/analysis/TransitiveInfoProviderMapImpl.java index 3d3969a7d8b542..923440606ee930 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/TransitiveInfoProviderMapImpl.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/TransitiveInfoProviderMapImpl.java @@ -18,8 +18,8 @@ import com.google.devtools.build.lib.collect.ImmutableSharedKeyMap; import com.google.devtools.build.lib.packages.Info; import com.google.devtools.build.lib.packages.Provider; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; import java.util.Map; import javax.annotation.Nullable; diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLine.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLine.java index ab26b329088a55..0514de1f3cdc05 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLine.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLine.java @@ -37,7 +37,7 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.concurrent.BlazeInterners; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.lib.util.Fingerprint; import com.google.devtools.build.lib.util.OnDemandString; diff --git a/src/main/java/com/google/devtools/build/lib/analysis/platform/BUILD b/src/main/java/com/google/devtools/build/lib/analysis/platform/BUILD index 889111f8d367fb..ca9668e8331f83 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/platform/BUILD +++ b/src/main/java/com/google/devtools/build/lib/analysis/platform/BUILD @@ -25,12 +25,11 @@ java_library( ), deps = [ "//src/main/java/com/google/devtools/build/lib/analysis:config/config_matching_provider", - "//src/main/java/com/google/devtools/build/lib/analysis:required_config_fragments_provider", "//src/main/java/com/google/devtools/build/lib/analysis:transitive_info_provider", "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/concurrent", "//src/main/java/com/google/devtools/build/lib/packages", - "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/starlarkbuildapi/platform", "//src/main/java/com/google/devtools/build/lib/util", "//src/main/java/com/google/devtools/build/lib/util:string", diff --git a/src/main/java/com/google/devtools/build/lib/analysis/platform/ToolchainInfo.java b/src/main/java/com/google/devtools/build/lib/analysis/platform/ToolchainInfo.java index 9ee99af9e21404..9f88d0e97da9e5 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/platform/ToolchainInfo.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/platform/ToolchainInfo.java @@ -21,7 +21,7 @@ import com.google.devtools.build.lib.packages.Attribute; import com.google.devtools.build.lib.packages.BuiltinProvider; import com.google.devtools.build.lib.packages.NativeInfo; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.starlarkbuildapi.platform.ToolchainInfoApi; import java.util.Map; import net.starlark.java.eval.Dict; @@ -59,7 +59,7 @@ public ToolchainInfo toolchainInfo(Dict kwargs, StarlarkThread t } } - @AutoCodec.VisibleForSerialization final ImmutableSortedMap values; + @VisibleForSerialization final ImmutableSortedMap values; private ImmutableSet fieldNames; // initialized lazily (with monitor synchronization) /** Constructs a ToolchainInfo. The {@code values} map itself is not retained. */ diff --git a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkActionFactory.java b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkActionFactory.java index 44ff502fdf6ae0..d00394c5a815f4 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkActionFactory.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkActionFactory.java @@ -67,7 +67,7 @@ import com.google.devtools.build.lib.server.FailureDetails; import com.google.devtools.build.lib.server.FailureDetails.FailureDetail; import com.google.devtools.build.lib.server.FailureDetails.Interrupted; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.lib.starlarkbuildapi.FileApi; import com.google.devtools.build.lib.starlarkbuildapi.StarlarkActionFactoryApi; @@ -273,7 +273,7 @@ public void doNothing(String mnemonic, Object inputs) throws EvalException { registerAction(action); } - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final GeneratedMessage.GeneratedExtension SPAWN_INFO = SpawnInfo.spawnInfo; diff --git a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkCustomCommandLine.java b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkCustomCommandLine.java index b72bde043fde8a..2ae61bdb1293b5 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkCustomCommandLine.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkCustomCommandLine.java @@ -35,6 +35,7 @@ import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.concurrent.BlazeInterners; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.starlarkbuildapi.DirectoryExpander; import com.google.devtools.build.lib.starlarkbuildapi.FileApi; @@ -112,7 +113,7 @@ private VectorArg(int features) { this.features = features; } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static VectorArg create(int features) { return interner.intern(new VectorArg(features)); @@ -597,7 +598,7 @@ private ScalarArg(boolean hasFormat) { this.hasFormat = hasFormat; } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static ScalarArg create(boolean hasFormat) { return interner.intern(new ScalarArg(hasFormat)); diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BUILD b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BUILD index 9d4441232f68aa..2e23da97477ea9 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BUILD +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BUILD @@ -157,6 +157,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/packages", "//src/main/java/com/google/devtools/build/lib/rules:repository/repo_recorded_input", "//src/main/java/com/google/devtools/build/lib/skyframe:sky_functions", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant", "//src/main/java/com/google/devtools/build/skyframe:skyframe-objects", @@ -251,11 +252,10 @@ java_library( ], deps = [ "//src/main/java/com/google/devtools/build/lib/cmdline", - "//src/main/java/com/google/devtools/build/lib/concurrent", "//src/main/java/com/google/devtools/build/lib/packages", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/skyframe:skyframe-objects", - "//third_party:guava", ], ) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelFetchAllValue.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelFetchAllValue.java index 7e2831598c2bba..a0eaa8f47c2876 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelFetchAllValue.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelFetchAllValue.java @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.skyframe.SkyFunctions; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.skyframe.AbstractSkyKey; import com.google.devtools.build.skyframe.SkyFunctionName; @@ -47,7 +48,7 @@ public static BazelFetchAllValue create( } /** Key type for BazelFetchAllValue. */ - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec public static class Key extends AbstractSkyKey { private static final SkyKeyInterner interner = SkyKey.newInterner(); @@ -56,7 +57,7 @@ private Key(Boolean arg) { super(arg); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static BazelFetchAllValue.Key create(Boolean arg) { return interner.intern(new BazelFetchAllValue.Key(arg)); diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BzlmodRepoRuleValue.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BzlmodRepoRuleValue.java index 54debf54af9f78..77d9c068a991ff 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BzlmodRepoRuleValue.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BzlmodRepoRuleValue.java @@ -17,6 +17,7 @@ import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.packages.Package; import com.google.devtools.build.lib.packages.Rule; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.skyframe.AbstractSkyKey; import com.google.devtools.build.skyframe.SkyFunctionName; @@ -68,7 +69,7 @@ private Key(RepositoryName arg) { super(arg); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static Key create(RepositoryName arg) { return interner.intern(new Key(arg)); diff --git a/src/main/java/com/google/devtools/build/lib/bazel/commands/BUILD b/src/main/java/com/google/devtools/build/lib/bazel/commands/BUILD index 0ace636128ad20..5c074c83ccabbc 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/commands/BUILD +++ b/src/main/java/com/google/devtools/build/lib/bazel/commands/BUILD @@ -45,11 +45,10 @@ java_library( "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/packages", - "//src/main/java/com/google/devtools/build/lib/packages:label_printer", "//src/main/java/com/google/devtools/build/lib/packages/semantics", "//src/main/java/com/google/devtools/build/lib/pkgcache", - "//src/main/java/com/google/devtools/build/lib/query2/common:abstract-blaze-query-env", - "//src/main/java/com/google/devtools/build/lib/query2/common:universe-scope", + "//src/main/java/com/google/devtools/build/lib/query2", + "//src/main/java/com/google/devtools/build/lib/query2/common:cquery-node", "//src/main/java/com/google/devtools/build/lib/query2/engine", "//src/main/java/com/google/devtools/build/lib/rules:repository/repository_directory_value", "//src/main/java/com/google/devtools/build/lib/rules:repository/repository_function", diff --git a/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java b/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java index f1cd8511a2adb2..d9d64471dc2a22 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java @@ -30,6 +30,7 @@ import com.google.devtools.build.lib.events.Reporter; import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions; import com.google.devtools.build.lib.pkgcache.PackageOptions; +import com.google.devtools.build.lib.query2.cquery.CqueryOptions; import com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction; import com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue; import com.google.devtools.build.lib.runtime.BlazeCommand; @@ -38,17 +39,18 @@ import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.runtime.KeepGoingOption; import com.google.devtools.build.lib.runtime.LoadingPhaseThreadsOption; +import com.google.devtools.build.lib.runtime.commands.TestCommand; import com.google.devtools.build.lib.server.FailureDetails; import com.google.devtools.build.lib.server.FailureDetails.FailureDetail; import com.google.devtools.build.lib.server.FailureDetails.FetchCommand.Code; import com.google.devtools.build.lib.skyframe.PrecomputedValue; import com.google.devtools.build.lib.skyframe.RepositoryMappingValue.RepositoryMappingResolutionException; -import com.google.devtools.build.lib.util.AbruptExitException; import com.google.devtools.build.lib.util.DetailedExitCode; import com.google.devtools.build.lib.util.InterruptedFailureDetails; import com.google.devtools.build.skyframe.EvaluationContext; import com.google.devtools.build.skyframe.EvaluationResult; import com.google.devtools.build.skyframe.SkyValue; +import com.google.devtools.common.options.OptionsParser; import com.google.devtools.common.options.OptionsParsingResult; import java.util.List; import javax.annotation.Nullable; @@ -56,12 +58,16 @@ /** Fetches external repositories. Which is so fetch. */ @Command( name = FetchCommand.NAME, + builds = true, + inherits = {TestCommand.class}, options = { FetchOptions.class, + CqueryOptions.class, PackageOptions.class, KeepGoingOption.class, LoadingPhaseThreadsOption.class }, + usesConfigurationOptions = true, help = "resource:fetch.txt", shortDescription = "Fetches external repositories that are prerequisites to the targets.", allowResidue = true, @@ -70,6 +76,14 @@ public final class FetchCommand implements BlazeCommand { public static final String NAME = "fetch"; + @Override + public void editOptions(OptionsParser optionsParser) { + // We only need to inject these options with fetch target (when there is a residue) + if (!optionsParser.getResidue().isEmpty()) { + TargetFetcher.injectOptionsToFetchTarget(optionsParser); + } + } + @Override public BlazeCommandResult exec(CommandEnvironment env, OptionsParsingResult options) { BlazeCommandResult invalidResult = validateOptions(env, options); @@ -100,7 +114,6 @@ public BlazeCommandResult exec(CommandEnvironment env, OptionsParsingResult opti BlazeCommandResult result; LoadingPhaseThreadsOption threadsOption = options.getOptions(LoadingPhaseThreadsOption.class); try { - env.syncPackageLoading(options); if (!options.getResidue().isEmpty()) { result = fetchTarget(env, options, options.getResidue()); } else if (!fetchOptions.repos.isEmpty()) { @@ -108,9 +121,6 @@ public BlazeCommandResult exec(CommandEnvironment env, OptionsParsingResult opti } else { // --all, --configure, or just 'fetch' result = fetchAll(env, threadsOption, fetchOptions.configure); } - } catch (AbruptExitException e) { - return createFailedBlazeCommandResult( - env.getReporter(), e.getMessage(), e.getDetailedExitCode()); } catch (InterruptedException e) { return createFailedBlazeCommandResult( env.getReporter(), "Fetch interrupted: " + e.getMessage()); diff --git a/src/main/java/com/google/devtools/build/lib/bazel/commands/TargetFetcher.java b/src/main/java/com/google/devtools/build/lib/bazel/commands/TargetFetcher.java index 94de6ab029f779..71df720e849966 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/commands/TargetFetcher.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/commands/TargetFetcher.java @@ -14,30 +14,39 @@ package com.google.devtools.build.lib.bazel.commands; +import static com.google.common.collect.ImmutableMap.toImmutableMap; + import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.devtools.build.lib.buildtool.BuildRequest; +import com.google.devtools.build.lib.buildtool.BuildResult; +import com.google.devtools.build.lib.buildtool.BuildTool; +import com.google.devtools.build.lib.buildtool.CqueryProcessor; import com.google.devtools.build.lib.cmdline.RepositoryMapping; import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.cmdline.TargetPattern; import com.google.devtools.build.lib.cmdline.TargetPattern.Parser; -import com.google.devtools.build.lib.packages.LabelPrinter; -import com.google.devtools.build.lib.packages.Target; -import com.google.devtools.build.lib.query2.common.AbstractBlazeQueryEnvironment; -import com.google.devtools.build.lib.query2.common.UniverseScope; -import com.google.devtools.build.lib.query2.engine.QueryEnvironment.Setting; -import com.google.devtools.build.lib.query2.engine.QueryEvalResult; -import com.google.devtools.build.lib.query2.engine.QueryException; +import com.google.devtools.build.lib.query2.NamedThreadSafeOutputFormatterCallback; +import com.google.devtools.build.lib.query2.common.CqueryNode; +import com.google.devtools.build.lib.query2.cquery.ConfiguredTargetQueryEnvironment; +import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction; import com.google.devtools.build.lib.query2.engine.QueryExpression; +import com.google.devtools.build.lib.query2.engine.QueryParser; import com.google.devtools.build.lib.query2.engine.QuerySyntaxException; -import com.google.devtools.build.lib.query2.engine.ThreadSafeOutputFormatterCallback; import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.runtime.KeepGoingOption; import com.google.devtools.build.lib.runtime.LoadingPhaseThreadsOption; -import com.google.devtools.build.lib.runtime.commands.QueryCommand; import com.google.devtools.build.lib.skyframe.RepositoryMappingValue.RepositoryMappingResolutionException; +import com.google.devtools.common.options.OptionPriority.PriorityCategory; +import com.google.devtools.common.options.OptionsParser; +import com.google.devtools.common.options.OptionsParsingException; import com.google.devtools.common.options.OptionsParsingResult; -import java.io.IOException; -import java.util.EnumSet; +import java.util.Collection; import java.util.List; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Stream; /** Fetches all repos needed for building a given set of targets. */ public class TargetFetcher { @@ -47,7 +56,7 @@ private TargetFetcher(CommandEnvironment env) { this.env = env; } - /** Uses `deps` query to find and fetch all repos needed for these targets */ + /** Uses cquery to find and fetch all repos needed to build these targets */ public static void fetchTargets( CommandEnvironment env, OptionsParsingResult options, List targets) throws RepositoryMappingResolutionException, InterruptedException, TargetFetcherException { @@ -56,28 +65,17 @@ public static void fetchTargets( private void fetchTargets(OptionsParsingResult options, List targets) throws InterruptedException, TargetFetcherException, RepositoryMappingResolutionException { - AbstractBlazeQueryEnvironment queryEnv = getQueryEnv(options); - QueryExpression expr = createQueryExpression(targets, queryEnv); - QueryEvalResult queryEvalResult; - try { - queryEvalResult = - queryEnv.evaluateQuery( - expr, - new ThreadSafeOutputFormatterCallback<>() { - @Override - public void processOutput(Iterable partialResult) {} - }); - } catch (IOException e) { - // Should be impossible since our OutputFormatterCallback doesn't throw IOException. - throw new IllegalStateException(e); - } catch (QueryException e) { - throw new TargetFetcherException( - String.format( - "Fetching target dependencies for %s encountered an error: %s", - expr, e.getMessage())); - } + QueryExpression expr = createQueryExpression(targets); + BuildRequest request = createBuildRequest(env, options, targets); + TargetPattern.Parser mainRepoTargetParser = getMainRepoMappingParser(env); - if (!queryEvalResult.getSuccess()) { + BuildResult result = + new BuildTool( + env, + new CqueryProcessor( + expr, mainRepoTargetParser, Optional.of(createNoOutputFormatter()))) + .processRequest(request, /* validator= */ null); + if (!result.getSuccess()) { throw new TargetFetcherException( String.format( "Fetching some target dependencies for %s failed, but --keep_going specified. " @@ -86,33 +84,59 @@ public void processOutput(Iterable partialResult) {} } } - AbstractBlazeQueryEnvironment getQueryEnv(OptionsParsingResult options) + /** Creates special output formatter for fetch that doesn't print anything */ + private NamedThreadSafeOutputFormatterCallback createNoOutputFormatter() { + return new NamedThreadSafeOutputFormatterCallback() { + @Override + public String getName() { + return "no_output"; + } + + @Override + public void processOutput(Iterable partialResult) { + // Just do nothing! + // This will be later used to collect repos for vendoring + } + }; + } + + private BuildRequest createBuildRequest( + CommandEnvironment env, OptionsParsingResult options, List targets) { + return BuildRequest.builder() + .setCommandName(env.getCommandName()) + .setId(env.getCommandId()) + .setOptions(options) + .setStartupOptions(env.getRuntime().getStartupOptionsProvider()) + .setOutErr(env.getReporter().getOutErr()) + .setTargets(targets) + .setStartTimeMillis(env.getCommandStartTime()) + .setCheckforActionConflicts(false) + .setReportIncompatibleTargets(false) + .build(); + } + + private Parser getMainRepoMappingParser(CommandEnvironment env) throws RepositoryMappingResolutionException, InterruptedException { - boolean keepGoing = options.getOptions(KeepGoingOption.class).keepGoing; - LoadingPhaseThreadsOption threadsOption = options.getOptions(LoadingPhaseThreadsOption.class); RepositoryMapping repoMapping = env.getSkyframeExecutor() - .getMainRepoMapping(keepGoing, threadsOption.threads, env.getReporter()); - TargetPattern.Parser targetParser = - new Parser(env.getRelativeWorkingDirectory(), RepositoryName.MAIN, repoMapping); - return QueryCommand.newQueryEnvironment( - env, - keepGoing, - false, - UniverseScope.EMPTY, - threadsOption.threads, - EnumSet.noneOf(Setting.class), - /* useGraphlessQuery= */ true, - targetParser, - LabelPrinter.legacy()); + .getMainRepoMapping( + env.getOptions().getOptions(KeepGoingOption.class).keepGoing, + env.getOptions().getOptions(LoadingPhaseThreadsOption.class).threads, + env.getReporter()); + return new Parser(env.getRelativeWorkingDirectory(), RepositoryName.MAIN, repoMapping); } - private QueryExpression createQueryExpression( - List targets, AbstractBlazeQueryEnvironment queryEnv) + private QueryExpression createQueryExpression(List targets) throws TargetFetcherException { String query = "deps(" + Joiner.on(" union ").join(targets) + ")"; + + ImmutableMap functions = + Stream.of(ConfiguredTargetQueryEnvironment.FUNCTIONS, env.getRuntime().getQueryFunctions()) + .flatMap(Collection::stream) + .collect(toImmutableMap(QueryFunction::getName, Function.identity())); + try { - return QueryExpression.parse(query, queryEnv); + return QueryParser.parse(query, functions); } catch (QuerySyntaxException e) { throw new TargetFetcherException( String.format( @@ -121,6 +145,29 @@ private QueryExpression createQueryExpression( } } + static void injectOptionsToFetchTarget(OptionsParser optionsParser) { + try { + optionsParser.parse( + PriorityCategory.COMPUTED_DEFAULT, + "Options required to fetch target", + ImmutableList.of("--nobuild")); + optionsParser.parse( + PriorityCategory.COMPUTED_DEFAULT, + "Fetch target should include 'tags = [\"manual\"]' targets by default", + ImmutableList.of("--build_manual_tests")); + optionsParser.parse( + PriorityCategory.SOFTWARE_REQUIREMENT, + "Fetch target should not exclude test_suite rules", + ImmutableList.of("--noexpand_test_suites")); + optionsParser.parse( + PriorityCategory.SOFTWARE_REQUIREMENT, + "Fetch target should not exclude tests", + ImmutableList.of("--nobuild_tests_only")); + } catch (OptionsParsingException e) { + throw new IllegalStateException("Fetch target needed options failed to parse", e); + } + } + static class TargetFetcherException extends Exception { public TargetFetcherException(String message) { super(message); diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BUILD b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BUILD index 72e589410700ce..900f1ab1d0d6a6 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BUILD +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BUILD @@ -40,6 +40,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/rules/cpp", "//src/main/java/com/google/devtools/build/lib/rules/java:java-compilation", "//src/main/java/com/google/devtools/build/lib/rules/java:java-rules", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant", "//src/main/java/com/google/devtools/build/lib/util:filetype", diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaBuildInfoFactory.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaBuildInfoFactory.java index dba04abd693cd4..d83799807f16d3 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaBuildInfoFactory.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaBuildInfoFactory.java @@ -19,14 +19,14 @@ import com.google.devtools.build.lib.rules.java.BuildInfoPropertiesTranslator; import com.google.devtools.build.lib.rules.java.GenericBuildInfoPropertiesTranslator; import com.google.devtools.build.lib.rules.java.JavaBuildInfoFactory; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; /** * BuildInfoFactory for Java. */ public class BazelJavaBuildInfoFactory extends JavaBuildInfoFactory { - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final GenericBuildInfoPropertiesTranslator VOLATILE_KEYS = new GenericBuildInfoPropertiesTranslator( ImmutableMap.builder() @@ -35,12 +35,12 @@ public class BazelJavaBuildInfoFactory extends JavaBuildInfoFactory { .put("build.timestamp", "%BUILD_TIMESTAMP%") .buildOrThrow()); - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final GenericBuildInfoPropertiesTranslator NONVOLATILE_KEYS = new GenericBuildInfoPropertiesTranslator( ImmutableMap.of("build.label", "%" + BuildInfo.BUILD_EMBED_LABEL + "|%")); - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final GenericBuildInfoPropertiesTranslator REDACTED_KEYS = new GenericBuildInfoPropertiesTranslator( ImmutableMap.builder() diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/CqueryProcessor.java b/src/main/java/com/google/devtools/build/lib/buildtool/CqueryProcessor.java index d2a607991afd3b..64fac989abd332 100644 --- a/src/main/java/com/google/devtools/build/lib/buildtool/CqueryProcessor.java +++ b/src/main/java/com/google/devtools/build/lib/buildtool/CqueryProcessor.java @@ -14,10 +14,11 @@ package com.google.devtools.build.lib.buildtool; import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.cmdline.TargetPattern; import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions; +import com.google.devtools.build.lib.query2.NamedThreadSafeOutputFormatterCallback; import com.google.devtools.build.lib.query2.PostAnalysisQueryEnvironment.TopLevelConfigurations; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.cquery.ConfiguredTargetQueryEnvironment; import com.google.devtools.build.lib.query2.cquery.CqueryOptions; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction; @@ -26,14 +27,30 @@ import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.build.skyframe.WalkableGraph; import java.util.Collection; +import java.util.Optional; import net.starlark.java.eval.StarlarkSemantics; /** Performs {@code cquery} processing. */ -public final class CqueryProcessor extends PostAnalysisQueryProcessor { +public final class CqueryProcessor extends PostAnalysisQueryProcessor { + + /** + * Only passed when this is a call from a non query command like Fetch or Vendor, where we don't + * need the output printed + */ + private Optional> noOutputFormatter; public CqueryProcessor( QueryExpression queryExpression, TargetPattern.Parser mainRepoTargetParser) { super(queryExpression, mainRepoTargetParser); + this.noOutputFormatter = Optional.empty(); + } + + public CqueryProcessor( + QueryExpression queryExpression, + TargetPattern.Parser mainRepoTargetParser, + Optional> noOutputFormatter) { + this(queryExpression, mainRepoTargetParser); + this.noOutputFormatter = noOutputFormatter; } @Override @@ -66,6 +83,7 @@ protected ConfiguredTargetQueryEnvironment getQueryEnvironment( request.getTopLevelArtifactContext(), request .getOptions(CqueryOptions.class) - .getLabelPrinter(starlarkSemantics, mainRepoTargetParser.getRepoMapping())); + .getLabelPrinter(starlarkSemantics, mainRepoTargetParser.getRepoMapping()), + noOutputFormatter); } } diff --git a/src/main/java/com/google/devtools/build/lib/collect/BUILD b/src/main/java/com/google/devtools/build/lib/collect/BUILD index 41cfc7c751fb70..c9b0dae03e6f75 100644 --- a/src/main/java/com/google/devtools/build/lib/collect/BUILD +++ b/src/main/java/com/google/devtools/build/lib/collect/BUILD @@ -26,8 +26,10 @@ java_library( deps = [ "//src/main/java/com/google/devtools/build/lib/collect/compacthashset", "//src/main/java/com/google/devtools/build/lib/concurrent", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant", + "//third_party:error_prone_annotations", "//third_party:guava", "//third_party:jsr305", "//third_party/protobuf:protobuf_java", diff --git a/src/main/java/com/google/devtools/build/lib/collect/ImmutableSharedKeyMap.java b/src/main/java/com/google/devtools/build/lib/collect/ImmutableSharedKeyMap.java index ded1fa7b3970af..cc0ef62b251122 100644 --- a/src/main/java/com/google/devtools/build/lib/collect/ImmutableSharedKeyMap.java +++ b/src/main/java/com/google/devtools/build/lib/collect/ImmutableSharedKeyMap.java @@ -19,7 +19,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Interner; import com.google.devtools.build.lib.concurrent.BlazeInterners; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.ArrayList; import java.util.Arrays; diff --git a/src/main/java/com/google/devtools/build/lib/collect/IterableCodecs.java b/src/main/java/com/google/devtools/build/lib/collect/IterableCodecs.java index 4061fa23f97547..092a42c06dc37b 100644 --- a/src/main/java/com/google/devtools/build/lib/collect/IterableCodecs.java +++ b/src/main/java/com/google/devtools/build/lib/collect/IterableCodecs.java @@ -20,7 +20,7 @@ import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec; import com.google.devtools.build.lib.skyframe.serialization.SerializationContext; import com.google.devtools.build.lib.skyframe.serialization.SerializationException; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.protobuf.CodedInputStream; import com.google.protobuf.CodedOutputStream; @@ -94,5 +94,5 @@ private static ImmutableList deserialize( * *

We use this instead of emitting a count to avoid possibly running deduplication twice. */ - @SerializationConstant @AutoCodec.VisibleForSerialization static final Object DONE = new Object(); + @SerializationConstant @VisibleForSerialization static final Object DONE = new Object(); } diff --git a/src/main/java/com/google/devtools/build/lib/collect/nestedset/BUILD b/src/main/java/com/google/devtools/build/lib/collect/nestedset/BUILD index 66db3d2a74ffed..c1402b68d00cb5 100644 --- a/src/main/java/com/google/devtools/build/lib/collect/nestedset/BUILD +++ b/src/main/java/com/google/devtools/build/lib/collect/nestedset/BUILD @@ -33,6 +33,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/packages/semantics", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:constants", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant", "//src/main/java/com/google/devtools/build/lib/util:detailed_exit_code", diff --git a/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSet.java b/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSet.java index d7a5df7ea20628..0af3626882c824 100644 --- a/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSet.java +++ b/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSet.java @@ -29,8 +29,8 @@ import com.google.devtools.build.lib.server.FailureDetails.FailureDetail; import com.google.devtools.build.lib.server.FailureDetails.Interrupted; import com.google.devtools.build.lib.server.FailureDetails.Interrupted.Code; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.lib.util.DetailedExitCode; import com.google.devtools.build.lib.util.ExitCode; diff --git a/src/main/java/com/google/devtools/build/lib/collect/nestedset/Order.java b/src/main/java/com/google/devtools/build/lib/collect/nestedset/Order.java index fe290b5d4c8d41..70200b607ee926 100644 --- a/src/main/java/com/google/devtools/build/lib/collect/nestedset/Order.java +++ b/src/main/java/com/google/devtools/build/lib/collect/nestedset/Order.java @@ -15,7 +15,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import java.util.HashMap; @@ -120,28 +120,28 @@ public enum Order { this.emptyDepset = new Depset(null, this.emptySet); } - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final Order STABLE_ORDER_CONSTANT = STABLE_ORDER; - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final Order COMPILE_ORDER_CONSTANT = COMPILE_ORDER; - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final Order LINK_ORDER_CONSTANT = LINK_ORDER; - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final Order NAIVE_LINK_ORDER_CONSTANT = NAIVE_LINK_ORDER; - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final NestedSet EMPTY_STABLE = STABLE_ORDER.emptySet(); - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final NestedSet EMPTY_COMPILE = COMPILE_ORDER.emptySet(); - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final NestedSet EMPTY_LINK = LINK_ORDER.emptySet(); - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final NestedSet EMPTY_NAIVE_LINK = NAIVE_LINK_ORDER.emptySet(); /** diff --git a/src/main/java/com/google/devtools/build/lib/io/BUILD b/src/main/java/com/google/devtools/build/lib/io/BUILD index 58032606d38374..4a80a07cf4dba9 100644 --- a/src/main/java/com/google/devtools/build/lib/io/BUILD +++ b/src/main/java/com/google/devtools/build/lib/io/BUILD @@ -60,7 +60,7 @@ java_library( srcs = ["FileSymlinkCycleUniquenessFunction.java"], deps = [ ":abstract_chain_uniqueness_function", - "//src/main/java/com/google/devtools/build/lib/concurrent", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/vfs", "//src/main/java/com/google/devtools/build/skyframe:skyframe-objects", @@ -73,7 +73,7 @@ java_library( srcs = ["FileSymlinkInfiniteExpansionException.java"], deps = [ ":file_symlink_exception", - "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/vfs", "//third_party:guava", ], @@ -84,7 +84,7 @@ java_library( srcs = ["FileSymlinkInfiniteExpansionUniquenessFunction.java"], deps = [ ":abstract_chain_uniqueness_function", - "//src/main/java/com/google/devtools/build/lib/concurrent", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/vfs", "//src/main/java/com/google/devtools/build/skyframe:skyframe-objects", diff --git a/src/main/java/com/google/devtools/build/lib/io/FileSymlinkCycleUniquenessFunction.java b/src/main/java/com/google/devtools/build/lib/io/FileSymlinkCycleUniquenessFunction.java index 7479bf9a9319fc..6a26c05fb3112f 100644 --- a/src/main/java/com/google/devtools/build/lib/io/FileSymlinkCycleUniquenessFunction.java +++ b/src/main/java/com/google/devtools/build/lib/io/FileSymlinkCycleUniquenessFunction.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.io; import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.AbstractSkyKey; @@ -34,7 +35,7 @@ public static SkyKey key(ImmutableList cycle) { return Key.create(AbstractFileChainUniquenessFunction.canonicalize(cycle)); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec static class Key extends AbstractSkyKey.WithCachedHashCode> { private static final SkyKeyInterner interner = SkyKey.newInterner(); @@ -43,7 +44,7 @@ private Key(ImmutableList arg) { super(arg); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static Key create(ImmutableList arg) { return interner.intern(new Key(arg)); diff --git a/src/main/java/com/google/devtools/build/lib/io/FileSymlinkInfiniteExpansionException.java b/src/main/java/com/google/devtools/build/lib/io/FileSymlinkInfiniteExpansionException.java index cc2a02dc82dcc1..d33283bad19664 100644 --- a/src/main/java/com/google/devtools/build/lib/io/FileSymlinkInfiniteExpansionException.java +++ b/src/main/java/com/google/devtools/build/lib/io/FileSymlinkInfiniteExpansionException.java @@ -16,7 +16,7 @@ import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.vfs.RootedPath; /** Exception indicating that a symlink has an unbounded expansion on resolution. */ diff --git a/src/main/java/com/google/devtools/build/lib/io/FileSymlinkInfiniteExpansionUniquenessFunction.java b/src/main/java/com/google/devtools/build/lib/io/FileSymlinkInfiniteExpansionUniquenessFunction.java index fac0ee36076b79..0a321735203fc9 100644 --- a/src/main/java/com/google/devtools/build/lib/io/FileSymlinkInfiniteExpansionUniquenessFunction.java +++ b/src/main/java/com/google/devtools/build/lib/io/FileSymlinkInfiniteExpansionUniquenessFunction.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.io; import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.AbstractSkyKey; @@ -35,7 +36,7 @@ public static SkyKey key(ImmutableList cycle) { return Key.create(AbstractFileChainUniquenessFunction.canonicalize(cycle)); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec static class Key extends AbstractSkyKey.WithCachedHashCode> { private static final SkyKeyInterner interner = SkyKey.newInterner(); @@ -44,7 +45,7 @@ private Key(ImmutableList arg) { super(arg); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static Key create(ImmutableList arg) { return interner.intern(new Key(arg)); diff --git a/src/main/java/com/google/devtools/build/lib/packages/AspectsList.java b/src/main/java/com/google/devtools/build/lib/packages/AspectsList.java index 9d355d50429d30..fe50baf411e6fc 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/AspectsList.java +++ b/src/main/java/com/google/devtools/build/lib/packages/AspectsList.java @@ -21,7 +21,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import java.util.HashMap; import java.util.LinkedHashMap; diff --git a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java index 16cf08cbcfdbea..fefdf568595788 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java @@ -37,7 +37,7 @@ import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassNamePredicate; import com.google.devtools.build.lib.packages.Type.ConversionException; import com.google.devtools.build.lib.packages.Type.LabelClass; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.lib.starlarkbuildapi.NativeComputedDefaultApi; import com.google.devtools.build.lib.util.FileType; @@ -1657,9 +1657,9 @@ protected AbstractLabelLateBoundDefault(Class fragmentClass, Label de } } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization static class AlwaysNullLateBoundDefault extends SimpleLateBoundDefault { - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final AlwaysNullLateBoundDefault INSTANCE = new AlwaysNullLateBoundDefault(); private AlwaysNullLateBoundDefault() { diff --git a/src/main/java/com/google/devtools/build/lib/packages/BUILD b/src/main/java/com/google/devtools/build/lib/packages/BUILD index 04366d6e980dc1..24b258ad43e4d7 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/BUILD +++ b/src/main/java/com/google/devtools/build/lib/packages/BUILD @@ -83,6 +83,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/profiler", "//src/main/java/com/google/devtools/build/lib/skyframe:detailed_exceptions", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant", "//src/main/java/com/google/devtools/build/lib/starlarkbuildapi", diff --git a/src/main/java/com/google/devtools/build/lib/packages/PackageSpecification.java b/src/main/java/com/google/devtools/build/lib/packages/PackageSpecification.java index 320ee9b7726fce..ca518950703956 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/PackageSpecification.java +++ b/src/main/java/com/google/devtools/build/lib/packages/PackageSpecification.java @@ -21,7 +21,7 @@ import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import com.google.devtools.build.lib.cmdline.PackageIdentifier; import com.google.devtools.build.lib.cmdline.RepositoryName; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.lib.vfs.PathFragment; import javax.annotation.Nullable; diff --git a/src/main/java/com/google/devtools/build/lib/packages/PredicatesWithMessage.java b/src/main/java/com/google/devtools/build/lib/packages/PredicatesWithMessage.java index b8fb3ad9a19b08..aa553d1e7b631d 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/PredicatesWithMessage.java +++ b/src/main/java/com/google/devtools/build/lib/packages/PredicatesWithMessage.java @@ -13,7 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.packages; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; /** diff --git a/src/main/java/com/google/devtools/build/lib/packages/RequiredProviders.java b/src/main/java/com/google/devtools/build/lib/packages/RequiredProviders.java index 9195a4f0944caa..fab94488a0a70f 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/RequiredProviders.java +++ b/src/main/java/com/google/devtools/build/lib/packages/RequiredProviders.java @@ -19,7 +19,7 @@ import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.Objects; import java.util.function.Function; diff --git a/src/main/java/com/google/devtools/build/lib/packages/Rule.java b/src/main/java/com/google/devtools/build/lib/packages/Rule.java index ca9dac1cfdb812..f6cc9b73dbdbc4 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Rule.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Rule.java @@ -47,7 +47,7 @@ import com.google.devtools.build.lib.packages.Package.ConfigSettingVisibilityPolicy; import com.google.devtools.build.lib.packages.RuleClass.ToolchainResolutionMode; import com.google.devtools.build.lib.server.FailureDetails.PackageLoading; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java index 0ed3b6d925bd53..50a3f38d6d8853 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java +++ b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java @@ -50,8 +50,8 @@ import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType; import com.google.devtools.build.lib.packages.RuleFactory.AttributeValues; import com.google.devtools.build.lib.packages.Type.ConversionException; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.lib.starlarkbuildapi.StarlarkSubruleApi; import com.google.devtools.build.lib.util.HashCodes; diff --git a/src/main/java/com/google/devtools/build/lib/packages/StarlarkNativeAspect.java b/src/main/java/com/google/devtools/build/lib/packages/StarlarkNativeAspect.java index 2e5aed51b5df10..d4986499ea0923 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/StarlarkNativeAspect.java +++ b/src/main/java/com/google/devtools/build/lib/packages/StarlarkNativeAspect.java @@ -16,13 +16,13 @@ import com.google.common.base.Function; import com.google.common.collect.ImmutableSet; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import net.starlark.java.eval.Printer; /** A natively-defined aspect that is may be referenced by Starlark attribute definitions. */ public abstract class StarlarkNativeAspect extends NativeAspectClass implements StarlarkAspect { - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final Function EMPTY_FUNCTION = input -> AspectParameters.EMPTY; @Override diff --git a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFileValue.java b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFileValue.java index efa5166209d79a..386110a693f656 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFileValue.java +++ b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFileValue.java @@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.SkyFunctionName; @@ -51,7 +52,7 @@ private WorkspaceFileKey(RootedPath path, int idx) { this.idx = idx; } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static WorkspaceFileKey create(RootedPath path, int idx) { return interner.intern(new WorkspaceFileKey(path, idx)); diff --git a/src/main/java/com/google/devtools/build/lib/pkgcache/BUILD b/src/main/java/com/google/devtools/build/lib/pkgcache/BUILD index 3d52551332714e..e0aa19ba0707f6 100644 --- a/src/main/java/com/google/devtools/build/lib/pkgcache/BUILD +++ b/src/main/java/com/google/devtools/build/lib/pkgcache/BUILD @@ -36,6 +36,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/packages", "//src/main/java/com/google/devtools/build/lib/query2/engine", "//src/main/java/com/google/devtools/build/lib/skyframe:detailed_exceptions", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/util:detailed_exit_code", "//src/main/java/com/google/devtools/build/lib/util:filetype", diff --git a/src/main/java/com/google/devtools/build/lib/pkgcache/TestFilter.java b/src/main/java/com/google/devtools/build/lib/pkgcache/TestFilter.java index f72338ece96bff..ac15341e87a9d8 100644 --- a/src/main/java/com/google/devtools/build/lib/pkgcache/TestFilter.java +++ b/src/main/java/com/google/devtools/build/lib/pkgcache/TestFilter.java @@ -22,6 +22,7 @@ import com.google.devtools.build.lib.packages.TargetUtils; import com.google.devtools.build.lib.packages.TestSize; import com.google.devtools.build.lib.packages.TestTimeout; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import java.util.HashSet; import java.util.List; @@ -54,7 +55,7 @@ public static TestFilter forOptions(LoadingOptions options) { private final ImmutableList testLangFilterList; private final Predicate impl; - @AutoCodec.VisibleForSerialization + @VisibleForSerialization TestFilter( ImmutableSet testSizeFilterSet, ImmutableSet testTimeoutFilterSet, diff --git a/src/main/java/com/google/devtools/build/lib/query2/BUILD b/src/main/java/com/google/devtools/build/lib/query2/BUILD index d5bd7fdf50181d..8c3327c9eae63b 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/BUILD +++ b/src/main/java/com/google/devtools/build/lib/query2/BUILD @@ -27,6 +27,7 @@ java_library( ), deps = [ "//src/main/java/com/google/devtools/build/lib/actions", + "//src/main/java/com/google/devtools/build/lib/actions:action_lookup_key", "//src/main/java/com/google/devtools/build/lib/actions:artifacts", "//src/main/java/com/google/devtools/build/lib/actions:commandline_item", "//src/main/java/com/google/devtools/build/lib/actions:file_metadata", @@ -74,6 +75,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/query2/common:QueryTransitivePackagePreloader", "//src/main/java/com/google/devtools/build/lib/query2/common:UniverseSkyKey", "//src/main/java/com/google/devtools/build/lib/query2/common:abstract-blaze-query-env", + "//src/main/java/com/google/devtools/build/lib/query2/common:cquery-node", "//src/main/java/com/google/devtools/build/lib/query2/common:options", "//src/main/java/com/google/devtools/build/lib/query2/common:universe-scope", "//src/main/java/com/google/devtools/build/lib/query2/compat:fake-load-target", diff --git a/src/main/java/com/google/devtools/build/lib/query2/PostAnalysisQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/PostAnalysisQueryEnvironment.java index 74b8498c814216..0b9c1af92a7717 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/PostAnalysisQueryEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/query2/PostAnalysisQueryEnvironment.java @@ -24,7 +24,9 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import com.google.devtools.build.lib.actions.ActionLookupKey; import com.google.devtools.build.lib.analysis.AliasProvider; +import com.google.devtools.build.lib.analysis.AspectValue; import com.google.devtools.build.lib.analysis.ConfiguredTargetValue; import com.google.devtools.build.lib.analysis.TargetAndConfiguration; import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue; @@ -74,6 +76,7 @@ import com.google.devtools.build.lib.supplier.InterruptibleSupplier; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.skyframe.SkyKey; +import com.google.devtools.build.skyframe.SkyValue; import com.google.devtools.build.skyframe.WalkableGraph; import java.io.IOException; import java.io.OutputStream; @@ -144,7 +147,7 @@ public PostAnalysisQueryEnvironment( public abstract String getOutputFormat(); - protected abstract KeyExtractor getConfiguredTargetKeyExtractor(); + protected abstract KeyExtractor getConfiguredTargetKeyExtractor(); @Override public QueryEvalResult evaluateQuery( @@ -217,12 +220,18 @@ public T getOrCreate(T target) { protected abstract T getNullConfiguredTarget(Label label) throws InterruptedException; @Nullable - public ConfiguredTargetValue getConfiguredTargetValue(SkyKey key) throws InterruptedException { - return (ConfiguredTargetValue) walkableGraphSupplier.get().getValue(key); + public SkyValue getConfiguredTargetValue(SkyKey key) throws InterruptedException { + return walkableGraphSupplier.get().getValue(key); + } + + @Nullable + public AspectValue getAspectValue(SkyKey key) throws InterruptedException { + return (AspectValue) walkableGraphSupplier.get().getValue(key); } private boolean isAliasConfiguredTarget(ConfiguredTargetKey key) throws InterruptedException { - return AliasProvider.isAlias(getConfiguredTargetValue(key).getConfiguredTarget()); + return AliasProvider.isAlias( + ((ConfiguredTargetValue) getConfiguredTargetValue(key)).getConfiguredTarget()); } public InterruptibleSupplier> @@ -362,7 +371,7 @@ private Set unwindReverseDependencyDelegationLayersIfFound( if (!rdep.functionName().equals(SkyFunctions.CONFIGURED_TARGET)) { continue; } - ConfiguredTargetKey actualParentKey = getConfiguredTargetKey(getValueFromKey(rdep)); + var actualParentKey = getConfiguredTargetKey(getValueFromKey(rdep)); if (actualParentKey.equals(child)) { // The parent has the same value as the child because it is delegating. foundDelegatingRdep = true; @@ -386,7 +395,7 @@ private void unwindReverseDependencyDelegationLayers( output.add(rdep); continue; } - ConfiguredTargetKey actualParentKey = getConfiguredTargetKey(getValueFromKey(rdep)); + var actualParentKey = getConfiguredTargetKey(getValueFromKey(rdep)); if (!actualParentKey.equals(child)) { output.add(rdep); continue; @@ -479,19 +488,24 @@ private ImmutableList> targetifyValues( } } + boolean explicitAspects = + settings.containsAll(ImmutableSet.of(Setting.INCLUDE_ASPECTS, Setting.EXPLICIT_ASPECTS)); + ImmutableList.Builder> values = ImmutableList.builder(); - // TODO(bazel-team): An even better approach would be to treat aspects and toolchains as + // TODO(bazel-team): The end-goal approach is to treat aspects and toolchains as // first-class query nodes just like targets. In other words, let query expressions reference // them (they also have identifying labels) and make the graph connections between targets, // aspects, and toolchains explicit. That would permit more detailed queries and eliminate the - // per-key-type special casing below. The challenge is to generalize all query code that - // currently assumes its inputs are configured targets. Toolchains may have additional caveats: - // see b/148550864. + // per-key-type special casing below. + // This is being experimentally implemented in phases. Currently support for aspects has been + // implemented behind the --experimental_explicit_aspects flag. + // See https://github.com/bazelbuild/bazel/issues/16310 for details. for (SkyKey key : dependencies) { if (knownCtDeps.contains(key)) { continue; } - if (key.functionName().equals(SkyFunctions.CONFIGURED_TARGET)) { + if (key.functionName().equals(SkyFunctions.CONFIGURED_TARGET) + || (explicitAspects && key.functionName().equals(SkyFunctions.ASPECT))) { T dependency = getValueFromKey(key); Preconditions.checkState( dependency != null, @@ -501,17 +515,24 @@ private ImmutableList> targetifyValues( + " configurability team.", key); - boolean implicit = + boolean implicitConfiguredTarget = // Check both the original guess key and the second correct key. In the case of the // target platform, Util.findImplicitDeps also uses the original guess key. implicitDeps == null || implicitDeps.contains(key) || implicitDeps.contains(getConfiguredTargetKey(dependency)); + + boolean implicit = + !(key.argument() instanceof ConfiguredTargetKey) || implicitConfiguredTarget; + values.add(new ClassifiedDependency<>(dependency, implicit)); knownCtDeps.add(key); } else if (settings.contains(Setting.INCLUDE_ASPECTS) - && key.functionName().equals(SkyFunctions.ASPECT) - && !resolvedAspectClasses.contains(((AspectKey) key).getAspectClass())) { + && key.functionName().equals(SkyFunctions.ASPECT)) { + Preconditions.checkState(!settings.contains(Setting.EXPLICIT_ASPECTS)); + if (resolvedAspectClasses.contains(((AspectKey) key).getAspectClass())) { + continue; + } // When an aspect is attached to an alias configured target, it bypasses standard dependency // resolution and just Skyframe-loads the same aspect for the alias' referent. That means // the original aspect's attribute deps aren't Skyframe-resolved through AspectFunction's @@ -550,8 +571,8 @@ private Map>> targetifyValues( targetifyValues( fromTargetsByKey.get(fromKey), entry.getValue(), - /*knownCtDeps=*/ new HashSet<>(), - /*resolvedAspectClasses=*/ new HashSet<>())); + /* knownCtDeps= */ new HashSet<>(), + /* resolvedAspectClasses= */ new HashSet<>())); } return result; } @@ -586,7 +607,7 @@ private static ImmutableList getDependencies( @Nullable protected abstract BuildConfigurationValue getConfiguration(T target); - protected abstract ConfiguredTargetKey getConfiguredTargetKey(T target); + protected abstract ActionLookupKey getConfiguredTargetKey(T target); @Override public ThreadSafeMutableSet getTransitiveClosure( @@ -649,11 +670,13 @@ public static class TopLevelConfigurations { /** A map of non-null configured top-level targets sorted by configuration checksum. */ private final ImmutableMap nonNulls; + /** * {@code nonNulls} may often have many duplicate values in its value set so we store a sorted * set of all the non-null configurations here. */ private final ImmutableSortedSet nonNullConfigs; + /** A list of null configured top-level targets. */ private final ImmutableList

If this changes, {@link AspectResolver#aspectMatchesConfiguredTarget} should be updated. + */ + @Nullable + default BuildConfigurationKey getConfigurationKey() { + return getLookupKey().getConfigurationKey(); + } + + /** + * If the configured target is an alias, return the actual target, otherwise return the current + * target. This follows alias chains. + */ + default CqueryNode getActual() { + return this; + } + + /** + * If the configured target is an alias, return the original label, otherwise return the current + * label. This is not the same as {@code getActual().getLabel()}, because it does not follow alias + * chains. + */ + default Label getOriginalLabel() { + return getLabel(); + } + + /** + * The configuration conditions that trigger this configured target's configurable attributes. For + * targets that do not support configurable attributes, this will be an empty map. + */ + default ImmutableMap getConfigConditions() { + return ImmutableMap.of(); + } + + default boolean isRuleConfiguredTarget() { + return false; + } + + /** + * The base configured target if it has been merged with aspects otherwise the current value. + * + *

Unwrapping is recursive if there are multiple layers. + */ + default CqueryNode unwrapIfMerged() { + return this; + } + + /** + * This is only intended to be called from the query dialects of Starlark. + * + * @return a map of provider names to their values, or null if there are no providers + */ + @Nullable + default Dict getProvidersDictForQuery() { + return null; + } +} diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallback.java index 6ee85ab00d9de7..5b4bc337b73979 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallback.java @@ -15,7 +15,6 @@ package com.google.devtools.build.lib.query2.cquery; import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.configuredtargets.OutputFileConfiguredTarget; import com.google.devtools.build.lib.events.ExtendedEventHandler; import com.google.devtools.build.lib.packages.Attribute; @@ -23,6 +22,7 @@ import com.google.devtools.build.lib.packages.LabelPrinter; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.Target; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.TargetAccessor; import com.google.devtools.build.lib.query2.query.output.BuildOutputFormatter; import com.google.devtools.build.lib.query2.query.output.BuildOutputFormatter.AttributeReader; @@ -42,7 +42,7 @@ class BuildOutputFormatterCallback extends CqueryThreadsafeCallback { CqueryOptions options, OutputStream out, SkyframeExecutor skyframeExecutor, - TargetAccessor accessor, + TargetAccessor accessor, LabelPrinter labelPrinter) { super(eventHandler, options, out, skyframeExecutor, accessor, /* uniquifyResults= */ false); this.labelPrinter = labelPrinter; @@ -73,8 +73,7 @@ public Iterable getPossibleValues(Rule rule, Attribute attr) { } @Nullable - private ConfiguredAttributeMapper getAttributeMap(ConfiguredTarget kct) - throws InterruptedException { + private ConfiguredAttributeMapper getAttributeMap(CqueryNode kct) throws InterruptedException { Rule associatedRule = accessor.getTarget(kct).getAssociatedRule(); if (associatedRule == null) { return null; @@ -94,7 +93,7 @@ private ConfiguredAttributeMapper getAttributeMap(ConfiguredTarget kct) } @Override - public void processOutput(Iterable partialResult) + public void processOutput(Iterable partialResult) throws InterruptedException, IOException { BuildOutputFormatter.TargetOutputter outputter = new TargetOutputter( @@ -106,7 +105,7 @@ public void processOutput(Iterable partialResult) (rule, attr) -> false, System.lineSeparator(), labelPrinter); - for (ConfiguredTarget configuredTarget : partialResult) { + for (CqueryNode configuredTarget : partialResult) { Target target = accessor.getTarget(configuredTarget); outputter.output(target, new CqueryAttributeReader(getAttributeMap(configuredTarget))); } diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfigFunction.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfigFunction.java index 1b105be912fa65..a31868af7a2d40 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfigFunction.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfigFunction.java @@ -14,8 +14,8 @@ package com.google.devtools.build.lib.query2.cquery; import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.query2.common.AbstractBlazeQueryEnvironment; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.engine.Callback; import com.google.devtools.build.lib.query2.engine.QueryEnvironment; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.Argument; @@ -59,7 +59,7 @@ public List getArgumentTypes() { /** * This function is only viable with ConfiguredTargetQueryEnvironment which extends {@link - * AbstractBlazeQueryEnvironment }. + * AbstractBlazeQueryEnvironment }. */ @Override @SuppressWarnings("unchecked") @@ -85,6 +85,6 @@ public QueryTaskFuture eval( targetExpression.toString(), targetsFuture, configuration, - (Callback) callback)); + (Callback) callback)); } } diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetAccessor.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetAccessor.java index c25a6e6ed24b18..6df105f18161b8 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetAccessor.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetAccessor.java @@ -29,6 +29,7 @@ import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.Target; import com.google.devtools.build.lib.packages.TargetUtils; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.TargetAccessor; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.TargetNotFoundException; import com.google.devtools.build.lib.query2.engine.QueryException; @@ -47,7 +48,7 @@ * *

Incomplete; we'll implement getVisibility when needed. */ -public class ConfiguredTargetAccessor implements TargetAccessor { +public class ConfiguredTargetAccessor implements TargetAccessor { private final WalkableGraph walkableGraph; private final ConfiguredTargetQueryEnvironment queryEnvironment; @@ -74,56 +75,55 @@ public ConfiguredTargetAccessor( } @Override - public String getTargetKind(ConfiguredTarget target) { + public String getTargetKind(CqueryNode target) { Target actualTarget = getTarget(target); return actualTarget.getTargetKind(); } @Override - public String getLabel(ConfiguredTarget target) { + public String getLabel(CqueryNode target) { return target.getOriginalLabel().toString(); } @Override - public String getPackage(ConfiguredTarget target) { + public String getPackage(CqueryNode target) { return target.getOriginalLabel().getPackageIdentifier().getPackageFragment().toString(); } @Override - public boolean isRule(ConfiguredTarget target) { + public boolean isRule(CqueryNode target) { Target actualTarget = getTarget(target); return actualTarget instanceof Rule; } @Override - public boolean isTestRule(ConfiguredTarget target) { + public boolean isTestRule(CqueryNode target) { Target actualTarget = getTarget(target); return TargetUtils.isTestRule(actualTarget); } @Override - public boolean isTestSuite(ConfiguredTarget target) { + public boolean isTestSuite(CqueryNode target) { Target actualTarget = getTarget(target); return TargetUtils.isTestSuiteRule(actualTarget); } @Override - public List getPrerequisites( + public List getPrerequisites( QueryExpression caller, - ConfiguredTarget keyedConfiguredTarget, + CqueryNode keyedConfiguredTarget, String attrName, String errorMsgPrefix) throws QueryException, InterruptedException { // Process aliases. - ConfiguredTarget actual = keyedConfiguredTarget.getActual(); + CqueryNode actual = keyedConfiguredTarget.getActual(); Preconditions.checkArgument( isRule(actual), "%s %s is not a rule configured target", errorMsgPrefix, getLabel(actual)); - ImmutableListMultimap depsByLabel = + ImmutableListMultimap depsByLabel = Multimaps.index( - queryEnvironment.getFwdDeps(ImmutableList.of(actual)), - ConfiguredTarget::getOriginalLabel); + queryEnvironment.getFwdDeps(ImmutableList.of(actual)), CqueryNode::getOriginalLabel); Rule rule = (Rule) getTarget(actual); ImmutableMap configConditions = actual.getConfigConditions(); @@ -141,39 +141,39 @@ public List getPrerequisites( errorMsgPrefix, rule.getRuleClass(), attrName), ConfigurableQuery.Code.ATTRIBUTE_MISSING); } - ImmutableList.Builder toReturn = ImmutableList.builder(); + ImmutableList.Builder toReturn = ImmutableList.builder(); attributeMapper.visitLabels(attrName, label -> toReturn.addAll(depsByLabel.get(label))); return toReturn.build(); } @Override - public List getStringListAttr(ConfiguredTarget target, String attrName) { + public List getStringListAttr(CqueryNode target, String attrName) { Target actualTarget = getTarget(target); return TargetUtils.getStringListAttr(actualTarget, attrName); } @Override - public String getStringAttr(ConfiguredTarget target, String attrName) { + public String getStringAttr(CqueryNode target, String attrName) { Target actualTarget = getTarget(target); return TargetUtils.getStringAttr(actualTarget, attrName); } @Override - public Iterable getAttrAsString(ConfiguredTarget target, String attrName) { + public Iterable getAttrAsString(CqueryNode target, String attrName) { Target actualTarget = getTarget(target); return TargetUtils.getAttrAsString(actualTarget, attrName); } @Override - public ImmutableSet> getVisibility( - QueryExpression caller, ConfiguredTarget from) throws QueryException { + public ImmutableSet> getVisibility( + QueryExpression caller, CqueryNode from) throws QueryException { // TODO(bazel-team): implement this if needed. throw new QueryException( "visible() is not supported on configured targets", ConfigurableQuery.Code.VISIBLE_FUNCTION_NOT_SUPPORTED); } - public Target getTarget(ConfiguredTarget configuredTarget) { + public Target getTarget(CqueryNode configuredTarget) { // Dereference any aliases that might be present. Label label = configuredTarget.getOriginalLabel(); try { @@ -190,8 +190,7 @@ SkyFunction.LookupEnvironment getLookupEnvironment() { } /** Returns the rule that generates the given output file. */ - RuleConfiguredTarget getGeneratingConfiguredTarget(ConfiguredTarget kct) - throws InterruptedException { + RuleConfiguredTarget getGeneratingConfiguredTarget(CqueryNode kct) throws InterruptedException { Preconditions.checkArgument(kct instanceof OutputFileConfiguredTarget); return (RuleConfiguredTarget) ((ConfiguredTargetValue) diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java index 45284c8ccd34ae..1ec7f14c4b9791 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java @@ -23,6 +23,8 @@ import com.google.common.util.concurrent.AsyncFunction; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.MoreExecutors; +import com.google.devtools.build.lib.actions.ActionLookupKey; +import com.google.devtools.build.lib.analysis.AspectValue; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.ConfiguredTargetValue; import com.google.devtools.build.lib.analysis.TopLevelArtifactContext; @@ -40,6 +42,7 @@ import com.google.devtools.build.lib.query2.NamedThreadSafeOutputFormatterCallback; import com.google.devtools.build.lib.query2.PostAnalysisQueryEnvironment; import com.google.devtools.build.lib.query2.SkyQueryEnvironment; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.cquery.ProtoOutputFormatterCallback.OutputType; import com.google.devtools.build.lib.query2.engine.Callback; import com.google.devtools.build.lib.query2.engine.KeyExtractor; @@ -50,10 +53,12 @@ import com.google.devtools.build.lib.query2.query.aspectresolvers.AspectResolver; import com.google.devtools.build.lib.rules.AliasConfiguredTarget; import com.google.devtools.build.lib.server.FailureDetails.ConfigurableQuery; +import com.google.devtools.build.lib.skyframe.AspectKeyCreator.AspectKey; import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey; import com.google.devtools.build.lib.skyframe.SkyframeExecutor; import com.google.devtools.build.lib.skyframe.config.BuildConfigurationKey; import com.google.devtools.build.skyframe.SkyKey; +import com.google.devtools.build.skyframe.SkyValue; import com.google.devtools.build.skyframe.WalkableGraph; import java.io.OutputStream; import java.util.ArrayList; @@ -61,6 +66,7 @@ import java.util.Comparator; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.function.Function; import java.util.function.Supplier; @@ -71,11 +77,11 @@ * {@link QueryEnvironment} that runs queries over the configured target (analysis) graph. * *

Aspects are partially supported. Their dependencies appear as implicit dependencies on the - * targets they're connected to, but the aspects themselves aren't visible as query nodes. See - * comments on {@link PostAnalysisQueryEnvironment#targetifyValues} and b/163052263 for details. + * targets they're connected to. When using the --experimental_explicit_aspects flag, the aspects + * themselves are visible as query nodes. See https://github.com/bazelbuild/bazel/issues/16310 for + * details. */ -public class ConfiguredTargetQueryEnvironment - extends PostAnalysisQueryEnvironment { +public class ConfiguredTargetQueryEnvironment extends PostAnalysisQueryEnvironment { /** Common query functions and cquery specific functions. */ public static final ImmutableList FUNCTIONS = populateFunctions(); /** Cquery specific functions. */ @@ -85,12 +91,18 @@ public class ConfiguredTargetQueryEnvironment private final TopLevelArtifactContext topLevelArtifactContext; - private final KeyExtractor configuredTargetKeyExtractor; + private final KeyExtractor configuredTargetKeyExtractor; private final ConfiguredTargetAccessor accessor; /** - * Stores every configuration in the transitive closure of the build graph as a map from its + * Only passed when this is a call from a non query command like Fetch or Vendor, where we don't + * need the output printed + */ + private Optional> noOutputFormatter; + + /** + * F Stores every configuration in the transitive closure of the build graph as a map from its * user-friendly hash to the configuration itself. * *

This is used to find configured targets in, e.g. {@code somepath} queries. Given {@code @@ -107,7 +119,7 @@ public class ConfiguredTargetQueryEnvironment private final ImmutableMap transitiveConfigurations; @Override - protected KeyExtractor getConfiguredTargetKeyExtractor() { + protected KeyExtractor getConfiguredTargetKeyExtractor() { return configuredTargetKeyExtractor; } @@ -135,7 +147,7 @@ public ConfiguredTargetQueryEnvironment( settings, labelPrinter); this.accessor = new ConfiguredTargetAccessor(walkableGraphSupplier.get(), this); - this.configuredTargetKeyExtractor = ConfiguredTargetKey::fromConfiguredTarget; + this.configuredTargetKeyExtractor = CqueryNode::getLookupKey; this.transitiveConfigurations = getTransitiveConfigurations(transitiveConfigurationKeys, walkableGraphSupplier.get()); this.topLevelArtifactContext = topLevelArtifactContext; @@ -152,7 +164,8 @@ public ConfiguredTargetQueryEnvironment( Supplier walkableGraphSupplier, CqueryOptions cqueryOptions, TopLevelArtifactContext topLevelArtifactContext, - LabelPrinter labelPrinter) + LabelPrinter labelPrinter, + Optional> noOutputFormatter) throws InterruptedException { this( keepGoing, @@ -167,6 +180,7 @@ public ConfiguredTargetQueryEnvironment( topLevelArtifactContext, labelPrinter); this.cqueryOptions = cqueryOptions; + this.noOutputFormatter = noOutputFormatter; } private static ImmutableList populateFunctions() { @@ -192,9 +206,9 @@ private static ImmutableMap getTransitiveConfig } @Override - public ImmutableList> + public ImmutableList> getDefaultOutputFormatters( - TargetAccessor accessor, + TargetAccessor accessor, ExtendedEventHandler eventHandler, OutputStream out, SkyframeExecutor skyframeExecutor, @@ -204,78 +218,112 @@ private static ImmutableMap getTransitiveConfig throws QueryException, InterruptedException { AspectResolver aspectResolver = cqueryOptions.aspectDeps.createResolver(packageManager, eventHandler); - return ImmutableList.of( - new LabelAndConfigurationOutputFormatterCallback( - eventHandler, cqueryOptions, out, skyframeExecutor, accessor, true, getLabelPrinter()), - new LabelAndConfigurationOutputFormatterCallback( - eventHandler, cqueryOptions, out, skyframeExecutor, accessor, false, getLabelPrinter()), - new TransitionsOutputFormatterCallback( - eventHandler, - cqueryOptions, - out, - skyframeExecutor, - accessor, - ruleClassProvider, - getLabelPrinter()), - new ProtoOutputFormatterCallback( - eventHandler, - cqueryOptions, - out, - skyframeExecutor, - accessor, - aspectResolver, - OutputType.BINARY, - ruleClassProvider, - getLabelPrinter()), - new ProtoOutputFormatterCallback( - eventHandler, - cqueryOptions, - out, - skyframeExecutor, - accessor, - aspectResolver, - OutputType.DELIMITED_BINARY, - ruleClassProvider, - labelPrinter), - new ProtoOutputFormatterCallback( - eventHandler, - cqueryOptions, - out, - skyframeExecutor, - accessor, - aspectResolver, - OutputType.TEXT, - ruleClassProvider, - getLabelPrinter()), - new ProtoOutputFormatterCallback( - eventHandler, - cqueryOptions, - out, - skyframeExecutor, - accessor, - aspectResolver, - OutputType.JSON, - ruleClassProvider, - getLabelPrinter()), - new BuildOutputFormatterCallback( - eventHandler, cqueryOptions, out, skyframeExecutor, accessor, getLabelPrinter()), - new GraphOutputFormatterCallback( - eventHandler, - cqueryOptions, - out, - skyframeExecutor, - accessor, - kct -> getFwdDeps(ImmutableList.of(kct)), - getLabelPrinter()), - new StarlarkOutputFormatterCallback( - eventHandler, cqueryOptions, out, skyframeExecutor, accessor, starlarkSemantics), - new FilesOutputFormatterCallback( - eventHandler, cqueryOptions, out, skyframeExecutor, accessor, topLevelArtifactContext)); + ImmutableList.Builder> formatters = + ImmutableList.>builder() + .add( + new LabelAndConfigurationOutputFormatterCallback( + eventHandler, + cqueryOptions, + out, + skyframeExecutor, + accessor, + true, + getLabelPrinter()), + new LabelAndConfigurationOutputFormatterCallback( + eventHandler, + cqueryOptions, + out, + skyframeExecutor, + accessor, + false, + getLabelPrinter()), + new TransitionsOutputFormatterCallback( + eventHandler, + cqueryOptions, + out, + skyframeExecutor, + accessor, + ruleClassProvider, + getLabelPrinter()), + new ProtoOutputFormatterCallback( + eventHandler, + cqueryOptions, + out, + skyframeExecutor, + accessor, + aspectResolver, + OutputType.BINARY, + ruleClassProvider, + getLabelPrinter()), + new ProtoOutputFormatterCallback( + eventHandler, + cqueryOptions, + out, + skyframeExecutor, + accessor, + aspectResolver, + OutputType.DELIMITED_BINARY, + ruleClassProvider, + labelPrinter), + new ProtoOutputFormatterCallback( + eventHandler, + cqueryOptions, + out, + skyframeExecutor, + accessor, + aspectResolver, + OutputType.TEXT, + ruleClassProvider, + getLabelPrinter()), + new ProtoOutputFormatterCallback( + eventHandler, + cqueryOptions, + out, + skyframeExecutor, + accessor, + aspectResolver, + OutputType.JSON, + ruleClassProvider, + getLabelPrinter()), + new BuildOutputFormatterCallback( + eventHandler, + cqueryOptions, + out, + skyframeExecutor, + accessor, + getLabelPrinter()), + new GraphOutputFormatterCallback( + eventHandler, + cqueryOptions, + out, + skyframeExecutor, + accessor, + kct -> getFwdDeps(ImmutableList.of(kct)), + getLabelPrinter()), + new StarlarkOutputFormatterCallback( + eventHandler, + cqueryOptions, + out, + skyframeExecutor, + accessor, + starlarkSemantics), + new FilesOutputFormatterCallback( + eventHandler, + cqueryOptions, + out, + skyframeExecutor, + accessor, + topLevelArtifactContext)); + + if (noOutputFormatter.isPresent()) { + formatters.add(noOutputFormatter.get()); + } + return formatters.build(); } @Override public String getOutputFormat() { - return cqueryOptions.outputFormat; + return noOutputFormatter.isPresent() ? "no_output" : cqueryOptions.outputFormat; } @Override @@ -285,7 +333,7 @@ public ConfiguredTargetAccessor getAccessor() { @Override public QueryTaskFuture getTargetsMatchingPattern( - QueryExpression owner, String pattern, Callback callback) { + QueryExpression owner, String pattern, Callback callback) { TargetPattern patternToEval; try { patternToEval = getPattern(pattern); @@ -311,7 +359,7 @@ public QueryTaskFuture getTargetsMatchingPattern( /* excludedSubdirectories= */ ImmutableSet.of(), (Callback) partialResult -> { - List transformedResult = new ArrayList<>(); + List transformedResult = new ArrayList<>(); for (Target target : partialResult) { transformedResult.addAll( getConfiguredTargetsForConfigFunction(target.getLabel())); @@ -325,14 +373,13 @@ public QueryTaskFuture getTargetsMatchingPattern( } /** - * Returns the {@link ConfiguredTarget} for the given label and configuration if it exists, else - * null. + * Returns the {@link CqueryNode} for the given label and configuration if it exists, else null. */ @Nullable - private ConfiguredTarget getConfiguredTarget( + private CqueryNode getConfiguredTarget( Label label, @Nullable BuildConfigurationValue configuration) throws InterruptedException { BuildConfigurationKey configurationKey = configuration == null ? null : configuration.getKey(); - ConfiguredTarget target = + CqueryNode target = getValueFromKey( ConfiguredTargetKey.builder() .setLabel(label) @@ -346,11 +393,25 @@ private ConfiguredTarget getConfiguredTarget( return target; } + /** + * Returns the {@link CqueryNode} for the given key if its value is a supported instance of + * CqueryNode. This function can only receive keys of node types that the calling logic can + * support. For example, if the caller does not support handling of AspectKey types of + * CqueryNodes, then this function should not be called with an AspectKey key. + */ @Override @Nullable - protected ConfiguredTarget getValueFromKey(SkyKey key) throws InterruptedException { - ConfiguredTargetValue value = getConfiguredTargetValue(key); - return value == null ? null : value.getConfiguredTarget(); + protected CqueryNode getValueFromKey(SkyKey key) throws InterruptedException { + SkyValue value = getConfiguredTargetValue(key); + if (value == null) { + return null; + } else if (value instanceof ConfiguredTargetValue) { + return ((ConfiguredTargetValue) value).getConfiguredTarget(); + } else if (value instanceof AspectValue && key instanceof AspectKey) { + return (AspectKey) key; + } else { + throw new IllegalStateException("unknown value type for CqueryNode"); + } } /** @@ -358,16 +419,16 @@ protected ConfiguredTarget getValueFromKey(SkyKey key) throws InterruptedExcepti * *

If there are no matches, returns an empty list. */ - private ImmutableList getConfiguredTargetsForConfigFunction(Label label) + private ImmutableList getConfiguredTargetsForConfigFunction(Label label) throws InterruptedException { - ImmutableList.Builder ans = ImmutableList.builder(); + ImmutableList.Builder ans = ImmutableList.builder(); for (BuildConfigurationValue config : transitiveConfigurations.values()) { - ConfiguredTarget kct = getConfiguredTarget(label, config); + CqueryNode kct = getConfiguredTarget(label, config); if (kct != null) { ans.add(kct); } } - ConfiguredTarget nullConfiguredTarget = getNullConfiguredTarget(label); + CqueryNode nullConfiguredTarget = getNullConfiguredTarget(label); if (nullConfiguredTarget != null) { ans.add(nullConfiguredTarget); } @@ -392,19 +453,19 @@ QueryTaskCallable getConfiguredTargetsForConfigFunction( String pattern, QueryTaskFuture> targetsFuture, String configPrefix, - Callback callback) { + Callback callback) { // There's no technical reason other callers beside ConfigFunction can't call this. But they'd // need to adjust the error messaging below to not make it config()-specific. Please don't just // remove that line: the counter-priority is making error messages as clear, precise, and // actionable as possible. return () -> { - ThreadSafeMutableSet targets = - (ThreadSafeMutableSet) targetsFuture.getIfSuccessful(); - List transformedResult = new ArrayList<>(); + ThreadSafeMutableSet targets = + (ThreadSafeMutableSet) targetsFuture.getIfSuccessful(); + List transformedResult = new ArrayList<>(); boolean userFriendlyConfigName = true; - for (ConfiguredTarget target : targets) { + for (CqueryNode target : targets) { Label label = getCorrectLabel(target); - ConfiguredTarget keyedConfiguredTarget; + CqueryNode keyedConfiguredTarget; switch (configPrefix) { case "host": throw new QueryException( @@ -479,19 +540,19 @@ QueryTaskCallable getConfiguredTargetsForConfigFunction( * the "actual" target instead of the alias target. Grr. */ @Override - public Label getCorrectLabel(ConfiguredTarget target) { + public Label getCorrectLabel(CqueryNode target) { // Dereference any aliases that might be present. return target.getOriginalLabel(); } @Nullable @Override - protected ConfiguredTarget getTargetConfiguredTarget(Label label) throws InterruptedException { + protected CqueryNode getTargetConfiguredTarget(Label label) throws InterruptedException { if (topLevelConfigurations.isTopLevelTarget(label)) { return getConfiguredTarget( label, topLevelConfigurations.getConfigurationForTopLevelTarget(label)); } else { - ConfiguredTarget toReturn; + CqueryNode toReturn; for (BuildConfigurationValue configuration : topLevelConfigurations.getConfigurations()) { toReturn = getConfiguredTarget(label, configuration); if (toReturn != null) { @@ -504,13 +565,13 @@ protected ConfiguredTarget getTargetConfiguredTarget(Label label) throws Interru @Nullable @Override - protected ConfiguredTarget getNullConfiguredTarget(Label label) throws InterruptedException { + protected CqueryNode getNullConfiguredTarget(Label label) throws InterruptedException { return getConfiguredTarget(label, null); } @Nullable @Override - protected RuleConfiguredTarget getRuleConfiguredTarget(ConfiguredTarget configuredTarget) { + protected RuleConfiguredTarget getRuleConfiguredTarget(CqueryNode configuredTarget) { if (configuredTarget instanceof RuleConfiguredTarget) { return (RuleConfiguredTarget) configuredTarget; } @@ -519,7 +580,7 @@ protected RuleConfiguredTarget getRuleConfiguredTarget(ConfiguredTarget configur @Nullable @Override - protected BuildConfigurationValue getConfiguration(ConfiguredTarget target) { + protected BuildConfigurationValue getConfiguration(CqueryNode target) { try { return target.getConfigurationKey() == null ? null @@ -530,15 +591,13 @@ protected BuildConfigurationValue getConfiguration(ConfiguredTarget target) { } @Override - protected ConfiguredTargetKey getConfiguredTargetKey(ConfiguredTarget target) { - return ConfiguredTargetKey.fromConfiguredTarget(target); + protected ActionLookupKey getConfiguredTargetKey(CqueryNode target) { + return target.getLookupKey(); } @Override - public ThreadSafeMutableSet createThreadSafeMutableSet() { + public ThreadSafeMutableSet createThreadSafeMutableSet() { return new ThreadSafeMutableKeyExtractorBackedSetImpl<>( - configuredTargetKeyExtractor, - ConfiguredTarget.class, - SkyQueryEnvironment.DEFAULT_THREAD_COUNT); + configuredTargetKeyExtractor, CqueryNode.class, SkyQueryEnvironment.DEFAULT_THREAD_COUNT); } } diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryThreadsafeCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryThreadsafeCallback.java index 178eee97380270..73f92b29df00cd 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryThreadsafeCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryThreadsafeCallback.java @@ -15,10 +15,10 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableSet; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue; import com.google.devtools.build.lib.events.ExtendedEventHandler; import com.google.devtools.build.lib.query2.NamedThreadSafeOutputFormatterCallback; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.TargetAccessor; import com.google.devtools.build.lib.skyframe.SkyframeExecutor; import com.google.devtools.build.lib.skyframe.config.BuildConfigurationKey; @@ -42,7 +42,7 @@ * focused on completeness, should output full configuration checksums. */ public abstract class CqueryThreadsafeCallback - extends NamedThreadSafeOutputFormatterCallback { + extends NamedThreadSafeOutputFormatterCallback { protected final ExtendedEventHandler eventHandler; protected final CqueryOptions options; @@ -64,7 +64,7 @@ public abstract class CqueryThreadsafeCallback CqueryOptions options, OutputStream out, SkyframeExecutor skyframeExecutor, - TargetAccessor accessor, + TargetAccessor accessor, boolean uniquifyResults) { this.eventHandler = eventHandler; this.options = options; @@ -119,4 +119,3 @@ protected static String shortId(@Nullable BuildConfigurationValue config) { return config == null ? "null" : config.shortId(); } } - diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryTransitionResolver.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryTransitionResolver.java index 16ae3e2e455be8..f9e9acfd83333e 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryTransitionResolver.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryTransitionResolver.java @@ -24,7 +24,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimaps; import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.DependencyKind; import com.google.devtools.build.lib.analysis.DependencyKind.NonAttributeDependencyKind; import com.google.devtools.build.lib.analysis.DependencyKind.ToolchainDependencyKind; @@ -43,6 +42,7 @@ import com.google.devtools.build.lib.events.ExtendedEventHandler; import com.google.devtools.build.lib.packages.RuleClassProvider; import com.google.devtools.build.lib.packages.Target; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData; import com.google.devtools.build.lib.skyframe.ConfiguredTargetEvaluationExceptions.ReportedException; import com.google.devtools.build.lib.skyframe.ConfiguredTargetEvaluationExceptions.UnreportedException; @@ -126,7 +126,7 @@ public CqueryTransitionResolver( * @see ResolvedTransition for more details. * @param configuredTarget the configured target whose dependencies are being looked up. */ - public ImmutableSet dependencies(ConfiguredTarget configuredTarget) + public ImmutableSet dependencies(CqueryNode configuredTarget) throws EvaluateException, InterruptedException { if (!(configuredTarget instanceof RuleConfiguredTarget)) { return ImmutableSet.of(); @@ -250,7 +250,7 @@ private static String getDependencyName(DependencyKind kind) { } @Nullable - private ConfigurationTransition getRuleTransition(ConfiguredTarget configuredTarget) { + private ConfigurationTransition getRuleTransition(CqueryNode configuredTarget) { if (configuredTarget instanceof RuleConfiguredTarget) { return computeTransition( accessor.getTarget(configuredTarget).getAssociatedRule(), diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallback.java index f873120c8417c1..eafe8007bb152c 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallback.java @@ -19,6 +19,7 @@ import com.google.devtools.build.lib.analysis.TopLevelArtifactHelper; import com.google.devtools.build.lib.analysis.configuredtargets.InputFileConfiguredTarget; import com.google.devtools.build.lib.events.ExtendedEventHandler; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.TargetAccessor; import com.google.devtools.build.lib.skyframe.SkyframeExecutor; import java.io.IOException; @@ -36,7 +37,7 @@ public class FilesOutputFormatterCallback extends CqueryThreadsafeCallback { CqueryOptions options, OutputStream out, SkyframeExecutor skyframeExecutor, - TargetAccessor accessor, + TargetAccessor accessor, TopLevelArtifactContext topLevelArtifactContext) { // Different targets may provide the same artifact, so we deduplicate the collection of all // results at the end. @@ -50,14 +51,17 @@ public String getName() { } @Override - public void processOutput(Iterable partialResult) + public void processOutput(Iterable partialResult) throws IOException, InterruptedException { - for (ConfiguredTarget target : partialResult) { - if (!TopLevelArtifactHelper.shouldConsiderForDisplay(target) - && !(target instanceof InputFileConfiguredTarget)) { + for (CqueryNode target : partialResult) { + if (!(target instanceof ConfiguredTarget) + || (!TopLevelArtifactHelper.shouldConsiderForDisplay(target) + && !(target instanceof InputFileConfiguredTarget))) { continue; } - TopLevelArtifactHelper.getAllArtifactsToBuild(target, topLevelArtifactContext) + + var cf = (ConfiguredTarget) target; + TopLevelArtifactHelper.getAllArtifactsToBuild(cf, topLevelArtifactContext) .getImportantArtifacts() .toList() .stream() diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallback.java index d42edca19c95d9..a03dfcff227a14 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallback.java @@ -15,12 +15,12 @@ package com.google.devtools.build.lib.query2.cquery; import com.google.common.collect.ImmutableSet; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.events.ExtendedEventHandler; import com.google.devtools.build.lib.graph.Digraph; import com.google.devtools.build.lib.graph.Node; import com.google.devtools.build.lib.packages.LabelPrinter; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.TargetAccessor; import com.google.devtools.build.lib.query2.query.output.GraphOutputWriter; import com.google.devtools.build.lib.query2.query.output.GraphOutputWriter.NodeReader; @@ -38,15 +38,15 @@ public String getName() { /** Interface for finding a configured target's direct dependencies. */ @FunctionalInterface public interface DepsRetriever { - Iterable getDirectDeps(ConfiguredTarget target) throws InterruptedException; + Iterable getDirectDeps(CqueryNode target) throws InterruptedException; } private final DepsRetriever depsRetriever; - private final GraphOutputWriter.NodeReader nodeReader = - new NodeReader() { + private final GraphOutputWriter.NodeReader nodeReader = + new NodeReader() { - private final Comparator configuredTargetOrdering = + private final Comparator configuredTargetOrdering = (ct1, ct2) -> { // Order graph output first by target label, then by configuration hash. Label label1 = ct1.getOriginalLabel(); @@ -66,18 +66,18 @@ public interface DepsRetriever { }; @Override - public String getLabel(Node node, LabelPrinter labelPrinter) { + public String getLabel(Node node, LabelPrinter labelPrinter) { // Node payloads are ConfiguredTargets. Output node labels are target labels + config // hashes. - ConfiguredTarget kct = node.getLabel(); + CqueryNode kct = node.getLabel(); return String.format( "%s (%s)", - labelPrinter.toString(kct.getOriginalLabel()), + kct.getDescription(labelPrinter), shortId(getConfiguration(kct.getConfigurationKey()))); } @Override - public Comparator comparator() { + public Comparator comparator() { return configuredTargetOrdering; } }; @@ -89,7 +89,7 @@ public Comparator comparator() { CqueryOptions options, OutputStream out, SkyframeExecutor skyframeExecutor, - TargetAccessor accessor, + TargetAccessor accessor, DepsRetriever depsRetriever, LabelPrinter labelPrinter) { super(eventHandler, options, out, skyframeExecutor, accessor, /* uniquifyResults= */ false); @@ -98,23 +98,23 @@ public Comparator comparator() { } @Override - public void processOutput(Iterable partialResult) throws InterruptedException { + public void processOutput(Iterable partialResult) throws InterruptedException { // Transform the cquery-backed graph into a Digraph to make it suitable for GraphOutputWriter. // Note that this involves an extra iteration over the entire query result subgraph. We could // conceptually merge transformation and output writing into the same iteration if needed. - Digraph graph = new Digraph<>(); - ImmutableSet allNodes = ImmutableSet.copyOf(partialResult); - for (ConfiguredTarget configuredTarget : partialResult) { - Node node = graph.createNode(configuredTarget); - for (ConfiguredTarget dep : depsRetriever.getDirectDeps(configuredTarget)) { + Digraph graph = new Digraph<>(); + ImmutableSet allNodes = ImmutableSet.copyOf(partialResult); + for (CqueryNode configuredTarget : partialResult) { + Node node = graph.createNode(configuredTarget); + for (CqueryNode dep : depsRetriever.getDirectDeps(configuredTarget)) { if (allNodes.contains(dep)) { - Node depNode = graph.createNode(dep); + Node depNode = graph.createNode(dep); graph.addEdge(node, depNode); } } } - GraphOutputWriter graphWriter = + GraphOutputWriter graphWriter = new GraphOutputWriter<>( nodeReader, options.getLineTerminator(), diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/LabelAndConfigurationOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/LabelAndConfigurationOutputFormatterCallback.java index 3aa922b3d8b49f..b9a411ef0c2e5b 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/LabelAndConfigurationOutputFormatterCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/LabelAndConfigurationOutputFormatterCallback.java @@ -22,6 +22,7 @@ import com.google.devtools.build.lib.events.ExtendedEventHandler; import com.google.devtools.build.lib.packages.LabelPrinter; import com.google.devtools.build.lib.packages.Target; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.TargetAccessor; import com.google.devtools.build.lib.skyframe.SkyframeExecutor; import com.google.devtools.build.lib.util.ClassName; @@ -37,7 +38,7 @@ public class LabelAndConfigurationOutputFormatterCallback extends CqueryThreadsa CqueryOptions options, OutputStream out, SkyframeExecutor skyframeExecutor, - TargetAccessor accessor, + TargetAccessor accessor, boolean showKind, LabelPrinter labelPrinter) { super(eventHandler, options, out, skyframeExecutor, accessor, /* uniquifyResults= */ false); @@ -51,8 +52,8 @@ public String getName() { } @Override - public void processOutput(Iterable partialResult) { - for (ConfiguredTarget keyedConfiguredTarget : partialResult) { + public void processOutput(Iterable partialResult) { + for (CqueryNode keyedConfiguredTarget : partialResult) { StringBuilder output = new StringBuilder(); if (showKind) { Target actualTarget = accessor.getTarget(keyedConfiguredTarget); @@ -60,7 +61,7 @@ public void processOutput(Iterable partialResult) { } output = output - .append(labelPrinter.toString(keyedConfiguredTarget.getOriginalLabel())) + .append(keyedConfiguredTarget.getDescription(labelPrinter)) .append(" (") .append(shortId(getConfiguration(keyedConfiguredTarget.getConfigurationKey()))) .append(")"); @@ -74,9 +75,13 @@ public void processOutput(Iterable partialResult) { } private static ImmutableSortedSet requiredFragmentStrings( - ConfiguredTarget keyedConfiguredTarget) { + CqueryNode keyedConfiguredTarget) { + if (!(keyedConfiguredTarget instanceof ConfiguredTarget)) { + return ImmutableSortedSet.of(); + } + RequiredConfigFragmentsProvider requiredFragments = - keyedConfiguredTarget + ((ConfiguredTarget) keyedConfiguredTarget) .getProvider(RequiredConfigFragmentsProvider.class); if (requiredFragments == null) { return ImmutableSortedSet.of(); diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallback.java index c9b63cd4881147..df4b277a9abf7b 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallback.java @@ -24,7 +24,7 @@ import com.google.devtools.build.lib.analysis.AnalysisProtosV2.Configuration; import com.google.devtools.build.lib.analysis.AnalysisProtosV2.CqueryResult; import com.google.devtools.build.lib.analysis.AnalysisProtosV2.CqueryResultOrBuilder; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; +import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue; import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; @@ -37,6 +37,7 @@ import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.RuleClassProvider; import com.google.devtools.build.lib.packages.Target; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.cquery.CqueryOptions.Transitions; import com.google.devtools.build.lib.query2.cquery.CqueryTransitionResolver.EvaluateException; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.TargetAccessor; @@ -56,6 +57,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; /** Proto output formatter for cquery results. */ class ProtoOutputFormatterCallback extends CqueryThreadsafeCallback { @@ -80,11 +82,24 @@ public String formatName() { private static class ConfigurationCache { private final Map cache = new HashMap<>(); + private final Function configurationGetter; + + private ConfigurationCache( + Function configurationGetter) { + this.configurationGetter = configurationGetter; + } public int getId(BuildConfigurationEvent buildConfigurationEvent) { return cache.computeIfAbsent(buildConfigurationEvent, event -> cache.size() + 1); } + public int getId(BuildOptions options) { + BuildConfigurationValue configurationValue = + configurationGetter.apply(BuildConfigurationKey.create(options)); + BuildConfigurationEvent buildConfigurationEvent = configurationValue.toBuildEvent(); + return getId(buildConfigurationEvent); + } + public ImmutableList getConfigurations() { return cache.entrySet().stream() .map( @@ -110,20 +125,21 @@ public ImmutableList getConfigurations() { private final OutputType outputType; private final AspectResolver resolver; private final SkyframeExecutor skyframeExecutor; - private final ConfigurationCache configurationCache = new ConfigurationCache(); + private final ConfigurationCache configurationCache = + new ConfigurationCache(this::getConfiguration); private final JsonFormat.Printer jsonPrinter = JsonFormat.printer(); private final RuleClassProvider ruleClassProvider; private final Map partialResultMap; private final LabelPrinter labelPrinter; - private ConfiguredTarget currentTarget; + private CqueryNode currentTarget; ProtoOutputFormatterCallback( ExtendedEventHandler eventHandler, CqueryOptions options, OutputStream out, SkyframeExecutor skyframeExecutor, - TargetAccessor accessor, + TargetAccessor accessor, AspectResolver resolver, OutputType outputType, RuleClassProvider ruleClassProvider, @@ -222,7 +238,7 @@ public String getName() { } @Override - public void processOutput(Iterable partialResult) + public void processOutput(Iterable partialResult) throws InterruptedException, IOException { partialResult.forEach( kct -> partialResultMap.put(kct.getOriginalLabel(), accessor.getTarget(kct))); @@ -237,7 +253,7 @@ public void processOutput(Iterable partialResult) ConfiguredProtoOutputFormatter formatter = new ConfiguredProtoOutputFormatter(); formatter.setOptions(options, resolver, skyframeExecutor.getDigestFunction().getHashFunction()); - for (ConfiguredTarget keyedConfiguredTarget : partialResult) { + for (CqueryNode keyedConfiguredTarget : partialResult) { AnalysisProtosV2.ConfiguredTarget.Builder builder = AnalysisProtosV2.ConfiguredTarget.newBuilder(); @@ -261,9 +277,7 @@ public void processOutput(Iterable partialResult) .setLabel(labelPrinter.toString(resolvedTransition.label()))); } else { for (BuildOptions options : resolvedTransition.options()) { - BuildConfigurationEvent buildConfigurationEvent = - getConfiguration(BuildConfigurationKey.create(options)).toBuildEvent(); - int configurationId = configurationCache.getId(buildConfigurationEvent); + int configurationId = configurationCache.getId(options); targetBuilder .getRuleBuilder() diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/StarlarkOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/StarlarkOutputFormatterCallback.java index a4ecf8707b5263..e744685c556ec5 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/StarlarkOutputFormatterCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/StarlarkOutputFormatterCallback.java @@ -17,7 +17,6 @@ import static com.google.devtools.build.lib.analysis.config.StarlarkDefinedConfigTransition.COMMAND_LINE_OPTION_PREFIX; import com.google.common.collect.ImmutableMap; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue; import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.analysis.config.FragmentOptions; @@ -25,6 +24,7 @@ import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.ExtendedEventHandler; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.TargetAccessor; import com.google.devtools.build.lib.query2.engine.QueryException; import com.google.devtools.build.lib.server.FailureDetails.ConfigurableQuery; @@ -64,7 +64,7 @@ private class CqueryDialectGlobals { parameters = { @Param(name = "target"), }) - public Object buildOptions(ConfiguredTarget target) { + public Object buildOptions(CqueryNode target) { BuildConfigurationValue config = getConfiguration(target.getConfigurationKey()); if (config == null) { @@ -118,7 +118,7 @@ public Object buildOptions(ConfiguredTarget target) { parameters = { @Param(name = "target"), }) - public Object providers(ConfiguredTarget target) { + public Object providers(CqueryNode target) { Dict ret = target.getProvidersDictForQuery(); if (ret == null) { return Starlark.NONE; @@ -129,7 +129,7 @@ public Object providers(ConfiguredTarget target) { private static final Object[] NO_ARGS = new Object[0]; - // Starlark function with single required parameter "target", a ConfiguredTarget query result. + // Starlark function with single required parameter "target", a CqueryNode query result. private final StarlarkFunction formatFn; private final StarlarkSemantics starlarkSemantics; @@ -138,7 +138,7 @@ public Object providers(ConfiguredTarget target) { CqueryOptions options, OutputStream out, SkyframeExecutor skyframeExecutor, - TargetAccessor accessor, + TargetAccessor accessor, StarlarkSemantics starlarkSemantics) throws QueryException, InterruptedException { super(eventHandler, options, out, skyframeExecutor, accessor, /* uniquifyResults= */ false); @@ -227,8 +227,8 @@ public String getName() { } @Override - public void processOutput(Iterable partialResult) throws InterruptedException { - for (ConfiguredTarget target : partialResult) { + public void processOutput(Iterable partialResult) throws InterruptedException { + for (CqueryNode target : partialResult) { try { StarlarkThread thread = new StarlarkThread(Mutability.create("cquery evaluation"), starlarkSemantics); diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterCallback.java index b1d59927c0d87a..cd0393c1aeb454 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterCallback.java @@ -17,7 +17,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue; import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.analysis.config.BuildOptions.OptionsDiff; @@ -32,6 +31,7 @@ import com.google.devtools.build.lib.packages.RuleClassProvider; import com.google.devtools.build.lib.packages.RuleTransitionData; import com.google.devtools.build.lib.packages.Target; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.cquery.CqueryTransitionResolver.EvaluateException; import com.google.devtools.build.lib.query2.cquery.CqueryTransitionResolver.ResolvedTransition; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.TargetAccessor; @@ -63,7 +63,7 @@ public String getName() { CqueryOptions options, OutputStream out, SkyframeExecutor skyframeExecutor, - TargetAccessor accessor, + TargetAccessor accessor, RuleClassProvider ruleClassProvider, LabelPrinter labelPrinter) { super(eventHandler, options, out, skyframeExecutor, accessor, /* uniquifyResults= */ false); @@ -74,7 +74,7 @@ public String getName() { } @Override - public void processOutput(Iterable partialResult) throws InterruptedException { + public void processOutput(Iterable partialResult) throws InterruptedException { CqueryOptions.Transitions verbosity = options.transitions; if (verbosity.equals(CqueryOptions.Transitions.NONE)) { eventHandler.handle( @@ -85,7 +85,7 @@ public void processOutput(Iterable partialResult) throws Inter } partialResult.forEach( kct -> partialResultMap.put(kct.getOriginalLabel(), accessor.getTarget(kct))); - for (ConfiguredTarget keyedConfiguredTarget : partialResult) { + for (CqueryNode keyedConfiguredTarget : partialResult) { Target target = partialResultMap.get(keyedConfiguredTarget.getOriginalLabel()); BuildConfigurationValue config = getConfiguration(keyedConfiguredTarget.getConfigurationKey()); @@ -130,7 +130,7 @@ public void processOutput(Iterable partialResult) throws Inter } } - private static String getRuleClassTransition(ConfiguredTarget ct, Target target) { + private static String getRuleClassTransition(CqueryNode ct, Target target) { String output = ""; if (ct instanceof RuleConfiguredTarget) { TransitionFactory factory = diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java index 87b6e1e8c6a1ea..6ae3a13f962a71 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java @@ -647,7 +647,10 @@ enum Setting { NO_NODEP_DEPS, /** Include aspect-generated output. No-op for query, which always follows aspects. */ - INCLUDE_ASPECTS; + INCLUDE_ASPECTS, + + /** Include configured aspect targets in cquery output. */ + EXPLICIT_ASPECTS; } /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/BUILD b/src/main/java/com/google/devtools/build/lib/rules/BUILD index 96acbd10969530..9ffaae384abbd2 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/BUILD +++ b/src/main/java/com/google/devtools/build/lib/rules/BUILD @@ -255,7 +255,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/analysis:rule_definition_environment", "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/packages", - "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant", "//src/main/java/net/starlark/java/eval", "//third_party:guava", @@ -393,12 +393,13 @@ java_library( srcs = ["repository/RepositoryDirectoryValue.java"], deps = [ "//src/main/java/com/google/devtools/build/lib/cmdline", - "//src/main/java/com/google/devtools/build/lib/concurrent", "//src/main/java/com/google/devtools/build/lib/skyframe:directory_listing_value", "//src/main/java/com/google/devtools/build/lib/skyframe:sky_functions", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/vfs", "//src/main/java/com/google/devtools/build/skyframe:skyframe-objects", + "//third_party:error_prone_annotations", "//third_party:guava", "//third_party:jsr305", ], @@ -463,6 +464,7 @@ java_library( deps = [ "//src/main/java/com/google/devtools/build/lib/concurrent", "//src/main/java/com/google/devtools/build/lib/skyframe:sky_functions", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/vfs", "//src/main/java/com/google/devtools/build/skyframe:skyframe-objects", diff --git a/src/main/java/com/google/devtools/build/lib/rules/LabelBuildSettings.java b/src/main/java/com/google/devtools/build/lib/rules/LabelBuildSettings.java index 35634ce3247bb6..f86b8eed8902ac 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/LabelBuildSettings.java +++ b/src/main/java/com/google/devtools/build/lib/rules/LabelBuildSettings.java @@ -28,7 +28,7 @@ import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.packages.RuleClass.ToolchainResolutionMode; import com.google.devtools.build.lib.rules.LateBoundAlias.AbstractAliasRule; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import net.starlark.java.eval.Starlark; diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java index f23d9f9d47b0e1..5bee3a203370de 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java @@ -18,7 +18,7 @@ import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.rules.android.AndroidDataConverter.JoinerType; import com.google.devtools.build.lib.rules.android.databinding.DataBindingContext; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.Collections; diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/BUILD b/src/main/java/com/google/devtools/build/lib/rules/android/BUILD index f37c4d7ddfda6b..b3162f6a788326 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/BUILD +++ b/src/main/java/com/google/devtools/build/lib/rules/android/BUILD @@ -69,7 +69,6 @@ java_library( "//src/main/java/com/google/devtools/build/lib/analysis:platform_configuration", "//src/main/java/com/google/devtools/build/lib/analysis:platform_options", "//src/main/java/com/google/devtools/build/lib/analysis:required_config_fragments_provider", - "//src/main/java/com/google/devtools/build/lib/analysis:resolved_toolchain_context", "//src/main/java/com/google/devtools/build/lib/analysis:rule_definition_environment", "//src/main/java/com/google/devtools/build/lib/analysis:rule_error_consumer", "//src/main/java/com/google/devtools/build/lib/analysis:starlark/function_transition_util", @@ -93,6 +92,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/rules/java:java-rules", "//src/main/java/com/google/devtools/build/lib/rules/proto", "//src/main/java/com/google/devtools/build/lib/skyframe:configured_target_and_data", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant", "//src/main/java/com/google/devtools/build/lib/starlarkbuildapi/android", diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/RClassGeneratorActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/RClassGeneratorActionBuilder.java index b4a2ff68eb6832..598b167374a292 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/RClassGeneratorActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/RClassGeneratorActionBuilder.java @@ -15,7 +15,7 @@ import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.rules.android.AndroidDataConverter.JoinerType; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.errorprone.annotations.CanIgnoreReturnValue; diff --git a/src/main/java/com/google/devtools/build/lib/rules/config/BUILD b/src/main/java/com/google/devtools/build/lib/rules/config/BUILD index 12717d074d0e71..9fd517105be826 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/config/BUILD +++ b/src/main/java/com/google/devtools/build/lib/rules/config/BUILD @@ -26,7 +26,6 @@ java_library( ":config_feature_flag_options", ":feature_flag_value", "//src/main/java/com/google/devtools/build/lib/actions", - "//src/main/java/com/google/devtools/build/lib/actions:artifact_owner", "//src/main/java/com/google/devtools/build/lib/actions:artifacts", "//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster", "//src/main/java/com/google/devtools/build/lib/analysis:build_setting_provider", @@ -38,7 +37,6 @@ java_library( "//src/main/java/com/google/devtools/build/lib/analysis:config/core_options", "//src/main/java/com/google/devtools/build/lib/analysis:config/fragment", "//src/main/java/com/google/devtools/build/lib/analysis:config/fragment_options", - "//src/main/java/com/google/devtools/build/lib/analysis:config/invalid_configuration_exception", "//src/main/java/com/google/devtools/build/lib/analysis:config/starlark_defined_config_transition", "//src/main/java/com/google/devtools/build/lib/analysis:config/toolchain_type_requirement", "//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/no_transition", @@ -63,6 +61,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/packages", "//src/main/java/com/google/devtools/build/lib/rules/core", "//src/main/java/com/google/devtools/build/lib/rules/platform", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant", "//src/main/java/com/google/devtools/build/lib/starlarkbuildapi/config", diff --git a/src/main/java/com/google/devtools/build/lib/rules/config/ConfigRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/config/ConfigRuleClasses.java index 25972796b66fa1..f7767d283cd1a4 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/config/ConfigRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/config/ConfigRuleClasses.java @@ -32,7 +32,7 @@ import com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.packages.Type; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/BUILD b/src/main/java/com/google/devtools/build/lib/rules/cpp/BUILD index 0da6a4f4cc4ed8..8ec70b0f13e657 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/BUILD +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/BUILD @@ -111,6 +111,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/shell", "//src/main/java/com/google/devtools/build/lib/skyframe:action_execution_value", "//src/main/java/com/google/devtools/build/lib/skyframe:tree_artifact_value", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant", "//src/main/java/com/google/devtools/build/lib/starlarkbuildapi", diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java index 70b24712ec204e..f61334a34c33cf 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java @@ -36,8 +36,8 @@ import com.google.devtools.build.lib.rules.cpp.CcToolchainVariables.SingleVariables; import com.google.devtools.build.lib.rules.cpp.CcToolchainVariables.StringChunk; import com.google.devtools.build.lib.rules.cpp.CcToolchainVariables.StringValueParser; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain; diff --git a/src/main/java/com/google/devtools/build/lib/rules/genquery/BUILD b/src/main/java/com/google/devtools/build/lib/rules/genquery/BUILD index 6df1f3fbc1fabe..a08c5d6173d4f6 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/genquery/BUILD +++ b/src/main/java/com/google/devtools/build/lib/rules/genquery/BUILD @@ -91,6 +91,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/skyframe:target_loading_util", "//src/main/java/com/google/devtools/build/lib/skyframe:transitive_target_key", "//src/main/java/com/google/devtools/build/lib/skyframe:transitive_target_value", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/vfs", "//src/main/java/com/google/devtools/build/skyframe", diff --git a/src/main/java/com/google/devtools/build/lib/rules/genquery/GenQueryDirectPackageProviderFactory.java b/src/main/java/com/google/devtools/build/lib/rules/genquery/GenQueryDirectPackageProviderFactory.java index e6c6ab705f7845..0594d42f328504 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/genquery/GenQueryDirectPackageProviderFactory.java +++ b/src/main/java/com/google/devtools/build/lib/rules/genquery/GenQueryDirectPackageProviderFactory.java @@ -36,6 +36,7 @@ import com.google.devtools.build.lib.packages.Target; import com.google.devtools.build.lib.skyframe.TargetLoadingUtil; import com.google.devtools.build.lib.skyframe.TargetLoadingUtil.TargetAndErrorIfAny; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.skyframe.AbstractSkyKey; import com.google.devtools.build.skyframe.PartialReevaluationMailbox; @@ -79,7 +80,7 @@ private Key(ImmutableList

This class is an implementation detail of {@link DirectoryListingValue}. */ -@AutoCodec.VisibleForSerialization +@VisibleForSerialization public final class DirectoryListingStateValue implements SkyValue { private final CompactSortedDirents compactSortedDirents; @@ -57,7 +58,7 @@ public static Key key(RootedPath rootedPath) { } /** Key type for DirectoryListingStateValue. */ - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec public static class Key extends AbstractSkyKey { private static final SkyKeyInterner interner = SkyKey.newInterner(); @@ -66,7 +67,7 @@ private Key(RootedPath arg) { super(arg); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static Key create(RootedPath arg) { return interner.intern(new Key(arg)); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/DirectoryListingValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/DirectoryListingValue.java index 8ec4723344e08e..e131030fa86e27 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/DirectoryListingValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/DirectoryListingValue.java @@ -16,6 +16,7 @@ import com.google.devtools.build.lib.actions.FileValue; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.AbstractSkyKey; @@ -62,7 +63,7 @@ public static Key key(RootedPath directoryUnderRoot) { } /** Key type for DirectoryListingValue. */ - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec public static class Key extends AbstractSkyKey { private static final SkyKeyInterner interner = SkyKey.newInterner(); @@ -71,7 +72,7 @@ private Key(RootedPath arg) { super(arg); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static Key create(RootedPath arg) { return interner.intern(new Key(arg)); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ExternalPackageFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ExternalPackageFunction.java index a593b51c0696a8..d6bfbd451faade 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ExternalPackageFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ExternalPackageFunction.java @@ -16,7 +16,7 @@ import com.google.devtools.build.lib.packages.WorkspaceFileValue; import com.google.devtools.build.lib.repository.ExternalPackageHelper; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.SkyFunction; @@ -31,7 +31,7 @@ * that will contain all the bind statements from the WORKSPACE file. */ public class ExternalPackageFunction implements SkyFunction { - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final SkyKey KEY = () -> SkyFunctions.EXTERNAL_PACKAGE; private final ExternalPackageHelper externalPackageHelper; diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/IgnoredPackagePrefixesValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/IgnoredPackagePrefixesValue.java index 71c57166fe76bf..89b58b0ace3166 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/IgnoredPackagePrefixesValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/IgnoredPackagePrefixesValue.java @@ -16,6 +16,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.cmdline.RepositoryName; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.lib.vfs.PathFragment; @@ -28,7 +29,7 @@ public class IgnoredPackagePrefixesValue implements SkyValue { private final ImmutableSet patterns; - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization public static final IgnoredPackagePrefixesValue EMPTY_LIST = new IgnoredPackagePrefixesValue(ImmutableSet.of()); @@ -68,7 +69,7 @@ public boolean equals(Object obj) { return false; } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec static class Key extends AbstractSkyKey { private static final SkyKeyInterner interner = SkyKey.newInterner(); @@ -77,7 +78,7 @@ private Key(RepositoryName arg) { super(arg); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static Key create(RepositoryName arg) { return interner.intern(new Key(arg)); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupValue.java index 7f597c69acaa0e..213773174dc645 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupValue.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.skyframe; import com.google.devtools.build.lib.cmdline.RepositoryName; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.vfs.RootedPath; @@ -34,7 +35,7 @@ static Key key(RootedPath directory) { return Key.create(directory); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec static class Key extends AbstractSkyKey { private static final SkyKeyInterner interner = SkyKey.newInterner(); @@ -43,7 +44,7 @@ private Key(RootedPath arg) { super(arg); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static Key create(RootedPath arg) { return interner.intern(new Key(arg)); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/NonRuleConfiguredTargetValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/NonRuleConfiguredTargetValue.java index f71c2d744929a5..446ca39a272f1c 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/NonRuleConfiguredTargetValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/NonRuleConfiguredTargetValue.java @@ -22,8 +22,8 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; import com.google.devtools.build.lib.packages.Package; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; import javax.annotation.Nullable; /** A non-rule configured target in the context of a Skyframe graph. */ diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageErrorFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageErrorFunction.java index b2cfb77b59dec7..9c9ee459e3f4ad 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageErrorFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageErrorFunction.java @@ -18,6 +18,7 @@ import com.google.devtools.build.lib.packages.BuildFileContainsErrorsException; import com.google.devtools.build.lib.packages.NoSuchPackageException; import com.google.devtools.build.lib.packages.Package; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.skyframe.AbstractSkyKey; import com.google.devtools.build.skyframe.SkyFunction; @@ -44,7 +45,7 @@ public static Key key(PackageIdentifier packageIdentifier) { return Key.create(packageIdentifier); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec static class Key extends AbstractSkyKey { private static final SkyKeyInterner interner = SkyKey.newInterner(); @@ -53,7 +54,7 @@ private Key(PackageIdentifier arg) { super(arg); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static Key create(PackageIdentifier arg) { return interner.intern(new Key(arg)); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageErrorMessageValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageErrorMessageValue.java index 54c68a635525b2..400c65e42450d0 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageErrorMessageValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageErrorMessageValue.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.skyframe; import com.google.devtools.build.lib.cmdline.PackageIdentifier; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.skyframe.AbstractSkyKey; @@ -74,7 +75,7 @@ public static SkyKey key(PackageIdentifier pkgId) { return Key.create(pkgId); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec static class Key extends AbstractSkyKey { private static final SkyKeyInterner interner = SkyKey.newInterner(); @@ -83,7 +84,7 @@ private Key(PackageIdentifier arg) { super(arg); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static Key create(PackageIdentifier arg) { return interner.intern(new Key(arg)); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupValue.java index 170bd16771aa75..a773362927152a 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupValue.java @@ -20,6 +20,7 @@ import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.packages.BuildFileName; import com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.lib.vfs.PathFragment; @@ -135,7 +136,7 @@ static boolean appliesToKey(SkyKey key, Predicate identifierP } /** {@link SkyKey} for {@link PackageLookupValue} computation. */ - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec static class Key extends AbstractSkyKey { private static final SkyKeyInterner interner = SkyKey.newInterner(); @@ -144,7 +145,7 @@ private Key(PackageIdentifier arg) { super(arg); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static Key create(PackageIdentifier arg) { return interner.intern(new Key(arg)); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java index 5ef5c37946c4c5..9ebeaa31e08c96 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java @@ -22,8 +22,8 @@ import com.google.devtools.build.lib.packages.Package.ConfigSettingVisibilityPolicy; import com.google.devtools.build.lib.packages.RuleVisibility; import com.google.devtools.build.lib.pkgcache.PathPackageLocator; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; import com.google.devtools.build.skyframe.AbstractSkyKey; import com.google.devtools.build.skyframe.Differencer.DiffWithDelta.Delta; import com.google.devtools.build.skyframe.Injectable; diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternValue.java index c691a3edbbd8f6..a310d0ea215fe7 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternValue.java @@ -22,6 +22,7 @@ import com.google.devtools.build.lib.pkgcache.FilteringPolicies; import com.google.devtools.build.lib.server.FailureDetails.TargetPatterns; import com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternKey; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.skyframe.AbstractSkyKey; @@ -197,7 +198,7 @@ private Key(TargetPatternKey arg) { super(arg); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static Key create(TargetPatternKey arg) { return interner.intern(new Key(arg)); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsValue.java index cd0492d7ebb3aa..3324eaa240155b 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsValue.java @@ -16,12 +16,11 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Interner; -import com.google.devtools.build.lib.concurrent.BlazeInterners; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; import com.google.devtools.build.lib.query2.common.UniverseSkyKey; import com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternKey; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.skyframe.SkyFunctionName; @@ -62,11 +61,10 @@ public static TargetPatternSequence key(ImmutableList patterns, PathFrag /** The argument value for {@link SkyKey}s of {@link PrepareDepsOfPatternsFunction}. */ @ThreadSafe - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec static class TargetPatternSequence implements UniverseSkyKey { - private static final Interner interner = - BlazeInterners.newWeakInterner(); + private static final SkyKeyInterner interner = SkyKey.newInterner(); private final ImmutableList patterns; private final PathFragment offset; @@ -76,7 +74,7 @@ private TargetPatternSequence(ImmutableList patterns, PathFragment offse this.offset = Preconditions.checkNotNull(offset); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static TargetPatternSequence create(ImmutableList patterns, PathFragment offset) { return interner.intern(new TargetPatternSequence(patterns, offset)); @@ -91,6 +89,11 @@ public PathFragment getOffset() { return offset; } + @Override + public SkyKeyInterner getSkyKeyInterner() { + return interner; + } + @Override public boolean equals(Object o) { if (this == o) { diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java index 70fa69d79d6095..86b253ce2b8f17 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java @@ -44,7 +44,7 @@ import com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.FileType; import com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.ResolvedFile; import com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.ResolvedFileFactory; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.lib.util.Fingerprint; import com.google.devtools.build.lib.vfs.Dirent; @@ -75,7 +75,7 @@ public final class RecursiveFilesystemTraversalFunction implements SkyFunction { private static final byte[] MISSING_FINGERPRINT = new BigInteger(1, "NonexistentFileStateValue".getBytes(UTF_8)).toByteArray(); - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final HasDigest NON_EXISTENT_HAS_DIGEST = () -> MISSING_FINGERPRINT; private static final FileInfo NON_EXISTENT_FILE_INFO = diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursivePkgValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursivePkgValue.java index 7e190be53e0766..f0539bfc5a703c 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursivePkgValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursivePkgValue.java @@ -14,19 +14,19 @@ package com.google.devtools.build.lib.skyframe; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Interner; import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; -import com.google.devtools.build.lib.concurrent.BlazeInterners; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.SkyFunctionName; +import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.build.skyframe.SkyValue; /** @@ -72,10 +72,10 @@ public boolean hasErrors() { return hasErrors; } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec static class Key extends RecursivePkgSkyKey { - private static final Interner interner = BlazeInterners.newWeakInterner(); + private static final SkyKeyInterner interner = SkyKey.newInterner(); private Key( RepositoryName repositoryName, @@ -84,7 +84,7 @@ private Key( super(repositoryName, rootedPath, excludedPaths); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static Key create( RepositoryName repositoryName, @@ -97,5 +97,10 @@ static Key create( public SkyFunctionName functionName() { return SkyFunctions.RECURSIVE_PKG; } + + @Override + public SkyKeyInterner getSkyKeyInterner() { + return interner; + } } } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternErrorFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternErrorFunction.java index 8b7799306c8433..07b0361af18c87 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternErrorFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternErrorFunction.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.skyframe; import com.google.devtools.build.lib.cmdline.TargetParsingException; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.util.DetailedExitCode; import com.google.devtools.build.skyframe.SkyFunction; @@ -37,7 +38,7 @@ public static Key key(TargetParsingException e) { return Key.create(e.getMessage(), e.getDetailedExitCode()); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec static class Key implements SkyKey { private static final SkyKeyInterner interner = SkyKey.newInterner(); @@ -49,7 +50,7 @@ private Key(String message, DetailedExitCode detailedExitCode) { this.detailedExitCode = detailedExitCode; } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static Key create(String message, DetailedExitCode detailedExitCode) { return interner.intern(new Key(message, detailedExitCode)); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionValue.java index 8ad9fbac3f9caa..a80943335ed2d6 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionValue.java @@ -14,11 +14,10 @@ package com.google.devtools.build.lib.skyframe; import com.google.auto.value.AutoValue; -import com.google.common.collect.Interner; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.TopLevelArtifactContext; -import com.google.devtools.build.lib.concurrent.BlazeInterners; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.skyframe.SkyFunctionName; import com.google.devtools.build.skyframe.SkyKey; @@ -58,9 +57,9 @@ public static Iterable keys( @AutoCodec @AutoValue public abstract static class TestCompletionKey implements SkyKey { - private static final Interner interner = BlazeInterners.newWeakInterner(); + private static final SkyKeyInterner interner = SkyKey.newInterner(); - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static TestCompletionKey create( ConfiguredTargetKey configuredTargetKey, @@ -85,5 +84,10 @@ public final SkyFunctionName functionName() { public final boolean valueIsShareable() { return false; } + + @Override + public final SkyKeyInterner getSkyKeyInterner() { + return interner; + } } } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TreeArtifactValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/TreeArtifactValue.java index 58f0add3e730f3..1ba1353abea99b 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/TreeArtifactValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/TreeArtifactValue.java @@ -39,7 +39,7 @@ import com.google.devtools.build.lib.concurrent.ErrorClassifier; import com.google.devtools.build.lib.concurrent.NamedForkJoinPool; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.lib.util.Fingerprint; import com.google.devtools.build.lib.vfs.Dirent; @@ -68,12 +68,13 @@ public class TreeArtifactValue implements HasDigest, SkyValue { private static final ForkJoinPool VISITOR_POOL = NamedForkJoinPool.newNamedPool( "tree-artifact-visitor", Runtime.getRuntime().availableProcessors()); + /** * Comparator based on exec path which works on {@link ActionInput} as opposed to {@link * com.google.devtools.build.lib.actions.Artifact}. This way, we can use an {@link ActionInput} to * search {@link #childData}. */ - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final Comparator EXEC_PATH_COMPARATOR = (input1, input2) -> input1.getExecPath().compareTo(input2.getExecPath()); @@ -182,15 +183,15 @@ public static ArchivedRepresentation create( @SuppressWarnings("WeakerAccess") // Serialization constant. @SerializationConstant - @AutoCodec.VisibleForSerialization + @VisibleForSerialization static final TreeArtifactValue EMPTY = new TreeArtifactValue( MetadataDigestUtils.fromMetadata(ImmutableMap.of()), EMPTY_MAP, 0L, - /*archivedRepresentation=*/ null, - /*materializationExecPath=*/ null, - /*entirelyRemote=*/ false); + /* archivedRepresentation= */ null, + /* materializationExecPath= */ null, + /* entirelyRemote= */ false); private final byte[] digest; private final ImmutableSortedMap childData; diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceNameValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceNameValue.java index 62a55f40fb14b2..b5cca7d38c0011 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceNameValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceNameValue.java @@ -14,7 +14,7 @@ package com.google.devtools.build.lib.skyframe; import com.google.common.base.Preconditions; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.build.skyframe.SkyValue; @@ -29,7 +29,7 @@ * the WORKSPACE file. */ public class WorkspaceNameValue implements SkyValue { - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final SkyKey KEY = () -> SkyFunctions.WORKSPACE_NAME; private final String workspaceName; diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/config/BUILD b/src/main/java/com/google/devtools/build/lib/skyframe/config/BUILD index 0293d953287e4a..563158ec6894ee 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/config/BUILD +++ b/src/main/java/com/google/devtools/build/lib/skyframe/config/BUILD @@ -72,6 +72,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/concurrent", "//src/main/java/com/google/devtools/build/lib/skyframe:sky_functions", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/vfs:pathfragment", "//src/main/java/com/google/devtools/build/skyframe:skyframe-objects", diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/config/PlatformMappingValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/config/PlatformMappingValue.java index 6e2b173a941a89..3fa55dd37f70ff 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/config/PlatformMappingValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/config/PlatformMappingValue.java @@ -33,6 +33,7 @@ import com.google.devtools.build.lib.cmdline.RepositoryMapping; import com.google.devtools.build.lib.concurrent.ThreadSafety; import com.google.devtools.build.lib.skyframe.SkyFunctions; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.skyframe.SkyFunctionName; @@ -83,7 +84,7 @@ public static Key create(@Nullable PathFragment workspaceRelativeMappingPath) { } @AutoCodec.Instantiator - @AutoCodec.VisibleForSerialization + @VisibleForSerialization static Key create(PathFragment workspaceRelativeMappingPath, boolean wasExplicitlySetByUser) { return interner.intern(new Key(workspaceRelativeMappingPath, wasExplicitlySetByUser)); } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/BUILD b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/BUILD index 8f33abbf48ef42..d05bc916ab9535 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/BUILD +++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/BUILD @@ -26,6 +26,7 @@ java_library( exclude = [ "SerializationConstants.java", "CodecScanningConstants.java", + "VisibleForSerialization.java", ], ), add_opens = [ @@ -53,3 +54,8 @@ java_library( "//src/main/java/com/google/devtools/build/lib/util:resource_usage", ], ) + +java_library( + name = "visible-for-serialization", + srcs = ["VisibleForSerialization.java"], +) diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/VisibleForSerialization.java b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/VisibleForSerialization.java new file mode 100644 index 00000000000000..15551aa87fc439 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/VisibleForSerialization.java @@ -0,0 +1,29 @@ +// Copyright 2023 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.skyframe.serialization; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Signals that the annotated element is only visible for use by serialization. It should not be + * used by other callers. + * + *

TODO(janakr): Add an ErrorProne checker to enforce this. + */ +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD}) +@Retention(RetentionPolicy.SOURCE) // Documentation only. +public @interface VisibleForSerialization {} diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/AutoCodec.java b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/AutoCodec.java index 0fe0dd14c8c0e7..eb3a7ea0b1fd24 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/AutoCodec.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/AutoCodec.java @@ -98,13 +98,4 @@ enum Strategy { * com.google.devtools.build.lib.skyframe.serialization.SerializationContext#addExplicitlyAllowedClass}. */ Class[] explicitlyAllowClass() default {}; - - /** - * Signals that the annotated element is only visible for use by serialization. It should not be - * used by other callers. - * - *

TODO(janakr): Add an ErrorProne checker to enforce this. - */ - @Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD}) - @interface VisibleForSerialization {} } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/toolchains/BUILD b/src/main/java/com/google/devtools/build/lib/skyframe/toolchains/BUILD index e08f783554c4ab..ae29a94a24983e 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/toolchains/BUILD +++ b/src/main/java/com/google/devtools/build/lib/skyframe/toolchains/BUILD @@ -122,6 +122,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/skyframe:configured_target_key", "//src/main/java/com/google/devtools/build/lib/skyframe:sky_functions", "//src/main/java/com/google/devtools/build/lib/skyframe/config", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/skyframe:skyframe-objects", "//third_party:auto_value", @@ -191,6 +192,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/analysis/platform", "//src/main/java/com/google/devtools/build/lib/skyframe:sky_functions", "//src/main/java/com/google/devtools/build/lib/skyframe/config", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/skyframe:skyframe-objects", "//third_party:auto_value", diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/toolchains/RegisteredExecutionPlatformsValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/toolchains/RegisteredExecutionPlatformsValue.java index b9178a9e4dbdd9..8470966ae974e4 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/toolchains/RegisteredExecutionPlatformsValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/toolchains/RegisteredExecutionPlatformsValue.java @@ -19,6 +19,7 @@ import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey; import com.google.devtools.build.lib.skyframe.SkyFunctions; import com.google.devtools.build.lib.skyframe.config.BuildConfigurationKey; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.skyframe.SkyFunctionName; import com.google.devtools.build.skyframe.SkyKey; @@ -38,7 +39,7 @@ public static SkyKey key(BuildConfigurationKey configurationKey) { /** {@link SkyKey} implementation used for {@link RegisteredExecutionPlatformsFunction}. */ @AutoCodec - @AutoCodec.VisibleForSerialization + @VisibleForSerialization static class Key implements SkyKey { private static final SkyKeyInterner interner = SkyKey.newInterner(); @@ -49,7 +50,7 @@ private Key(BuildConfigurationKey configurationKey) { } @AutoCodec.Instantiator - @AutoCodec.VisibleForSerialization + @VisibleForSerialization static Key of(BuildConfigurationKey configurationKey) { return interner.intern(new Key(configurationKey)); } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/toolchains/RegisteredToolchainsValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/toolchains/RegisteredToolchainsValue.java index 63565937d7d2bc..513a1fbd8ab41b 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/toolchains/RegisteredToolchainsValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/toolchains/RegisteredToolchainsValue.java @@ -19,6 +19,7 @@ import com.google.devtools.build.lib.analysis.platform.DeclaredToolchainInfo; import com.google.devtools.build.lib.skyframe.SkyFunctions; import com.google.devtools.build.lib.skyframe.config.BuildConfigurationKey; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.skyframe.SkyFunctionName; import com.google.devtools.build.skyframe.SkyKey; @@ -48,7 +49,7 @@ private Key(BuildConfigurationKey configurationKey) { } @AutoCodec.Instantiator - @AutoCodec.VisibleForSerialization + @VisibleForSerialization static Key of(BuildConfigurationKey configurationKey) { return interner.intern(new Key(configurationKey)); } diff --git a/src/main/java/com/google/devtools/build/lib/util/BUILD b/src/main/java/com/google/devtools/build/lib/util/BUILD index e7c57f38b53239..bc801a49651358 100644 --- a/src/main/java/com/google/devtools/build/lib/util/BUILD +++ b/src/main/java/com/google/devtools/build/lib/util/BUILD @@ -226,6 +226,7 @@ java_library( ], deps = [ ":string", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant", "//src/main/java/com/google/devtools/build/lib/vfs:ospathpolicy", diff --git a/src/main/java/com/google/devtools/build/lib/util/FileType.java b/src/main/java/com/google/devtools/build/lib/util/FileType.java index 31b134e399d7e8..af9f86f9608277 100644 --- a/src/main/java/com/google/devtools/build/lib/util/FileType.java +++ b/src/main/java/com/google/devtools/build/lib/util/FileType.java @@ -19,7 +19,7 @@ import com.google.common.base.Predicates; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.lib.vfs.OsPathPolicy; import java.util.ArrayList; diff --git a/src/main/java/com/google/devtools/build/lib/util/FileTypeSet.java b/src/main/java/com/google/devtools/build/lib/util/FileTypeSet.java index 0a81056d148f8c..323b786075b4ec 100644 --- a/src/main/java/com/google/devtools/build/lib/util/FileTypeSet.java +++ b/src/main/java/com/google/devtools/build/lib/util/FileTypeSet.java @@ -17,7 +17,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import java.util.ArrayList; import java.util.Arrays; diff --git a/src/main/java/com/google/devtools/build/lib/vfs/BUILD b/src/main/java/com/google/devtools/build/lib/vfs/BUILD index f80997f0305041..141ce7f5daa71d 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/BUILD +++ b/src/main/java/com/google/devtools/build/lib/vfs/BUILD @@ -68,6 +68,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/concurrent", "//src/main/java/com/google/devtools/build/lib/io:file_symlink_exception", "//src/main/java/com/google/devtools/build/lib/profiler", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/util:filetype", "//src/main/java/com/google/devtools/build/skyframe:skyframe-objects", diff --git a/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java b/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java index c74062eacc0869..74fdb7786a8838 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java @@ -15,6 +15,7 @@ import static com.google.common.base.Preconditions.checkArgument; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.skyframe.SkyKey; import java.util.Comparator; @@ -51,7 +52,7 @@ public final class RootedPath implements Comparable, FileStateKey { /** Constructs a {@link RootedPath} from a {@link Root} and path fragment relative to the root. */ @AutoCodec.Instantiator - @AutoCodec.VisibleForSerialization + @VisibleForSerialization static RootedPath createInternal(Root root, PathFragment rootRelativePath) { checkArgument( rootRelativePath.isAbsolute() == root.isAbsolute(), diff --git a/src/main/java/com/google/devtools/build/skyframe/BUILD b/src/main/java/com/google/devtools/build/skyframe/BUILD index d9c920b6d48b6a..7b07ff1b43edae 100644 --- a/src/main/java/com/google/devtools/build/skyframe/BUILD +++ b/src/main/java/com/google/devtools/build/skyframe/BUILD @@ -28,7 +28,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/bugreport", "//src/main/java/com/google/devtools/build/lib/collect/compacthashset", "//src/main/java/com/google/devtools/build/lib/concurrent", - "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant", "//src/main/java/com/google/devtools/build/lib/util:TestType", "//third_party:auto_value", diff --git a/src/main/java/com/google/devtools/build/skyframe/GroupedDeps.java b/src/main/java/com/google/devtools/build/skyframe/GroupedDeps.java index e9d1ebfa788881..d39601245c8c62 100644 --- a/src/main/java/com/google/devtools/build/skyframe/GroupedDeps.java +++ b/src/main/java/com/google/devtools/build/skyframe/GroupedDeps.java @@ -22,7 +22,7 @@ import com.google.common.collect.Lists; import com.google.devtools.build.lib.collect.compacthashset.CompactHashSet; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadHostile; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import java.lang.annotation.ElementType; import java.lang.annotation.Target; @@ -338,7 +338,7 @@ public boolean contains(SkyKey key) { return elements.contains(key); } - @SerializationConstant @AutoCodec.VisibleForSerialization + @SerializationConstant @VisibleForSerialization static final @Compressed Object EMPTY_COMPRESSED = new Object(); /** diff --git a/src/main/java/net/starlark/java/eval/Dict.java b/src/main/java/net/starlark/java/eval/Dict.java index 6ff9a7eb66f474..d782efa74c4824 100644 --- a/src/main/java/net/starlark/java/eval/Dict.java +++ b/src/main/java/net/starlark/java/eval/Dict.java @@ -453,13 +453,13 @@ public static Dict copyOf(@Nullable Mutability mu, Map) m; + ImmutableMap immutableMap = (ImmutableMap) m; return new Dict<>(immutableMap); } if (m instanceof Dict && ((Dict) m).isImmutable()) { @SuppressWarnings("unchecked") - var dict = (Dict) m; + Dict dict = (Dict) m; return dict; } diff --git a/src/main/java/net/starlark/java/eval/Module.java b/src/main/java/net/starlark/java/eval/Module.java index 740f275247c5bc..b7279a202c6ccd 100644 --- a/src/main/java/net/starlark/java/eval/Module.java +++ b/src/main/java/net/starlark/java/eval/Module.java @@ -184,7 +184,7 @@ public String getDocumentation() { */ @Nullable public Object getPredeclared(String name) { - var value = predeclared.get(name); + Object value = predeclared.get(name); if (value == null) { return null; } diff --git a/src/test/java/com/google/devtools/build/lib/buildtool/BUILD b/src/test/java/com/google/devtools/build/lib/buildtool/BUILD index c95ca9d16896f2..cf2af7d2be1e05 100644 --- a/src/test/java/com/google/devtools/build/lib/buildtool/BUILD +++ b/src/test/java/com/google/devtools/build/lib/buildtool/BUILD @@ -474,7 +474,6 @@ java_test( "//src/main/protobuf:invocation_policy_java_proto", "//src/test/java/com/google/devtools/build/lib/buildtool/util", "//src/test/java/com/google/devtools/build/lib/events:testutil", - "//src/test/java/com/google/devtools/build/lib/testutil:TestConstants", "//src/test/java/com/google/devtools/build/lib/testutil:TestUtils", "//src/test/java/com/google/devtools/build/skyframe:testutil", "//third_party:guava", diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/BUILD b/src/test/java/com/google/devtools/build/lib/query2/cquery/BUILD index 9e1d90b6515857..d3bd09d275d5a0 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/BUILD +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/BUILD @@ -19,11 +19,11 @@ java_test( deps = [ ":configured_target_query_helper", ":configured_target_query_test", - "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/packages", "//src/main/java/com/google/devtools/build/lib/packages:label_printer", "//src/main/java/com/google/devtools/build/lib/query2", + "//src/main/java/com/google/devtools/build/lib/query2/common:cquery-node", "//src/main/java/com/google/devtools/build/lib/query2/engine", "//src/main/java/com/google/devtools/build/lib/query2/query/aspectresolvers", "//src/main/java/com/google/devtools/build/lib/util:filetype", @@ -42,11 +42,10 @@ java_test( deps = [ ":configured_target_query_helper", ":configured_target_query_test", - "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", - "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/packages:label_printer", "//src/main/java/com/google/devtools/build/lib/query2", + "//src/main/java/com/google/devtools/build/lib/query2/common:cquery-node", "//src/main/java/com/google/devtools/build/lib/query2/engine", "//third_party:guava", "//third_party:junit4", @@ -67,11 +66,12 @@ java_test( "//src/main/java/com/google/devtools/build/lib/analysis:config/fragment_options", "//src/main/java/com/google/devtools/build/lib/analysis:config/transition_factories", "//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/patch_transition", - "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", "//src/main/java/com/google/devtools/build/lib/analysis:test/test_configuration", "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/packages", + "//src/main/java/com/google/devtools/build/lib/packages:label_printer", + "//src/main/java/com/google/devtools/build/lib/query2/common:cquery-node", "//src/main/java/com/google/devtools/build/lib/query2/engine", "//src/main/java/com/google/devtools/build/lib/util:filetype", "//src/main/java/com/google/devtools/build/lib/vfs", @@ -89,9 +89,9 @@ java_library( testonly = 1, srcs = ["ConfiguredTargetQueryHelper.java"], deps = [ - "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", "//src/main/java/com/google/devtools/build/lib/packages:label_printer", "//src/main/java/com/google/devtools/build/lib/query2", + "//src/main/java/com/google/devtools/build/lib/query2/common:cquery-node", "//src/main/java/com/google/devtools/build/lib/query2/engine", "//src/main/java/com/google/devtools/build/skyframe", "//src/main/java/com/google/devtools/build/skyframe:skyframe-objects", @@ -111,9 +111,9 @@ java_library( "//src/main/java/com/google/devtools/build/lib/analysis:config/build_options", "//src/main/java/com/google/devtools/build/lib/analysis:config/fragment_options", "//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/split_transition", - "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/query2", + "//src/main/java/com/google/devtools/build/lib/query2/common:cquery-node", "//src/main/java/com/google/devtools/build/lib/query2/engine", "//src/test/java/com/google/devtools/build/lib/analysis/util", "//src/test/java/com/google/devtools/build/lib/query2/testutil", @@ -133,11 +133,11 @@ java_test( ":configured_target_query_test", "//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster", "//src/main/java/com/google/devtools/build/lib/analysis:config/execution_transition_factory", - "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/packages", "//src/main/java/com/google/devtools/build/lib/packages:label_printer", "//src/main/java/com/google/devtools/build/lib/query2", + "//src/main/java/com/google/devtools/build/lib/query2/common:cquery-node", "//src/main/java/com/google/devtools/build/lib/query2/engine", "//src/main/java/com/google/devtools/build/lib/query2/query/aspectresolvers", "//src/main/java/com/google/devtools/build/lib/util:filetype", @@ -164,12 +164,11 @@ java_test( "//src/main/java/com/google/devtools/build/lib/analysis:config/transition_factories", "//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/no_transition", "//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/transition_factory", - "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", - "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/packages", "//src/main/java/com/google/devtools/build/lib/packages:label_printer", "//src/main/java/com/google/devtools/build/lib/query2", + "//src/main/java/com/google/devtools/build/lib/query2/common:cquery-node", "//src/main/java/com/google/devtools/build/lib/query2/engine", "//src/main/java/com/google/devtools/build/lib/util:filetype", "//src/test/java/com/google/devtools/build/lib/analysis/util", @@ -188,10 +187,10 @@ java_test( ":configured_target_query_helper", ":configured_target_query_test", "//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster", - "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", "//src/main/java/com/google/devtools/build/lib/analysis:top_level_artifact_context", "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/query2", + "//src/main/java/com/google/devtools/build/lib/query2/common:cquery-node", "//src/main/java/com/google/devtools/build/lib/query2/engine", "//third_party:guava", "//third_party:junit4", diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallbackTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallbackTest.java index b5fb358560b7f8..fc3672a33eb77f 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallbackTest.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallbackTest.java @@ -19,12 +19,12 @@ import static com.google.devtools.build.lib.packages.BuildType.OUTPUT; import com.google.common.eventbus.EventBus; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.util.MockRule; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.Reporter; import com.google.devtools.build.lib.packages.LabelPrinter; import com.google.devtools.build.lib.query2.PostAnalysisQueryEnvironment; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.Setting; import com.google.devtools.build.lib.query2.engine.QueryExpression; import com.google.devtools.build.lib.query2.engine.QueryParser; @@ -75,7 +75,7 @@ private List getOutput(String queryExpression) throws Exception { Set targetPatternSet = new LinkedHashSet<>(); expression.collectTargetPatterns(targetPatternSet); helper.setQuerySettings(Setting.NO_IMPLICIT_DEPS); - PostAnalysisQueryEnvironment env = + PostAnalysisQueryEnvironment env = ((ConfiguredTargetQueryHelper) helper).getPostAnalysisQueryEnvironment(targetPatternSet); ByteArrayOutputStream output = new ByteArrayOutputStream(); diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryHelper.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryHelper.java index b1be0899732587..9fe9d68a291531 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryHelper.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryHelper.java @@ -14,10 +14,10 @@ package com.google.devtools.build.lib.query2.cquery; import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.util.AnalysisTestCase; import com.google.devtools.build.lib.packages.LabelPrinter; import com.google.devtools.build.lib.query2.PostAnalysisQueryEnvironment.TopLevelConfigurations; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction; import com.google.devtools.build.lib.query2.testutil.AbstractQueryTest.QueryHelper; import com.google.devtools.build.lib.query2.testutil.PostAnalysisQueryHelper; @@ -32,7 +32,7 @@ * AnalysisTestCase} must be run manually. @BeforeClass and @AfterClass are completely ignored for * now. */ -public class ConfiguredTargetQueryHelper extends PostAnalysisQueryHelper { +public class ConfiguredTargetQueryHelper extends PostAnalysisQueryHelper { @Override protected ConfiguredTargetQueryEnvironment getPostAnalysisQueryEnvironment( WalkableGraph walkableGraph, @@ -56,7 +56,7 @@ protected ConfiguredTargetQueryEnvironment getPostAnalysisQueryEnvironment( } @Override - public String getLabel(ConfiguredTarget target) { + public String getLabel(CqueryNode target) { return target.getOriginalLabel().toString(); } } diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQuerySemanticsTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQuerySemanticsTest.java index c81f3e5453bec9..23c4d7646c6054 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQuerySemanticsTest.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQuerySemanticsTest.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.query2.cquery; +import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.lib.packages.Attribute.attr; import static com.google.devtools.build.lib.packages.BuildType.LABEL; @@ -23,7 +24,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue; import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.analysis.config.BuildOptionsView; @@ -38,6 +38,8 @@ import com.google.devtools.build.lib.cmdline.TargetParsingException; import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.packages.BuildType; +import com.google.devtools.build.lib.packages.LabelPrinter; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.Setting; import com.google.devtools.build.lib.query2.engine.QueryException; import com.google.devtools.build.lib.server.FailureDetails; @@ -121,9 +123,8 @@ public void testLabelFunction_getCorrectlyConfiguredDeps() throws Exception { setUpLabelsFunctionTests(); // Test that this retrieves the correctly configured version(s) of the dep(s). - ConfiguredTarget patchDep = - Iterables.getOnlyElement(eval("labels('patch_dep', //test:my_rule)")); - ConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule")); + CqueryNode patchDep = Iterables.getOnlyElement(eval("labels('patch_dep', //test:my_rule)")); + CqueryNode myRule = Iterables.getOnlyElement(eval("//test:my_rule")); String targetConfiguration = myRule.getConfigurationChecksum(); assertThat(patchDep.getConfigurationChecksum()).doesNotMatch(targetConfiguration); } @@ -132,12 +133,12 @@ public void testLabelFunction_getCorrectlyConfiguredDeps() throws Exception { public void testLabelsFunction_splitTransitionAttribute() throws Exception { setUpLabelsFunctionTests(); - ConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule")); + CqueryNode myRule = Iterables.getOnlyElement(eval("//test:my_rule")); String targetConfiguration = myRule.getConfigurationChecksum(); - Set splitDeps = eval("labels('split_dep', //test:my_rule)"); + Set splitDeps = eval("labels('split_dep', //test:my_rule)"); assertThat(splitDeps).hasSize(2); - for (ConfiguredTarget kct : splitDeps) { + for (CqueryNode kct : splitDeps) { assertThat(kct.getConfigurationChecksum()).doesNotMatch(targetConfiguration); } } @@ -146,13 +147,13 @@ public void testLabelsFunction_splitTransitionAttribute() throws Exception { public void testLabelsFunction_labelListAttribute() throws Exception { setUpLabelsFunctionTests(); - ConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule")); + CqueryNode myRule = Iterables.getOnlyElement(eval("//test:my_rule")); String targetConfiguration = myRule.getConfigurationChecksum(); // Test that this works for label_lists as well. - Set deps = eval("labels('patch_dep_list', //test:my_rule)"); + Set deps = eval("labels('patch_dep_list', //test:my_rule)"); assertThat(deps).hasSize(2); - for (ConfiguredTarget kct : deps) { + for (CqueryNode kct : deps) { assertThat(kct.getConfigurationChecksum()).doesNotMatch(targetConfiguration); } } @@ -195,7 +196,7 @@ public void testGetPrerequisitesFromAliasReturnsActualPrerequisites() throws Exc "rule_with_dep(name = 'actual', dep = ':dep')", "rule_with_dep(name = 'dep')"); - ConfiguredTarget dep = Iterables.getOnlyElement(eval("labels('dep', '//test:alias')")); + CqueryNode dep = Iterables.getOnlyElement(eval("labels('dep', '//test:alias')")); assertThat(dep.getLabel()).isEqualTo(Label.parseCanonicalUnchecked("//test:dep")); } @@ -223,8 +224,8 @@ public void testAlias_filtering() throws Exception { "alias(name = 'other_impl_dep', actual = 'impl_dep')", "simple_rule(name='impl_dep')"); - ConfiguredTarget other = Iterables.getOnlyElement(eval("//test:other_my_rule")); - ConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule")); + CqueryNode other = Iterables.getOnlyElement(eval("//test:other_my_rule")); + CqueryNode myRule = Iterables.getOnlyElement(eval("//test:my_rule")); // Note: {@link ConfiguredTarget#getLabel} returns the label of the "actual" value not the // label of the alias, so we need to check the underlying label. assertThat(other.getLabel()).isEqualTo(myRule.getLabel()); @@ -249,7 +250,7 @@ public void testTopLevelTransition() throws Exception { writeFile("test/BUILD", "rule_class_transition(name='rule_class')"); - Set ruleClass = eval("//test:rule_class"); + Set ruleClass = eval("//test:rule_class"); DummyTestOptions testOptions = getConfiguration(Iterables.getOnlyElement(ruleClass)) .getOptions() @@ -376,10 +377,10 @@ public void testConfig_configHash() throws Exception { // setting --universe_scope we ensure only the transitioned version exists. helper.setUniverseScope("//test:buildme"); helper.setQuerySettings(Setting.ONLY_TARGET_DEPS, Setting.NO_IMPLICIT_DEPS); - Set result = eval("deps(//test:buildme, 1)"); + Set result = eval("deps(//test:buildme, 1)"); assertThat(result).hasSize(2); - ImmutableList stableOrderList = ImmutableList.copyOf(result); + ImmutableList stableOrderList = ImmutableList.copyOf(result); int myDepIndex = stableOrderList.get(0).getLabel().toString().equals("//test:mydep") ? 0 : 1; BuildConfigurationValue myDepConfig = getConfiguration(stableOrderList.get(myDepIndex)); BuildConfigurationValue stringFlagConfig = @@ -404,11 +405,11 @@ public void testConfig_configHashPrefix() throws Exception { createConfigRulesAndBuild(); writeFile("mytest/BUILD", "simple_rule(name = 'mytarget')"); - Set result = eval("//mytest:mytarget"); + Set result = eval("//mytest:mytarget"); String configHash = getConfiguration(Iterables.getOnlyElement(result)).checksum(); String hashPrefix = configHash.substring(0, configHash.length() / 2); - Set resultFromPrefix = eval("config(//mytest:mytarget," + hashPrefix + ")"); + Set resultFromPrefix = eval("config(//mytest:mytarget," + hashPrefix + ")"); assertThat(resultFromPrefix).containsExactlyElementsIn(result); } @@ -417,7 +418,7 @@ public void testConfig_configHashUnknownPrefix() throws Exception { createConfigRulesAndBuild(); writeFile("mytest/BUILD", "simple_rule(name = 'mytarget')"); - Set result = eval("//mytest:mytarget"); + Set result = eval("//mytest:mytarget"); String configHash = getConfiguration(Iterables.getOnlyElement(result)).checksum(); String rightPrefix = configHash.substring(0, configHash.length() / 2); char lastChar = rightPrefix.charAt(rightPrefix.length() - 1); @@ -440,7 +441,7 @@ public void testConfig_exprArgumentFailure() throws Exception { EvalThrowsResult evalThrowsResult = evalThrows( "config(filter(\"??not-a-valid-regex\", //test:foo.java), null)", - /*unconditionallyThrows=*/ true); + /* unconditionallyThrows= */ true); assertThat(evalThrowsResult.getMessage()) .startsWith("illegal 'filter' pattern regexp '??not-a-valid-regex'"); assertThat(evalThrowsResult.getFailureDetail().hasQuery()).isTrue(); @@ -503,12 +504,12 @@ public void testRecursiveTargetPatternOutsideOfScopeFailsGracefully() throws Exc public void testMultipleTopLevelConfigurations_nullConfigs() throws Exception { writeFile("test/BUILD", "java_library(name='my_java',", " srcs = ['foo.java'],", ")"); - Set result = eval("//test:my_java+//test:foo.java"); + Set result = eval("//test:my_java+//test:foo.java"); assertThat(result).hasSize(2); - Iterator resultIterator = result.iterator(); - ConfiguredTarget first = resultIterator.next(); + Iterator resultIterator = result.iterator(); + CqueryNode first = resultIterator.next(); if (first.getLabel().toString().equals("//test:foo.java")) { assertThat(getConfiguration(first)).isNull(); assertThat(getConfiguration(resultIterator.next())).isNotNull(); @@ -538,7 +539,7 @@ public void testSomePath_depInCustomConfiguration() throws Exception { // cases cquery prefers the top-level configured one, which won't produce a match since that's // not the one down this dependency path. helper.setUniverseScope("//test:buildme"); - Set result = eval("somepath(//test:buildme, //test:mydep)"); + Set result = eval("somepath(//test:buildme, //test:mydep)"); assertThat(result.stream().map(kct -> kct.getLabel().toString()).collect(Collectors.toList())) .contains("//test:mydep"); } @@ -584,8 +585,7 @@ public void testQueryHandlesDroppingFragments() throws Exception { "simple_rule(name='foo', deps = [':bar'])", "simple_rule(name='bar')"); - Set result = - eval("somepath(//test:top, filter(//test:bar, deps(//test:top)))"); + Set result = eval("somepath(//test:top, filter(//test:bar, deps(//test:top)))"); assertThat(result).isNotEmpty(); } @@ -604,7 +604,7 @@ public void testLabelExpressionsMatchesAllConfiguredTargetsWithLabel() throws Ex "simple_rule(name = 'simple')"); helper.setUniverseScope("//test:transitioner,//test:simple"); - Set result = eval("//test:simple"); + Set result = eval("//test:simple"); assertThat(result.size()).isEqualTo(2); } @@ -626,7 +626,243 @@ public void testConfigFunctionRefinesMultipleMatches() throws Exception { "simple_rule(name = 'simple')"); helper.setUniverseScope("//test:transitioner,//test:simple"); - Set result = eval("config(//test:simple, target)"); + Set result = eval("config(//test:simple, target)"); assertThat(result.size()).isEqualTo(1); } + + @Test + public void testAspectDepsAppearInCqueryDeps() throws Exception { + writeFile( + "donut/test.bzl", + "TestAspectInfo = provider('TestAspectInfo', fields = ['info'])", + "def _test_aspect_impl(target, ctx):", + " return [", + " TestAspectInfo(", + " info = depset([target.label]),", + " ),", + " ]", + "", + "_test_aspect = aspect(", + " implementation = _test_aspect_impl,", + " attr_aspects = ['deps'],", + " attrs = {", + " '_test_attr': attr.label(", + " allow_files = True,", + " default = Label('//donut:test_filegroup'),", + " ),", + " },", + " provides = [TestAspectInfo],", + ")", + "def _test_impl(ctx):", + " pass", + "test_rule = rule(", + " _test_impl,", + " attrs = {", + " 'deps': attr.label_list(", + " aspects = [_test_aspect],", + " ),", + " },", + ")"); + writeFile( + "donut/BUILD", + "load(':test.bzl', 'test_rule')", + "filegroup(", + " name = 'test_filegroup',", + " srcs = ['test.bzl'],", + ")", + "test_rule(", + " name = 'test_rule_dep',", + ")", + "test_rule(", + " name = 'test_rule',", + " deps = [':test_rule_dep'],", + ")"); + + helper.setQuerySettings(Setting.INCLUDE_ASPECTS, Setting.EXPLICIT_ASPECTS); + var result = + eval("filter(//donut, deps(//donut:test_rule))").stream() + .map(cf -> cf.getDescription(LabelPrinter.legacy())) + .collect(ImmutableList.toImmutableList()); + assertThat(result) + .containsExactly( + "//donut:test_rule", + "//donut:test_rule_dep", + "//donut:test.bzl%_test_aspect of //donut:test_rule_dep", + "//donut:test.bzl", + "//donut:test_filegroup"); + } + + // TODO: Disable this due to https://github.com/bazelbuild/bazel/pull/21567#issuecomment-1978992760 + // Re-enable once the problem is understood and fixed. + // @Test + // public void testAspectOnAspectDepsAppearInCqueryDeps() throws Exception { + // writeFile( + // "donut/test.bzl", + // "TestAspectInfo = provider('TestAspectInfo', fields = ['info'])", + // "TestAspectOnAspectInfo = provider('TestAspectOnAspectInfo', fields = ['info'])", + // "def _test_aspect_impl(target, ctx):", + // " return [", + // " TestAspectInfo(", + // " info = depset([target.label]),", + // " ),", + // " ]", + // "_test_aspect = aspect(", + // " implementation = _test_aspect_impl,", + // " attr_aspects = ['deps'],", + // " attrs = {", + // " '_test_attr': attr.label(", + // " allow_files = True,", + // " default = Label('//donut:test_aspect_filegroup'),", + // " ),", + // " },", + // " provides = [TestAspectInfo],", + // ")", + // "def _test_aspect_on_aspect_impl(target, ctx):", + // " return [", + // " TestAspectOnAspectInfo(", + // " info = depset(", + // " direct = [target.label],", + // " transitive = [target[TestAspectInfo].info],", + // " ),", + // " ),", + // " ]", + // "_test_aspect_on_aspect = aspect(", + // " implementation = _test_aspect_on_aspect_impl,", + // " attr_aspects = ['deps'],", + // " attrs = {", + // " '_test_attr': attr.label(", + // " allow_files = True,", + // " default = Label('//donut:test_aspect_on_aspect_filegroup'),", + // " ),", + // " },", + // " required_aspect_providers = [TestAspectInfo],", + // " provides = [TestAspectOnAspectInfo],", + // ")", + // "def _test_impl(ctx):", + // " pass", + // "test_rule = rule(", + // " _test_impl,", + // " attrs = {", + // " 'deps': attr.label_list(", + // " aspects = [_test_aspect],", + // " ),", + // " },", + // ")", + // "def _test_aspect_on_aspect_rule_impl(ctx):", + // " pass", + // "test_aspect_on_aspect_rule = rule(", + // " _test_aspect_on_aspect_rule_impl,", + // " attrs = {", + // " 'deps': attr.label_list(", + // " aspects = [_test_aspect, _test_aspect_on_aspect],", + // " ),", + // " },", + // ")"); + // writeFile("donut/test_aspect.file"); + // writeFile("donut/test_aspect_on_aspect.file"); + // writeFile( + // "donut/BUILD", + // "load(':test.bzl', 'test_rule', 'test_aspect_on_aspect_rule')", + // "filegroup(", + // " name = 'test_aspect_filegroup',", + // " srcs = ['test_aspect.file'],", + // ")", + // "filegroup(", + // " name = 'test_aspect_on_aspect_filegroup',", + // " srcs = ['test_aspect_on_aspect.file'],", + // ")", + // "test_rule(", + // " name = 'test_rule_dep',", + // ")", + // "test_rule(", + // " name = 'test_rule',", + // " deps = [':test_rule_dep'],", + // ")", + // "test_aspect_on_aspect_rule(", + // " name = 'test_aspect_on_aspect_rule',", + // " deps = ['test_rule'],", + // ")"); + + // helper.setUniverseScope("//donut/..."); + // helper.setQuerySettings(Setting.INCLUDE_ASPECTS, Setting.EXPLICIT_ASPECTS); + // var result = + // eval("filter(//donut, deps(//donut:test_aspect_on_aspect_rule))").stream() + // .map(cf -> cf.getDescription(LabelPrinter.legacy())) + // .collect(toImmutableList()); + // assertThat(result) + // .containsExactly( + // "//donut:test.bzl%_test_aspect_on_aspect on top of" + // + " [//donut:test.bzl%_test_aspect of //donut:test_rule_dep]", + // "//donut:test.bzl%_test_aspect_on_aspect on top of" + // + " [//donut:test.bzl%_test_aspect of //donut:test_rule]", + // "//donut:test_rule_dep", + // "//donut:test_rule", + // "//donut:test.bzl%_test_aspect of //donut:test_rule_dep", + // "//donut:test.bzl%_test_aspect of //donut:test_rule", + // "//donut:test_aspect_on_aspect_rule", + // "//donut:test_aspect.file", + // "//donut:test_aspect_on_aspect_filegroup", + // "//donut:test_aspect_on_aspect.file", + // "//donut:test_aspect_filegroup"); + // } + + @Test + public void testAspectDepsAppearInCqueryRdeps() throws Exception { + writeFile( + "donut/test.bzl", + "TestAspectInfo = provider('TestAspectInfo', fields = ['info'])", + "def _test_aspect_impl(target, ctx):", + " return [", + " TestAspectInfo(", + " info = depset([target.label]),", + " ),", + " ]", + "", + "_test_aspect = aspect(", + " implementation = _test_aspect_impl,", + " attr_aspects = ['deps'],", + " attrs = {", + " '_test_attr': attr.label(", + " allow_files = True,", + " default = Label('//donut:test_filegroup'),", + " ),", + " },", + " provides = [TestAspectInfo],", + ")", + "def _test_impl(ctx):", + " pass", + "test_rule = rule(", + " _test_impl,", + " attrs = {", + " 'deps': attr.label_list(", + " aspects = [_test_aspect],", + " ),", + " },", + ")"); + writeFile( + "donut/BUILD", + "load(':test.bzl', 'test_rule')", + "filegroup(", + " name = 'test_filegroup',", + " srcs = ['test.bzl'],", + ")", + "test_rule(", + " name = 'test_rule_dep',", + ")", + "test_rule(", + " name = 'test_rule',", + " deps = [':test_rule_dep'],", + ")"); + + helper.setQuerySettings(Setting.INCLUDE_ASPECTS, Setting.EXPLICIT_ASPECTS); + var result = + eval("rdeps(//donut/..., //donut:test_filegroup)").stream() + .map(cf -> cf.getDescription(LabelPrinter.legacy())) + .collect(toImmutableList()); + assertThat(result) + .containsExactly( + "//donut:test_filegroup", + "//donut:test_rule", + "//donut:test.bzl%_test_aspect of //donut:test_rule_dep"); + } } diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryTest.java index 75176014fb2645..ed8e1af4932b0f 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryTest.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryTest.java @@ -18,7 +18,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue; import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.analysis.config.BuildOptionsView; @@ -26,6 +25,7 @@ import com.google.devtools.build.lib.analysis.config.transitions.SplitTransition; import com.google.devtools.build.lib.analysis.util.DummyTestFragment.DummyTestOptions; import com.google.devtools.build.lib.events.EventHandler; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction; import com.google.devtools.build.lib.query2.testutil.PostAnalysisQueryTest; import java.util.HashMap; @@ -38,10 +38,10 @@ /** Tests for {@link ConfiguredTargetQueryEnvironment}. */ @RunWith(JUnit4.class) -public abstract class ConfiguredTargetQueryTest extends PostAnalysisQueryTest { +public abstract class ConfiguredTargetQueryTest extends PostAnalysisQueryTest { @Override - protected QueryHelper createQueryHelper() { + protected QueryHelper createQueryHelper() { return new ConfiguredTargetQueryHelper(); } @@ -57,7 +57,7 @@ public HashMap getDefaultFunctions() { } @Override - protected final BuildConfigurationValue getConfiguration(ConfiguredTarget kct) { + protected final BuildConfigurationValue getConfiguration(CqueryNode kct) { return getHelper() .getSkyframeExecutor() .getConfiguration(getHelper().getReporter(), kct.getConfigurationKey()); @@ -93,12 +93,12 @@ public Map split(BuildOptionsView options, EventHandler ev public void testMultipleTopLevelConfigurations_nullConfigs() throws Exception { writeFile("test/BUILD", "java_library(name='my_java',", " srcs = ['foo.java'],", ")"); - Set result = eval("//test:my_java+//test:foo.java"); + Set result = eval("//test:my_java+//test:foo.java"); assertThat(result).hasSize(2); - Iterator resultIterator = result.iterator(); - ConfiguredTarget first = resultIterator.next(); + Iterator resultIterator = result.iterator(); + CqueryNode first = resultIterator.next(); if (first.getLabel().toString().equals("//test:foo.java")) { assertThat(getConfiguration(first)).isNull(); assertThat(getConfiguration(resultIterator.next())).isNotNull(); diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallbackTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallbackTest.java index 89c17b687f9f99..a2b0a929371635 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallbackTest.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallbackTest.java @@ -18,13 +18,13 @@ import com.google.common.collect.ImmutableList; import com.google.common.eventbus.EventBus; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.OutputGroupInfo; import com.google.devtools.build.lib.analysis.OutputGroupInfo.ValidationMode; import com.google.devtools.build.lib.analysis.TopLevelArtifactContext; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.Reporter; import com.google.devtools.build.lib.query2.PostAnalysisQueryEnvironment; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.engine.QueryExpression; import com.google.devtools.build.lib.query2.engine.QueryParser; import java.io.ByteArrayOutputStream; @@ -112,7 +112,7 @@ private List getOutput(String queryExpression, List outputGroups QueryExpression expression = QueryParser.parse(queryExpression, getDefaultFunctions()); Set targetPatternSet = new LinkedHashSet<>(); expression.collectTargetPatterns(targetPatternSet); - PostAnalysisQueryEnvironment env = + PostAnalysisQueryEnvironment env = ((ConfiguredTargetQueryHelper) helper).getPostAnalysisQueryEnvironment(targetPatternSet); ByteArrayOutputStream output = new ByteArrayOutputStream(); diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallbackTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallbackTest.java index d6b2c38aec4b57..8c1ebc9e2c77e8 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallbackTest.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallbackTest.java @@ -17,11 +17,11 @@ import com.google.common.collect.ImmutableList; import com.google.common.eventbus.EventBus; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.Reporter; import com.google.devtools.build.lib.packages.LabelPrinter; import com.google.devtools.build.lib.query2.PostAnalysisQueryEnvironment; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.Setting; import com.google.devtools.build.lib.query2.engine.QueryExpression; import com.google.devtools.build.lib.query2.engine.QueryParser; @@ -71,7 +71,7 @@ private List getOutput(String queryExpression) throws Exception { Set targetPatternSet = new LinkedHashSet<>(); expression.collectTargetPatterns(targetPatternSet); helper.setQuerySettings(Setting.NO_IMPLICIT_DEPS); - PostAnalysisQueryEnvironment env = + PostAnalysisQueryEnvironment env = ((ConfiguredTargetQueryHelper) helper).getPostAnalysisQueryEnvironment(targetPatternSet); ByteArrayOutputStream output = new ByteArrayOutputStream(); diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallbackTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallbackTest.java index 4d685137abecd6..9fe3f5bbc55c03 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallbackTest.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallbackTest.java @@ -25,7 +25,6 @@ import com.google.devtools.build.lib.analysis.AnalysisProtosV2; import com.google.devtools.build.lib.analysis.AnalysisProtosV2.Configuration; import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory; import com.google.devtools.build.lib.analysis.util.MockRule; import com.google.devtools.build.lib.events.Event; @@ -34,6 +33,7 @@ import com.google.devtools.build.lib.packages.LabelPrinter; import com.google.devtools.build.lib.packages.RuleClassProvider; import com.google.devtools.build.lib.query2.PostAnalysisQueryEnvironment; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.cquery.CqueryOptions.Transitions; import com.google.devtools.build.lib.query2.cquery.ProtoOutputFormatterCallback.OutputType; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.Setting; @@ -189,9 +189,9 @@ public void testConfigurations() throws Exception { AnalysisProtosV2.ConfiguredTarget parentRuleProto = getRuleProtoByName(resultsList, "//test:parent_rule"); - Set keyedTargets = eval("deps(//test:parent_rule)"); + Set keyedTargets = eval("deps(//test:parent_rule)"); - ConfiguredTarget parentRule = getKeyedTargetByLabel(keyedTargets, "//test:parent_rule"); + CqueryNode parentRule = getKeyedTargetByLabel(keyedTargets, "//test:parent_rule"); assertThat(parentRuleProto.getConfiguration().getChecksum()) .isEqualTo(parentRule.getConfigurationChecksum()); @@ -211,7 +211,7 @@ public void testConfigurations() throws Exception { AnalysisProtosV2.ConfiguredTarget transitionRuleProto = getRuleProtoByName(resultsList, "//test:transition_rule"); - ConfiguredTarget transitionRule = getKeyedTargetByLabel(keyedTargets, "//test:transition_rule"); + CqueryNode transitionRule = getKeyedTargetByLabel(keyedTargets, "//test:transition_rule"); assertThat(transitionRuleProto.getConfiguration().getChecksum()) .isEqualTo(transitionRule.getConfigurationChecksum()); @@ -227,7 +227,7 @@ public void testConfigurations() throws Exception { assertThat(depRuleConfiguration.getMnemonic()).matches("k8-opt-exec-.*"); assertThat(depRuleConfiguration.getIsTool()).isTrue(); - ConfiguredTarget depRule = getKeyedTargetByLabel(keyedTargets, "//test:dep"); + CqueryNode depRule = getKeyedTargetByLabel(keyedTargets, "//test:dep"); assertThat(depRuleProto.getConfiguration().getChecksum()) .isEqualTo(depRule.getConfigurationChecksum()); @@ -263,7 +263,7 @@ public void testConfigurations() throws Exception { .containsExactly(patchedConfiguredRuleInput, depConfiguredRuleInput); } - private ConfiguredTarget getKeyedTargetByLabel(Set keyedTargets, String label) { + private CqueryNode getKeyedTargetByLabel(Set keyedTargets, String label) { return Iterables.getOnlyElement( keyedTargets.stream() .filter(t -> label.equals(t.getLabel().getCanonicalForm())) @@ -486,7 +486,7 @@ private InputStream queryAndGetInputStream( Set targetPatternSet = new LinkedHashSet<>(); expression.collectTargetPatterns(targetPatternSet); helper.setQuerySettings(Setting.NO_IMPLICIT_DEPS); - PostAnalysisQueryEnvironment env = + PostAnalysisQueryEnvironment env = ((ConfiguredTargetQueryHelper) helper).getPostAnalysisQueryEnvironment(targetPatternSet); ByteArrayOutputStream out = new ByteArrayOutputStream(); ProtoOutputFormatterCallback callback = diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterTest.java index 6876b3530df418..1f2982fe2626e2 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterTest.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterTest.java @@ -20,7 +20,6 @@ import com.google.common.eventbus.EventBus; import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.config.TransitionFactories; import com.google.devtools.build.lib.analysis.config.transitions.NoTransition; import com.google.devtools.build.lib.analysis.config.transitions.TransitionFactory; @@ -30,6 +29,7 @@ import com.google.devtools.build.lib.packages.LabelPrinter; import com.google.devtools.build.lib.packages.RuleTransitionData; import com.google.devtools.build.lib.query2.PostAnalysisQueryEnvironment; +import com.google.devtools.build.lib.query2.common.CqueryNode; import com.google.devtools.build.lib.query2.cquery.CqueryOptions.Transitions; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.Setting; import com.google.devtools.build.lib.query2.engine.QueryExpression; @@ -235,7 +235,7 @@ private List getOutput(String queryExpression, CqueryOptions.Transitions Set targetPatternSet = new LinkedHashSet<>(); expression.collectTargetPatterns(targetPatternSet); helper.setQuerySettings(Setting.NO_IMPLICIT_DEPS); - PostAnalysisQueryEnvironment env = + PostAnalysisQueryEnvironment env = ((ConfiguredTargetQueryHelper) helper).getPostAnalysisQueryEnvironment(targetPatternSet); options.transitions = verbosity; // TODO(blaze-configurability): Test late-bound attributes. diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/BUILD b/src/test/java/com/google/devtools/build/lib/skyframe/BUILD index 3c21607a83f8b5..0436d73c5acf9b 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/BUILD +++ b/src/test/java/com/google/devtools/build/lib/skyframe/BUILD @@ -269,6 +269,7 @@ java_test( "//src/main/java/com/google/devtools/build/lib/skyframe:workspace_name_value", "//src/main/java/com/google/devtools/build/lib/skyframe/config", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant-annotation", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils", diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutorTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutorTest.java index bfde8fec39b5d6..fdfb97f2e01a96 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutorTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutorTest.java @@ -116,6 +116,7 @@ import com.google.devtools.build.lib.skyframe.serialization.DeserializationContext; import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec; import com.google.devtools.build.lib.skyframe.serialization.SerializationContext; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.testutil.MoreAsserts; import com.google.devtools.build.lib.testutil.TestUtils; @@ -1232,7 +1233,7 @@ public void sharedActionsWithTree() throws Exception { /** Dummy action that creates a tree output. */ // AutoCodec because the superclass has a WrappedRunnable inside it. @AutoCodec - @AutoCodec.VisibleForSerialization + @VisibleForSerialization static class TreeArtifactAction extends TestAction { @SuppressWarnings("unused") // Only needed for serialization. private final SpecialArtifact output; diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/serialization/BUILD b/src/test/java/com/google/devtools/build/lib/skyframe/serialization/BUILD index 6cd5859134fd62..16b86a045c7efe 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/serialization/BUILD +++ b/src/test/java/com/google/devtools/build/lib/skyframe/serialization/BUILD @@ -400,6 +400,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/skyframe:precomputed_value", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils", diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/serialization/ImmutableMapCodecTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/serialization/ImmutableMapCodecTest.java index ff5009c3c80b9c..425a71ca15308f 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/serialization/ImmutableMapCodecTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/serialization/ImmutableMapCodecTest.java @@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Ordering; import com.google.devtools.build.lib.skyframe.serialization.SerializationException.NoCodecException; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; import com.google.devtools.build.lib.skyframe.serialization.testutils.SerializationTester; import com.google.devtools.build.lib.skyframe.serialization.testutils.SerializationTester.VerificationFunction; diff --git a/src/test/java/com/google/devtools/build/skyframe/BUILD b/src/test/java/com/google/devtools/build/skyframe/BUILD index c62eb1c4822573..925e5448f4b9d2 100644 --- a/src/test/java/com/google/devtools/build/skyframe/BUILD +++ b/src/test/java/com/google/devtools/build/skyframe/BUILD @@ -35,6 +35,7 @@ java_library( deps = [ "//src/main/java/com/google/devtools/build/lib/concurrent", "//src/main/java/com/google/devtools/build/lib/events", + "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/util", "//src/main/java/com/google/devtools/build/skyframe", diff --git a/src/test/java/com/google/devtools/build/skyframe/GraphTester.java b/src/test/java/com/google/devtools/build/skyframe/GraphTester.java index 6b90abd7a961b9..d8954c3339ed3b 100644 --- a/src/test/java/com/google/devtools/build/skyframe/GraphTester.java +++ b/src/test/java/com/google/devtools/build/skyframe/GraphTester.java @@ -19,14 +19,14 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Interner; import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.concurrent.BlazeInterners; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.ExtendedEventHandler.Postable; +import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.skyframe.SkyFunctionException.Transience; +import com.google.devtools.build.skyframe.SkyKey.SkyKeyInterner; import com.google.devtools.build.skyframe.SkyframeLookupResult.QueryDepCallback; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.HashMap; @@ -509,16 +509,16 @@ public static ValueComputer formatter(SkyKey key, String format) { StringValue.of(String.format(format, StringValue.from(deps.get(key)).getValue())); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec static class Key extends AbstractSkyKey { - private static final Interner interner = BlazeInterners.newWeakInterner(); + private static final SkyKeyInterner interner = SkyKey.newInterner(); private Key(String arg) { super(arg); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static Key create(String arg) { return interner.intern(new Key(arg)); @@ -528,18 +528,23 @@ static Key create(String arg) { public SkyFunctionName functionName() { return SkyFunctionName.FOR_TESTING; } + + @Override + public SkyKeyInterner getSkyKeyInterner() { + return interner; + } } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec static class NonHermeticKey extends AbstractSkyKey { - private static final Interner interner = BlazeInterners.newWeakInterner(); + private static final SkyKeyInterner interner = SkyKey.newInterner(); private NonHermeticKey(String arg) { super(arg); } - @AutoCodec.VisibleForSerialization + @VisibleForSerialization @AutoCodec.Instantiator static NonHermeticKey create(String arg) { return interner.intern(new NonHermeticKey(arg)); @@ -549,6 +554,11 @@ static NonHermeticKey create(String arg) { public SkyFunctionName functionName() { return FOR_TESTING_NONHERMETIC; } + + @Override + public SkyKeyInterner getSkyKeyInterner() { + return interner; + } } private static final SkyFunctionName FOR_TESTING_NONHERMETIC = diff --git a/src/test/py/bazel/BUILD b/src/test/py/bazel/BUILD index ea335ac97760ab..40c922817adcf2 100644 --- a/src/test/py/bazel/BUILD +++ b/src/test/py/bazel/BUILD @@ -305,6 +305,10 @@ py_test( size = "medium", srcs = ["bzlmod/bazel_fetch_test.py"], data = ["//tools/build_defs/repo:http_src"], + shard_count = 5, + tags = [ + "requires-network", + ], deps = [ ":bzlmod_test_utils", ":test_base", diff --git a/src/test/py/bazel/bzlmod/bazel_fetch_test.py b/src/test/py/bazel/bzlmod/bazel_fetch_test.py index 072caedba197e0..cec2f7dc10f05c 100644 --- a/src/test/py/bazel/bzlmod/bazel_fetch_test.py +++ b/src/test/py/bazel/bzlmod/bazel_fetch_test.py @@ -37,6 +37,7 @@ def setUp(self): 'common --noenable_workspace', 'common --experimental_isolated_extension_usages', 'common --registry=' + self.main_registry.getURL(), + 'common --registry=https://bcr.bazel.build', 'common --verbose_failures', # Set an explicit Java language version 'common --java_language_version=8', @@ -261,6 +262,43 @@ def testForceFetch(self): _, _, stderr = self.RunBazel(['fetch', '--repo=@hello', '--force']) self.assertIn('No more Orange Juice!', ''.join(stderr)) + def testFetchTarget(self): + self.main_registry.createCcModule('aaa', '1.0').createCcModule( + 'bbb', '1.0', {'aaa': '1.0'} + ) + self.ScratchFile( + 'MODULE.bazel', + [ + 'bazel_dep(name = "bbb", version = "1.0")', + ], + ) + self.ScratchFile( + 'BUILD', + [ + 'cc_binary(', + ' name = "main",', + ' srcs = ["main.cc"],', + ' deps = [', + ' "@bbb//:lib_bbb",', + ' ],', + ')', + ], + ) + self.ScratchFile( + 'main.cc', + [ + '#include "aaa.h"', + 'int main() {', + ' hello_aaa("Hello there!");', + '}', + ], + ) + self.RunBazel(['fetch', '//:main']) + # If we can run the target with --nofetch, this means we successfully + # fetched all its needed repos + _, stdout, _ = self.RunBazel(['run', '//:main', '--nofetch']) + self.assertIn('Hello there! => aaa@1.0', stdout) + if __name__ == '__main__': absltest.main() diff --git a/src/test/py/bazel/bzlmod/external_repo_completion_test.py b/src/test/py/bazel/bzlmod/external_repo_completion_test.py index ac5f6991bd53f7..95bceed06ae9c9 100644 --- a/src/test/py/bazel/bzlmod/external_repo_completion_test.py +++ b/src/test/py/bazel/bzlmod/external_repo_completion_test.py @@ -139,7 +139,7 @@ def setUp(self): self.main_registry.createLocalPathModule('ext', '1.0', 'ext') scratchFile( self.projects_dir.joinpath('ext', 'BUILD'), - ['cc_library(name="lib_ext")'], + ['cc_library(name="lib_ext", visibility = ["//visibility:public"])'], ) scratchFile( self.projects_dir.joinpath('ext', 'tools', 'BUILD'), @@ -153,7 +153,7 @@ def setUp(self): self.main_registry.createLocalPathModule('ext2', '1.0', 'ext2') scratchFile( self.projects_dir.joinpath('ext2', 'BUILD'), - ['cc_library(name="lib_ext2")'], + ['cc_library(name="lib_ext2", visibility = ["//visibility:public"])'], ) scratchFile(self.projects_dir.joinpath('ext2', 'ext.bzl'), ext_src)