119
119
import com .google .devtools .build .lib .remote .util .TracingMetadataUtils ;
120
120
import com .google .devtools .build .lib .remote .util .Utils .InMemoryOutput ;
121
121
import com .google .devtools .build .lib .skyframe .TreeArtifactValue ;
122
+ import com .google .devtools .build .lib .testutil .TestConstants ;
122
123
import com .google .devtools .build .lib .util .Fingerprint ;
123
124
import com .google .devtools .build .lib .util .OS ;
124
125
import com .google .devtools .build .lib .util .TempPathGenerator ;
@@ -2327,16 +2328,28 @@ public void buildMerkleTree_withMemoization_works() throws Exception {
2327
2328
}
2328
2329
2329
2330
@ Test
2330
- public void buildRemoteActionForRemotePersistentWorkers () throws Exception {
2331
+ public void buildRemoteActionForRemotePersistentWorkers (@ TestParameter boolean enablePathMapping )
2332
+ throws Exception {
2331
2333
var input = ActionsTestUtil .createArtifact (artifactRoot , "input" );
2332
2334
fakeFileCache .createScratchInput (input , "value" );
2333
2335
var toolInput = ActionsTestUtil .createArtifact (artifactRoot , "worker_input" );
2334
2336
fakeFileCache .createScratchInput (toolInput , "worker value" );
2337
+
2338
+ Artifact toolDat = ActionsTestUtil .createArtifact (artifactRoot , "tool.dat" );
2339
+ fakeFileCache .createScratchInput (toolDat , "tool.dat" );
2340
+ RunfilesTree runfilesTree =
2341
+ createRunfilesTree ("outputs/worker_input.runfiles" , ImmutableList .of (toolDat ));
2342
+ ActionInput runfilesArtifact =
2343
+ ActionsTestUtil .createRunfilesArtifact (artifactRoot , "outputs/worker_input.runfiles" );
2344
+ fakeFileCache .addRunfilesTree (runfilesArtifact , runfilesTree );
2345
+
2335
2346
Spawn spawn =
2336
2347
new SpawnBuilder ("@flagfile" )
2337
2348
.withExecutionInfo (ExecutionRequirements .SUPPORTS_WORKERS , "1" )
2338
- .withInputs (input , toolInput )
2339
- .withTool (toolInput )
2349
+ .withInputs (input , toolInput , runfilesArtifact )
2350
+ .withTools (toolInput , runfilesArtifact )
2351
+ .setPathMapper (
2352
+ enablePathMapping ? path -> PathFragment .create ("mapped_" + path ) : PathMapper .NOOP )
2340
2353
.build ();
2341
2354
FakeSpawnExecutionContext context = newSpawnExecutionContext (spawn );
2342
2355
remoteOptions .markToolInputs = true ;
@@ -2352,7 +2365,9 @@ public void buildRemoteActionForRemotePersistentWorkers() throws Exception {
2352
2365
Platform .Property .newBuilder ()
2353
2366
.setName ("persistentWorkerKey" )
2354
2367
.setValue (
2355
- "628637504c26bb74fb6bb3f60fb7132b3aa574b866db4181770774882a8853e5" ))
2368
+ enablePathMapping
2369
+ ? "85e3ad12f36ccb7b5eddbfe8f6bc28f57004634c537faac32d33a30b8d456bb8"
2370
+ : "5b1f31685d47bab5267d65bf671a682a486240ae351d74130a12d452190bd5f3" ))
2356
2371
.build ());
2357
2372
var merkleTree = remoteAction .getMerkleTree ();
2358
2373
var outputDirectory =
@@ -2376,8 +2391,55 @@ public void buildRemoteActionForRemotePersistentWorkers() throws Exception {
2376
2391
.setNodeProperties (
2377
2392
NodeProperties .newBuilder ()
2378
2393
.addProperties (NodeProperty .newBuilder ().setName ("bazel_tool_input" )));
2394
+ var toolRunfilesDirectoryDigest =
2395
+ Digest .newBuilder ()
2396
+ .setHash ("d5cf7403c6b6c97f7b404c829a3d70c618412411c4554ed29b0f59815c53d952" )
2397
+ .setSizeBytes (79 )
2398
+ .build ();
2399
+ var toolRunfilesDirectory =
2400
+ DirectoryNode .newBuilder ()
2401
+ .setName ("worker_input.runfiles" )
2402
+ .setDigest (toolRunfilesDirectoryDigest );
2379
2403
assertThat (outputDirectory )
2380
- .isEqualTo (Directory .newBuilder ().addFiles (inputFile ).addFiles (toolFile ).build ());
2404
+ .isEqualTo (
2405
+ Directory .newBuilder ()
2406
+ .addFiles (inputFile )
2407
+ .addFiles (toolFile )
2408
+ .addDirectories (toolRunfilesDirectory )
2409
+ .build ());
2410
+ var runfilesDirectory = merkleTree .getDirectoryByDigest (toolRunfilesDirectoryDigest );
2411
+ var runfilesSubdirectoryDigest =
2412
+ Digest .newBuilder ()
2413
+ .setHash ("2773ed2d89aed9db55b83230eb8c66f56a02884e151009a3b070164bb6800cc8" )
2414
+ .setSizeBytes (106 )
2415
+ .build ();
2416
+ assertThat (runfilesDirectory )
2417
+ .isEqualTo (
2418
+ Directory .newBuilder ()
2419
+ .addDirectories (
2420
+ DirectoryNode .newBuilder ()
2421
+ .setName (TestConstants .WORKSPACE_NAME )
2422
+ .setDigest (runfilesSubdirectoryDigest ))
2423
+ .build ());
2424
+ var runfilesSubdirectory = merkleTree .getDirectoryByDigest (runfilesSubdirectoryDigest );
2425
+ assertThat (runfilesSubdirectory )
2426
+ .isEqualTo (
2427
+ Directory .newBuilder ()
2428
+ .addFiles (
2429
+ FileNode .newBuilder ()
2430
+ .setName ("tool.dat" )
2431
+ .setDigest (
2432
+ Digest .newBuilder ()
2433
+ .setHash (
2434
+ "968b7e2e112917824f4ea807dbc3adeebc00de2836f98c68418f525295f9a0c1" )
2435
+ .setSizeBytes (8 ))
2436
+ .setIsExecutable (true )
2437
+ .setNodeProperties (
2438
+ NodeProperties .newBuilder ()
2439
+ .addProperties (
2440
+ NodeProperty .newBuilder ().setName ("bazel_tool_input" )))
2441
+ .build ())
2442
+ .build ());
2381
2443
2382
2444
// Check that if an non-tool input changes, the persistent worker key does not change.
2383
2445
fakeFileCache .createScratchInput (input , "value2" );
@@ -2388,7 +2450,9 @@ public void buildRemoteActionForRemotePersistentWorkers() throws Exception {
2388
2450
Platform .Property .newBuilder ()
2389
2451
.setName ("persistentWorkerKey" )
2390
2452
.setValue (
2391
- "628637504c26bb74fb6bb3f60fb7132b3aa574b866db4181770774882a8853e5" ))
2453
+ enablePathMapping
2454
+ ? "85e3ad12f36ccb7b5eddbfe8f6bc28f57004634c537faac32d33a30b8d456bb8"
2455
+ : "5b1f31685d47bab5267d65bf671a682a486240ae351d74130a12d452190bd5f3" ))
2392
2456
.build ());
2393
2457
2394
2458
// Check that if a tool input changes, the persistent worker key changes.
@@ -2400,7 +2464,9 @@ public void buildRemoteActionForRemotePersistentWorkers() throws Exception {
2400
2464
Platform .Property .newBuilder ()
2401
2465
.setName ("persistentWorkerKey" )
2402
2466
.setValue (
2403
- "98e07ff5afc8f4d127e93d326c87c132f89cfd009517422671e6abec2fe05e2b" ))
2467
+ enablePathMapping
2468
+ ? "6667700b8ff75e77f50c0d6b471e9052c856a21648c8204f0772fc455df6d6dc"
2469
+ : "63335231cbbf2ff838acdd19da768ce6524e929c4dcedcdce77c822a480fa49b" ))
2404
2470
.build ());
2405
2471
}
2406
2472
@@ -2685,7 +2751,13 @@ public PathFragment getExecPath() {
2685
2751
@ Override
2686
2752
public SortedMap <PathFragment , Artifact > getMapping () {
2687
2753
return artifacts .stream ()
2688
- .collect (toImmutableSortedMap (naturalOrder (), Artifact ::getExecPath , identity ()));
2754
+ .collect (
2755
+ toImmutableSortedMap (
2756
+ naturalOrder (),
2757
+ artifact ->
2758
+ PathFragment .create (TestConstants .WORKSPACE_NAME )
2759
+ .getRelative (artifact .getRunfilesPath ()),
2760
+ identity ()));
2689
2761
}
2690
2762
2691
2763
@ Override
0 commit comments