Program: 53192
Project: 53192
Buggy source:
/** 
 * Consider the following graph of C/C++ library dependencies of a python binary rule.  In this case we dynamically link all C/C++ library deps except for ones that request static linkage via the `force_static` parameter (e.g. library `C` in this example): Python Binary | | A (shared) / \ /   \ /     \ /       \ B (shared)   ... /    \ /      \ /      ... C (static) \ \ \ \ D (shared) Handling this force static dep is tricky -- we need to make sure we *only* statically link it into the shared lib `B` and that it does *not* contribute to the link line formed for `A`. What's more, we need to make sure `D` still contributes to the link for `A`.
 */
@Test public void doNotPullInStaticLibsAcrossSharedLibs(){
  SourcePathResolver resolver=new SourcePathResolver(new BuildRuleResolver());
  BuildRule d=new FakeNativeLinkable("String_Node_Str",resolver,NativeLinkableInput.builder().addArgs("String_Node_Str").build(),Optional.<Linker.LinkableDepType>absent(),ImmutableMap.<String,SourcePath>of());
  BuildRule c=new FakeNativeLinkable("String_Node_Str",resolver,NativeLinkableInput.builder().addArgs("String_Node_Str").build(),Optional.of(Linker.LinkableDepType.STATIC),ImmutableMap.<String,SourcePath>of(),d);
  BuildRule b=new FakeNativeLinkable("String_Node_Str",resolver,NativeLinkableInput.builder().addArgs("String_Node_Str").build(),Optional.<Linker.LinkableDepType>absent(),ImmutableMap.<String,SourcePath>of(),c);
  BuildRule a=new FakeNativeLinkable("String_Node_Str",resolver,NativeLinkableInput.builder().addArgs("String_Node_Str").build(),Optional.<Linker.LinkableDepType>absent(),ImmutableMap.<String,SourcePath>of(),b);
  NativeLinkableInput inputForTop=NativeLinkables.getTransitiveNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM,ImmutableList.of(a),Linker.LinkableDepType.SHARED,false);
  assertThat(inputForTop.getArgs(),Matchers.containsInAnyOrder("String_Node_Str","String_Node_Str","String_Node_Str"));
  assertThat(inputForTop.getArgs(),Matchers.not(Matchers.contains("String_Node_Str")));
  NativeLinkableInput inputForB=NativeLinkables.getTransitiveNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM,ImmutableList.of(c),Linker.LinkableDepType.SHARED,false);
  assertThat(inputForB.getArgs(),Matchers.containsInAnyOrder("String_Node_Str","String_Node_Str"));
}

Fixed version (ground truth):
/** 
 * Consider the following graph of C/C++ library dependencies of a python binary rule.  In this case we dynamically link all C/C++ library deps except for ones that request static linkage via the `force_static` parameter (e.g. library `C` in this example): Python Binary | | A (shared) / \ /   \ /     \ /       \ B (shared)   ... /    \ /      \ /      ... C (static) \ \ \ \ D (shared) Handling this force static dep is tricky -- we need to make sure we *only* statically link it into the shared lib `B` and that it does *not* contribute to the link line formed for `A`. What's more, we need to make sure `D` still contributes to the link for `A`.
 */
@Test public void doNotPullInStaticLibsAcrossSharedLibs(){
  SourcePathResolver resolver=new SourcePathResolver(new BuildRuleResolver());
  BuildRule d=new FakeNativeLinkable("String_Node_Str",resolver,NativeLinkableInput.builder().addArgs("String_Node_Str").build(),NativeLinkable.Linkage.ANY,ImmutableMap.<String,SourcePath>of());
  BuildRule c=new FakeNativeLinkable("String_Node_Str",resolver,NativeLinkableInput.builder().addArgs("String_Node_Str").build(),NativeLinkable.Linkage.STATIC,ImmutableMap.<String,SourcePath>of(),d);
  BuildRule b=new FakeNativeLinkable("String_Node_Str",resolver,NativeLinkableInput.builder().addArgs("String_Node_Str").build(),NativeLinkable.Linkage.ANY,ImmutableMap.<String,SourcePath>of(),c);
  BuildRule a=new FakeNativeLinkable("String_Node_Str",resolver,NativeLinkableInput.builder().addArgs("String_Node_Str").build(),NativeLinkable.Linkage.ANY,ImmutableMap.<String,SourcePath>of(),b);
  NativeLinkableInput inputForTop=NativeLinkables.getTransitiveNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM,ImmutableList.of(a),Linker.LinkableDepType.SHARED,false);
  assertThat(inputForTop.getArgs(),Matchers.containsInAnyOrder("String_Node_Str","String_Node_Str","String_Node_Str"));
  assertThat(inputForTop.getArgs(),Matchers.not(Matchers.contains("String_Node_Str")));
  NativeLinkableInput inputForB=NativeLinkables.getTransitiveNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM,ImmutableList.of(c),Linker.LinkableDepType.SHARED,false);
  assertThat(inputForB.getArgs(),Matchers.containsInAnyOrder("String_Node_Str","String_Node_Str"));
}