Search in sources :

Example 11 with Platform

use of com.facebook.buck.util.environment.Platform in project buck by facebook.

the class NdkCxxPlatformTest method checkRootAndPlatformDoNotAffectRuleKeys.

// The important aspects we check for in rule keys is that the host platform and the path
// to the NDK don't cause changes.
@Test
public void checkRootAndPlatformDoNotAffectRuleKeys() throws Exception {
    ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot());
    // Test all major compiler and runtime combinations.
    ImmutableList<Pair<NdkCxxPlatformCompiler.Type, NdkCxxPlatforms.CxxRuntime>> configs = ImmutableList.of(new Pair<>(NdkCxxPlatformCompiler.Type.GCC, NdkCxxPlatforms.CxxRuntime.GNUSTL), new Pair<>(NdkCxxPlatformCompiler.Type.CLANG, NdkCxxPlatforms.CxxRuntime.GNUSTL), new Pair<>(NdkCxxPlatformCompiler.Type.CLANG, NdkCxxPlatforms.CxxRuntime.LIBCXX));
    for (Pair<NdkCxxPlatformCompiler.Type, NdkCxxPlatforms.CxxRuntime> config : configs) {
        Map<String, ImmutableMap<NdkCxxPlatforms.TargetCpuType, RuleKey>> preprocessAndCompileRukeKeys = Maps.newHashMap();
        Map<String, ImmutableMap<NdkCxxPlatforms.TargetCpuType, RuleKey>> compileRukeKeys = Maps.newHashMap();
        Map<String, ImmutableMap<NdkCxxPlatforms.TargetCpuType, RuleKey>> linkRukeKeys = Maps.newHashMap();
        // directories.
        for (String dir : ImmutableList.of("android-ndk-r9c", "android-ndk-r10b")) {
            for (Platform platform : ImmutableList.of(Platform.LINUX, Platform.MACOS, Platform.WINDOWS)) {
                Path root = tmp.newFolder(dir);
                MoreFiles.writeLinesToFile(ImmutableList.of("r9c"), root.resolve("RELEASE.TXT"));
                ImmutableMap<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform> platforms = NdkCxxPlatforms.getPlatforms(CxxPlatformUtils.DEFAULT_CONFIG, filesystem, root, NdkCxxPlatformCompiler.builder().setType(config.getFirst()).setVersion("gcc-version").setGccVersion("clang-version").build(), NdkCxxPlatforms.CxxRuntime.GNUSTL, "target-app-platform", ImmutableSet.of("x86"), platform, new AlwaysFoundExecutableFinder(), /* strictToolchainPaths */
                false);
                preprocessAndCompileRukeKeys.put(String.format("NdkCxxPlatform(%s, %s)", dir, platform), constructCompileRuleKeys(Operation.PREPROCESS_AND_COMPILE, platforms));
                compileRukeKeys.put(String.format("NdkCxxPlatform(%s, %s)", dir, platform), constructCompileRuleKeys(Operation.COMPILE, platforms));
                linkRukeKeys.put(String.format("NdkCxxPlatform(%s, %s)", dir, platform), constructLinkRuleKeys(platforms));
                MoreFiles.deleteRecursively(root);
            }
        }
        // If everything worked, we should be able to collapse all the generated rule keys down
        // to a singleton set.
        assertThat(Arrays.toString(preprocessAndCompileRukeKeys.entrySet().toArray()), Sets.newHashSet(preprocessAndCompileRukeKeys.values()), Matchers.hasSize(1));
        assertThat(Arrays.toString(compileRukeKeys.entrySet().toArray()), Sets.newHashSet(compileRukeKeys.values()), Matchers.hasSize(1));
        assertThat(Arrays.toString(linkRukeKeys.entrySet().toArray()), Sets.newHashSet(linkRukeKeys.values()), Matchers.hasSize(1));
    }
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) Platform(com.facebook.buck.util.environment.Platform) ImmutableMap(com.google.common.collect.ImmutableMap) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Pair(com.facebook.buck.model.Pair) Test(org.junit.Test)

Aggregations

Platform (com.facebook.buck.util.environment.Platform)11 Path (java.nio.file.Path)8 ImmutableMap (com.google.common.collect.ImmutableMap)5 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)4 Test (org.junit.Test)3 AndroidBuckConfig (com.facebook.buck.android.AndroidBuckConfig)2 AppleConfig (com.facebook.buck.apple.AppleConfig)2 AppleLibraryDescription (com.facebook.buck.apple.AppleLibraryDescription)2 BuckConfig (com.facebook.buck.cli.BuckConfig)2 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)2 JavaBuckConfig (com.facebook.buck.jvm.java.JavaBuckConfig)2 CommandThreadFactory (com.facebook.buck.log.CommandThreadFactory)2 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)2 Architecture (com.facebook.buck.util.environment.Architecture)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 Paths (java.nio.file.Paths)2 HashMap (java.util.HashMap)2