test/com/facebook/buck/features/apple/projectV2/ProjectGeneratorTest.java
/**
   * Ensure target map filters out duplicated targets with an explicit and implicit static flavor.
   * Ensure the filtering prefers the main workspace target over other project targets.
   *
   * @throws IOException
   */
Ensure target map filters out duplicated targets with an explicit and implicit static flavor.
Ensure the filtering prefers the main workspace target over other project targets.


Ensure target map filters out duplicated targets with an explicit and implicit static flavor . Ensure the filtering prefers the main workspace target over other project targets .
@Test
  public void ruleToTargetMapFiltersDuplicatePBXTarget() throws IOException {
    BuildTarget explicitStaticBuildTarget =
        BuildTargetFactory.newInstance(
            rootPath, "//foo", "lib", CxxDescriptionEnhancer.STATIC_FLAVOR);
    TargetNode<?> explicitStaticNode =
        AppleLibraryBuilder.createBuilder(explicitStaticBuildTarget)
            .setSrcs(
                ImmutableSortedSet.of(
                    SourceWithFlags.of(FakeSourcePath.of("foo.m"), ImmutableList.of("-foo")),
                    SourceWithFlags.of(FakeSourcePath.of("bar.m"))))
            .setHeaders(ImmutableSortedSet.of(FakeSourcePath.of("foo.h")))
            .build();
    BuildTarget implicitStaticBuildTarget =
        BuildTargetFactory.newInstance(rootPath, "//foo", "lib");
    TargetNode<?> implicitStaticNode =
        AppleLibraryBuilder.createBuilder(implicitStaticBuildTarget)
            .setSrcs(
                ImmutableSortedSet.of(
                    SourceWithFlags.of(FakeSourcePath.of("foo.m"), ImmutableList.of("-foo")),
                    SourceWithFlags.of(FakeSourcePath.of("bar.m"))))
            .setHeaders(ImmutableSortedSet.of(FakeSourcePath.of("foo.h")))
            .build();
    ProjectGenerator projectGenerator =
        createProjectGenerator(
            ImmutableSet.of(explicitStaticNode, implicitStaticNode),
            Optional.of(explicitStaticBuildTarget));
    projectGenerator.createXcodeProjects();
    assertEquals(
        explicitStaticBuildTarget,
        Iterables.getOnlyElement(projectGenerator.getBuildTargetToGeneratedTargetMap().keySet()));
    PBXTarget target =
        Iterables.getOnlyElement(projectGenerator.getBuildTargetToGeneratedTargetMap().values());
    assertHasSingleSourcesPhaseWithSourcesAndFlags(
        target,
        ImmutableMap.of(
            "foo.m", Optional.of("-foo"),
            "bar.m", Optional.empty()));
  }
@ Test public void ruleToTargetMapFiltersDuplicatePBXTarget ( ) throws IOException { BuildTarget explicitStaticBuildTarget = BuildTargetFactory . newInstance ( rootPath , "//foo" , "lib" , CxxDescriptionEnhancer . STATIC_FLAVOR ) ; TargetNode < ? > explicitStaticNode = AppleLibraryBuilder . createBuilder ( explicitStaticBuildTarget ) . setSrcs ( ImmutableSortedSet . of ( SourceWithFlags . of ( FakeSourcePath . of ( "foo.m" ) , ImmutableList . of ( "-foo" ) ) , SourceWithFlags . of ( FakeSourcePath . of ( "bar.m" ) ) ) ) . setHeaders ( ImmutableSortedSet . of ( FakeSourcePath . of ( "foo.h" ) ) ) . build ( ) ; BuildTarget implicitStaticBuildTarget = BuildTargetFactory . newInstance ( rootPath , "//foo" , "lib" ) ; TargetNode < ? > implicitStaticNode = AppleLibraryBuilder . createBuilder ( implicitStaticBuildTarget ) . setSrcs ( ImmutableSortedSet . of ( SourceWithFlags . of ( FakeSourcePath . of ( "foo.m" ) , ImmutableList . of ( "-foo" ) ) , SourceWithFlags . of ( FakeSourcePath . of ( "bar.m" ) ) ) ) . setHeaders ( ImmutableSortedSet . of ( FakeSourcePath . of ( "foo.h" ) ) ) . build ( ) ; ProjectGenerator projectGenerator = createProjectGenerator ( ImmutableSet . of ( explicitStaticNode , implicitStaticNode ) , Optional . of ( explicitStaticBuildTarget ) ) ; projectGenerator . createXcodeProjects ( ) ; assertEquals ( explicitStaticBuildTarget , Iterables . getOnlyElement ( projectGenerator . getBuildTargetToGeneratedTargetMap ( ) . keySet ( ) ) ) ; PBXTarget target = Iterables . getOnlyElement ( projectGenerator . getBuildTargetToGeneratedTargetMap ( ) . values ( ) ) ; assertHasSingleSourcesPhaseWithSourcesAndFlags ( target , ImmutableMap . of ( "foo.m" , Optional . of ( "-foo" ) , "bar.m" , Optional . empty ( ) ) ) ; }
Ensure target map filters out duplicated targets with an explicit and implicit static flavor.
Ensure target map filters out duplicated targets with an explicit and implicit static flavor .
// `implicitStaticBuildTarget` should be filtered out since it duplicates // `explicitStaticBuildTarget`, the workspace target, which takes precedence.