Search in sources :

Example 51 with ConfiguredTarget

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

the class AndroidSkylarkSplitTransitionTest method testAndroidSplitTransitionNoTransition.

@Test
public void testAndroidSplitTransitionNoTransition() throws Exception {
    writeAndroidSplitTransitionTestFiles();
    useConfiguration("--fat_apk_cpu=", "--android_crosstool_top=", "--cpu=k8");
    ConfiguredTarget target = getConfiguredTarget("//test/skylark:test");
    @SuppressWarnings("unchecked") Map<Object, List<ConfiguredTarget>> splitDeps = (Map<Object, List<ConfiguredTarget>>) target.get("split_attr_deps");
    // Split transition isn't in effect, so the deps are compiled normally (i.e. using --cpu).
    assertThat(splitDeps.get(Runtime.NONE)).hasSize(2);
    assertThat(splitDeps.get(Runtime.NONE).get(0).getConfiguration().getCpu()).isEqualTo("k8");
    assertThat(splitDeps.get(Runtime.NONE).get(1).getConfiguration().getCpu()).isEqualTo("k8");
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 52 with ConfiguredTarget

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

the class AndroidSkylarkSplitTransitionTest method testAndroidSplitTransition.

@Test
public void testAndroidSplitTransition() throws Exception {
    writeAndroidSplitTransitionTestFiles();
    useConfiguration("--fat_apk_cpu=k8,armeabi-v7a");
    ConfiguredTarget target = getConfiguredTarget("//test/skylark:test");
    // Check that ctx.split_attr.deps has this structure:
    // {
    //   "k8": [ConfiguredTarget],
    //   "armeabi-v7a": [ConfiguredTarget],
    // }
    @SuppressWarnings("unchecked") Map<String, List<ConfiguredTarget>> splitDeps = (Map<String, List<ConfiguredTarget>>) target.get("split_attr_deps");
    assertThat(splitDeps).containsKey("k8");
    assertThat(splitDeps).containsKey("armeabi-v7a");
    assertThat(splitDeps.get("k8")).hasSize(2);
    assertThat(splitDeps.get("armeabi-v7a")).hasSize(2);
    assertThat(splitDeps.get("k8").get(0).getConfiguration().getCpu()).isEqualTo("k8");
    assertThat(splitDeps.get("k8").get(1).getConfiguration().getCpu()).isEqualTo("k8");
    assertThat(splitDeps.get("armeabi-v7a").get(0).getConfiguration().getCpu()).isEqualTo("armeabi-v7a");
    assertThat(splitDeps.get("armeabi-v7a").get(1).getConfiguration().getCpu()).isEqualTo("armeabi-v7a");
    // Check that ctx.split_attr.dep has this structure (that is, that the values are not lists):
    // {
    //   "k8": ConfiguredTarget,
    //   "armeabi-v7a": ConfiguredTarget,
    // }
    @SuppressWarnings("unchecked") Map<String, ConfiguredTarget> splitDep = (Map<String, ConfiguredTarget>) target.get("split_attr_dep");
    assertThat(splitDep).containsKey("k8");
    assertThat(splitDep).containsKey("armeabi-v7a");
    assertThat(splitDep.get("k8").getConfiguration().getCpu()).isEqualTo("k8");
    assertThat(splitDep.get("armeabi-v7a").getConfiguration().getCpu()).isEqualTo("armeabi-v7a");
    // The regular ctx.attr.deps should be a single list with all the branches of the split merged
    // together (i.e. for aspects).
    @SuppressWarnings("unchecked") List<ConfiguredTarget> attrDeps = (List<ConfiguredTarget>) target.get("attr_deps");
    assertThat(attrDeps).hasSize(4);
    ListMultimap<String, Object> attrDepsMap = ArrayListMultimap.create();
    for (ConfiguredTarget ct : attrDeps) {
        attrDepsMap.put(ct.getConfiguration().getCpu(), target);
    }
    assertThat(attrDepsMap.get("k8")).hasSize(2);
    assertThat(attrDepsMap.get("armeabi-v7a")).hasSize(2);
    // Check that even though my_rule.dep is defined as a single label, ctx.attr.dep is still a list
    // with multiple ConfiguredTarget objects because of the two different CPUs. 
    @SuppressWarnings("unchecked") List<ConfiguredTarget> attrDep = (List<ConfiguredTarget>) target.get("attr_dep");
    assertThat(attrDep).hasSize(2);
    ListMultimap<String, Object> attrDepMap = ArrayListMultimap.create();
    for (ConfiguredTarget ct : attrDep) {
        attrDepMap.put(ct.getConfiguration().getCpu(), target);
    }
    assertThat(attrDepMap.get("k8")).hasSize(1);
    assertThat(attrDepMap.get("armeabi-v7a")).hasSize(1);
    // Check that the deps were correctly accessed from within Skylark.
    @SuppressWarnings("unchecked") List<ConfiguredTarget> k8Deps = (List<ConfiguredTarget>) target.get("k8_deps");
    assertThat(k8Deps).hasSize(2);
    assertThat(k8Deps.get(0).getConfiguration().getCpu()).isEqualTo("k8");
    assertThat(k8Deps.get(1).getConfiguration().getCpu()).isEqualTo("k8");
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 53 with ConfiguredTarget

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

the class CcCommonTest method testEmptyLibrary.

@Test
public void testEmptyLibrary() throws Exception {
    ConfiguredTarget emptylib = getConfiguredTarget("//empty:emptylib");
    // because those have a potentially significant run-time startup cost.
    if (emptyShouldOutputStaticLibrary()) {
        assertEquals("libemptylib.a", baseNamesOf(getFilesToBuild(emptylib)));
    } else {
        assertThat(getFilesToBuild(emptylib)).isEmpty();
    }
    assertTrue(emptylib.getProvider(CcExecutionDynamicLibrariesProvider.class).getExecutionDynamicLibraryArtifacts().isEmpty());
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Test(org.junit.Test)

Example 54 with ConfiguredTarget

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

the class CcCommonTest method testCcLibraryThirdPartyIncludesNotWarned.

@Test
public void testCcLibraryThirdPartyIncludesNotWarned() throws Exception {
    eventCollector.clear();
    ConfiguredTarget target = scratchConfiguredTarget("third_party/pkg", "lib", "licenses(['unencumbered'])", "cc_library(name = 'lib',", "           srcs = ['foo.cc'],", "           includes = ['./'])");
    assertThat(view.hasErrors(target)).isFalse();
    assertNoEvents();
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Test(org.junit.Test)

Example 55 with ConfiguredTarget

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

the class CcCommonTest method testDylibLibrarySuffixIsStripped.

@Test
public void testDylibLibrarySuffixIsStripped() throws Exception {
    ConfiguredTarget archiveInSrcsTest = scratchConfiguredTarget("archive_in_src_darwin", "archive_in_srcs", "cc_binary(name = 'archive_in_srcs',", "    srcs = ['libarchive.34.dylib'])");
    Artifact executable = getExecutable(archiveInSrcsTest);
    CppLinkAction linkAction = (CppLinkAction) getGeneratingAction(executable);
    assertThat(linkAction.getLinkCommandLine().toString()).contains(" -larchive.34 ");
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) 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