@Test public void nonTestLibraryDepDoesNotIncludePrivateHeadersOfLibrary() throws Exception { SourcePathResolver pathResolver = new SourcePathResolver(new BuildRuleResolver()); BuildTarget libTarget = BuildTargetFactory.newInstance("//:lib"); BuildRuleParams libParams = new FakeBuildRuleParamsBuilder(libTarget).build(); FakeCxxLibrary libRule = new FakeCxxLibrary( libParams, pathResolver, BuildTargetFactory.newInstance("//:header"), BuildTargetFactory.newInstance("//:symlink"), Paths.get("symlink/tree/lib"), BuildTargetFactory.newInstance("//:privateheader"), BuildTargetFactory.newInstance("//:privatesymlink"), Paths.get("private/symlink/tree/lib"), new FakeBuildRule("//:archive", pathResolver), new FakeBuildRule("//:shared", pathResolver), Paths.get("output/path/lib.so"), "lib.so", // This library has no tests. ImmutableSortedSet.<BuildTarget>of()); BuildTarget otherLibDepTarget = BuildTargetFactory.newInstance("//:other"); BuildRuleParams otherLibDepParams = new FakeBuildRuleParamsBuilder(otherLibDepTarget) .setDeclaredDeps(ImmutableSortedSet.<BuildRule>of(libRule)) .build(); ImmutableList<CxxPreprocessorInput> otherInput = CxxDescriptionEnhancer.collectCxxPreprocessorInput( TargetGraph.EMPTY, otherLibDepParams, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMultimap.<CxxSource.Type, String>of(), ImmutableList.<HeaderSymlinkTree>of(), ImmutableSet.<FrameworkPath>of(), CxxPreprocessables.getTransitiveCxxPreprocessorInput( TargetGraph.EMPTY, CxxPlatformUtils.DEFAULT_PLATFORM, FluentIterable.from(otherLibDepParams.getDeps()) .filter(Predicates.instanceOf(CxxPreprocessorDep.class)))); assertThat( "Non-test rule with library dep should include public and not private headers", CxxPreprocessorInput.concat(otherInput).getIncludeRoots(), allOf( hasItem(Paths.get("symlink/tree/lib")), not(hasItem(Paths.get("private/symlink/tree/lib"))))); }
@Test public void libraryTestIncludesPrivateHeadersOfLibraryUnderTest() throws Exception { SourcePathResolver pathResolver = new SourcePathResolver(new BuildRuleResolver()); BuildTarget libTarget = BuildTargetFactory.newInstance("//:lib"); BuildTarget testTarget = BuildTargetFactory.newInstance("//:test"); BuildRuleParams libParams = new FakeBuildRuleParamsBuilder(libTarget).build(); FakeCxxLibrary libRule = new FakeCxxLibrary( libParams, pathResolver, BuildTargetFactory.newInstance("//:header"), BuildTargetFactory.newInstance("//:symlink"), Paths.get("symlink/tree/lib"), BuildTargetFactory.newInstance("//:privateheader"), BuildTargetFactory.newInstance("//:privatesymlink"), Paths.get("private/symlink/tree/lib"), new FakeBuildRule("//:archive", pathResolver), new FakeBuildRule("//:shared", pathResolver), Paths.get("output/path/lib.so"), "lib.so", // Ensure the test is listed as a dep of the lib. ImmutableSortedSet.of(testTarget)); BuildRuleParams testParams = new FakeBuildRuleParamsBuilder(testTarget) .setDeclaredDeps(ImmutableSortedSet.<BuildRule>of(libRule)) .build(); ImmutableList<CxxPreprocessorInput> combinedInput = CxxDescriptionEnhancer.collectCxxPreprocessorInput( TargetGraph.EMPTY, testParams, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMultimap.<CxxSource.Type, String>of(), ImmutableList.<HeaderSymlinkTree>of(), ImmutableSet.<FrameworkPath>of(), CxxPreprocessables.getTransitiveCxxPreprocessorInput( TargetGraph.EMPTY, CxxPlatformUtils.DEFAULT_PLATFORM, FluentIterable.from(testParams.getDeps()) .filter(Predicates.instanceOf(CxxPreprocessorDep.class)))); assertThat( "Test of library should include both public and private headers", CxxPreprocessorInput.concat(combinedInput).getIncludeRoots(), hasItems(Paths.get("symlink/tree/lib"), Paths.get("private/symlink/tree/lib"))); }