Search in sources :

Example 1 with AlwaysFoundExecutableFinder

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

the class ProjectGeneratorTest method testAggregateTargetForLibraryForBuildWithBuck.

@Test
public void testAggregateTargetForLibraryForBuildWithBuck() throws IOException {
    BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "library").build();
    TargetNode<?, ?> binaryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.m"), ImmutableList.of("-foo")))).build();
    ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(binaryNode);
    final TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
    final AppleDependenciesCache cache = new AppleDependenciesCache(targetGraph);
    ProjectGenerator projectGenerator = new ProjectGenerator(targetGraph, cache, nodes.stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet()), projectCell, OUTPUT_DIRECTORY, PROJECT_NAME, "BUCK", ImmutableSet.of(), Optional.of(libraryTarget), ImmutableList.of("--flag", "value with spaces"), false, Optional.empty(), ImmutableSet.of(), Optional.empty(), new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, getBuildRuleResolverNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
    projectGenerator.createXcodeProjects();
    PBXTarget buildWithBuckTarget = null;
    for (PBXTarget target : projectGenerator.getGeneratedProject().getTargets()) {
        if (target.getProductName() != null && target.getProductName().endsWith("-Buck")) {
            buildWithBuckTarget = target;
        }
    }
    assertThat(buildWithBuckTarget, is(notNullValue()));
    assertHasConfigurations(buildWithBuckTarget, "Debug");
    assertKeepsConfigurationsInMainGroup(projectGenerator.getGeneratedProject(), buildWithBuckTarget);
    assertEquals("Should have exact number of build phases", 1, buildWithBuckTarget.getBuildPhases().size());
    PBXBuildPhase buildPhase = Iterables.getOnlyElement(buildWithBuckTarget.getBuildPhases());
    assertThat(buildPhase, instanceOf(PBXShellScriptBuildPhase.class));
    PBXShellScriptBuildPhase shellScriptBuildPhase = (PBXShellScriptBuildPhase) buildPhase;
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("buck -- \"--show-output --report-absolute-paths --flag 'value with spaces'\" " + libraryTarget.getFullyQualifiedName() + " dwarf dwarf-and-dsym"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) TargetNode(com.facebook.buck.rules.TargetNode) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) BuildTarget(com.facebook.buck.model.BuildTarget) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase) TargetGraph(com.facebook.buck.rules.TargetGraph) AppleDependenciesCache(com.facebook.buck.apple.AppleDependenciesCache) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 2 with AlwaysFoundExecutableFinder

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

the class ProjectGeneratorTest method testAggregateTargetForBundleForBuildWithBuck.

@Test
public void testAggregateTargetForBundleForBuildWithBuck() throws IOException {
    BuildTarget binaryTarget = BuildTarget.builder(rootPath, "//foo", "binary").build();
    TargetNode<?, ?> binaryNode = AppleBinaryBuilder.createBuilder(binaryTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).build();
    BuildTarget bundleTarget = BuildTarget.builder(rootPath, "//foo", "bundle").build();
    TargetNode<?, ?> bundleNode = AppleBundleBuilder.createBuilder(bundleTarget).setExtension(Either.ofLeft(AppleBundleExtension.APP)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(binaryTarget).build();
    ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(bundleNode, binaryNode);
    final TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
    final AppleDependenciesCache cache = new AppleDependenciesCache(targetGraph);
    ProjectGenerator projectGenerator = new ProjectGenerator(targetGraph, cache, nodes.stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet()), projectCell, OUTPUT_DIRECTORY, PROJECT_NAME, "BUCK", ImmutableSet.of(), Optional.of(bundleTarget), ImmutableList.of("--flag", "value with spaces"), false, Optional.empty(), ImmutableSet.of(), Optional.empty(), new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, getBuildRuleResolverNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
    projectGenerator.createXcodeProjects();
    PBXTarget buildWithBuckTarget = null;
    for (PBXTarget target : projectGenerator.getGeneratedProject().getTargets()) {
        if (target.getProductName() != null && target.getProductName().endsWith("-Buck")) {
            buildWithBuckTarget = target;
        }
    }
    assertThat(buildWithBuckTarget, is(notNullValue()));
    assertHasConfigurations(buildWithBuckTarget, "Debug");
    assertKeepsConfigurationsInMainGroup(projectGenerator.getGeneratedProject(), buildWithBuckTarget);
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    assertEquals("Should have exact number of build phases", 2, buildWithBuckTarget.getBuildPhases().size());
    PBXBuildPhase buildPhase = Iterables.get(buildWithBuckTarget.getBuildPhases(), 0);
    assertThat(buildPhase, instanceOf(PBXShellScriptBuildPhase.class));
    PBXShellScriptBuildPhase shellScriptBuildPhase = (PBXShellScriptBuildPhase) buildPhase;
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("-- \"--show-output --report-absolute-paths --flag 'value with spaces'\" " + bundleTarget.getFullyQualifiedName() + " dwarf dwarf-and-dsym"));
    Path fixUUIDScriptPath = ProjectGenerator.getFixUUIDScriptPath(filesystem);
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("python " + fixUUIDScriptPath + " --verbose " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.app") + " " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.dSYM") + " " + bundleTarget.getShortName()));
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("machoutils absolutify_object_paths --binary $BUCK_BUNDLE_OUTPUT_PATH/bundle " + "--output " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.app/bundle") + " --old_compdir " + "\"./////////////////////"));
    // skipping some slashes: ".//////////// ..... ///////"
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("////////\" --new_compdir \"" + filesystem.getRootPath().toString() + "\""));
    PBXBuildPhase codesignPhase = buildWithBuckTarget.getBuildPhases().get(1);
    assertThat(codesignPhase, instanceOf(PBXShellScriptBuildPhase.class));
    PBXShellScriptBuildPhase codesignShellScriptPhase = (PBXShellScriptBuildPhase) codesignPhase;
    Path codesignScriptPath = ProjectGenerator.getCodesignScriptPath(filesystem);
    assertThat(codesignShellScriptPhase.getShellScript(), containsString("python " + codesignScriptPath + " /usr/bin/codesign " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.app")));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) TargetNode(com.facebook.buck.rules.TargetNode) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) BuildTarget(com.facebook.buck.model.BuildTarget) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase) AppleDependenciesCache(com.facebook.buck.apple.AppleDependenciesCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 3 with AlwaysFoundExecutableFinder

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

the class WorkspaceAndProjectGeneratorTest method targetsForWorkspaceWithExtraTargets.

@Test
public void targetsForWorkspaceWithExtraTargets() throws IOException, InterruptedException {
    BuildTarget fooLibTarget = BuildTarget.builder(rootCell.getRoot(), "//foo", "FooLib").build();
    TargetNode<AppleLibraryDescription.Arg, ?> fooLib = AppleLibraryBuilder.createBuilder(fooLibTarget).build();
    BuildTarget barLibTarget = BuildTarget.builder(rootCell.getRoot(), "//bar", "BarLib").build();
    TargetNode<AppleLibraryDescription.Arg, ?> barLib = AppleLibraryBuilder.createBuilder(barLibTarget).build();
    BuildTarget bazLibTarget = BuildTarget.builder(rootCell.getRoot(), "//baz", "BazLib").build();
    TargetNode<AppleLibraryDescription.Arg, ?> bazLib = AppleLibraryBuilder.createBuilder(bazLibTarget).setDeps(ImmutableSortedSet.of(barLibTarget)).build();
    TargetNode<XcodeWorkspaceConfigDescription.Arg, ?> workspaceNode = XcodeWorkspaceConfigBuilder.createBuilder(BuildTarget.builder(rootCell.getRoot(), "//foo", "workspace").build()).setWorkspaceName(Optional.of("workspace")).setSrcTarget(Optional.of(fooLibTarget)).setExtraTargets(ImmutableSortedSet.of(bazLibTarget)).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(fooLib, barLib, bazLib, workspaceNode);
    WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(rootCell, targetGraph, workspaceNode.getConstructorArg(), workspaceNode.getBuildTarget(), ImmutableSet.of(ProjectGenerator.Option.INCLUDE_TESTS, ProjectGenerator.Option.INCLUDE_DEPENDENCIES_TESTS), false, /* combinedProject */
    false, /* buildWithBuck */
    ImmutableList.of(), Optional.empty(), 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"));
    ProjectGenerator barProjectGenerator = projectGenerators.get(Paths.get("bar"));
    ProjectGenerator bazProjectGenerator = projectGenerators.get(Paths.get("baz"));
    assertNotNull("The Foo project should have been generated", fooProjectGenerator);
    assertNotNull("The Bar project should have been generated", barProjectGenerator);
    assertNotNull("The Baz project should have been generated", bazProjectGenerator);
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(fooProjectGenerator.getGeneratedProject(), "//foo:FooLib");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(barProjectGenerator.getGeneratedProject(), "//bar:BarLib");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(bazProjectGenerator.getGeneratedProject(), "//baz:BazLib");
    XCScheme mainScheme = generator.getSchemeGenerators().get("workspace").getOutputScheme().get();
    XCScheme.BuildAction mainSchemeBuildAction = mainScheme.getBuildAction().get();
    // I wish we could use Hamcrest contains() here, but we hit
    // https://code.google.com/p/hamcrest/issues/detail?id=190 if we do that.
    assertThat(mainSchemeBuildAction.getBuildActionEntries(), hasSize(3));
    assertThat(mainSchemeBuildAction.getBuildActionEntries().get(0), withNameAndBuildingFor("FooLib", equalTo(XCScheme.BuildActionEntry.BuildFor.DEFAULT)));
    assertThat(mainSchemeBuildAction.getBuildActionEntries().get(1), withNameAndBuildingFor("BarLib", equalTo(XCScheme.BuildActionEntry.BuildFor.DEFAULT)));
    assertThat(mainSchemeBuildAction.getBuildActionEntries().get(2), withNameAndBuildingFor("BazLib", equalTo(XCScheme.BuildActionEntry.BuildFor.DEFAULT)));
}
Also used : Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) HashMap(java.util.HashMap) TargetGraph(com.facebook.buck.rules.TargetGraph) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) BuildTarget(com.facebook.buck.model.BuildTarget) XCScheme(com.facebook.buck.apple.xcode.XCScheme) Test(org.junit.Test)

Example 4 with AlwaysFoundExecutableFinder

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

the class WorkspaceAndProjectGeneratorTest method combinedProjectShouldDiscoverDependenciesAndTests.

@Test
public void combinedProjectShouldDiscoverDependenciesAndTests() throws IOException, InterruptedException {
    WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(rootCell, targetGraph, workspaceNode.getConstructorArg(), workspaceNode.getBuildTarget(), ImmutableSet.of(ProjectGenerator.Option.INCLUDE_TESTS, ProjectGenerator.Option.INCLUDE_DEPENDENCIES_TESTS), true, /* combinedProject */
    false, /* buildWithBuck */
    ImmutableList.of(), Optional.empty(), 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());
    assertTrue("Combined project generation should not populate the project generators map", projectGenerators.isEmpty());
    Optional<ProjectGenerator> projectGeneratorOptional = generator.getCombinedProjectGenerator();
    assertTrue("Combined project generator should be present", projectGeneratorOptional.isPresent());
    ProjectGenerator projectGenerator = projectGeneratorOptional.get();
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:bin");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:bin-xctest");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib-xctest");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//bar:lib");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//baz:lib");
}
Also used : Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) HashMap(java.util.HashMap) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 5 with AlwaysFoundExecutableFinder

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

the class WorkspaceAndProjectGeneratorTest method requiredBuildTargetsForCombinedProject.

@Test
public void requiredBuildTargetsForCombinedProject() throws IOException, InterruptedException {
    BuildTarget genruleTarget = BuildTarget.builder(rootCell.getRoot(), "//foo", "gen").build();
    TargetNode<GenruleDescription.Arg, ?> genrule = GenruleBuilder.newGenruleBuilder(genruleTarget).setOut("source.m").build();
    BuildTarget libraryTarget = BuildTarget.builder(rootCell.getRoot(), "//foo", "lib").build();
    TargetNode<AppleLibraryDescription.Arg, ?> library = AppleLibraryBuilder.createBuilder(libraryTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new DefaultBuildTargetSourcePath(genruleTarget)))).build();
    TargetNode<XcodeWorkspaceConfigDescription.Arg, ?> workspaceNode = XcodeWorkspaceConfigBuilder.createBuilder(BuildTarget.builder(rootCell.getRoot(), "//foo", "workspace").build()).setSrcTarget(Optional.of(libraryTarget)).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(genrule, library, workspaceNode);
    WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(rootCell, targetGraph, workspaceNode.getConstructorArg(), workspaceNode.getBuildTarget(), ImmutableSet.of(), true, /* combinedProject */
    false, /* buildWithBuck */
    ImmutableList.of(), Optional.empty(), 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());
    assertEquals(generator.getRequiredBuildTargets(), ImmutableSet.of(genruleTarget));
}
Also used : Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) HashMap(java.util.HashMap) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) BuildTarget(com.facebook.buck.model.BuildTarget) 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