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