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");
}
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");
}
Aggregations