use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.VariableValue 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");
}
use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.VariableValue in project bazel by bazelbuild.
the class CcToolchainFeaturesTest method testLibraryToLinkValue.
@Test
public void testLibraryToLinkValue() {
assertThat(LibraryToLinkValue.forDynamicLibrary("foo", false).getFieldValue("LibraryToLinkValue", LibraryToLinkValue.NAME_FIELD_NAME).getStringValue(LibraryToLinkValue.NAME_FIELD_NAME)).isEqualTo("foo");
assertThat(LibraryToLinkValue.forDynamicLibrary("foo", false).getFieldValue("LibraryToLinkValue", LibraryToLinkValue.OBJECT_FILES_FIELD_NAME)).isNull();
assertThat(LibraryToLinkValue.forObjectFileGroup(ImmutableList.of("foo", "bar"), false).getFieldValue("LibraryToLinkValue", LibraryToLinkValue.NAME_FIELD_NAME)).isNull();
Iterable<? extends VariableValue> objects = LibraryToLinkValue.forObjectFileGroup(ImmutableList.of("foo", "bar"), false).getFieldValue("LibraryToLinkValue", LibraryToLinkValue.OBJECT_FILES_FIELD_NAME).getSequenceValue(LibraryToLinkValue.OBJECT_FILES_FIELD_NAME);
ImmutableList.Builder<String> objectNames = ImmutableList.builder();
for (VariableValue object : objects) {
objectNames.add(object.getStringValue("name"));
}
assertThat(objectNames.build()).containsExactly("foo", "bar");
}
use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.VariableValue in project bazel by bazelbuild.
the class CppLinkActionTest method testExposesRuntimeLibrarySearchDirectoriesVariable.
@Test
public void testExposesRuntimeLibrarySearchDirectoriesVariable() throws Exception {
scratch.file("x/BUILD", "cc_binary(", " name = 'foo',", " srcs = ['some-dir/bar.so', 'some-other-dir/qux.so'],", ")");
scratch.file("x/some-dir/bar.so");
scratch.file("x/some-other-dir/qux.so");
ConfiguredTarget configuredTarget = getConfiguredTarget("//x:foo");
CppLinkAction linkAction = (CppLinkAction) getGeneratingAction(configuredTarget, "x/foo" + OsUtils.executableExtension());
Iterable<? extends VariableValue> runtimeLibrarySearchDirectories = linkAction.getLinkCommandLine().getBuildVariables().getSequenceVariable(CppLinkActionBuilder.RUNTIME_LIBRARY_SEARCH_DIRECTORIES_VARIABLE);
List<String> directories = new ArrayList<>();
for (VariableValue value : runtimeLibrarySearchDirectories) {
directories.add(value.getStringValue("runtime_library_search_directory"));
}
assertThat(Joiner.on(" ").join(directories)).matches(".*some-dir .*some-other-dir");
}
Aggregations