Search in sources :

Example 6 with AlwaysFoundExecutableFinder

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

the class WorkspaceAndProjectGeneratorTest method workspaceAndProjectsShouldDiscoverDependenciesAndTests.

@Test
public void workspaceAndProjectsShouldDiscoverDependenciesAndTests() throws IOException, InterruptedException {
    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"));
    ProjectGenerator quxProjectGenerator = projectGenerators.get(Paths.get("qux"));
    assertNull("The Qux project should not be generated at all", quxProjectGenerator);
    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:bin");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(fooProjectGenerator.getGeneratedProject(), "//foo:lib");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(fooProjectGenerator.getGeneratedProject(), "//foo:bin-xctest");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(fooProjectGenerator.getGeneratedProject(), "//foo:lib-xctest");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(barProjectGenerator.getGeneratedProject(), "//bar:lib");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(bazProjectGenerator.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 7 with AlwaysFoundExecutableFinder

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

the class WorkspaceAndProjectGeneratorTest method targetsForWorkspaceWithExtraSchemes.

@Test
public void targetsForWorkspaceWithExtraSchemes() throws IOException, InterruptedException {
    setUpWorkspaceWithSchemeAndProjects();
    WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(rootCell, targetGraph, workspaceWithExtraSchemeNode.getConstructorArg(), workspaceWithExtraSchemeNode.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"));
    ProjectGenerator quxProjectGenerator = projectGenerators.get(Paths.get("qux"));
    assertNotNull("The Qux project should have been generated", quxProjectGenerator);
    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:FooBin");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(fooProjectGenerator.getGeneratedProject(), "//foo:FooLib");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(fooProjectGenerator.getGeneratedProject(), "//foo:FooBinTest");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(fooProjectGenerator.getGeneratedProject(), "//foo:FooLibTest");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(barProjectGenerator.getGeneratedProject(), "//bar:BarLib");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(bazProjectGenerator.getGeneratedProject(), "//baz:BazLib");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(quxProjectGenerator.getGeneratedProject(), "//qux:QuxBin");
    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(2));
    assertThat(mainSchemeBuildAction.getBuildActionEntries().get(0), withNameAndBuildingFor("BarLib", equalTo(XCScheme.BuildActionEntry.BuildFor.DEFAULT)));
    assertThat(mainSchemeBuildAction.getBuildActionEntries().get(1), withNameAndBuildingFor("QuxBin", equalTo(XCScheme.BuildActionEntry.BuildFor.DEFAULT)));
    XCScheme fooScheme = generator.getSchemeGenerators().get("FooScheme").getOutputScheme().get();
    XCScheme.BuildAction fooSchemeBuildAction = fooScheme.getBuildAction().get();
    assertThat(fooSchemeBuildAction.getBuildActionEntries(), hasSize(6));
    assertThat(fooSchemeBuildAction.getBuildActionEntries().get(0), withNameAndBuildingFor("BarLib", equalTo(XCScheme.BuildActionEntry.BuildFor.DEFAULT)));
    assertThat(fooSchemeBuildAction.getBuildActionEntries().get(1), withNameAndBuildingFor("FooLib", equalTo(XCScheme.BuildActionEntry.BuildFor.DEFAULT)));
    assertThat(fooSchemeBuildAction.getBuildActionEntries().get(2), withNameAndBuildingFor("FooBin", equalTo(XCScheme.BuildActionEntry.BuildFor.DEFAULT)));
    assertThat(fooSchemeBuildAction.getBuildActionEntries().get(3), withNameAndBuildingFor("BazLib", equalTo(XCScheme.BuildActionEntry.BuildFor.TEST_ONLY)));
    assertThat(fooSchemeBuildAction.getBuildActionEntries().get(4), withNameAndBuildingFor("FooLibTest", equalTo(XCScheme.BuildActionEntry.BuildFor.TEST_ONLY)));
    assertThat(fooSchemeBuildAction.getBuildActionEntries().get(5), withNameAndBuildingFor("FooBinTest", equalTo(XCScheme.BuildActionEntry.BuildFor.TEST_ONLY)));
}
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) XCScheme(com.facebook.buck.apple.xcode.XCScheme) Test(org.junit.Test)

Example 8 with AlwaysFoundExecutableFinder

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

the class WorkspaceAndProjectGeneratorTest method buildWithBuck.

@Test
public void buildWithBuck() throws IOException, InterruptedException {
    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.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"));
    assertThat(fooProjectGenerator, is(notNullValue()));
    PBXTarget buildWithBuckTarget = null;
    for (PBXTarget target : fooProjectGenerator.getGeneratedProject().getTargets()) {
        if (target.getProductName() != null && target.getProductName().endsWith("-Buck")) {
            buildWithBuckTarget = target;
            break;
        }
    }
    assertThat(buildWithBuckTarget, is(notNullValue()));
    assertThat(buildWithBuckTarget, is(instanceOf(PBXAggregateTarget.class)));
    String gid = buildWithBuckTarget.getGlobalID();
    Optional<XCScheme> scheme = Iterables.getOnlyElement(generator.getSchemeGenerators().values()).getOutputScheme();
    assertThat(scheme.isPresent(), is(true));
    XCScheme.BuildableReference buildWithBuckBuildableReference = null;
    for (XCScheme.BuildActionEntry buildActionEntry : scheme.get().getBuildAction().get().getBuildActionEntries()) {
        XCScheme.BuildableReference buildableReference = buildActionEntry.getBuildableReference();
        if (buildableReference.getBlueprintIdentifier().equals(gid)) {
            buildWithBuckBuildableReference = buildableReference;
        }
    }
    assertThat(buildWithBuckBuildableReference, is(notNullValue()));
    assertThat(buildWithBuckBuildableReference.getBuildableName(), equalTo("//foo:bin-Buck"));
}
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) XCScheme(com.facebook.buck.apple.xcode.XCScheme) Test(org.junit.Test)

Example 9 with AlwaysFoundExecutableFinder

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

the class WorkspaceAndProjectGeneratorTest method workspaceAndProjectsWithoutTests.

@Test
public void workspaceAndProjectsWithoutTests() throws IOException, InterruptedException {
    WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(rootCell, targetGraph, workspaceNode.getConstructorArg(), workspaceNode.getBuildTarget(), ImmutableSet.of(), 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"));
    ProjectGenerator quxProjectGenerator = projectGenerators.get(Paths.get("qux"));
    assertNull("The Qux project should not be generated at all", quxProjectGenerator);
    assertNull("The Baz project should not be generated at all", bazProjectGenerator);
    assertNotNull("The Foo project should have been generated", fooProjectGenerator);
    assertNotNull("The Bar project should have been generated", barProjectGenerator);
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(fooProjectGenerator.getGeneratedProject(), "//foo:bin");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(fooProjectGenerator.getGeneratedProject(), "//foo:lib");
    ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(barProjectGenerator.getGeneratedProject(), "//bar: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 10 with AlwaysFoundExecutableFinder

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

the class WorkspaceAndProjectGeneratorTest method requiredBuildTargets.

@Test
public void requiredBuildTargets() 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(), 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());
    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