Skip to content

Commit 0dc53a2

Browse files
Googlercopybara-github
Googler
authored andcommitted
Refactoring: include exec_properties as a separate field in Spawn and change the code to use that instead of the platform.
This is in preparation for target level execution properties (See https://docs.google.com/document/d/1w3fu8zu_sRw_gK1dFAvkY2suhbQQ82tc0zdjet-dpCI/edit#heading=h.5mcn15i0e1ch) RELNOTES: None PiperOrigin-RevId: 265386594
1 parent 4ba404f commit 0dc53a2

23 files changed

+151
-32
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import com.google.common.base.Preconditions;
1818
import com.google.common.collect.ImmutableList;
19+
import com.google.common.collect.ImmutableMap;
1920
import com.google.common.collect.ImmutableSet;
2021
import com.google.common.collect.Iterables;
2122
import com.google.devtools.build.lib.actions.extra.ExtraActionInfo;
@@ -549,6 +550,11 @@ public SkylarkDict<String, String> getEnv() {
549550
return SkylarkDict.copyOf(null, env.getFixedEnv().toMap());
550551
}
551552

553+
@Override
554+
public ImmutableMap<String, String> getExecProperties() {
555+
return getOwner().getExecProperties();
556+
}
557+
552558
@Override
553559
@Nullable
554560
public PlatformInfo getExecutionPlatform() {

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

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414
package com.google.devtools.build.lib.actions;
1515

16+
import com.google.common.collect.ImmutableMap;
1617
import com.google.common.collect.ImmutableSet;
1718
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
1819
import javax.annotation.Nullable;
@@ -250,6 +251,9 @@ default boolean hasLooseHeaders() {
250251
return false;
251252
}
252253

254+
/** Returns a String to String map containing the execution properties of this action. */
255+
ImmutableMap<String, String> getExecProperties();
256+
253257
/**
254258
* Returns the {@link PlatformInfo} platform this action should be executed on. If the execution
255259
* platform is {@code null}, then the host platform is assumed.

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

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public final String getKey(ActionKeyContext actionKeyContext) {
4040
getExecutionPlatform().addTo(fp);
4141
}
4242

43+
fp.addStringMap(getExecProperties());
44+
4345
// Compute the actual key and store it.
4446
cachedKey = fp.hexDigestAndReset();
4547
} catch (CommandLineExpansionException e) {

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

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.google.auto.value.AutoValue;
1717
import com.google.common.base.Preconditions;
1818
import com.google.common.collect.ImmutableList;
19+
import com.google.common.collect.ImmutableMap;
1920
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
2021
import com.google.devtools.build.lib.cmdline.Label;
2122
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
@@ -46,6 +47,7 @@ public abstract class ActionOwner {
4647
"system",
4748
null,
4849
null,
50+
ImmutableMap.<String, String>of(),
4951
null);
5052

5153
@AutoCodec.Instantiator
@@ -58,6 +60,7 @@ public static ActionOwner create(
5860
String configurationChecksum,
5961
@Nullable BuildConfigurationEvent configuration,
6062
@Nullable String additionalProgressInfo,
63+
ImmutableMap<String, String> execProperties,
6164
@Nullable PlatformInfo executionPlatform) {
6265
return new AutoValue_ActionOwner(
6366
location,
@@ -68,6 +71,7 @@ public static ActionOwner create(
6871
configuration,
6972
targetKind,
7073
additionalProgressInfo,
74+
execProperties,
7175
executionPlatform);
7276
}
7377

@@ -111,6 +115,9 @@ public static ActionOwner create(
111115
@Nullable
112116
abstract String getAdditionalProgressInfo();
113117

118+
/** Returns a String to String map containing the execution properties of this action. */
119+
abstract ImmutableMap<String, String> getExecProperties();
120+
114121
/**
115122
* Returns the {@link PlatformInfo} platform this action should be executed on. If the execution
116123
* platform is {@code null}, then the host platform is assumed.

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

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414
package com.google.devtools.build.lib.actions;
1515

16+
import com.google.common.collect.ImmutableMap;
1617
import com.google.devtools.build.lib.actions.ActionLookupValue.ActionLookupKey;
1718
import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact;
1819
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
@@ -88,6 +89,11 @@ Iterable<T> generateActionForInputArtifacts(
8889
/** Returns the output TreeArtifact. */
8990
Artifact getOutputTreeArtifact();
9091

92+
@Override
93+
default ImmutableMap<String, String> getExecProperties() {
94+
return ImmutableMap.<String, String>of();
95+
}
96+
9197
@Override
9298
@Nullable
9399
default PlatformInfo getExecutionPlatform() {

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

+5
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ public String getMnemonic() {
150150
return action.getMnemonic();
151151
}
152152

153+
@Override
154+
public ImmutableMap<String, String> getCombinedExecProperties() {
155+
return action.getOwner().getExecProperties();
156+
}
157+
153158
@Override
154159
@Nullable
155160
public PlatformInfo getExecutionPlatform() {

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

+5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ public String getMnemonic() {
8787
return spawn.getMnemonic();
8888
}
8989

90+
@Override
91+
public ImmutableMap<String, String> getCombinedExecProperties() {
92+
return spawn.getCombinedExecProperties();
93+
}
94+
9095
@Override
9196
@Nullable
9297
public PlatformInfo getExecutionPlatform() {

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

+5
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ public String getMnemonic() {
139139
return owner.getMnemonic();
140140
}
141141

142+
@Override
143+
public ImmutableMap<String, String> getCombinedExecProperties() {
144+
return owner.getExecProperties();
145+
}
146+
142147
@Override
143148
@Nullable
144149
public PlatformInfo getExecutionPlatform() {

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

+8
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ public interface Spawn {
111111
*/
112112
String getMnemonic();
113113

114+
/**
115+
* Returns execution properties related to this spawn.
116+
*
117+
* <p>Note that this includes data from the execution platform's exec_properties as well as
118+
* target-level exec_properties. TODO(agoulti): implement target-level exec_properties.
119+
*/
120+
ImmutableMap<String, String> getCombinedExecProperties();
121+
114122
@Nullable
115123
PlatformInfo getExecutionPlatform();
116124
}

src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java

+9
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,14 @@ public static ActionOwner createActionOwner(
514514
ImmutableList<AspectDescriptor> aspectDescriptors,
515515
BuildConfiguration configuration,
516516
@Nullable PlatformInfo executionPlatform) {
517+
ImmutableMap<String, String> execProperties;
518+
if (executionPlatform != null) {
519+
execProperties = executionPlatform.execProperties();
520+
} else {
521+
execProperties = ImmutableMap.of();
522+
}
523+
// TODO(agoulti): Insert logic to include per-target execution properties
524+
517525
return ActionOwner.create(
518526
rule.getLabel(),
519527
aspectDescriptors,
@@ -523,6 +531,7 @@ public static ActionOwner createActionOwner(
523531
configuration.checksum(),
524532
configuration.toBuildEvent(),
525533
configuration.isHostConfiguration() ? HOST_CONFIGURATION_PROGRESS_TAG : null,
534+
execProperties,
526535
executionPlatform);
527536
}
528537

src/main/java/com/google/devtools/build/lib/analysis/platform/PlatformUtils.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.common.base.Strings;
2020
import com.google.common.collect.ImmutableSortedMap;
2121
import com.google.common.collect.Ordering;
22+
import com.google.devtools.build.lib.actions.Spawn;
2223
import com.google.devtools.build.lib.actions.UserExecException;
2324
import com.google.devtools.build.lib.remote.options.RemoteOptions;
2425
import com.google.protobuf.TextFormat;
@@ -33,35 +34,36 @@
3334
public final class PlatformUtils {
3435

3536
@Nullable
36-
public static Platform getPlatformProto(
37-
@Nullable PlatformInfo executionPlatform, @Nullable RemoteOptions remoteOptions)
37+
public static Platform getPlatformProto(Spawn spawn, @Nullable RemoteOptions remoteOptions)
3838
throws UserExecException {
3939
SortedMap<String, String> defaultExecProperties =
4040
remoteOptions != null
4141
? remoteOptions.getRemoteDefaultExecProperties()
4242
: ImmutableSortedMap.of();
4343

44-
if (executionPlatform == null && defaultExecProperties.isEmpty()) {
44+
if (spawn.getExecutionPlatform() == null
45+
&& spawn.getCombinedExecProperties().isEmpty()
46+
&& defaultExecProperties.isEmpty()) {
4547
return null;
4648
}
4749

4850
Platform.Builder platformBuilder = Platform.newBuilder();
4951

50-
if (executionPlatform != null && !executionPlatform.execProperties().isEmpty()) {
51-
for (Map.Entry<String, String> entry : executionPlatform.execProperties().entrySet()) {
52+
if (!spawn.getCombinedExecProperties().isEmpty()) {
53+
for (Map.Entry<String, String> entry : spawn.getCombinedExecProperties().entrySet()) {
5254
platformBuilder.addPropertiesBuilder().setName(entry.getKey()).setValue(entry.getValue());
5355
}
54-
} else if (executionPlatform != null
55-
&& !Strings.isNullOrEmpty(executionPlatform.remoteExecutionProperties())) {
56+
} else if (spawn.getExecutionPlatform() != null
57+
&& !Strings.isNullOrEmpty(spawn.getExecutionPlatform().remoteExecutionProperties())) {
5658
// Try and get the platform info from the execution properties.
5759
try {
5860
TextFormat.getParser()
59-
.merge(executionPlatform.remoteExecutionProperties(), platformBuilder);
61+
.merge(spawn.getExecutionPlatform().remoteExecutionProperties(), platformBuilder);
6062
} catch (ParseException e) {
6163
throw new UserExecException(
6264
String.format(
6365
"Failed to parse remote_execution_properties from platform %s",
64-
executionPlatform.label()),
66+
spawn.getExecutionPlatform().label()),
6567
e);
6668
}
6769
} else {

src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ public void logSpawn(
129129
}
130130
builder.setRemotable(Spawns.mayBeExecutedRemotely(spawn));
131131

132-
Platform execPlatform =
133-
PlatformUtils.getPlatformProto(spawn.getExecutionPlatform(), remoteOptions);
132+
Platform execPlatform = PlatformUtils.getPlatformProto(spawn, remoteOptions);
134133
if (execPlatform != null) {
135134
builder.setPlatform(buildPlatform(execPlatform));
136135
}

src/main/java/com/google/devtools/build/lib/includescanning/SpawnIncludeScanner.java

+5
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ public RunfilesSupplier getRunfilesSupplier() {
194194
throw new UnsupportedOperationException();
195195
}
196196

197+
@Override
198+
public ImmutableMap<String, String> getExecProperties() {
199+
return actionExecutionMetadata.getExecProperties();
200+
}
201+
197202
@Override
198203
@Nullable
199204
public PlatformInfo getExecutionPlatform() {

src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public CacheHandle lookup(Spawn spawn, SpawnExecutionContext context)
132132
Digest merkleTreeRoot = merkleTree.getRootDigest();
133133

134134
// Get the remote platform properties.
135-
Platform platform = PlatformUtils.getPlatformProto(spawn.getExecutionPlatform(), options);
135+
Platform platform = PlatformUtils.getPlatformProto(spawn, options);
136136

137137
Command command =
138138
RemoteSpawnRunner.buildCommand(

src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public SpawnResult exec(Spawn spawn, SpawnExecutionContext context)
169169
maybeWriteParamFilesLocally(spawn);
170170

171171
// Get the remote platform properties.
172-
Platform platform = PlatformUtils.getPlatformProto(spawn.getExecutionPlatform(), remoteOptions);
172+
Platform platform = PlatformUtils.getPlatformProto(spawn, remoteOptions);
173173

174174
Command command =
175175
buildCommand(

src/main/java/com/google/devtools/build/lib/sandbox/DockerSandboxedSpawnRunner.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,7 @@ private String executeCommand(List<String> cmdLine, InputStream stdIn) throws Us
377377

378378
private Optional<String> dockerContainerFromSpawn(Spawn spawn) throws ExecException {
379379
Platform platform =
380-
PlatformUtils.getPlatformProto(
381-
spawn.getExecutionPlatform(), cmdEnv.getOptions().getOptions(RemoteOptions.class));
380+
PlatformUtils.getPlatformProto(spawn, cmdEnv.getOptions().getOptions(RemoteOptions.class));
382381

383382
if (platform != null) {
384383
try {

src/test/java/com/google/devtools/build/lib/actions/ResourceManagerTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
1818

1919
import com.google.common.collect.ImmutableList;
20+
import com.google.common.collect.ImmutableMap;
2021
import com.google.common.collect.ImmutableSet;
2122
import com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle;
2223
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
@@ -547,6 +548,11 @@ public MiddlemanType getActionType() {
547548
throw new IllegalStateException();
548549
}
549550

551+
@Override
552+
public ImmutableMap<String, String> getExecProperties() {
553+
throw new IllegalStateException();
554+
}
555+
550556
@Nullable
551557
@Override
552558
public PlatformInfo getExecutionPlatform() {

src/test/java/com/google/devtools/build/lib/actions/util/ActionsTestUtil.java

+1
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ public Label getLabel() {
346346
"dummy-configuration",
347347
null,
348348
null,
349+
ImmutableMap.<String, String>of(),
349350
null);
350351

351352
@AutoCodec

src/test/java/com/google/devtools/build/lib/analysis/platform/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ java_test(
2323
"//src/main/java/com/google/devtools/build/lib:packages-internal",
2424
"//src/main/java/com/google/devtools/build/lib:syntax",
2525
"//src/main/java/com/google/devtools/build/lib:util",
26+
"//src/main/java/com/google/devtools/build/lib/actions",
2627
"//src/main/java/com/google/devtools/build/lib/analysis/platform",
2728
"//src/main/java/com/google/devtools/build/lib/analysis/platform:platform_utils",
2829
"//src/main/java/com/google/devtools/build/lib/analysis/platform:utils",

0 commit comments

Comments
 (0)