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