Search in sources :

Example 26 with AlwaysFoundExecutableFinder

use of com.facebook.buck.io.AlwaysFoundExecutableFinder in project buck by facebook.

the class WorkspaceAndProjectGeneratorTest method buildWithBuckFocused.

@Test
public void buildWithBuckFocused() throws IOException, InterruptedException {
    final String fooLib = "//foo:lib";
    Optional<Path> buck = new ExecutableFinder().getOptionalExecutable(Paths.get("buck"), ImmutableMap.of());
    assumeThat(buck.isPresent(), is(true));
    WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(rootCell, targetGraph, workspaceNode.getConstructorArg(), workspaceNode.getBuildTarget(), ImmutableSet.of(ProjectGenerator.Option.INCLUDE_TESTS, ProjectGenerator.Option.INCLUDE_DEPENDENCIES_TESTS), false, /* combinedProject */
    true, /* buildWithBuck */
    ImmutableList.of(), Optional.of(ImmutableSet.of(BuildTargetFactory.newInstance(fooLib).getUnflavoredBuildTarget())), false, /* parallelizeBuild */
    new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, "BUCK", getBuildRuleResolverForNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
    Map<Path, ProjectGenerator> projectGenerators = new HashMap<>();
    generator.generateWorkspaceAndDependentProjects(projectGenerators, MoreExecutors.newDirectExecutorService());
    ProjectGenerator fooProjectGenerator = projectGenerators.get(Paths.get("foo"));
    assertThat(fooProjectGenerator, is(notNullValue()));
    for (PBXTarget target : fooProjectGenerator.getGeneratedProject().getTargets()) {
        if (target.getName() != null && !target.getName().equals(fooLib) && !target.getName().endsWith("-Buck")) {
            // all non-lib and non-Buck targets should have 0 steps as they are not in focus
            // (focus on .*lib.* only)
            assertThat(target.getBuildPhases().size(), Matchers.equalTo(0));
        }
    }
}
Also used : Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) HashMap(java.util.HashMap) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 27 with AlwaysFoundExecutableFinder

use of com.facebook.buck.io.AlwaysFoundExecutableFinder in project buck by facebook.

the class PythonBinaryDescriptionTest method transitiveNativeDepsUsingMergedNativeLinkStrategy.

@Test
public void transitiveNativeDepsUsingMergedNativeLinkStrategy() throws Exception {
    CxxLibraryBuilder transitiveCxxDepBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:transitive_dep")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("transitive_dep.c"))));
    CxxLibraryBuilder cxxDepBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("dep.c")))).setDeps(ImmutableSortedSet.of(transitiveCxxDepBuilder.getTarget()));
    CxxLibraryBuilder cxxBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:cxx")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("cxx.c")))).setDeps(ImmutableSortedSet.of(cxxDepBuilder.getTarget()));
    PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().build(), new AlwaysFoundExecutableFinder()) {

        @Override
        public NativeLinkStrategy getNativeLinkStrategy() {
            return NativeLinkStrategy.MERGED;
        }
    };
    PythonBinaryBuilder binaryBuilder = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin"), config, PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
    binaryBuilder.setMainModule("main");
    binaryBuilder.setDeps(ImmutableSortedSet.of(cxxBuilder.getTarget()));
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(transitiveCxxDepBuilder.build(), cxxDepBuilder.build(), cxxBuilder.build(), binaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
    transitiveCxxDepBuilder.build(resolver);
    cxxDepBuilder.build(resolver);
    cxxBuilder.build(resolver);
    PythonBinary binary = binaryBuilder.build(resolver);
    assertThat(Iterables.transform(binary.getComponents().getNativeLibraries().keySet(), Object::toString), Matchers.containsInAnyOrder("libomnibus.so", "libcxx.so"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 28 with AlwaysFoundExecutableFinder

use of com.facebook.buck.io.AlwaysFoundExecutableFinder 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)

Example 29 with AlwaysFoundExecutableFinder

use of com.facebook.buck.io.AlwaysFoundExecutableFinder in project buck by facebook.

the class NdkCxxPlatformTest method headerVerificationWhitelistsNdkRoot.

@Test
public void headerVerificationWhitelistsNdkRoot() throws IOException {
    ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot());
    String dir = "android-ndk-r9c";
    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(NdkCxxPlatformCompiler.Type.GCC).setVersion("gcc-version").setGccVersion("clang-version").build(), NdkCxxPlatforms.CxxRuntime.GNUSTL, "target-app-platform", ImmutableSet.of("x86"), Platform.LINUX, new AlwaysFoundExecutableFinder(), /* strictToolchainPaths */
    false);
    for (NdkCxxPlatform ndkCxxPlatform : platforms.values()) {
        assertTrue(ndkCxxPlatform.getCxxPlatform().getHeaderVerification().isWhitelisted(root.resolve("test.h").toString()));
    }
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 30 with AlwaysFoundExecutableFinder

use of com.facebook.buck.io.AlwaysFoundExecutableFinder in project buck by facebook.

the class PythonBuckConfigTest method testPexArgs.

@Test
public void testPexArgs() throws Exception {
    PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("python", ImmutableMap.of("pex_flags", "--hello --world"))).build(), new AlwaysFoundExecutableFinder());
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    assertThat(config.getPexTool(resolver).getCommandPrefix(new SourcePathResolver(new SourcePathRuleFinder(resolver))), hasConsecutiveItems("--hello", "--world"));
}
Also used : DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Aggregations

AlwaysFoundExecutableFinder (com.facebook.buck.io.AlwaysFoundExecutableFinder)39 Test (org.junit.Test)37 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)30 Path (java.nio.file.Path)18 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)17 BuildTarget (com.facebook.buck.model.BuildTarget)16 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)14 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)14 TargetGraph (com.facebook.buck.rules.TargetGraph)14 HashMap (java.util.HashMap)12 PrebuiltCxxLibraryBuilder (com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder)9 CxxLibraryBuilder (com.facebook.buck.cxx.CxxLibraryBuilder)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)8 XCScheme (com.facebook.buck.apple.xcode.XCScheme)6 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)6 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)6 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)6 AppleDependenciesCache (com.facebook.buck.apple.AppleDependenciesCache)5 SourcePath (com.facebook.buck.rules.SourcePath)5 ShBinaryBuilder (com.facebook.buck.shell.ShBinaryBuilder)5