use of com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder.ToolchainInvocation in project bazel by bazelbuild.
the class ProtoCompileActionBuilderTest method commandLine_basic.
@Test
public void commandLine_basic() throws Exception {
FilesToRunProvider plugin = new FilesToRunProvider(ImmutableList.<Artifact>of(), null, /* runfilesSupport */
artifact("//:dont-care", "protoc-gen-javalite.exe"));
ProtoLangToolchainProvider toolchainNoPlugin = ProtoLangToolchainProvider.create("--java_out=param1,param2:$(OUT)", null, /* pluginExecutable */
mock(TransitiveInfoCollection.class), /* runtime */
NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER));
ProtoLangToolchainProvider toolchainWithPlugin = ProtoLangToolchainProvider.create("--$(PLUGIN_OUT)=param3,param4:$(OUT)", plugin, mock(TransitiveInfoCollection.class), /* runtime */
NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER));
SupportData supportData = SupportData.create(Predicates.<TransitiveInfoCollection>alwaysFalse(), ImmutableList.of(artifact("//:dont-care", "source_file.proto")), NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER), /* protosInDirectDeps */
NestedSetBuilder.create(STABLE_ORDER, artifact("//:dont-care", "import1.proto"), artifact("//:dont-care", "import2.proto")), true);
CustomCommandLine cmdLine = createCommandLineFromToolchains(ImmutableList.of(new ToolchainInvocation("dontcare_because_no_plugin", toolchainNoPlugin, "foo.srcjar"), new ToolchainInvocation("pluginName", toolchainWithPlugin, "bar.srcjar")), supportData.getDirectProtoSources(), supportData.getTransitiveImports(), null, /* protosInDirectDeps */
"//foo:bar", true, /* allowServices */
ImmutableList.<String>of());
assertThat(cmdLine.arguments()).containsExactly("--java_out=param1,param2:foo.srcjar", "--PLUGIN_pluginName_out=param3,param4:bar.srcjar", "--plugin=protoc-gen-PLUGIN_pluginName=protoc-gen-javalite.exe", "-Iimport1.proto=import1.proto", "-Iimport2.proto=import2.proto", "source_file.proto").inOrder();
}
use of com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder.ToolchainInvocation in project bazel by bazelbuild.
the class ProtoCompileActionBuilderTest method commandLine_strictDeps.
@Test
public void commandLine_strictDeps() throws Exception {
ProtoLangToolchainProvider toolchain = ProtoLangToolchainProvider.create("--java_out=param1,param2:$(OUT)", null, /* pluginExecutable */
mock(TransitiveInfoCollection.class), /* runtime */
NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER));
SupportData supportData = SupportData.create(Predicates.<TransitiveInfoCollection>alwaysFalse(), ImmutableList.of(artifact("//:dont-care", "source_file.proto")), NestedSetBuilder.create(STABLE_ORDER, artifact("//:dont-care", "import1.proto")), NestedSetBuilder.create(STABLE_ORDER, artifact("//:dont-care", "import1.proto"), artifact("//:dont-care", "import2.proto")), true);
CustomCommandLine cmdLine = createCommandLineFromToolchains(ImmutableList.of(new ToolchainInvocation("dontcare", toolchain, "foo.srcjar")), supportData.getDirectProtoSources(), supportData.getTransitiveImports(), supportData.getProtosInDirectDeps(), "//foo:bar", true, /* allowServices */
ImmutableList.<String>of());
assertThat(cmdLine.arguments()).containsExactly("--java_out=param1,param2:foo.srcjar", "-Iimport1.proto=import1.proto", "-Iimport2.proto=import2.proto", "--direct_dependencies=import1.proto", createStrictProtoDepsViolationErrorMessage("//foo:bar"), "source_file.proto").inOrder();
}
use of com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder.ToolchainInvocation in project bazel by bazelbuild.
the class ProtoCompileActionBuilderTest method outReplacementAreLazilyEvaluated.
@Test
public void outReplacementAreLazilyEvaluated() throws Exception {
final boolean[] hasBeenCalled = new boolean[1];
hasBeenCalled[0] = false;
CharSequence outReplacement = new LazyString() {
@Override
public String toString() {
hasBeenCalled[0] = true;
return "mu";
}
};
ProtoLangToolchainProvider toolchain = ProtoLangToolchainProvider.create("--java_out=param1,param2:$(OUT)", null, /* pluginExecutable */
mock(TransitiveInfoCollection.class), /* runtime */
NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER));
SupportData supportData = SupportData.create(Predicates.<TransitiveInfoCollection>alwaysFalse(), ImmutableList.<Artifact>of(), NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER), /* protosInDirectDeps */
NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER), true);
CustomCommandLine cmdLine = createCommandLineFromToolchains(ImmutableList.of(new ToolchainInvocation("pluginName", toolchain, outReplacement)), supportData.getDirectProtoSources(), supportData.getTransitiveImports(), supportData.getProtosInDirectDeps(), "//foo:bar", true, /* allowServices */
ImmutableList.<String>of());
assertThat(hasBeenCalled[0]).isFalse();
cmdLine.arguments();
assertThat(hasBeenCalled[0]).isTrue();
}
Aggregations