37
37
import com .google .devtools .build .lib .vfs .Root ;
38
38
import com .google .devtools .build .lib .vfs .inmemoryfs .InMemoryFileSystem ;
39
39
import javax .annotation .Nullable ;
40
- import org .junit .Ignore ;
41
40
import org .junit .Test ;
42
41
import org .junit .runner .RunWith ;
43
42
import org .junit .runners .JUnit4 ;
@@ -83,11 +82,11 @@ public void commandLine_basic() throws Exception {
83
82
artifact ("//:dont-care" , "import1.proto" ),
84
83
artifact ("//:dont-care" , "import2.proto" )),
85
84
/* transitiveProtoPathFlags= */ NestedSetBuilder .emptySet (STABLE_ORDER ),
86
- /* protoSourceRoot= */ "" ,
87
- /* directProtoSourceRoots= */ NestedSetBuilder .< String > stableOrder (). build ( ),
85
+ /* protoSourceRoot= */ ". " ,
86
+ /* directProtoSourceRoots= */ NestedSetBuilder .create ( Order . STABLE_ORDER , "." ),
88
87
/* hasProtoSources= */ true ,
89
88
/* protosInExports= */ null ,
90
- /* exportedProtoSourceRoots= */ null );
89
+ /* exportedProtoSourceRoots= */ NestedSetBuilder . emptySet ( STABLE_ORDER ) );
91
90
92
91
CustomCommandLine cmdLine =
93
92
createCommandLineFromToolchains (
@@ -97,11 +96,11 @@ public void commandLine_basic() throws Exception {
97
96
new ToolchainInvocation ("pluginName" , toolchainWithPlugin , "bar.srcjar" )),
98
97
supportData .getDirectProtoSources (),
99
98
supportData .getTransitiveImports (),
100
- /* transitiveProtoPathFlags= */ NestedSetBuilder .< String > stableOrder (). build (),
101
- /* directProtoSourceRoots= */ NestedSetBuilder .< String > stableOrder (). build (),
102
- /* exportedProtoSourceRoots= */ null ,
103
- /* protosInDirectDeps= */ null ,
104
- /* protosInExports= */ null ,
99
+ supportData . getTransitiveProtoPathFlags (),
100
+ supportData . getDirectProtoSourceRoots (),
101
+ supportData . getExportedProtoSourceRoots () ,
102
+ /* protosInDirectDeps */ null ,
103
+ supportData . getProtosInExports () ,
105
104
Label .parseAbsoluteUnchecked ("//foo:bar" ),
106
105
/* allowServices= */ true ,
107
106
/* protocOpts= */ ImmutableList .of ());
@@ -169,22 +168,22 @@ public void commandLine_strictDeps() throws Exception {
169
168
artifact ("//:dont-care" , "import1.proto" ),
170
169
artifact ("//:dont-care" , "import2.proto" )),
171
170
/* transitiveProtoPathFlags= */ NestedSetBuilder .emptySet (STABLE_ORDER ),
172
- /* protoSourceRoot= */ "" ,
173
- /* directProtoSourceRoots= */ NestedSetBuilder .< String > stableOrder (). build ( ),
171
+ /* protoSourceRoot= */ ". " ,
172
+ NestedSetBuilder .create ( Order . STABLE_ORDER , "." ),
174
173
/* hasProtoSources= */ true ,
175
174
/* protosInExports= */ null ,
176
- /* exportedProtoSourceRoots= */ null );
175
+ NestedSetBuilder . create ( Order . STABLE_ORDER , "." ) );
177
176
178
177
CustomCommandLine cmdLine =
179
178
createCommandLineFromToolchains (
180
179
ImmutableList .of (new ToolchainInvocation ("dontcare" , toolchain , "foo.srcjar" )),
181
180
supportData .getDirectProtoSources (),
182
181
supportData .getTransitiveImports (),
183
- /* transitiveProtoPathFlags= */ NestedSetBuilder . emptySet ( STABLE_ORDER ),
184
- /* directProtoSourceRoots= */ NestedSetBuilder . emptySet ( STABLE_ORDER ),
185
- /* exportedProtoSourceRoots= */ null ,
182
+ supportData . getTransitiveProtoPathFlags ( ),
183
+ supportData . getDirectProtoSourceRoots ( ),
184
+ supportData . getExportedProtoSourceRoots () ,
186
185
supportData .getProtosInDirectDeps (),
187
- /* protosInExports= */ null ,
186
+ supportData . getProtosInExports () ,
188
187
Label .parseAbsoluteUnchecked ("//foo:bar" ),
189
188
/* allowServices= */ true ,
190
189
/* protocOpts= */ ImmutableList .of ());
@@ -349,28 +348,32 @@ public void testProtoCommandLineArgv() throws Exception {
349
348
assertThat (
350
349
protoArgv (
351
350
null /* directDependencies */ ,
352
- ImmutableList .of (derivedArtifact ("//:dont-care" , "foo.proto" ))))
351
+ ImmutableList .of (derivedArtifact ("//:dont-care" , "foo.proto" )),
352
+ ImmutableList .of ("." )))
353
353
.containsExactly ("-Ifoo.proto=out/foo.proto" );
354
354
355
355
assertThat (
356
356
protoArgv (
357
357
ImmutableList .of () /* directDependencies */ ,
358
- ImmutableList .of (derivedArtifact ("//:dont-care" , "foo.proto" ))))
358
+ ImmutableList .of (derivedArtifact ("//:dont-care" , "foo.proto" )),
359
+ ImmutableList .of ("." )))
359
360
.containsExactly ("-Ifoo.proto=out/foo.proto" , "--direct_dependencies=" );
360
361
361
362
assertThat (
362
- protoArgv (
363
- ImmutableList .of (
364
- derivedArtifact ("//:dont-care" , "foo.proto" )) /* directDependencies */ ,
365
- ImmutableList .of (derivedArtifact ("//:dont-care" , "foo.proto" ))))
363
+ protoArgv (
364
+ ImmutableList .of (
365
+ derivedArtifact ("//:dont-care" , "foo.proto" )) /* directDependencies */ ,
366
+ ImmutableList .of (derivedArtifact ("//:dont-care" , "foo.proto" )),
367
+ ImmutableList .of ("." )))
366
368
.containsExactly ("-Ifoo.proto=out/foo.proto" , "--direct_dependencies" , "foo.proto" );
367
369
368
370
assertThat (
369
371
protoArgv (
370
372
ImmutableList .of (
371
373
derivedArtifact ("//:dont-care" , "foo.proto" ),
372
374
derivedArtifact ("//:dont-care" , "bar.proto" )) /* directDependencies */ ,
373
- ImmutableList .of (derivedArtifact ("//:dont-care" , "foo.proto" ))))
375
+ ImmutableList .of (derivedArtifact ("//:dont-care" , "foo.proto" )),
376
+ ImmutableList .of ("." )))
374
377
.containsExactly (
375
378
"-Ifoo.proto=out/foo.proto" , "--direct_dependencies" , "foo.proto:bar.proto" );
376
379
}
@@ -386,17 +389,20 @@ public void testIncludeMapsOfExternalFiles() throws Exception {
386
389
assertThat (
387
390
protoArgv (
388
391
null /* protosInDirectoDependencies */ ,
389
- ImmutableList .of (artifact ("@bla//foo:bar" , "external/bla/foo/bar.proto" ))))
392
+ ImmutableList .of (artifact ("@bla//foo:bar" , "external/bla/foo/bar.proto" )),
393
+ ImmutableList .of ("external/bla" )))
390
394
.containsExactly ("-Ifoo/bar.proto=external/bla/foo/bar.proto" );
391
395
}
392
396
393
- // TODO(b/34107586): Fix and enable test.
394
- @ Ignore
395
397
@ Test
396
398
public void directDependenciesOnExternalFiles () throws Exception {
397
399
ImmutableList <Artifact > protos =
398
400
ImmutableList .of (artifact ("@bla//foo:bar" , "external/bla/foo/bar.proto" ));
399
- assertThat (protoArgv (protos , protos )).containsExactly ("--direct_dependencies" , "foo/bar.proto" );
401
+ assertThat (protoArgv (protos , protos , ImmutableList .of ("external/bla" )))
402
+ .containsExactly (
403
+ "-Ifoo/bar.proto=external/bla/foo/bar.proto" ,
404
+ "--direct_dependencies" ,
405
+ "foo/bar.proto" );
400
406
}
401
407
402
408
private Artifact artifact (String ownerLabel , String path ) {
@@ -416,7 +422,8 @@ private Artifact derivedArtifact(String ownerLabel, String path) {
416
422
417
423
private static Iterable <String > protoArgv (
418
424
@ Nullable Iterable <Artifact > protosInDirectDependencies ,
419
- Iterable <Artifact > transitiveImports ) {
425
+ Iterable <Artifact > transitiveImports ,
426
+ Iterable <String > protoSourceRoots ) {
420
427
CustomCommandLine .Builder commandLine = CustomCommandLine .builder ();
421
428
NestedSet <Artifact > protosInDirectDependenciesBuilder =
422
429
protosInDirectDependencies != null
@@ -427,7 +434,7 @@ private static Iterable<String> protoArgv(
427
434
ProtoCompileActionBuilder .addIncludeMapArguments (
428
435
commandLine ,
429
436
protosInDirectDependenciesBuilder ,
430
- NestedSetBuilder .emptySet ( STABLE_ORDER ),
437
+ NestedSetBuilder .wrap ( Order . STABLE_ORDER , protoSourceRoots ),
431
438
transitiveImportsNestedSet );
432
439
return commandLine .build ().arguments ();
433
440
}
0 commit comments