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();
}
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();
}
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);
}
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);
}
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));
}
Aggregations