Search in sources :

Example 6 with RunfilesProvider

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

the class CppLinkActionTest method testCompilesTestSourcesIntoDynamicLibrary.

@Test
public void testCompilesTestSourcesIntoDynamicLibrary() throws Exception {
    if (OS.getCurrent() == OS.WINDOWS) {
        // its own suite with a TestSpec?
        return;
    }
    scratch.file("x/BUILD", "cc_test(name = 'a', srcs = ['a.cc'])", "cc_binary(name = 'b', srcs = ['a.cc'], linkstatic = 0)");
    scratch.file("x/a.cc", "int main() {}");
    useConfiguration("--experimental_link_compile_output_separately", "--force_pic");
    ConfiguredTarget configuredTarget = getConfiguredTarget("//x:a");
    String cpu = CrosstoolConfigurationHelper.defaultCpu();
    String extension = OsUtils.executableExtension();
    CppLinkAction linkAction = (CppLinkAction) getGeneratingAction(configuredTarget, "x/a" + extension);
    assertThat(artifactsToStrings(linkAction.getInputs())).contains("bin _solib_" + cpu + "/libx_Sliba.ifso");
    assertThat(linkAction.getArguments()).contains(getBinArtifactWithNoOwner("_solib_" + cpu + "/libx_Sliba.ifso").getExecPathString());
    RunfilesProvider runfilesProvider = configuredTarget.getProvider(RunfilesProvider.class);
    assertThat(artifactsToStrings(runfilesProvider.getDefaultRunfiles().getArtifacts())).contains("bin _solib_" + cpu + "/libx_Sliba.so");
    configuredTarget = getConfiguredTarget("//x:b");
    linkAction = (CppLinkAction) getGeneratingAction(configuredTarget, "x/b" + extension);
    assertThat(artifactsToStrings(linkAction.getInputs())).contains("bin x/_objs/b/x/a.pic.o");
    runfilesProvider = configuredTarget.getProvider(RunfilesProvider.class);
    assertThat(artifactsToStrings(runfilesProvider.getDefaultRunfiles().getArtifacts())).containsExactly("bin x/b");
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) RunfilesProvider(com.google.devtools.build.lib.analysis.RunfilesProvider) Test(org.junit.Test)

Example 7 with RunfilesProvider

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

the class SkylarkRuleImplementationFunctionsTest method testDefaultProvider.

@Test
public void testDefaultProvider() throws Exception {
    scratch.file("test/foo.bzl", "foo_provider = provider()", "def _impl(ctx):", "    default = ctx.default_provider(", "        runfiles=ctx.runfiles(ctx.files.runs),", "    )", "    foo = foo_provider()", "    return [foo, default]", "foo_rule = rule(", "    implementation = _impl,", "    attrs = {", "       'runs': attr.label_list(allow_files=True),", "    }", ")");
    scratch.file("test/bar.bzl", "load(':foo.bzl', 'foo_provider')", "def _impl(ctx):", "    dep = ctx.attr.deps[0]", // The goal is to test this object
    "    provider = dep[ctx.default_provider]", // so we return it here
    "    return struct(", "        default = provider,", "    )", "bar_rule = rule(", "    implementation = _impl,", "    attrs = {", "       'deps': attr.label_list(allow_files=True),", "    }", ")");
    scratch.file("test/BUILD", "load(':foo.bzl', 'foo_rule')", "load(':bar.bzl', 'bar_rule')", "foo_rule(name = 'dep_rule', runs = ['run.file', 'run2.file'])", "bar_rule(name = 'my_rule', deps = [':dep_rule'])");
    ConfiguredTarget configuredTarget = getConfiguredTarget("//test:my_rule");
    Object provider = configuredTarget.getProvider(SkylarkProviders.class).getValue("default");
    assertThat(provider).isInstanceOf(SkylarkClassObject.class);
    SkylarkClassObject defaultProvider = (SkylarkClassObject) provider;
    assertThat((defaultProvider).getConstructor().getPrintableName()).isEqualTo("default_provider");
    // Test .runfiles
    Object runfilesProvider = defaultProvider.getValue("runfiles");
    assertThat(runfilesProvider).isInstanceOf(RunfilesProvider.class);
    assertThat(Iterables.transform(((RunfilesProvider) runfilesProvider).getDefaultRunfiles().getAllArtifacts(), TO_STRING)).containsExactly("Artifact:[/workspace[source]]test/run.file", "Artifact:[/workspace[source]]test/run2.file");
}
Also used : SkylarkProviders(com.google.devtools.build.lib.analysis.SkylarkProviders) SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) RunfilesProvider(com.google.devtools.build.lib.analysis.RunfilesProvider) Test(org.junit.Test)

Aggregations

RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)7 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)5 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)5 Artifact (com.google.devtools.build.lib.actions.Artifact)4 RunfilesSupport (com.google.devtools.build.lib.analysis.RunfilesSupport)3 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)2 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)2 Label (com.google.devtools.build.lib.cmdline.Label)2 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 CompositeRunfilesSupplier (com.google.devtools.build.lib.actions.CompositeRunfilesSupplier)1 CommandHelper (com.google.devtools.build.lib.analysis.CommandHelper)1 FilesToRunProvider (com.google.devtools.build.lib.analysis.FilesToRunProvider)1 MiddlemanProvider (com.google.devtools.build.lib.analysis.MiddlemanProvider)1 SkylarkProviders (com.google.devtools.build.lib.analysis.SkylarkProviders)1 NestedSet (com.google.devtools.build.lib.collect.nestedset.NestedSet)1 CcLinkParamsProvider (com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider)1