Skip to content

Commit

Permalink
wip: send full worker args to remote for dynamic persistent workers
Browse files Browse the repository at this point in the history
  • Loading branch information
wiwa committed Apr 18, 2022
1 parent 76f6ee4 commit d9c7ae9
Showing 1 changed file with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,19 @@ public RemoteAction buildRemoteAction(Spawn spawn, SpawnExecutionContext context
Platform platform = PlatformUtils.getPlatformProto(spawn, remoteOptions);

if (toolSignature != null) {

StringBuilder cmdStr = new StringBuilder();
for (String c : toolSignature.command) {
cmdStr.append(c);
cmdStr.append(" ");
}
cmdStr.deleteCharAt(cmdStr.length()-1);

Map<String, String> platformAdditionalProperties =
ImmutableMap.of("persistentWorkerKey", toolSignature.contentHash);
ImmutableMap.of(
"persistentWorkerKey", toolSignature.toolHash,
"persistentWorkerCommand", cmdStr.toString()
);

platform =
PlatformUtils.getPlatformProto(
Expand Down Expand Up @@ -536,12 +547,7 @@ private ToolSignature computePersistentWorkerSignature(Spawn spawn, SpawnExecuti
new WorkerParser(
execRoot, Options.getDefaults(WorkerOptions.class), LocalEnvProvider.NOOP, null);
WorkerKey workerKey = workerParser.compute(spawn, context).getWorkerKey();
Fingerprint fingerprint = new Fingerprint();
fingerprint.addBytes(workerKey.getWorkerFilesCombinedHash().asBytes());
fingerprint.addIterableStrings(workerKey.getArgs());
fingerprint.addStringMap(workerKey.getEnv());
return new ToolSignature(
fingerprint.hexDigestAndReset(), workerKey.getWorkerFilesWithHashes().keySet());
return new ToolSignature(workerKey);
}

/** A value class representing the result of remotely executed {@link RemoteAction}. */
Expand Down Expand Up @@ -1383,14 +1389,28 @@ void report(Event evt) {
/**
* A simple value class combining a hash of the tool inputs (and their digests) as well as a set
* of the relative paths of all tool inputs.
*
* ???! We also need to spell out the actual command.
* This effectively means that this class is a subset of WorkerKey
*/
private static final class ToolSignature {
private final String contentHash;

private final ImmutableList<String> command;
private final ImmutableMap<String, String> env;
private final Set<PathFragment> toolInputs;
private final String toolHash;

private ToolSignature(WorkerKey workerKey) {
this.command = workerKey.getArgs();
this.env = workerKey.getEnv();
this.toolInputs = workerKey.getWorkerFilesWithHashes().keySet();

Fingerprint fingerprint = new Fingerprint();
fingerprint.addBytes(workerKey.getWorkerFilesCombinedHash().asBytes());
fingerprint.addIterableStrings(workerKey.getArgs());
fingerprint.addStringMap(workerKey.getEnv());

private ToolSignature(String contentHash, Set<PathFragment> toolInputs) {
this.contentHash = contentHash;
this.toolInputs = toolInputs;
this.toolHash = fingerprint.hexDigestAndReset();
}
}
}

0 comments on commit d9c7ae9

Please sign in to comment.