Program: 53087
Project: 53087
Buggy source:
public static PythonPackageComponents getAllComponents(BuildRuleParams params,BuildRuleResolver ruleResolver,SourcePathResolver pathResolver,final PythonPackageComponents packageComponents,final PythonPlatform pythonPlatform,CxxBuckConfig cxxBuckConfig,final CxxPlatform cxxPlatform,ImmutableList<? extends Arg> extraLdflags,final NativeLinkStrategy nativeLinkStrategy) throws NoSuchBuildTargetException {
  final PythonPackageComponents.Builder allComponents=new PythonPackageComponents.Builder(params.getBuildTarget());
  final Map<BuildTarget,CxxPythonExtension> extensions=new LinkedHashMap<>();
  final Map<BuildTarget,SharedNativeLinkTarget> nativeLinkTargetRoots=new LinkedHashMap<>();
  final Map<BuildTarget,NativeLinkable> nativeLinkableRoots=new LinkedHashMap<>();
  final Set<BuildTarget> excludedNativeLinkableRoots=new LinkedHashSet<>();
  allComponents.addComponent(packageComponents,params.getBuildTarget());
  new AbstractBreadthFirstThrowingTraversal<BuildRule,NoSuchBuildTargetException>(params.getDeps()){
    private final ImmutableList<BuildRule> empty=ImmutableList.of();
    @Override public Iterable<BuildRule> visit(    BuildRule rule) throws NoSuchBuildTargetException {
      Iterable<BuildRule> deps=empty;
      Optional<SharedNativeLinkTarget> linkTarget=nativeLinkStrategy == NativeLinkStrategy.MERGED ? NativeLinkables.getSharedNativeLinkTarget(rule,cxxPlatform) : Optional.<SharedNativeLinkTarget>absent();
      if (rule instanceof CxxPythonExtension) {
        extensions.put(rule.getBuildTarget(),(CxxPythonExtension)rule);
      }
 else       if (rule instanceof PythonPackagable) {
        PythonPackagable packagable=(PythonPackagable)rule;
        PythonPackageComponents comps=packagable.getPythonPackageComponents(pythonPlatform,cxxPlatform);
        allComponents.addComponent(comps,rule.getBuildTarget());
        if (hasNativeCode(cxxPlatform,comps)) {
          for (          BuildRule dep : rule.getDeps()) {
            if (dep instanceof NativeLinkable) {
              NativeLinkable linkable=(NativeLinkable)dep;
              excludedNativeLinkableRoots.add(linkable.getBuildTarget());
              nativeLinkableRoots.put(linkable.getBuildTarget(),linkable);
            }
          }
        }
        deps=rule.getDeps();
      }
 else       if (linkTarget.isPresent()) {
        nativeLinkTargetRoots.put(linkTarget.get().getBuildTarget(),linkTarget.get());
      }
 else       if (rule instanceof NativeLinkable) {
        nativeLinkableRoots.put(rule.getBuildTarget(),(NativeLinkable)rule);
      }
      return deps;
    }
  }
.start();
  if (nativeLinkStrategy == NativeLinkStrategy.MERGED) {
    Map<BuildTarget,SharedNativeLinkTarget> includedNativeLinkTargetRoots=new LinkedHashMap<>();
    for (    Map.Entry<BuildTarget,SharedNativeLinkTarget> ent : nativeLinkTargetRoots.entrySet()) {
      if (!excludedNativeLinkableRoots.contains(ent.getKey())) {
        includedNativeLinkTargetRoots.put(ent.getKey(),ent.getValue());
      }
    }
    Map<BuildTarget,CxxPythonExtension> includedExtensions=new LinkedHashMap<>();
    for (    CxxPythonExtension extension : extensions.values()) {
      SharedNativeLinkTarget target=extension.getNativeLinkTarget(pythonPlatform);
      includedExtensions.put(target.getBuildTarget(),extension);
      includedNativeLinkTargetRoots.put(target.getBuildTarget(),target);
    }
    OmnibusLibraries libraries=Omnibus.getSharedLibraries(params,ruleResolver,pathResolver,cxxBuckConfig,cxxPlatform,extraLdflags,includedNativeLinkTargetRoots.values(),Maps.filterKeys(nativeLinkableRoots,Predicates.not(Predicates.in(includedNativeLinkTargetRoots.keySet()))).values());
    for (    Map.Entry<BuildTarget,OmnibusRoot> root : libraries.getRoots().entrySet()) {
      CxxPythonExtension extension=includedExtensions.get(root.getKey());
      if (extension != null) {
        allComponents.addModule(extension.getModule(),root.getValue().getPath(),root.getKey());
      }
 else {
        String soname=Preconditions.checkNotNull(root.getValue().getSoname().orNull(),"String_Node_Str",params.getBuildTarget(),root.getKey());
        allComponents.addNativeLibraries(Paths.get(soname),root.getValue().getPath(),root.getKey());
      }
    }
    for (    OmnibusLibrary library : libraries.getLibraries()) {
      allComponents.addNativeLibraries(Paths.get(library.getSoname()),library.getPath(),params.getBuildTarget());
    }
  }
 else {
    Map<BuildTarget,NativeLinkable> extensionNativeDeps=new LinkedHashMap<>();
    for (    Map.Entry<BuildTarget,CxxPythonExtension> entry : extensions.entrySet()) {
      allComponents.addComponent(entry.getValue().getPythonPackageComponents(pythonPlatform,cxxPlatform),entry.getKey());
      extensionNativeDeps.putAll(Maps.uniqueIndex(entry.getValue().getNativeLinkTarget(pythonPlatform).getSharedNativeLinkTargetDeps(cxxPlatform),HasBuildTarget.TO_TARGET));
    }
    ImmutableMap<BuildTarget,NativeLinkable> nativeLinkables=NativeLinkables.getTransitiveNativeLinkables(cxxPlatform,Iterables.concat(nativeLinkableRoots.values(),extensionNativeDeps.values()));
    for (    NativeLinkable nativeLinkable : nativeLinkables.values()) {
      NativeLinkable.Linkage linkage=nativeLinkable.getPreferredLinkage(cxxPlatform);
      if (nativeLinkableRoots.containsKey(nativeLinkable.getBuildTarget()) || linkage != NativeLinkable.Linkage.STATIC) {
        ImmutableMap<String,SourcePath> libs=nativeLinkable.getSharedLibraries(cxxPlatform);
        for (        Map.Entry<String,SourcePath> ent : libs.entrySet()) {
          allComponents.addNativeLibraries(Paths.get(ent.getKey()),ent.getValue(),nativeLinkable.getBuildTarget());
        }
      }
    }
  }
  return allComponents.build();
}

Fixed version (ground truth):
public static PythonPackageComponents getAllComponents(BuildRuleParams params,BuildRuleResolver ruleResolver,SourcePathResolver pathResolver,final PythonPackageComponents packageComponents,final PythonPlatform pythonPlatform,CxxBuckConfig cxxBuckConfig,final CxxPlatform cxxPlatform,ImmutableList<? extends Arg> extraLdflags,final NativeLinkStrategy nativeLinkStrategy) throws NoSuchBuildTargetException {
  final PythonPackageComponents.Builder allComponents=new PythonPackageComponents.Builder(params.getBuildTarget());
  final Map<BuildTarget,CxxPythonExtension> extensions=new LinkedHashMap<>();
  final Map<BuildTarget,SharedNativeLinkTarget> nativeLinkTargetRoots=new LinkedHashMap<>();
  final Map<BuildTarget,NativeLinkable> nativeLinkableRoots=new LinkedHashMap<>();
  final Set<BuildTarget> excludedNativeLinkableRoots=new LinkedHashSet<>();
  allComponents.addComponent(packageComponents,params.getBuildTarget());
  new AbstractBreadthFirstThrowingTraversal<BuildRule,NoSuchBuildTargetException>(params.getDeps()){
    private final ImmutableList<BuildRule> empty=ImmutableList.of();
    @Override public Iterable<BuildRule> visit(    BuildRule rule) throws NoSuchBuildTargetException {
      Iterable<BuildRule> deps=empty;
      Optional<SharedNativeLinkTarget> linkTarget=nativeLinkStrategy == NativeLinkStrategy.MERGED ? NativeLinkables.getSharedNativeLinkTarget(rule,cxxPlatform) : Optional.<SharedNativeLinkTarget>absent();
      if (rule instanceof CxxPythonExtension) {
        extensions.put(rule.getBuildTarget(),(CxxPythonExtension)rule);
      }
 else       if (rule instanceof PythonPackagable) {
        PythonPackagable packagable=(PythonPackagable)rule;
        PythonPackageComponents comps=packagable.getPythonPackageComponents(pythonPlatform,cxxPlatform);
        allComponents.addComponent(comps,rule.getBuildTarget());
        if (hasNativeCode(cxxPlatform,comps)) {
          for (          BuildRule dep : rule.getDeps()) {
            if (dep instanceof NativeLinkable) {
              NativeLinkable linkable=(NativeLinkable)dep;
              excludedNativeLinkableRoots.add(linkable.getBuildTarget());
              nativeLinkableRoots.put(linkable.getBuildTarget(),linkable);
            }
          }
        }
        deps=rule.getDeps();
      }
 else       if (linkTarget.isPresent()) {
        nativeLinkTargetRoots.put(linkTarget.get().getBuildTarget(),linkTarget.get());
      }
 else       if (rule instanceof NativeLinkable) {
        nativeLinkableRoots.put(rule.getBuildTarget(),(NativeLinkable)rule);
      }
      return deps;
    }
  }
.start();
  if (nativeLinkStrategy == NativeLinkStrategy.MERGED) {
    final Set<BuildTarget> transitivelyExcludedNativeLinkables=new HashSet<>();
    new AbstractBreadthFirstTraversal<NativeLinkable>(Iterables.transform(excludedNativeLinkableRoots,Functions.forMap(nativeLinkableRoots))){
      @Override public Iterable<NativeLinkable> visit(      NativeLinkable linkable){
        transitivelyExcludedNativeLinkables.add(linkable.getBuildTarget());
        return Iterables.concat(linkable.getNativeLinkableDeps(cxxPlatform),linkable.getNativeLinkableExportedDeps(cxxPlatform));
      }
    }
.start();
    Map<BuildTarget,SharedNativeLinkTarget> includedNativeLinkTargetRoots=new LinkedHashMap<>();
    for (    Map.Entry<BuildTarget,SharedNativeLinkTarget> ent : nativeLinkTargetRoots.entrySet()) {
      if (!transitivelyExcludedNativeLinkables.contains(ent.getKey())) {
        includedNativeLinkTargetRoots.put(ent.getKey(),ent.getValue());
      }
    }
    Map<BuildTarget,CxxPythonExtension> includedExtensions=new LinkedHashMap<>();
    for (    CxxPythonExtension extension : extensions.values()) {
      SharedNativeLinkTarget target=extension.getNativeLinkTarget(pythonPlatform);
      includedExtensions.put(target.getBuildTarget(),extension);
      includedNativeLinkTargetRoots.put(target.getBuildTarget(),target);
    }
    OmnibusLibraries libraries=Omnibus.getSharedLibraries(params,ruleResolver,pathResolver,cxxBuckConfig,cxxPlatform,extraLdflags,includedNativeLinkTargetRoots.values(),Maps.filterKeys(nativeLinkableRoots,Predicates.not(Predicates.in(includedNativeLinkTargetRoots.keySet()))).values());
    for (    Map.Entry<BuildTarget,OmnibusRoot> root : libraries.getRoots().entrySet()) {
      CxxPythonExtension extension=includedExtensions.get(root.getKey());
      if (extension != null) {
        allComponents.addModule(extension.getModule(),root.getValue().getPath(),root.getKey());
      }
 else {
        String soname=Preconditions.checkNotNull(root.getValue().getSoname().orNull(),"String_Node_Str",params.getBuildTarget(),root.getKey());
        allComponents.addNativeLibraries(Paths.get(soname),root.getValue().getPath(),root.getKey());
      }
    }
    for (    OmnibusLibrary library : libraries.getLibraries()) {
      allComponents.addNativeLibraries(Paths.get(library.getSoname()),library.getPath(),params.getBuildTarget());
    }
  }
 else {
    Map<BuildTarget,NativeLinkable> extensionNativeDeps=new LinkedHashMap<>();
    for (    Map.Entry<BuildTarget,CxxPythonExtension> entry : extensions.entrySet()) {
      allComponents.addComponent(entry.getValue().getPythonPackageComponents(pythonPlatform,cxxPlatform),entry.getKey());
      extensionNativeDeps.putAll(Maps.uniqueIndex(entry.getValue().getNativeLinkTarget(pythonPlatform).getSharedNativeLinkTargetDeps(cxxPlatform),HasBuildTarget.TO_TARGET));
    }
    ImmutableMap<BuildTarget,NativeLinkable> nativeLinkables=NativeLinkables.getTransitiveNativeLinkables(cxxPlatform,Iterables.concat(nativeLinkableRoots.values(),extensionNativeDeps.values()));
    for (    NativeLinkable nativeLinkable : nativeLinkables.values()) {
      NativeLinkable.Linkage linkage=nativeLinkable.getPreferredLinkage(cxxPlatform);
      if (nativeLinkableRoots.containsKey(nativeLinkable.getBuildTarget()) || linkage != NativeLinkable.Linkage.STATIC) {
        ImmutableMap<String,SourcePath> libs=nativeLinkable.getSharedLibraries(cxxPlatform);
        for (        Map.Entry<String,SourcePath> ent : libs.entrySet()) {
          allComponents.addNativeLibraries(Paths.get(ent.getKey()),ent.getValue(),nativeLinkable.getBuildTarget());
        }
      }
    }
  }
  return allComponents.build();
}