39
39
import build .bazel .remote .execution .v2 .Digest ;
40
40
import build .bazel .remote .execution .v2 .Directory ;
41
41
import build .bazel .remote .execution .v2 .DirectoryNode ;
42
+ import build .bazel .remote .execution .v2 .ExecutionCapabilities ;
42
43
import build .bazel .remote .execution .v2 .FileNode ;
43
44
import build .bazel .remote .execution .v2 .NodeProperties ;
44
45
import build .bazel .remote .execution .v2 .NodeProperty ;
47
48
import build .bazel .remote .execution .v2 .OutputSymlink ;
48
49
import build .bazel .remote .execution .v2 .Platform ;
49
50
import build .bazel .remote .execution .v2 .RequestMetadata ;
51
+ import build .bazel .remote .execution .v2 .ServerCapabilities ;
50
52
import build .bazel .remote .execution .v2 .SymlinkAbsolutePathStrategy ;
51
53
import build .bazel .remote .execution .v2 .SymlinkNode ;
52
54
import build .bazel .remote .execution .v2 .Tree ;
55
+ import build .bazel .semver .SemVer ;
53
56
import com .google .common .base .Throwables ;
54
57
import com .google .common .collect .ImmutableClassToInstanceMap ;
55
58
import com .google .common .collect .ImmutableList ;
@@ -138,6 +141,23 @@ public class RemoteExecutionServiceTest {
138
141
private final Reporter reporter = new Reporter (new EventBus ());
139
142
private final StoredEventHandler eventHandler = new StoredEventHandler ();
140
143
144
+ // In the past, Bazel only supports RemoteApi version 2.0.
145
+ // Use this to ensure we are backward compatible with Servers that only support 2.0.
146
+ private final ApiVersion oldApiVersion = new ApiVersion (SemVer .newBuilder ().setMajor (2 ).build ());
147
+ private final ServerCapabilities legacyRemoteExecutorCapabilities =
148
+ ServerCapabilities .newBuilder ()
149
+ .setLowApiVersion (oldApiVersion .toSemVer ())
150
+ .setHighApiVersion (oldApiVersion .toSemVer ())
151
+ .setExecutionCapabilities (ExecutionCapabilities .newBuilder ().setExecEnabled (true ).build ())
152
+ .build ();
153
+
154
+ private final ServerCapabilities remoteExecutorCapabilities =
155
+ ServerCapabilities .newBuilder ()
156
+ .setLowApiVersion (ApiVersion .low .toSemVer ())
157
+ .setHighApiVersion (ApiVersion .high .toSemVer ())
158
+ .setExecutionCapabilities (ExecutionCapabilities .newBuilder ().setExecEnabled (true ).build ())
159
+ .build ();
160
+
141
161
RemoteOptions remoteOptions ;
142
162
private Path execRoot ;
143
163
private ArtifactRoot artifactRoot ;
@@ -177,6 +197,7 @@ public final void setUp() throws Exception {
177
197
178
198
cache = spy (new InMemoryRemoteCache (spy (new InMemoryCacheClient ()), remoteOptions , digestUtil ));
179
199
executor = mock (RemoteExecutionClient .class );
200
+ when (executor .getServerCapabilities ()).thenReturn (remoteExecutorCapabilities );
180
201
181
202
RequestMetadata metadata =
182
203
TracingMetadataUtils .buildMetadata ("none" , "none" , "action-id" , null );
@@ -195,9 +216,27 @@ public void buildRemoteAction_withRegularFileAsOutput() throws Exception {
195
216
196
217
RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
197
218
198
- assertThat (remoteAction .getCommand ().getOutputFilesList ()).containsExactly (execPath .toString ());
219
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ();
220
+ assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
199
221
assertThat (remoteAction .getCommand ().getOutputPathsList ()).containsExactly (execPath .toString ());
222
+ }
223
+
224
+ @ Test
225
+ public void legacy_buildRemoteAction_withRegularFileAsOutput () throws Exception {
226
+ when (executor .getServerCapabilities ()).thenReturn (legacyRemoteExecutorCapabilities );
227
+ PathFragment execPath = execRoot .getRelative ("path/to/tree" ).asFragment ();
228
+ Spawn spawn =
229
+ new SpawnBuilder ("dummy" )
230
+ .withOutput (ActionsTestUtil .createArtifactWithExecPath (artifactRoot , execPath ))
231
+ .build ();
232
+ FakeSpawnExecutionContext context = newSpawnExecutionContext (spawn );
233
+ RemoteExecutionService service = newRemoteExecutionService ();
234
+
235
+ RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
236
+
237
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).containsExactly (execPath .toString ());
200
238
assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
239
+ assertThat (remoteAction .getCommand ().getOutputPathsList ()).isEmpty ();
201
240
}
202
241
203
242
@ Test
@@ -213,8 +252,28 @@ public void buildRemoteAction_withTreeArtifactAsOutput() throws Exception {
213
252
214
253
RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
215
254
255
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ();
256
+ assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
257
+ assertThat (remoteAction .getCommand ().getOutputPathsList ()).containsExactly ("path/to/dir" );
258
+ }
259
+
260
+ @ Test
261
+ public void legacy_buildRemoteAction_withTreeArtifactAsOutput () throws Exception {
262
+ when (executor .getServerCapabilities ()).thenReturn (legacyRemoteExecutorCapabilities );
263
+ Spawn spawn =
264
+ new SpawnBuilder ("dummy" )
265
+ .withOutput (
266
+ ActionsTestUtil .createTreeArtifactWithGeneratingAction (
267
+ artifactRoot , PathFragment .create ("path/to/dir" )))
268
+ .build ();
269
+ FakeSpawnExecutionContext context = newSpawnExecutionContext (spawn );
270
+ RemoteExecutionService service = newRemoteExecutionService ();
271
+
272
+ RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
273
+
216
274
assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ();
217
275
assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).containsExactly ("path/to/dir" );
276
+ assertThat (remoteAction .getCommand ().getOutputPathsList ()).isEmpty ();
218
277
}
219
278
220
279
@ Test
@@ -230,11 +289,30 @@ public void buildRemoteAction_withUnresolvedSymlinkAsOutput() throws Exception {
230
289
231
290
RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
232
291
233
- assertThat (remoteAction .getCommand ().getOutputFilesList ()).containsExactly ( "path/to/link" );
292
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ( );
234
293
assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
235
294
assertThat (remoteAction .getCommand ().getOutputPathsList ()).containsExactly ("path/to/link" );
236
295
}
237
296
297
+ @ Test
298
+ public void legacy_buildRemoteAction_withUnresolvedSymlinkAsOutput () throws Exception {
299
+ when (executor .getServerCapabilities ()).thenReturn (legacyRemoteExecutorCapabilities );
300
+ Spawn spawn =
301
+ new SpawnBuilder ("dummy" )
302
+ .withOutput (
303
+ ActionsTestUtil .createUnresolvedSymlinkArtifactWithExecPath (
304
+ artifactRoot , PathFragment .create ("path/to/link" )))
305
+ .build ();
306
+ FakeSpawnExecutionContext context = newSpawnExecutionContext (spawn );
307
+ RemoteExecutionService service = newRemoteExecutionService ();
308
+
309
+ RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
310
+
311
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).containsExactly ("path/to/link" );
312
+ assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
313
+ assertThat (remoteAction .getCommand ().getOutputPathsList ()).isEmpty ();
314
+ }
315
+
238
316
@ Test
239
317
public void buildRemoteAction_withActionInputAsOutput () throws Exception {
240
318
Spawn spawn =
@@ -246,8 +324,42 @@ public void buildRemoteAction_withActionInputAsOutput() throws Exception {
246
324
247
325
RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
248
326
327
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ();
328
+ assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
329
+ assertThat (remoteAction .getCommand ().getOutputPathsList ()).containsExactly ("path/to/file" );
330
+ }
331
+
332
+ @ Test
333
+ public void legacy_buildRemoteAction_withActionInputFileAsOutput () throws Exception {
334
+ when (executor .getServerCapabilities ()).thenReturn (legacyRemoteExecutorCapabilities );
335
+ Spawn spawn =
336
+ new SpawnBuilder ("dummy" )
337
+ .withOutput (ActionInputHelper .fromPath (PathFragment .create ("path/to/file" )))
338
+ .build ();
339
+ FakeSpawnExecutionContext context = newSpawnExecutionContext (spawn );
340
+ RemoteExecutionService service = newRemoteExecutionService ();
341
+
342
+ RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
343
+
249
344
assertThat (remoteAction .getCommand ().getOutputFilesList ()).containsExactly ("path/to/file" );
250
345
assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
346
+ assertThat (remoteAction .getCommand ().getOutputPathsList ()).isEmpty ();
347
+ }
348
+
349
+ @ Test
350
+ public void buildRemoteAction_withActionInputDirectoryAsOutput () throws Exception {
351
+ Spawn spawn =
352
+ new SpawnBuilder ("dummy" )
353
+ .withOutput (ActionInputHelper .fromPath (PathFragment .create ("path/to/dir" )))
354
+ .build ();
355
+ FakeSpawnExecutionContext context = newSpawnExecutionContext (spawn );
356
+ RemoteExecutionService service = newRemoteExecutionService ();
357
+
358
+ RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
359
+
360
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ();
361
+ assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
362
+ assertThat (remoteAction .getCommand ().getOutputPathsList ()).containsExactly ("path/to/dir" );
251
363
}
252
364
253
365
@ Test
0 commit comments