@Test
 public void buildTargetsWithDifferentFlavorsProduceDifferentDefaultSonames() {
   BuildTarget target1 = BuildTargetFactory.newInstance("//:rule#one");
   BuildTarget target2 = BuildTargetFactory.newInstance("//:rule#two");
   assertNotEquals(
       CxxDescriptionEnhancer.getDefaultSharedLibrarySoname(
           target1, CxxPlatformUtils.DEFAULT_PLATFORM),
       CxxDescriptionEnhancer.getDefaultSharedLibrarySoname(
           target2, CxxPlatformUtils.DEFAULT_PLATFORM));
 }
Пример #2
0
 @Override
 public PythonPackageComponents getPythonPackageComponents(
     TargetGraph targetGraph, PythonPlatform pythonPlatform, CxxPlatform cxxPlatform) {
   if (headerOnly.apply(cxxPlatform)) {
     return PythonPackageComponents.of();
   }
   if (linkage == Linkage.STATIC) {
     return PythonPackageComponents.of();
   }
   if (!isPlatformSupported(cxxPlatform)) {
     return PythonPackageComponents.of();
   }
   ImmutableMap.Builder<Path, SourcePath> libs = ImmutableMap.builder();
   String sharedLibrarySoname =
       soname.or(
           CxxDescriptionEnhancer.getDefaultSharedLibrarySoname(getBuildTarget(), cxxPlatform));
   BuildRule sharedLibraryBuildRule =
       requireBuildRule(
           targetGraph, cxxPlatform.getFlavor(), CxxDescriptionEnhancer.SHARED_FLAVOR);
   libs.put(
       Paths.get(sharedLibrarySoname),
       new BuildTargetSourcePath(sharedLibraryBuildRule.getBuildTarget()));
   return PythonPackageComponents.of(
       /* modules */ ImmutableMap.<Path, SourcePath>of(),
       /* resources */ ImmutableMap.<Path, SourcePath>of(),
       /* nativeLibraries */ libs.build(),
       /* prebuiltLibraries */ ImmutableSet.<SourcePath>of(),
       /* zipSafe */ Optional.<Boolean>absent());
 }
Пример #3
0
 @Override
 public ImmutableMap<String, SourcePath> getSharedLibraries(
     TargetGraph targetGraph, CxxPlatform cxxPlatform) {
   if (headerOnly.apply(cxxPlatform)) {
     return ImmutableMap.of();
   }
   if (linkage == Linkage.STATIC) {
     return ImmutableMap.of();
   }
   if (!isPlatformSupported(cxxPlatform)) {
     return ImmutableMap.of();
   }
   ImmutableMap.Builder<String, SourcePath> libs = ImmutableMap.builder();
   String sharedLibrarySoname =
       soname.or(
           CxxDescriptionEnhancer.getDefaultSharedLibrarySoname(getBuildTarget(), cxxPlatform));
   BuildRule sharedLibraryBuildRule =
       requireBuildRule(
           targetGraph, cxxPlatform.getFlavor(), CxxDescriptionEnhancer.SHARED_FLAVOR);
   libs.put(
       sharedLibrarySoname, new BuildTargetSourcePath(sharedLibraryBuildRule.getBuildTarget()));
   return libs.build();
 }
Пример #4
0
  @Override
  public NativeLinkableInput getNativeLinkableInput(
      TargetGraph targetGraph, CxxPlatform cxxPlatform, Linker.LinkableDepType type) {

    if (!isPlatformSupported(cxxPlatform)) {
      return NativeLinkableInput.of();
    }

    if (headerOnly.apply(cxxPlatform)) {
      return NativeLinkableInput.of(
          ImmutableList.<SourcePath>of(),
          ImmutableList.<String>of(),
          Preconditions.checkNotNull(frameworks),
          ImmutableSet.<FrameworkPath>of());
    }

    // Build up the arguments used to link this library.  If we're linking the
    // whole archive, wrap the library argument in the necessary "ld" flags.
    final Pair<ImmutableList<String>, ImmutableSet<SourcePath>> flagsAndBuildInputs =
        exportedLinkerFlags.apply(cxxPlatform);
    ImmutableList.Builder<String> linkerArgsBuilder = ImmutableList.builder();
    linkerArgsBuilder.addAll(flagsAndBuildInputs.getFirst());

    final BuildRule libraryRule;
    if (type != Linker.LinkableDepType.SHARED || linkage == Linkage.STATIC) {
      libraryRule =
          requireBuildRule(
              targetGraph,
              cxxPlatform.getFlavor(),
              type == Linker.LinkableDepType.STATIC
                  ? CxxDescriptionEnhancer.STATIC_FLAVOR
                  : CxxDescriptionEnhancer.STATIC_PIC_FLAVOR);
      Path staticLibraryPath =
          CxxDescriptionEnhancer.getStaticLibraryPath(
              getBuildTarget(),
              cxxPlatform.getFlavor(),
              type == Linker.LinkableDepType.STATIC
                  ? CxxSourceRuleFactory.PicType.PDC
                  : CxxSourceRuleFactory.PicType.PIC);
      if (linkWhole) {
        Linker linker = cxxPlatform.getLd();
        linkerArgsBuilder.addAll(linker.linkWhole(staticLibraryPath.toString()));
      } else {
        linkerArgsBuilder.add(staticLibraryPath.toString());
      }
    } else {
      String sharedLibrarySoname =
          soname.or(
              CxxDescriptionEnhancer.getDefaultSharedLibrarySoname(
                  params.getBuildTarget(), cxxPlatform));
      Path sharedLibraryPath =
          CxxDescriptionEnhancer.getSharedLibraryPath(
              getBuildTarget(), sharedLibrarySoname, cxxPlatform);
      libraryRule =
          requireBuildRule(
              targetGraph, cxxPlatform.getFlavor(), CxxDescriptionEnhancer.SHARED_FLAVOR);
      linkerArgsBuilder.add(sharedLibraryPath.toString());
    }
    final ImmutableList<String> linkerArgs = linkerArgsBuilder.build();

    return NativeLinkableInput.of(
        ImmutableList.<SourcePath>builder()
            .add(new BuildTargetSourcePath(libraryRule.getBuildTarget()))
            .addAll(flagsAndBuildInputs.getSecond())
            .build(),
        linkerArgs,
        Preconditions.checkNotNull(frameworks),
        Preconditions.checkNotNull(libraries));
  }