Skip to content

Commit 3daedc3

Browse files
justinhorvitzcopybara-github
authored andcommitted
Split up actions java library target.
Notably, this separates Artifact and related types so that they don't have to be tied in with the rest of the actions library. Pulled some nested classes to the top level to achieve this and did some other drive-by cleanups, but otherwise just import statements and BUILD files. RELNOTES: None. PiperOrigin-RevId: 322699250
1 parent f1bbfc2 commit 3daedc3

File tree

130 files changed

+728
-352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+728
-352
lines changed

src/main/java/com/google/devtools/build/lib/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ java_library(
275275
":runtime/blaze_command_result",
276276
":runtime/command_dispatcher",
277277
"//src/main/java/com/google/devtools/build/lib/actions",
278+
"//src/main/java/com/google/devtools/build/lib/actions:artifacts",
278279
"//src/main/java/com/google/devtools/build/lib/actions:localhost_capacity",
280+
"//src/main/java/com/google/devtools/build/lib/actions:middleman_type",
279281
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster",
280282
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_options",
281283
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_phase_complete_event",

src/main/java/com/google/devtools/build/lib/actions/ActionAnalysisMetadata.java

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -211,41 +211,6 @@ NestedSet<Artifact> getInputFilesForExtraAction(ActionExecutionContext actionExe
211211
/** Returns the action type. Must not be {@code null}. */
212212
MiddlemanType getActionType();
213213

214-
/** The action type. */
215-
enum MiddlemanType {
216-
217-
/** A normal action. */
218-
NORMAL,
219-
220-
/** A normal middleman, which just encapsulates a list of artifacts. */
221-
AGGREGATING_MIDDLEMAN,
222-
223-
/**
224-
* A middleman that denotes a scheduling dependency.
225-
*
226-
* <p>If an action has dependencies through scheduling dependency middleman, those dependencies
227-
* will get built before the action is run and the build will error out if they cannot be built,
228-
* but the dependencies will not be considered inputs of the action.
229-
*
230-
* <p>This is useful in cases when an action <em>might</em> need some inputs, but that is only
231-
* found out right before it gets executed. The most salient case is C++ compilation where all
232-
* files that can possibly be included need to be built before the action is executed, but if
233-
* include scanning is used, only a subset of them will end up as inputs.
234-
*/
235-
SCHEDULING_DEPENDENCY_MIDDLEMAN,
236-
237-
/**
238-
* A runfiles middleman, which is validated by the dependency checker, but is not expanded
239-
* in blaze. Instead, the runfiles manifest is sent to remote execution client, which
240-
* performs the expansion.
241-
*/
242-
RUNFILES_MIDDLEMAN;
243-
244-
public boolean isMiddleman() {
245-
return this != NORMAL;
246-
}
247-
}
248-
249214
/**
250215
* Indicates whether this action has loose headers, or if this is an {@link ActionTemplate},
251216
* whether the expanded action(s) will have loose headers.

src/main/java/com/google/devtools/build/lib/actions/ActionCacheChecker.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.google.common.collect.ImmutableList;
2020
import com.google.common.collect.ImmutableMap;
2121
import com.google.common.collect.ImmutableSet;
22-
import com.google.devtools.build.lib.actions.ActionAnalysisMetadata.MiddlemanType;
2322
import com.google.devtools.build.lib.actions.cache.ActionCache;
2423
import com.google.devtools.build.lib.actions.cache.DigestUtils;
2524
import com.google.devtools.build.lib.actions.cache.MetadataHandler;

src/main/java/com/google/devtools/build/lib/actions/ActionInputHelper.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package com.google.devtools.build.lib.actions;
1616

1717
import com.google.common.annotations.VisibleForTesting;
18-
import com.google.common.base.Function;
1918
import com.google.common.base.Functions;
2019
import com.google.common.base.Preconditions;
2120
import com.google.common.collect.Iterables;
@@ -46,7 +45,7 @@ public void expand(Artifact mm, Collection<? super Artifact> output) {
4645
// TODO(bazel-team): Consider expanding recursively or throwing an exception here.
4746
// Most likely, this code will cause silent errors if we ever have a middleman that
4847
// contains a middleman.
49-
if (middlemanAction.getActionType() == Action.MiddlemanType.AGGREGATING_MIDDLEMAN) {
48+
if (middlemanAction.getActionType() == MiddlemanType.AGGREGATING_MIDDLEMAN) {
5049
Artifact.addNonMiddlemanArtifacts(
5150
middlemanAction.getInputs().toList(), output, Functions.<Artifact>identity());
5251
}
@@ -147,12 +146,8 @@ public static List<ActionInput> expandArtifacts(
147146
return result;
148147
}
149148

150-
/** Formatter for execPath String output. Public because {@link Artifact} uses it directly. */
151-
public static final Function<ActionInput, String> EXEC_PATH_STRING_FORMATTER =
152-
ActionInput::getExecPathString;
153-
154149
public static Iterable<String> toExecPaths(Iterable<? extends ActionInput> artifacts) {
155-
return Iterables.transform(artifacts, EXEC_PATH_STRING_FORMATTER);
150+
return Iterables.transform(artifacts, ActionInput::getExecPathString);
156151
}
157152

158153
/** Returns the {@link Path} for an {@link ActionInput}. */

src/main/java/com/google/devtools/build/lib/actions/ActionLookupData.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import com.google.common.base.MoreObjects;
1717
import com.google.common.base.Preconditions;
18-
import com.google.devtools.build.lib.actions.ActionLookupValue.ActionLookupKey;
1918
import com.google.devtools.build.lib.cmdline.Label;
2019
import com.google.devtools.build.lib.skyframe.SkyFunctions;
2120
import com.google.devtools.build.skyframe.ShareabilityOfValue;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2014 The Bazel Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package com.google.devtools.build.lib.actions;
15+
16+
import com.google.devtools.build.skyframe.SkyKey;
17+
18+
/**
19+
* {@link SkyKey} for an {@link ActionLookupValue}.
20+
*
21+
* <p>All subclasses of {@link ActionLookupValue} "own" artifacts with {@link ArtifactOwner}s that
22+
* are subclasses of {@link ActionLookupKey}. This allows callers to easily find the value key,
23+
* while remaining agnostic to what action lookup values actually exist.
24+
*/
25+
public interface ActionLookupKey extends ArtifactOwner, SkyKey {}

src/main/java/com/google/devtools/build/lib/actions/ActionLookupValue.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
import com.google.common.collect.ImmutableList;
1717
import com.google.devtools.build.lib.actions.Artifact.SourceArtifact;
18-
import com.google.devtools.build.lib.cmdline.Label;
19-
import com.google.devtools.build.skyframe.SkyKey;
2018
import com.google.devtools.build.skyframe.SkyValue;
2119
import javax.annotation.Nullable;
2220

@@ -61,15 +59,4 @@ default SourceArtifact getSourceArtifact() {
6159
return null;
6260
}
6361

64-
/**
65-
* All subclasses of ActionLookupValue "own" artifacts with {@link ArtifactOwner}s that are
66-
* subclasses of ActionLookupKey. This allows callers to easily find the value key, while
67-
* remaining agnostic to what ActionLookupValues actually exist.
68-
*/
69-
abstract class ActionLookupKey implements ArtifactOwner, SkyKey {
70-
@Override
71-
public Label getLabel() {
72-
return null;
73-
}
74-
}
7562
}

src/main/java/com/google/devtools/build/lib/actions/ActionRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ public interface ActionRegistry {
2424
void registerAction(ActionAnalysisMetadata... actions);
2525

2626
/** Get the key of the ConfiguredTarget/Aspect ultimately responsible for all these actions. */
27-
ActionLookupValue.ActionLookupKey getOwner();
27+
ActionLookupKey getOwner();
2828
}

src/main/java/com/google/devtools/build/lib/actions/ActionTemplate.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import com.google.common.collect.ImmutableList;
1717
import com.google.common.collect.ImmutableMap;
1818
import com.google.common.collect.ImmutableSet;
19-
import com.google.devtools.build.lib.actions.ActionLookupValue.ActionLookupKey;
2019
import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact;
2120
import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact;
2221
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;

src/main/java/com/google/devtools/build/lib/actions/Actions.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.google.common.escape.Escaper;
2323
import com.google.common.escape.Escapers;
2424
import com.google.common.flogger.GoogleLogger;
25-
import com.google.devtools.build.lib.actions.ActionLookupValue.ActionLookupKey;
2625
import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException;
2726
import com.google.devtools.build.lib.cmdline.Label;
2827
import com.google.devtools.build.lib.packages.OutputFile;

src/main/java/com/google/devtools/build/lib/actions/Artifact.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import com.google.common.collect.ImmutableList;
2727
import com.google.common.collect.Iterables;
2828
import com.google.common.collect.Streams;
29-
import com.google.devtools.build.lib.actions.ActionAnalysisMetadata.MiddlemanType;
30-
import com.google.devtools.build.lib.actions.ActionLookupValue.ActionLookupKey;
3129
import com.google.devtools.build.lib.actions.ArtifactResolver.ArtifactResolverSupplier;
3230
import com.google.devtools.build.lib.cmdline.Label;
3331
import com.google.devtools.build.lib.cmdline.LabelConstants;
@@ -299,12 +297,12 @@ boolean ownersEqual(Artifact other) {
299297

300298
@Override
301299
public ArtifactOwner getArtifactOwner() {
302-
return ArtifactOwner.NullArtifactOwner.INSTANCE;
300+
return ArtifactOwner.NULL_OWNER;
303301
}
304302

305303
@Override
306304
public Label getOwnerLabel() {
307-
return ArtifactOwner.NullArtifactOwner.INSTANCE.getLabel();
305+
return ArtifactOwner.NULL_OWNER.getLabel();
308306
}
309307

310308
@Override
@@ -385,7 +383,7 @@ public final ActionLookupData getGeneratingActionKey() {
385383
}
386384

387385
@Override
388-
public final ActionLookupValue.ActionLookupKey getArtifactOwner() {
386+
public final ActionLookupKey getArtifactOwner() {
389387
return owner instanceof ActionLookupData
390388
? getGeneratingActionKey().getActionLookupKey()
391389
: (ActionLookupKey) owner;
@@ -549,11 +547,10 @@ public final Label getOwner() {
549547

550548
/**
551549
* Gets the {@code ActionLookupKey} of the {@code ConfiguredTarget} that owns this artifact, if it
552-
* was set. Otherwise, this should be a dummy value -- either {@link
553-
* ArtifactOwner.NullArtifactOwner#INSTANCE} or a dummy owner set in tests. Such a dummy value
554-
* should only occur for source artifacts if created without specifying the owner, or for special
555-
* derived artifacts, such as target completion middleman artifacts, build info artifacts, and the
556-
* like.
550+
* was set. Otherwise, this should be a dummy value -- either {@link ArtifactOwner#NULL_OWNER} or
551+
* a dummy owner set in tests. Such a dummy value should only occur for source artifacts if
552+
* created without specifying the owner, or for special derived artifacts, such as target
553+
* completion middleman artifacts, build info artifacts, and the like.
557554
*/
558555
public abstract ArtifactOwner getArtifactOwner();
559556

@@ -1135,7 +1132,7 @@ public SourceArtifact deserialize(DeserializationContext context, CodedInputStre
11351132
* method.
11361133
*/
11371134
public static void addExecPaths(Iterable<Artifact> artifacts, Collection<String> output) {
1138-
addNonMiddlemanArtifacts(artifacts, output, ActionInputHelper.EXEC_PATH_STRING_FORMATTER);
1135+
addNonMiddlemanArtifacts(artifacts, output, ActionInput::getExecPathString);
11391136
}
11401137

11411138
/**
@@ -1175,7 +1172,8 @@ public static Iterable<String> toRootRelativePaths(Iterable<Artifact> artifacts)
11751172
* this method.
11761173
*/
11771174
public static Iterable<String> toExecPaths(Iterable<Artifact> artifacts) {
1178-
return ActionInputHelper.toExecPaths(Iterables.filter(artifacts, MIDDLEMAN_FILTER));
1175+
return Iterables.transform(
1176+
Iterables.filter(artifacts, MIDDLEMAN_FILTER), ActionInput::getExecPathString);
11791177
}
11801178

11811179
/**

src/main/java/com/google/devtools/build/lib/actions/ArtifactFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.google.common.base.Preconditions;
1818
import com.google.common.collect.ImmutableMap;
1919
import com.google.common.util.concurrent.Striped;
20-
import com.google.devtools.build.lib.actions.ActionLookupValue.ActionLookupKey;
2120
import com.google.devtools.build.lib.actions.Artifact.SourceArtifact;
2221
import com.google.devtools.build.lib.actions.Artifact.SpecialArtifactType;
2322
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
@@ -194,7 +193,7 @@ public SourceArtifact getSourceArtifact(PathFragment execPath, Root root, Artifa
194193

195194
@Override
196195
public SourceArtifact getSourceArtifact(PathFragment execPath, Root root) {
197-
return getSourceArtifact(execPath, root, ArtifactOwner.NullArtifactOwner.INSTANCE);
196+
return getSourceArtifact(execPath, root, ArtifactOwner.NULL_OWNER);
198197
}
199198

200199
private void validatePath(PathFragment rootRelativePath, ArtifactRoot root) {
@@ -544,7 +543,7 @@ private Artifact createArtifactIfNotValid(Root sourceRoot, PathFragment execPath
544543
}
545544
} else {
546545
// Must be a new artifact or artifact in the cache is stale, so create a new one.
547-
artifact = getSourceArtifact(execPath, sourceRoot, ArtifactOwner.NullArtifactOwner.INSTANCE);
546+
artifact = getSourceArtifact(execPath, sourceRoot, ArtifactOwner.NULL_OWNER);
548547
}
549548
return artifact;
550549
}

src/main/java/com/google/devtools/build/lib/actions/ArtifactOwner.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,35 @@
1313
// limitations under the License.
1414
package com.google.devtools.build.lib.actions;
1515

16-
import com.google.common.annotations.VisibleForTesting;
1716
import com.google.devtools.build.lib.cmdline.Label;
18-
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
17+
import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant;
18+
import javax.annotation.Nullable;
1919

2020
/**
2121
* An interface for {@code ActionLookupKey}, or at least for a {@link Label}. Only tests and
2222
* internal {@link Artifact}-generators should implement this interface -- otherwise, {@code
2323
* ActionLookupKey} and its subclasses should be the only implementation.
2424
*/
2525
public interface ArtifactOwner {
26+
27+
@Nullable
2628
Label getLabel();
2729

2830
/**
2931
* An {@link ArtifactOwner} that just returns null for its label. Only for use with resolved
3032
* source artifacts and tests.
3133
*/
32-
class NullArtifactOwner implements ArtifactOwner {
33-
@AutoCodec @VisibleForTesting
34-
public static final NullArtifactOwner INSTANCE = new NullArtifactOwner();
35-
36-
private NullArtifactOwner() {}
37-
38-
@Override
39-
public Label getLabel() {
40-
return null;
41-
}
34+
@SerializationConstant
35+
ArtifactOwner NULL_OWNER =
36+
new ArtifactOwner() {
37+
@Override
38+
public Label getLabel() {
39+
return null;
40+
}
4241

43-
@Override
44-
public String toString() {
45-
return "NULL_OWNER";
46-
}
47-
}
42+
@Override
43+
public String toString() {
44+
return "NULL_OWNER";
45+
}
46+
};
4847
}

src/main/java/com/google/devtools/build/lib/actions/Artifacts.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
import com.google.devtools.build.lib.util.Fingerprint;
1717
import java.util.Collection;
1818

19-
/** Helper functions for dealing with {@link Artifacts} */
19+
/** Helper functions for dealing with {@link Artifact}s. */
2020
public final class Artifacts {
2121

2222
private Artifacts() {}
2323

24-
public static void addToFingerprint(Fingerprint fp, Artifact artifact) {
24+
private static void addToFingerprint(Fingerprint fp, Artifact artifact) {
2525
fp.addString(artifact.getExecPathString());
2626
}
2727

0 commit comments

Comments
 (0)