Search in sources :

Example 6 with Variables

use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables in project bazel by bazelbuild.

the class LinkBuildVariablesTest method testIsCcTestLinkActionBuildVariable.

@Test
public void testIsCcTestLinkActionBuildVariable() throws Exception {
    scratch.file("x/BUILD", "cc_test(name = 'foo_test', srcs = ['a.cc'])", "cc_binary(name = 'foo', srcs = ['a.cc'])");
    scratch.file("x/a.cc");
    ConfiguredTarget testTarget = getConfiguredTarget("//x:foo_test");
    Variables testVariables = getLinkBuildVariables(testTarget, LinkTargetType.EXECUTABLE);
    assertThat(testVariables.isAvailable(CppLinkActionBuilder.IS_CC_TEST_LINK_ACTION_VARIABLE)).isTrue();
    ConfiguredTarget binaryTarget = getConfiguredTarget("//x:foo");
    Variables binaryVariables = getLinkBuildVariables(binaryTarget, LinkTargetType.EXECUTABLE);
    assertThat(binaryVariables.isAvailable(CppLinkActionBuilder.IS_CC_TEST_LINK_ACTION_VARIABLE)).isFalse();
}
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 7 with Variables

use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables in project bazel by bazelbuild.

the class LinkBuildVariablesTest method assertStripBinaryVariableIsPresent.

private void assertStripBinaryVariableIsPresent(String stripMode, String compilationMode, boolean isEnabled) throws Exception {
    useConfiguration("--strip=" + stripMode, "--compilation_mode=" + compilationMode);
    ConfiguredTarget target = getConfiguredTarget("//x:foo");
    Variables variables = getLinkBuildVariables(target, LinkTargetType.EXECUTABLE);
    assertThat(variables.isAvailable(CppLinkActionBuilder.STRIP_DEBUG_SYMBOLS_VARIABLE)).isEqualTo(isEnabled);
}
Also used : Variables(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget)

Example 8 with Variables

use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables in project bazel by bazelbuild.

the class LinkBuildVariablesTest method testLinkerParamFileIsExported.

@Test
public void testLinkerParamFileIsExported() throws Exception {
    AnalysisMock.get().ccSupport().setupCrosstool(mockToolsConfig);
    useConfiguration();
    scratch.file("x/BUILD", "cc_binary(name = 'bin', srcs = ['some-dir/bar.so'])");
    scratch.file("x/some-dir/bar.so");
    ConfiguredTarget target = getConfiguredTarget("//x:bin");
    Variables variables = getLinkBuildVariables(target, Link.LinkTargetType.EXECUTABLE);
    List<String> variableValue = getVariableValue(variables, CppLinkActionBuilder.LINKER_PARAM_FILE_VARIABLE);
    assertThat(Iterables.getOnlyElement(variableValue)).matches(".*bin/x/bin" + OsUtils.executableExtension() + "-2.params$");
}
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 9 with Variables

use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables in project bazel by bazelbuild.

the class LTOBackendArtifacts method scheduleLTOBackendAction.

public void scheduleLTOBackendAction(RuleContext ruleContext, FeatureConfiguration featureConfiguration, CcToolchainProvider ccToolchain, FdoSupportProvider fdoSupport, boolean usePic, boolean generateDwo) {
    LTOBackendAction.Builder builder = new LTOBackendAction.Builder();
    builder.addImportsInfo(bitcodeFiles, imports);
    builder.addInput(bitcodeFile);
    builder.addInput(index);
    builder.addTransitiveInputs(ccToolchain.getCompile());
    builder.addOutput(objectFile);
    builder.setProgressMessage("LTO Backend Compile " + objectFile.getFilename());
    builder.setMnemonic("CcLtoBackendCompile");
    // The command-line doesn't specify the full path to clang++, so we set it in the
    // environment.
    CppConfiguration cppConfiguration = ruleContext.getFragment(CppConfiguration.class);
    PathFragment compiler = cppConfiguration.getCppExecutable();
    builder.setExecutable(compiler);
    Variables.Builder buildVariablesBuilder = new Variables.Builder();
    buildVariablesBuilder.addStringVariable("thinlto_index", index.getExecPath().toString());
    // The output from the LTO backend step is a native object file.
    buildVariablesBuilder.addStringVariable("thinlto_output_object_file", objectFile.getExecPath().toString());
    // The input to the LTO backend step is the bitcode file.
    buildVariablesBuilder.addStringVariable("thinlto_input_bitcode_file", bitcodeFile.getExecPath().toString());
    Artifact autoFdoProfile = fdoSupport.getFdoSupport().buildProfileForLtoBackend(fdoSupport, featureConfiguration, buildVariablesBuilder, ruleContext);
    if (autoFdoProfile != null) {
        builder.addInput(autoFdoProfile);
    }
    if (generateDwo) {
        Artifact dwoFile = ruleContext.getRelatedArtifact(objectFile.getRootRelativePath(), ".dwo");
        builder.addOutput(dwoFile);
        buildVariablesBuilder.addStringVariable("per_object_debug_info_file", dwoFile.getExecPathString());
    }
    Variables buildVariables = buildVariablesBuilder.build();
    List<String> execArgs = new ArrayList<>();
    execArgs.addAll(featureConfiguration.getCommandLine("lto-backend", buildVariables));
    if (usePic) {
        execArgs.add("-fPIC");
    }
    execArgs.addAll(commandLine);
    builder.addExecutableArguments(execArgs);
    ruleContext.registerAction(builder.build(ruleContext));
}
Also used : Variables(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ArrayList(java.util.ArrayList) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 10 with Variables

use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables in project bazel by bazelbuild.

the class LinkBuildVariablesTest method testForcePicBuildVariable.

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

Aggregations

Variables (com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables)11 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)9 Test (org.junit.Test)8 Artifact (com.google.devtools.build.lib.actions.Artifact)2 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)2 ArrayList (java.util.ArrayList)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Builder (com.google.common.collect.ImmutableSet.Builder)1 Action (com.google.devtools.build.lib.actions.Action)1 ParameterFileWriteAction (com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction)1 IterablesChain (com.google.devtools.build.lib.collect.IterablesChain)1 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)1 SequenceBuilder (com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.SequenceBuilder)1 VariableValue (com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.VariableValue)1 VariablesExtension (com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.VariablesExtension)1 LibraryToLink (com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1