aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java
diff options
context:
space:
mode:
authorGravatar Alex Humesky <ahumesky@google.com>2015-10-05 19:55:22 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2015-10-06 07:03:51 +0000
commitd511eb3dfa8bdf4b84a15a081aae9ca51148c925 (patch)
tree7d85d9694b0f388152053e28f2c9549be876a772 /src/test/java
parent7241fd628a58aeb58643eb484de358d5fee30260 (diff)
Adds support for selecting the different STL implementations in the Android NDK.
The android_ndk_repository rule will default to the gnu-libstdcpp toolchain. Other STL impls can be selected with, for example, --android_crosstool_top=@androidndk//:toolchain-libcpp or --android_crosstool_top=@androidndk//:toolchain-stlport. -- MOS_MIGRATED_REVID=104685576
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/AndroidNdkCrosstoolsTest.java168
1 files changed, 117 insertions, 51 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/AndroidNdkCrosstoolsTest.java b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/AndroidNdkCrosstoolsTest.java
index 11f59a10c5..c1b32d9b34 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/AndroidNdkCrosstoolsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/AndroidNdkCrosstoolsTest.java
@@ -16,6 +16,9 @@ package com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools;
import static com.google.common.truth.Truth.assertThat;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.AndroidNdkCrosstools.NdkCrosstoolsException;
import com.google.devtools.build.lib.events.NullEventHandler;
import com.google.devtools.build.lib.util.ResourceFileLoader;
@@ -39,16 +42,53 @@ import java.util.Set;
@RunWith(JUnit4.class)
public class AndroidNdkCrosstoolsTest {
- private static final String API_LEVEL = "21";
+ private static final ImmutableSet<String> NDK_FILES, NDK_DIRECTORIES;
+
private static final String REPOSITORY_NAME = "testrepository";
+ private static final ApiLevel API_LEVEL =
+ new ApiLevel(NullEventHandler.INSTANCE, REPOSITORY_NAME, "21");
private static final NdkRelease NDK_RELEASE = NdkRelease.create("r10e (64-bit)");
- private static final CrosstoolRelease CROSSTOOL_RELEASE;
+ private static final ImmutableList<CrosstoolRelease> CROSSTOOL_RELEASES;
+ private static final ImmutableMap<String, String> STL_FILEGROUPS;
static {
try {
- // Protos are immutable, so this can be shared between tests.
- CROSSTOOL_RELEASE = AndroidNdkCrosstools.createCrosstoolRelease(
- NullEventHandler.INSTANCE, REPOSITORY_NAME, API_LEVEL, NDK_RELEASE);
+
+ String hostPlatform = AndroidNdkCrosstools.getHostPlatform(NDK_RELEASE);
+ NdkPaths ndkPaths = new NdkPaths(
+ REPOSITORY_NAME,
+ hostPlatform,
+ API_LEVEL);
+
+ ImmutableList.Builder<CrosstoolRelease> crosstools = ImmutableList.builder();
+ ImmutableMap.Builder<String, String> stlFilegroups = ImmutableMap.builder();
+ for (StlImpl ndkStlImpl : StlImpls.get(ndkPaths)) {
+ // Protos are immutable, so this can be shared between tests.
+ CrosstoolRelease crosstool = AndroidNdkCrosstools.create(
+ NullEventHandler.INSTANCE,
+ ndkPaths,
+ REPOSITORY_NAME,
+ API_LEVEL,
+ NDK_RELEASE,
+ ndkStlImpl,
+ hostPlatform);
+ crosstools.add(crosstool);
+ stlFilegroups.putAll(ndkStlImpl.getFilegroupNamesAndFilegroupFileGlobPatterns());
+ }
+
+ CROSSTOOL_RELEASES = crosstools.build();
+ STL_FILEGROUPS = stlFilegroups.build();
+
+ // ndkfiles.txt contains a list of every file in the ndk, created using this command at the
+ // root of the Android NDK for version r10e (64-bit):
+ // find . -xtype f | sed 's|^\./||' | sort
+ // and similarly for ndkdirectories, except "-xtype d" is used.
+ //
+ // It's unfortunate to have files like these, since they're large and brittle, but since the
+ // whole NDK can't be checked in to test against, it's about the most that can be done right
+ // now.
+ NDK_FILES = getFiles("ndkfiles.txt");
+ NDK_DIRECTORIES = getFiles("ndkdirectories.txt");
} catch (NdkCrosstoolsException e) {
throw new RuntimeException(e);
@@ -58,51 +98,65 @@ public class AndroidNdkCrosstoolsTest {
@Test
public void testPathsExist() throws Exception {
- // ndkfiles.txt contains a list of every file in the ndk, created using this command at the
- // root of the Android NDK for version r10e (64-bit):
- // find . -xtype f | sed 's|^\./||' | sort
- // and similarly for ndkdirectories, except "-xtype d" is used.
- //
- // It's unfortunate to have files like these, since they're large and brittle, but since the
- // whole NDK can't be checked in to test against, it's about the most that can be done right
- // now.
- Set<String> ndkFiles = getFiles("ndkfiles.txt");
- Set<String> ndkDirectories = getFiles("ndkdirectories.txt");
-
- for (CToolchain toolchain : CROSSTOOL_RELEASE.getToolchainList()) {
-
- // Test that all tool paths exist.
- for (ToolPath toolpath : toolchain.getToolPathList()) {
- String path = NdkPaths.stripRepositoryPrefix(toolpath.getPath());
- assertThat(ndkFiles).contains(path);
- }
-
- // Test that all cxx_builtin_include_directory paths exist.
- for (String includeDirectory : toolchain.getCxxBuiltinIncludeDirectoryList()) {
- // Special case for builtin_sysroot.
- if (!includeDirectory.equals("%sysroot%/usr/include")) {
- String path = NdkPaths.stripRepositoryPrefix(includeDirectory);
- assertThat(ndkDirectories).contains(path);
+ for (CrosstoolRelease crosstool : CROSSTOOL_RELEASES) {
+ for (CToolchain toolchain : crosstool.getToolchainList()) {
+
+ // Test that all tool paths exist.
+ for (ToolPath toolpath : toolchain.getToolPathList()) {
+ String path = NdkPaths.stripRepositoryPrefix(toolpath.getPath());
+ assertThat(NDK_FILES).contains(path);
+ }
+
+ // Test that all cxx_builtin_include_directory paths exist.
+ for (String includeDirectory : toolchain.getCxxBuiltinIncludeDirectoryList()) {
+ // Special case for builtin_sysroot.
+ if (!includeDirectory.equals("%sysroot%/usr/include")) {
+ String path = NdkPaths.stripRepositoryPrefix(includeDirectory);
+ assertThat(NDK_DIRECTORIES).contains(path);
+ }
+ }
+
+ // Test that the builtin_sysroot path exists.
+ {
+ String builtinSysroot = NdkPaths.stripRepositoryPrefix(toolchain.getBuiltinSysroot());
+ assertThat(NDK_DIRECTORIES).contains(builtinSysroot);
+ }
+
+ // Test that all include directories added through unfiltered_cxx_flag exist.
+ for (String flag : toolchain.getUnfilteredCxxFlagList()) {
+ if (!flag.equals("-isystem")) {
+ flag = NdkPaths.stripRepositoryPrefix(flag);
+ assertThat(NDK_DIRECTORIES).contains(flag);
+ }
}
}
+ }
+ }
- // Test that the builtin_sysroot path exists.
- {
- String builtinSysroot = NdkPaths.stripRepositoryPrefix(toolchain.getBuiltinSysroot());
- assertThat(ndkDirectories).contains(builtinSysroot);
- }
+ @Test
+ public void testStlFilegroupPathsExist() throws Exception {
- // Test that all include directories added through unfiltered_cxx_flag exist.
- for (String flag : toolchain.getUnfilteredCxxFlagList()) {
- if (!flag.equals("-isystem")) {
- flag = NdkPaths.stripRepositoryPrefix(flag);
- assertThat(ndkDirectories).contains(flag);
- }
+ for (String fileglob : STL_FILEGROUPS.values()) {
+ String fileglobNoWildcard = fileglob.substring(0, fileglob.lastIndexOf('/'));
+ assertThat(NDK_DIRECTORIES).contains(fileglobNoWildcard);
+ assertThat(findFileByPattern(fileglob)).isTrue();
+ }
+ }
+
+ private static boolean findFileByPattern(String globPattern) {
+
+ String start = globPattern.substring(0, globPattern.indexOf('*'));
+ String end = globPattern.substring(globPattern.lastIndexOf('.'));
+ for (String f : NDK_FILES) {
+ if (f.startsWith(start) && f.endsWith(end)) {
+ return true;
}
}
+ return false;
}
- private static Set<String> getFiles(String fileName) {
+ private static ImmutableSet<String> getFiles(String fileName) {
+
String ndkFilesContent;
try {
ndkFilesContent = ResourceFileLoader.loadResource(
@@ -111,7 +165,7 @@ public class AndroidNdkCrosstoolsTest {
throw new IllegalStateException(e);
}
- Set<String> ndkFiles = new HashSet<>();
+ ImmutableSet.Builder<String> ndkFiles = ImmutableSet.builder();
Scanner ndkFilesContentScanner = new Scanner(ndkFilesContent);
while (ndkFilesContentScanner.hasNext()) {
String path = ndkFilesContentScanner.nextLine();
@@ -122,20 +176,32 @@ public class AndroidNdkCrosstoolsTest {
ndkFiles.add(path);
}
ndkFilesContentScanner.close();
- return ndkFiles;
+ return ndkFiles.build();
+ }
+
+ @Test
+ public void testAllToolchainsHaveRuntimesFilegroup() {
+ for (CrosstoolRelease crosstool : CROSSTOOL_RELEASES) {
+ for (CToolchain toolchain : crosstool.getToolchainList()) {
+ assertThat(toolchain.getDynamicRuntimesFilegroup()).isNotEmpty();
+ assertThat(toolchain.getStaticRuntimesFilegroup()).isNotEmpty();
+ }
+ }
}
@Test
public void testDefaultToolchainsExist() {
- Set<String> toolchainNames = new HashSet<>();
- for (CToolchain toolchain : CROSSTOOL_RELEASE.getToolchainList()) {
- toolchainNames.add(toolchain.getToolchainIdentifier());
- }
+ for (CrosstoolRelease crosstool : CROSSTOOL_RELEASES) {
- for (DefaultCpuToolchain defaultCpuToolchain : CROSSTOOL_RELEASE.getDefaultToolchainList()) {
- assertThat(toolchainNames).contains(defaultCpuToolchain.getToolchainIdentifier());
+ Set<String> toolchainNames = new HashSet<>();
+ for (CToolchain toolchain : crosstool.getToolchainList()) {
+ toolchainNames.add(toolchain.getToolchainIdentifier());
+ }
+
+ for (DefaultCpuToolchain defaultCpuToolchain : crosstool.getDefaultToolchainList()) {
+ assertThat(toolchainNames).contains(defaultCpuToolchain.getToolchainIdentifier());
+ }
}
}
-
}