Search in sources :

Example 11 with Flavor

use of com.facebook.buck.model.Flavor in project buck by facebook.

the class AppleLibraryDescription method createMetadataForLibrary.

<U> Optional<U> createMetadataForLibrary(BuildTarget buildTarget, BuildRuleResolver resolver, Optional<ImmutableMap<BuildTarget, Version>> selectedVersions, AppleNativeTargetDescriptionArg args, Class<U> metadataClass) throws NoSuchBuildTargetException {
    // Forward to C/C++ library description.
    if (CxxLibraryDescription.METADATA_TYPE.containsAnyOf(buildTarget.getFlavors())) {
        CxxLibraryDescription.Arg delegateArg = delegate.createUnpopulatedConstructorArg();
        AppleDescriptions.populateCxxLibraryDescriptionArg(new SourcePathResolver(new SourcePathRuleFinder(resolver)), delegateArg, args, buildTarget);
        return delegate.createMetadata(buildTarget, resolver, delegateArg, selectedVersions, metadataClass);
    }
    if (metadataClass.isAssignableFrom(FrameworkDependencies.class) && buildTarget.getFlavors().contains(AppleDescriptions.FRAMEWORK_FLAVOR)) {
        Optional<Flavor> cxxPlatformFlavor = delegate.getCxxPlatforms().getFlavor(buildTarget);
        Preconditions.checkState(cxxPlatformFlavor.isPresent(), "Could not find cxx platform in:\n%s", Joiner.on(", ").join(buildTarget.getFlavors()));
        ImmutableSet.Builder<SourcePath> sourcePaths = ImmutableSet.builder();
        for (BuildTarget dep : args.deps) {
            Optional<FrameworkDependencies> frameworks = resolver.requireMetadata(BuildTarget.builder(dep).addFlavors(AppleDescriptions.FRAMEWORK_FLAVOR).addFlavors(AppleDescriptions.NO_INCLUDE_FRAMEWORKS_FLAVOR).addFlavors(cxxPlatformFlavor.get()).build(), FrameworkDependencies.class);
            if (frameworks.isPresent()) {
                sourcePaths.addAll(frameworks.get().getSourcePaths());
            }
        }
        // Not all parts of Buck use require yet, so require the rule here so it's available in the
        // resolver for the parts that don't.
        BuildRule buildRule = resolver.requireRule(buildTarget);
        sourcePaths.add(buildRule.getSourcePathToOutput());
        return Optional.of(metadataClass.cast(FrameworkDependencies.of(sourcePaths.build())));
    }
    return Optional.empty();
}
Also used : CxxLibraryDescription(com.facebook.buck.cxx.CxxLibraryDescription) FrameworkDependencies(com.facebook.buck.cxx.FrameworkDependencies) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) SourcePath(com.facebook.buck.rules.SourcePath) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule)

Example 12 with Flavor

use of com.facebook.buck.model.Flavor in project buck by facebook.

the class ApplePackageDescription method addDepsFromParam.

/**
   * Retrieve deps from macros in externally configured rules.
   *
   * This is used for ImplicitDepsInferringDescription, so it is flavor agnostic.
   */
private void addDepsFromParam(ImmutableSet.Builder<BuildTarget> builder, BuildTarget target, CellPathResolver cellNames) {
    // Add all macro expanded dependencies for these platforms.
    for (Flavor flavor : appleCxxPlatformFlavorDomain.getFlavors()) {
        AppleCxxPlatform platform = appleCxxPlatformFlavorDomain.getValue(flavor);
        Optional<ApplePackageConfig> packageConfig = config.getPackageConfigForPlatform(platform.getAppleSdk().getApplePlatform());
        if (packageConfig.isPresent()) {
            try {
                builder.addAll(AbstractGenruleDescription.PARSE_TIME_MACRO_HANDLER.extractParseTimeDeps(target, cellNames, packageConfig.get().getCommand()));
            } catch (MacroException e) {
                throw new HumanReadableException(e, "%s (for platform %s): %s", target, platform.getAppleSdk().getApplePlatform().getName(), e.getMessage());
            }
        }
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) MacroException(com.facebook.buck.model.MacroException) Flavor(com.facebook.buck.model.Flavor)

Example 13 with Flavor

use of com.facebook.buck.model.Flavor in project buck by facebook.

the class CxxLibraryDescription method addImplicitFlavorsForRuleTypes.

public ImmutableSortedSet<Flavor> addImplicitFlavorsForRuleTypes(ImmutableSortedSet<Flavor> argDefaultFlavors, BuildRuleType... types) {
    Optional<Flavor> typeFlavor = LIBRARY_TYPE.getFlavor(argDefaultFlavors);
    Optional<Flavor> platformFlavor = getCxxPlatforms().getFlavor(argDefaultFlavors);
    LOG.debug("Got arg default type %s platform %s", typeFlavor, platformFlavor);
    for (BuildRuleType type : types) {
        ImmutableMap<String, Flavor> libraryDefaults = cxxBuckConfig.getDefaultFlavorsForRuleType(type);
        if (!typeFlavor.isPresent()) {
            typeFlavor = Optional.ofNullable(libraryDefaults.get(CxxBuckConfig.DEFAULT_FLAVOR_LIBRARY_TYPE));
        }
        if (!platformFlavor.isPresent()) {
            platformFlavor = Optional.ofNullable(libraryDefaults.get(CxxBuckConfig.DEFAULT_FLAVOR_PLATFORM));
        }
    }
    ImmutableSortedSet<Flavor> result = ImmutableSortedSet.of(// Default to static if not otherwise specified.
    typeFlavor.orElse(CxxDescriptionEnhancer.STATIC_FLAVOR), platformFlavor.orElse(defaultCxxPlatform.getFlavor()));
    LOG.debug("Got default flavors %s for rule types %s", result, Arrays.toString(types));
    return result;
}
Also used : BuildRuleType(com.facebook.buck.rules.BuildRuleType) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor)

Example 14 with Flavor

use of com.facebook.buck.model.Flavor in project buck by facebook.

the class CxxLibraryDescription method createMetadata.

@Override
public <A extends Arg, U> Optional<U> createMetadata(BuildTarget buildTarget, BuildRuleResolver resolver, A args, Optional<ImmutableMap<BuildTarget, Version>> selectedVersions, final Class<U> metadataClass) throws NoSuchBuildTargetException {
    Map.Entry<Flavor, MetadataType> type = METADATA_TYPE.getFlavorAndValue(buildTarget).orElseThrow(IllegalArgumentException::new);
    BuildTarget baseTarget = buildTarget.withoutFlavors(type.getKey());
    switch(type.getValue()) {
        case CXX_HEADERS:
            {
                Optional<CxxHeaders> symlinkTree = Optional.empty();
                if (!args.exportedHeaders.isEmpty()) {
                    CxxPreprocessables.HeaderMode mode = HEADER_MODE.getRequiredValue(buildTarget);
                    baseTarget = baseTarget.withoutFlavors(mode.getFlavor());
                    symlinkTree = Optional.of(CxxSymlinkTreeHeaders.from((HeaderSymlinkTree) resolver.requireRule(baseTarget.withAppendedFlavors(Type.EXPORTED_HEADERS.getFlavor(), mode.getFlavor())), CxxPreprocessables.IncludeType.LOCAL));
                }
                return symlinkTree.map(metadataClass::cast);
            }
        case CXX_PREPROCESSOR_INPUT:
            {
                Map.Entry<Flavor, CxxPlatform> platform = cxxPlatforms.getFlavorAndValue(buildTarget).orElseThrow(IllegalArgumentException::new);
                Map.Entry<Flavor, HeaderVisibility> visibility = HEADER_VISIBILITY.getFlavorAndValue(buildTarget).orElseThrow(IllegalArgumentException::new);
                baseTarget = baseTarget.withoutFlavors(platform.getKey(), visibility.getKey());
                CxxPreprocessorInput.Builder cxxPreprocessorInputBuilder = CxxPreprocessorInput.builder();
                // TODO(andrewjcg): We currently always add exported flags and frameworks to the
                // preprocessor input to mimic existing behavior, but this should likely be fixed.
                cxxPreprocessorInputBuilder.putAllPreprocessorFlags(CxxFlags.getLanguageFlags(args.exportedPreprocessorFlags, args.exportedPlatformPreprocessorFlags, args.exportedLangPreprocessorFlags, platform.getValue()));
                cxxPreprocessorInputBuilder.addAllFrameworks(args.frameworks);
                if (visibility.getValue() == HeaderVisibility.PRIVATE && !args.headers.isEmpty()) {
                    HeaderSymlinkTree symlinkTree = (HeaderSymlinkTree) resolver.requireRule(baseTarget.withAppendedFlavors(platform.getKey(), Type.HEADERS.getFlavor()));
                    cxxPreprocessorInputBuilder.addIncludes(CxxSymlinkTreeHeaders.from(symlinkTree, CxxPreprocessables.IncludeType.LOCAL));
                }
                if (visibility.getValue() == HeaderVisibility.PUBLIC) {
                    // Add platform-agnostic headers.
                    boolean shouldCreatePublicHeaderSymlinks = args.xcodePublicHeadersSymlinks.orElse(true);
                    CxxPreprocessables.HeaderMode mode = CxxDescriptionEnhancer.getHeaderModeForPlatform(resolver, platform.getValue(), shouldCreatePublicHeaderSymlinks);
                    Optional<CxxHeaders> exportedHeaders = resolver.requireMetadata(baseTarget.withAppendedFlavors(MetadataType.CXX_HEADERS.getFlavor(), mode.getFlavor()), CxxHeaders.class);
                    exportedHeaders.ifPresent(cxxPreprocessorInputBuilder::addIncludes);
                    // Add platform-specific headers.
                    if (!args.exportedPlatformHeaders.getMatchingValues(platform.getKey().toString()).isEmpty()) {
                        HeaderSymlinkTree symlinkTree = (HeaderSymlinkTree) resolver.requireRule(baseTarget.withAppendedFlavors(platform.getKey(), Type.EXPORTED_HEADERS.getFlavor()));
                        cxxPreprocessorInputBuilder.addIncludes(CxxSymlinkTreeHeaders.from(symlinkTree, CxxPreprocessables.IncludeType.LOCAL));
                    }
                }
                CxxPreprocessorInput cxxPreprocessorInput = cxxPreprocessorInputBuilder.build();
                return Optional.of(cxxPreprocessorInput).map(metadataClass::cast);
            }
        case COMPILATION_DATABASE_DEPS:
            {
                return CxxDescriptionEnhancer.createCompilationDatabaseDependencies(buildTarget, cxxPlatforms, resolver, args).map(metadataClass::cast);
            }
    }
    throw new IllegalStateException(String.format("unhandled metadata type: %s", type.getValue()));
}
Also used : Optional(java.util.Optional) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) BuildTarget(com.facebook.buck.model.BuildTarget) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 15 with Flavor

use of com.facebook.buck.model.Flavor in project buck by facebook.

the class CxxPlatforms method getHostFlavor.

public static Flavor getHostFlavor() {
    String platformName = Platform.detect().getAutoconfName();
    Flavor hostFlavor = getHostFlavorMap().get(platformName);
    if (hostFlavor == null) {
        throw new HumanReadableException("Unable to determine the host platform.");
    }
    return hostFlavor;
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor)

Aggregations

Flavor (com.facebook.buck.model.Flavor)60 InternalFlavor (com.facebook.buck.model.InternalFlavor)42 BuildTarget (com.facebook.buck.model.BuildTarget)33 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)17 Test (org.junit.Test)17 SourcePath (com.facebook.buck.rules.SourcePath)14 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)14 ImmutableMap (com.google.common.collect.ImmutableMap)14 BuildRule (com.facebook.buck.rules.BuildRule)13 ImmutableSet (com.google.common.collect.ImmutableSet)13 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)12 HumanReadableException (com.facebook.buck.util.HumanReadableException)12 Path (java.nio.file.Path)12 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)11 Optional (java.util.Optional)10 ImmutableList (com.google.common.collect.ImmutableList)9 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)9 Map (java.util.Map)9 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)7 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)6