Search in sources :

Example 56 with ConfiguredTarget

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

the class CcCommonTest method testLinkStaticStatically.

@Test
public void testLinkStaticStatically() throws Exception {
    ConfiguredTarget statically = scratchConfiguredTarget("statically", "statically", "cc_library(name = 'statically',", "           srcs = ['statically.cc'],", "           linkstatic=1)");
    assertTrue(statically.getProvider(CcExecutionDynamicLibrariesProvider.class).getExecutionDynamicLibraryArtifacts().isEmpty());
    Artifact staticallyDotA = getOnlyElement(getFilesToBuild(statically));
    assertThat(getGeneratingAction(staticallyDotA)).isInstanceOf(CppLinkAction.class);
    PathFragment dotAPath = staticallyDotA.getExecPath();
    assertThat(dotAPath.getPathString()).endsWith(STATIC_LIB);
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 57 with ConfiguredTarget

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

the class ConstraintTest method testConstraint.

@Test
public void testConstraint() throws Exception {
    scratch.file("constraint/BUILD", "constraint_setting(name = 'basic')", "constraint_value(name = 'foo',", "    constraint_setting = ':basic',", "    )", "constraint_value(name = 'bar',", "    constraint_setting = ':basic',", "    )");
    ConfiguredTarget setting = getConfiguredTarget("//constraint:basic");
    assertThat(setting).isNotNull();
    assertThat(setting.getProvider(ConstraintSettingProvider.class)).isNotNull();
    assertThat(setting.getProvider(ConstraintSettingProvider.class).constraintSetting()).isEqualTo(Label.parseAbsolute("//constraint:basic"));
    ConfiguredTarget fooValue = getConfiguredTarget("//constraint:foo");
    assertThat(fooValue).isNotNull();
    assertThat(fooValue.getProvider(ConstraintValueProvider.class)).isNotNull();
    assertThat(fooValue.getProvider(ConstraintValueProvider.class).constraint().constraintSetting()).isEqualTo(Label.parseAbsolute("//constraint:basic"));
    assertThat(fooValue.getProvider(ConstraintValueProvider.class).value()).isEqualTo(Label.parseAbsolute("//constraint:foo"));
    ConfiguredTarget barValue = getConfiguredTarget("//constraint:bar");
    assertThat(barValue).isNotNull();
    assertThat(barValue.getProvider(ConstraintValueProvider.class).constraint().constraintSetting()).isEqualTo(Label.parseAbsolute("//constraint:basic"));
    assertThat(barValue.getProvider(ConstraintValueProvider.class).value()).isEqualTo(Label.parseAbsolute("//constraint:bar"));
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Test(org.junit.Test)

Example 58 with ConfiguredTarget

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

the class BazelProtoLibraryTest method testDescriptorSetOutput_strict_deps_multipleSrcs.

/**
   * When building a proto_library with multiple srcs (say foo.proto and bar.proto), we should allow
   * foo.proto to import bar.proto without tripping strict-deps checking. This means that
   * --direct_dependencies should list the srcs.
   */
@Test
public void testDescriptorSetOutput_strict_deps_multipleSrcs() throws Exception {
    useConfiguration("--proto_compiler=//proto:compiler", "--strict_proto_deps=error");
    ConfiguredTarget target = scratchConfiguredTarget("x", "foo", "proto_library(name='foo', srcs=['foo.proto', 'bar.proto'])");
    Artifact file = getFirstArtifactEndingWith(getFilesToBuild(target), ".proto.bin");
    assertThat(file.getRootRelativePathString()).isEqualTo("x/foo-descriptor-set.proto.bin");
    assertThat(getGeneratingSpawnAction(file).getRemainingArguments()).contains("--direct_dependencies=x/foo.proto:x/bar.proto");
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 59 with ConfiguredTarget

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

the class CppOutputGroupsTest method testSharedAndDynamicLibraryOutputGroups.

@Test
public void testSharedAndDynamicLibraryOutputGroups() throws Exception {
    scratch.file("src.cc");
    scratch.file("a/BUILD", "cc_library(name='lib', srcs=['src.cc'], linkstatic=0, alwayslink=1)", "filegroup(name='group_archive', srcs=[':lib'], output_group = 'archive')", "filegroup(name='group_dynamic', srcs=[':lib'], output_group = 'dynamic_library')");
    ConfiguredTarget groupArchive = getConfiguredTarget("//a:group_archive");
    ConfiguredTarget groupDynamic = getConfiguredTarget("//a:group_dynamic");
    assertThat(ActionsTestUtil.prettyArtifactNames(getFilesToBuild(groupArchive))).containsExactly("a/liblib.lo");
    assertThat(ActionsTestUtil.prettyArtifactNames(getFilesToBuild(groupDynamic))).containsExactly("a/liblib.so");
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Test(org.junit.Test)

Example 60 with ConfiguredTarget

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

the class CppOutputGroupsTest method testStaticAndDynamicLibraryOutputGroups.

@Test
public void testStaticAndDynamicLibraryOutputGroups() throws Exception {
    scratch.file("src.cc");
    scratch.file("a/BUILD", "cc_library(name='lib', srcs=['src.cc'], linkstatic=0, alwayslink=0)", "filegroup(name='group_archive', srcs=[':lib'], output_group = 'archive')", "filegroup(name='group_dynamic', srcs=[':lib'], output_group = 'dynamic_library')");
    ConfiguredTarget groupArchive = getConfiguredTarget("//a:group_archive");
    ConfiguredTarget groupDynamic = getConfiguredTarget("//a:group_dynamic");
    assertThat(ActionsTestUtil.prettyArtifactNames(getFilesToBuild(groupArchive))).containsExactly("a/liblib.a");
    assertThat(ActionsTestUtil.prettyArtifactNames(getFilesToBuild(groupDynamic))).containsExactly("a/liblib.so");
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Test(org.junit.Test)

Aggregations

ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)222 Test (org.junit.Test)178 Artifact (com.google.devtools.build.lib.actions.Artifact)51 FileConfiguredTarget (com.google.devtools.build.lib.analysis.FileConfiguredTarget)41 RuleConfiguredTarget (com.google.devtools.build.lib.analysis.RuleConfiguredTarget)25 Label (com.google.devtools.build.lib.cmdline.Label)17 SkylarkProviders (com.google.devtools.build.lib.analysis.SkylarkProviders)15 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)13 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)12 Nullable (javax.annotation.Nullable)10 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)9 Variables (com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables)9 MergedConfiguredTarget (com.google.devtools.build.lib.analysis.MergedConfiguredTarget)7 Map (java.util.Map)7 OutputGroupProvider (com.google.devtools.build.lib.analysis.OutputGroupProvider)6 TestAspects (com.google.devtools.build.lib.analysis.util.TestAspects)6 Attribute (com.google.devtools.build.lib.packages.Attribute)6 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)5 ConfigMatchingProvider (com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider)5 TestFilteringCompleteEvent (com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent)5