From 092e38fa89d8419ba8f776c6ae7abdd6b1f32f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Gelencse=CC=81r?= Date: Tue, 26 Nov 2024 09:52:26 +0100 Subject: [PATCH] done :tada: --- .../build/lib/remote/RemoteAction.java | 30 +++++++++++++++++++ .../lib/remote/RemoteExecutionService.java | 30 ------------------- .../build/lib/remote/RemoteSpawnCache.java | 2 ++ .../lib/remote/merkletree/MerkleTree.java | 2 +- 4 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteAction.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteAction.java index e8230f56933194..f56e1b21f8d060 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteAction.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteAction.java @@ -28,6 +28,7 @@ import com.google.devtools.build.lib.vfs.PathFragment; import java.util.SortedMap; import javax.annotation.Nullable; +import java.io.FileWriter; /** * A value class representing an action which can be executed remotely. @@ -73,6 +74,35 @@ public class RemoteAction { this.actionKey = actionKey; } + private void writeDirectoryToFile(FileWriter writer, String root, MerkleTree t) throws IOException { + writer.write("[Root proto of " + root + "]\n"); + writer.write(t.rootProto.toString()); + for (String dirName : t.directories.keySet()) { + MerkleTree dir = t.directories.get(dirName); + writeDirectoryToFile(writer, root + "/" + dirName, dir); + } + } + + public void writeToFile() { + String jsonPath = "/tmp/bazeldebug/" + actionKey.getDigest().getHash() + ".json"; + try (FileWriter writer = new FileWriter(jsonPath)) { + writer.write("[Action]\n"); + writer.write(action.toString()); + writer.write("\n\n"); + + writer.write("[Command]\n"); + writer.write(command.toString()); + writer.write("\n\n"); + + writer.write("[InputRoot]\n"); + writeDirectoryToFile(writer, ".", merkleTree); + + System.out.println(jsonPath + " written."); + } catch (IOException e) { + e.printStackTrace(); + } + } + public RemoteActionExecutionContext getRemoteActionExecutionContext() { return remoteActionExecutionContext; } diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java index e29a8b6dd8a769..aa2f64d06c7aa5 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java @@ -137,7 +137,6 @@ import io.reactivex.rxjava3.schedulers.Schedulers; import java.io.FileNotFoundException; import java.io.IOException; -import java.io.FileWriter; import java.io.File; import java.time.Instant; import java.util.ArrayList; @@ -671,36 +670,7 @@ public RemoteAction buildRemoteAction(Spawn spawn, SpawnExecutionContext context Spawns.mayBeCachedRemotely(spawn), buildSalt(spawn, spawnScrubber)); - System.out.println("[DEBUG] RemoteExecutionService.buildRemoteAction"); ActionKey actionKey = digestUtil.computeActionKey(action); - - String jsonPath = "/tmp/bazeldebug/" + actionKey.getDigest().getHash() + ".json"; - File file = new File(jsonPath); - try (FileWriter writer = new FileWriter(file)) { - writer.write("[Action]\n"); - writer.write(action.toString()); - writer.write("\n\n"); - - writer.write("[Command]\n"); - writer.write(command.toString()); - writer.write("\n\n"); - - writer.write("[Platform]\n"); - writer.write(platform.toString()); - writer.write("\n\n"); - - writer.write("[InputRoot]\n"); - writer.write(merkleTree.rootDigest.toString()); - writer.write("[Root proto]\n"); - writer.write(merkleTree.rootProto.toString()); - writer.write("[Files]\n"); - writer.write(merkleTree.files.toString()); - - System.out.println(jsonPath + " written."); - } catch (IOException e) { - e.printStackTrace(); - } - RequestMetadata metadata = TracingMetadataUtils.buildMetadata( buildRequestId, commandId, actionKey.getDigest().getHash(), spawn.getResourceOwner()); diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java index 06c97c5390db38..efc1123851fcd1 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java @@ -249,6 +249,8 @@ public void store(SpawnResult result) throws ExecException, InterruptedException return; } + action.writeToFile(); + if (options.experimentalGuardAgainstConcurrentChanges) { try (SilentCloseable c = prof.profile("checkForConcurrentModifications")) { checkForConcurrentModifications(); diff --git a/src/main/java/com/google/devtools/build/lib/remote/merkletree/MerkleTree.java b/src/main/java/com/google/devtools/build/lib/remote/merkletree/MerkleTree.java index f5c1a86179f5b5..142fcbd135a961 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/merkletree/MerkleTree.java +++ b/src/main/java/com/google/devtools/build/lib/remote/merkletree/MerkleTree.java @@ -100,7 +100,7 @@ private interface MerkleTreeDirectoryVisitor { public final Digest rootDigest; public final SortedSet files; private final SortedSet symlinks; - private final SortedMap directories; + public final SortedMap directories; private final long inputFiles; private final long inputBytes;