Search in sources :

Example 61 with ConfiguredTarget

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

the class LibraryLinkingTest method testCcLibraryLinkopts.

/**
   * Tests that the shared library version of a cc_library includes linkopts settings
   * in its link command line, but the archive library version doesn't.
   */
@Test
public void testCcLibraryLinkopts() throws Exception {
    scratch.overwriteFile("custom_malloc/BUILD", "cc_library(name = 'custom_malloc',", "           srcs = ['custom_malloc.cc'],", "           linkopts = ['-Lmalloc_dir -lmalloc_opt']);");
    ConfiguredTarget ccLib = getConfiguredTarget("//custom_malloc:custom_malloc");
    final String linkOpt1 = "-Lmalloc_dir";
    final String linkOpt2 = "-lmalloc_opt";
    // Archive library version:
    Artifact archiveLib = Iterables.getOnlyElement(Iterables.filter(ccLib.getProvider(FileProvider.class).getFilesToBuild(), new Predicate<Artifact>() {

        @Override
        public boolean apply(Artifact artifact) {
            return artifact.getFilename().equals("libcustom_malloc.a");
        }
    }));
    CppLinkAction archiveLink = (CppLinkAction) getGeneratingAction(archiveLib);
    List<String> args = archiveLink.getArgv();
    assertThat(args).doesNotContain(linkOpt1);
    assertThat(args).doesNotContain(linkOpt2);
    // Shared library version:
    Artifact soLib = Iterables.getOnlyElement(ccLib.getProvider(CcExecutionDynamicLibrariesProvider.class).getExecutionDynamicLibraryArtifacts());
    // This artifact is generated by a SolibSymlinkAction, so we need to go back two levels.
    CppLinkAction solibLink = (CppLinkAction) getGeneratingAction(getGeneratingAction(soLib).getPrimaryInput());
    args = solibLink.getArgv();
    assertThat(args).contains(linkOpt1);
    assertThat(args).contains(linkOpt2);
}
Also used : FileProvider(com.google.devtools.build.lib.analysis.FileProvider) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Example 62 with ConfiguredTarget

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

the class LibraryLinkingTest method testGeneratedLib.

@Test
public void testGeneratedLib() throws Exception {
    useConfiguration("--cpu=k8");
    ConfiguredTarget genlib = scratchConfiguredTarget("genrule", "thebinary.so", "genrule(name = 'genlib',", "        outs = ['genlib.a'],", "        cmd = '')", "cc_library(name = 'thelib',", "           srcs = [':genlib'],", "           linkstatic = 1)", "cc_binary(name = 'thebinary.so',", "          deps = [':thelib'],", "          linkstatic = 1,", "          linkshared = 1)");
    Artifact executable = getExecutable(genlib);
    CppLinkAction linkAction = (CppLinkAction) getGeneratingAction(executable);
    assertLinkopts(linkAction, "-shared", "-o", analysisMock.getProductName() + "-out/.+/genrule/thebinary.so", "-Wl,-whole-archive", analysisMock.getProductName() + "-out/.+/genrule/genlib.a", "-Wl,-no-whole-archive");
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 63 with ConfiguredTarget

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

the class LinkBuildVariablesTest method testLinkstampBuildVariable.

@Test
public void testLinkstampBuildVariable() throws Exception {
    scratch.file("x/BUILD", "cc_binary(", "   name = 'bin',", "   srcs = ['a.cc'],", "   deps = [':lib'],", ")", "cc_library(", "   name = 'lib',", "   srcs = ['b.cc'],", "   linkstamp = 'c.cc',", ")");
    scratch.file("x/a.cc");
    scratch.file("x/b.cc");
    scratch.file("x/c.cc");
    ConfiguredTarget target = getConfiguredTarget("//x:bin");
    Variables variables = getLinkBuildVariables(target, Link.LinkTargetType.EXECUTABLE);
    List<String> variableValue = getVariableValue(variables, CppLinkActionBuilder.LINKSTAMP_PATHS_VARIABLE);
    assertThat(Iterables.getOnlyElement(variableValue)).contains("c.o");
}
Also used : Variables(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Test(org.junit.Test)

Example 64 with ConfiguredTarget

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

the class LinkBuildVariablesTest method testInterfaceLibraryBuildingVariablesWhenGenerationPossible.

@Test
public void testInterfaceLibraryBuildingVariablesWhenGenerationPossible() throws Exception {
    // Make sure the interface shared object generation is enabled in the configuration
    // (which it is not by default for some windows toolchains)
    AnalysisMock.get().ccSupport().setupCrosstool(mockToolsConfig, "supports_interface_shared_objects: true");
    useConfiguration();
    scratch.file("x/BUILD", "cc_library(name = 'foo', srcs = ['a.cc'])");
    scratch.file("x/a.cc");
    ConfiguredTarget target = getConfiguredTarget("//x:foo");
    Variables variables = getLinkBuildVariables(target, LinkTargetType.DYNAMIC_LIBRARY);
    String interfaceLibraryBuilder = Iterables.getOnlyElement(getVariableValue(variables, CppLinkActionBuilder.INTERFACE_LIBRARY_BUILDER_VARIABLE));
    String interfaceLibraryInput = Iterables.getOnlyElement(getVariableValue(variables, CppLinkActionBuilder.INTERFACE_LIBRARY_INPUT_VARIABLE));
    String interfaceLibraryOutput = Iterables.getOnlyElement(getVariableValue(variables, CppLinkActionBuilder.INTERFACE_LIBRARY_OUTPUT_VARIABLE));
    String generateInterfaceLibrary = Iterables.getOnlyElement(getVariableValue(variables, CppLinkActionBuilder.GENERATE_INTERFACE_LIBRARY_VARIABLE));
    assertThat(generateInterfaceLibrary).isEqualTo("yes");
    assertThat(interfaceLibraryInput).endsWith("libfoo.so");
    assertThat(interfaceLibraryOutput).endsWith("libfoo.ifso");
    assertThat(interfaceLibraryBuilder).endsWith("build_interface_so");
}
Also used : Variables(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Test(org.junit.Test)

Example 65 with ConfiguredTarget

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

the class LinkBuildVariablesTest method testLibrariesToLinkAreExported.

@Test
public void testLibrariesToLinkAreExported() throws Exception {
    AnalysisMock.get().ccSupport().setupCrosstool(mockToolsConfig);
    useConfiguration();
    scratch.file("x/BUILD", "cc_library(name = 'foo', srcs = ['a.cc'])");
    scratch.file("x/a.cc");
    ConfiguredTarget target = getConfiguredTarget("//x:foo");
    Variables variables = getLinkBuildVariables(target, LinkTargetType.DYNAMIC_LIBRARY);
    VariableValue librariesToLinkSequence = variables.getVariable(CppLinkActionBuilder.LIBRARIES_TO_LINK_VARIABLE);
    assertThat(librariesToLinkSequence).isNotNull();
    Iterable<? extends VariableValue> librariesToLink = librariesToLinkSequence.getSequenceValue(CppLinkActionBuilder.LIBRARIES_TO_LINK_VARIABLE);
    assertThat(librariesToLink).hasSize(1);
    VariableValue nameValue = librariesToLink.iterator().next().getFieldValue(CppLinkActionBuilder.LIBRARIES_TO_LINK_VARIABLE, LibraryToLinkValue.NAME_FIELD_NAME);
    assertThat(nameValue).isNotNull();
    String name = nameValue.getStringValue(LibraryToLinkValue.NAME_FIELD_NAME);
    assertThat(name).matches(".*a\\..*o");
}
Also used : Variables(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables) VariableValue(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.VariableValue) 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