Search in sources :

Example 11 with CustomCommandLine

use of com.google.devtools.build.lib.analysis.actions.CustomCommandLine in project bazel by bazelbuild.

the class CustomCommandLineTest method testLabelArgs.

@Test
public void testLabelArgs() throws LabelSyntaxException {
    CustomCommandLine cl = CustomCommandLine.builder().add(Label.parseAbsolute("//a:b")).build();
    assertEquals(ImmutableList.of("//a:b"), cl.arguments());
}
Also used : CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) Test(org.junit.Test)

Example 12 with CustomCommandLine

use of com.google.devtools.build.lib.analysis.actions.CustomCommandLine in project bazel by bazelbuild.

the class CustomCommandLineTest method testCustomArgs.

@Test
public void testCustomArgs() {
    CustomCommandLine cl = CustomCommandLine.builder().add(new CustomArgv() {

        @Override
        public String argv() {
            return "--arg";
        }
    }).build();
    assertEquals(ImmutableList.of("--arg"), cl.arguments());
}
Also used : CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) CustomArgv(com.google.devtools.build.lib.analysis.actions.CustomCommandLine.CustomArgv) Test(org.junit.Test)

Example 13 with CustomCommandLine

use of com.google.devtools.build.lib.analysis.actions.CustomCommandLine 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();
}
Also used : ToolchainInvocation(com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder.ToolchainInvocation) CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) FilesToRunProvider(com.google.devtools.build.lib.analysis.FilesToRunProvider) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) Test(org.junit.Test)

Example 14 with CustomCommandLine

use of com.google.devtools.build.lib.analysis.actions.CustomCommandLine 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();
}
Also used : ToolchainInvocation(com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder.ToolchainInvocation) CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) Test(org.junit.Test)

Example 15 with CustomCommandLine

use of com.google.devtools.build.lib.analysis.actions.CustomCommandLine 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();
}
Also used : ToolchainInvocation(com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder.ToolchainInvocation) CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) LazyString(com.google.devtools.build.lib.util.LazyString) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) Test(org.junit.Test)

Aggregations

CustomCommandLine (com.google.devtools.build.lib.analysis.actions.CustomCommandLine)28 Test (org.junit.Test)22 Artifact (com.google.devtools.build.lib.actions.Artifact)6 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)5 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)3 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)3 ParameterFileWriteAction (com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction)3 ToolchainInvocation (com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder.ToolchainInvocation)3 SpawnAction (com.google.devtools.build.lib.analysis.actions.SpawnAction)2 LazyString (com.google.devtools.build.lib.util.LazyString)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 FilesToRunProvider (com.google.devtools.build.lib.analysis.FilesToRunProvider)1 CustomArgv (com.google.devtools.build.lib.analysis.actions.CustomCommandLine.CustomArgv)1 CustomMultiArgv (com.google.devtools.build.lib.analysis.actions.CustomCommandLine.CustomMultiArgv)1 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)1 AppleConfiguration (com.google.devtools.build.lib.rules.apple.AppleConfiguration)1 Platform (com.google.devtools.build.lib.rules.apple.Platform)1 DotdFile (com.google.devtools.build.lib.rules.cpp.CppCompileAction.DotdFile)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1 HashSet (java.util.HashSet)1