Search in sources :

Example 16 with Flavor

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

the class DistBuildTargetGraphCodec method decodeBuildTarget.

public static BuildTarget decodeBuildTarget(BuildJobStateBuildTarget remoteTarget, Cell cell) {
    UnflavoredBuildTarget unflavoredBuildTarget = UnflavoredBuildTarget.builder().setShortName(remoteTarget.getShortName()).setBaseName(remoteTarget.getBaseName()).setCellPath(cell.getRoot()).setCell(Optional.ofNullable(remoteTarget.getCellName())).build();
    ImmutableSet<Flavor> flavors = remoteTarget.flavors.stream().map(InternalFlavor::of).collect(MoreCollectors.toImmutableSet());
    return BuildTarget.builder().setUnflavoredBuildTarget(unflavoredBuildTarget).setFlavors(flavors).build();
}
Also used : UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor)

Example 17 with Flavor

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

the class PythonLibraryDescription method createMetadata.

@Override
public <A extends Arg, U> Optional<U> createMetadata(BuildTarget buildTarget, BuildRuleResolver resolver, A args, Optional<ImmutableMap<BuildTarget, Version>> selectedVersions, 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 PACKAGE_COMPONENTS:
            {
                Map.Entry<Flavor, PythonPlatform> pythonPlatform = pythonPlatforms.getFlavorAndValue(baseTarget).orElseThrow(IllegalArgumentException::new);
                Map.Entry<Flavor, CxxPlatform> cxxPlatform = cxxPlatforms.getFlavorAndValue(baseTarget).orElseThrow(IllegalArgumentException::new);
                baseTarget = buildTarget.withoutFlavors(pythonPlatform.getKey(), cxxPlatform.getKey());
                SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
                SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
                Path baseModule = PythonUtil.getBasePath(baseTarget, args.baseModule);
                PythonPackageComponents components = PythonPackageComponents.of(PythonUtil.getModules(baseTarget, resolver, ruleFinder, pathResolver, pythonPlatform.getValue(), cxxPlatform.getValue(), "srcs", baseModule, args.srcs, args.platformSrcs, args.versionedSrcs, selectedVersions), PythonUtil.getModules(baseTarget, resolver, ruleFinder, pathResolver, pythonPlatform.getValue(), cxxPlatform.getValue(), "resources", baseModule, args.resources, args.platformResources, args.versionedResources, selectedVersions), ImmutableMap.of(), ImmutableSet.of(), args.zipSafe);
                return Optional.of(components).map(metadataClass::cast);
            }
    }
    throw new IllegalStateException();
}
Also used : Path(java.nio.file.Path) BuildTarget(com.facebook.buck.model.BuildTarget) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 18 with Flavor

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

the class UnexpectedFlavorException method createWithSuggestions.

public static UnexpectedFlavorException createWithSuggestions(Cell cell, BuildTarget target) {
    // Get the specific message
    String exceptionMessage = createDefaultMessage(cell, target);
    // Get some suggestions on how to solve it.
    String suggestions = "";
    Optional<ImmutableSet<PatternAndMessage>> configMessagesForFlavors = cell.getBuckConfig().getUnexpectedFlavorsMessages();
    for (Flavor flavor : target.getFlavors()) {
        boolean foundInConfig = false;
        if (configMessagesForFlavors.isPresent()) {
            for (PatternAndMessage flavorPattern : configMessagesForFlavors.get()) {
                if (flavorPattern.getPattern().matcher(flavor.getName()).find()) {
                    foundInConfig = true;
                    suggestions += flavor.getName() + " : " + flavorPattern.getMessage() + "\n";
                }
            }
        }
        if (!foundInConfig) {
            for (PatternAndMessage flavorPattern : suggestedMessagesForFlavors) {
                if (flavorPattern.getPattern().matcher(flavor.getName()).find()) {
                    suggestions += flavor.getName() + " : " + flavorPattern.getMessage() + "\n";
                }
            }
        }
    }
    if (!suggestions.isEmpty()) {
        exceptionMessage += "\nHere are some things you can try to get the following " + "flavors to work::\n" + suggestions;
    }
    return new UnexpectedFlavorException(exceptionMessage);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Flavor(com.facebook.buck.model.Flavor) PatternAndMessage(com.facebook.buck.util.PatternAndMessage)

Example 19 with Flavor

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

the class BuildRuleParams method withAppendedFlavor.

public BuildRuleParams withAppendedFlavor(Flavor flavor) {
    Set<Flavor> flavors = Sets.newHashSet(getBuildTarget().getFlavors());
    flavors.add(flavor);
    BuildTarget target = BuildTarget.builder(getBuildTarget().getUnflavoredBuildTarget()).addAllFlavors(flavors).build();
    return new BuildRuleParams(this, target, projectFilesystem, cellRoots);
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) Flavor(com.facebook.buck.model.Flavor)

Example 20 with Flavor

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

the class SwiftLibraryDescription method createBuildRule.

@Override
public <A extends SwiftLibraryDescription.Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, final BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    Optional<LinkerMapMode> flavoredLinkerMapMode = LinkerMapMode.FLAVOR_DOMAIN.getValue(params.getBuildTarget());
    params = LinkerMapMode.removeLinkerMapModeFlavorInParams(params, flavoredLinkerMapMode);
    final BuildTarget buildTarget = params.getBuildTarget();
    // See if we're building a particular "type" and "platform" of this library, and if so, extract
    // them from the flavors attached to the build target.
    Optional<Map.Entry<Flavor, CxxPlatform>> platform = cxxPlatformFlavorDomain.getFlavorAndValue(buildTarget);
    final ImmutableSortedSet<Flavor> buildFlavors = buildTarget.getFlavors();
    ImmutableSortedSet<BuildRule> filteredExtraDeps = params.getExtraDeps().get().stream().filter(input -> !input.getBuildTarget().getUnflavoredBuildTarget().equals(buildTarget.getUnflavoredBuildTarget())).collect(MoreCollectors.toImmutableSortedSet());
    params = params.copyReplacingExtraDeps(Suppliers.ofInstance(filteredExtraDeps));
    if (!buildFlavors.contains(SWIFT_COMPANION_FLAVOR) && platform.isPresent()) {
        final CxxPlatform cxxPlatform = platform.get().getValue();
        Optional<SwiftPlatform> swiftPlatform = swiftPlatformFlavorDomain.getValue(buildTarget);
        if (!swiftPlatform.isPresent()) {
            throw new HumanReadableException("Platform %s is missing swift compiler", cxxPlatform);
        }
        // See if we're building a particular "type" and "platform" of this library, and if so,
        // extract them from the flavors attached to the build target.
        Optional<Map.Entry<Flavor, Type>> type = LIBRARY_TYPE.getFlavorAndValue(buildTarget);
        if (!buildFlavors.contains(SWIFT_COMPILE_FLAVOR) && type.isPresent()) {
            Set<Flavor> flavors = Sets.newHashSet(params.getBuildTarget().getFlavors());
            flavors.remove(type.get().getKey());
            BuildTarget target = BuildTarget.builder(params.getBuildTarget().getUnflavoredBuildTarget()).addAllFlavors(flavors).build();
            if (flavoredLinkerMapMode.isPresent()) {
                target = target.withAppendedFlavors(flavoredLinkerMapMode.get().getFlavor());
            }
            BuildRuleParams typeParams = params.withBuildTarget(target);
            switch(type.get().getValue()) {
                case SHARED:
                    return createSharedLibraryBuildRule(typeParams, resolver, target, swiftPlatform.get(), cxxPlatform, args.soname, flavoredLinkerMapMode);
                case STATIC:
                case MACH_O_BUNDLE:
            }
            throw new RuntimeException("unhandled library build type");
        }
        // All swift-compile rules of swift-lib deps are required since we need their swiftmodules
        // during compilation.
        final Function<BuildRule, BuildRule> requireSwiftCompile = input -> {
            try {
                Preconditions.checkArgument(input instanceof SwiftLibrary);
                return ((SwiftLibrary) input).requireSwiftCompileRule(cxxPlatform.getFlavor());
            } catch (NoSuchBuildTargetException e) {
                throw new HumanReadableException(e, "Could not find SwiftCompile with target %s", buildTarget);
            }
        };
        params = params.copyAppendingExtraDeps(params.getDeps().stream().filter(SwiftLibrary.class::isInstance).map(requireSwiftCompile).collect(MoreCollectors.toImmutableSet()));
        params = params.copyAppendingExtraDeps(params.getDeps().stream().filter(CxxLibrary.class::isInstance).map(input -> {
            BuildTarget companionTarget = input.getBuildTarget().withAppendedFlavors(SWIFT_COMPANION_FLAVOR);
            return resolver.getRuleOptional(companionTarget).map(requireSwiftCompile);
        }).filter(Optional::isPresent).map(Optional::get).collect(MoreCollectors.toImmutableSortedSet()));
        return new SwiftCompile(cxxPlatform, swiftBuckConfig, params, swiftPlatform.get().getSwift(), args.frameworks, args.moduleName.orElse(buildTarget.getShortName()), BuildTargets.getGenPath(params.getProjectFilesystem(), buildTarget, "%s"), args.srcs, args.compilerFlags, args.enableObjcInterop, args.bridgingHeader);
    }
    // Otherwise, we return the generic placeholder of this library.
    params = LinkerMapMode.restoreLinkerMapModeFlavorInParams(params, flavoredLinkerMapMode);
    return new SwiftLibrary(params, resolver, ImmutableSet.of(), swiftPlatformFlavorDomain, args.frameworks, args.libraries, args.supportedPlatformsRegex, args.preferredLinkage.orElse(NativeLinkable.Linkage.ANY));
}
Also used : CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) Linker(com.facebook.buck.cxx.Linker) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) CxxLibraryDescription(com.facebook.buck.cxx.CxxLibraryDescription) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) RichStream(com.facebook.buck.util.RichStream) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavored(com.facebook.buck.model.Flavored) Function(java.util.function.Function) BuildRule(com.facebook.buck.rules.BuildRule) FlavorDomain(com.facebook.buck.model.FlavorDomain) ImmutableList(com.google.common.collect.ImmutableList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Map(java.util.Map) NativeLinkable(com.facebook.buck.cxx.NativeLinkable) Predicates(com.google.common.base.Predicates) Suppliers(com.google.common.base.Suppliers) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) CxxDescriptionEnhancer(com.facebook.buck.cxx.CxxDescriptionEnhancer) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) CxxLinkableEnhancer(com.facebook.buck.cxx.CxxLinkableEnhancer) ImmutableSet(com.google.common.collect.ImmutableSet) FlavorConvertible(com.facebook.buck.model.FlavorConvertible) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) TargetGraph(com.facebook.buck.rules.TargetGraph) Set(java.util.Set) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) Sets(com.google.common.collect.Sets) LinkerMapMode(com.facebook.buck.cxx.LinkerMapMode) AbstractDescriptionArg(com.facebook.buck.rules.AbstractDescriptionArg) CxxLibrary(com.facebook.buck.cxx.CxxLibrary) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Pattern(java.util.regex.Pattern) BuildTargets(com.facebook.buck.model.BuildTargets) Description(com.facebook.buck.rules.Description) CxxLibrary(com.facebook.buck.cxx.CxxLibrary) Optional(java.util.Optional) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) LinkerMapMode(com.facebook.buck.cxx.LinkerMapMode) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildRule(com.facebook.buck.rules.BuildRule)

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