in src/com/facebook/buck/apple/AppleDescriptions.java [642:924]
static AppleBundle createAppleBundle(
XCodeDescriptions xcodeDescriptions,
CxxPlatformsProvider cxxPlatformsProvider,
FlavorDomain<UnresolvedAppleCxxPlatform> appleCxxPlatforms,
TargetGraph targetGraph,
BuildTarget buildTarget,
ProjectFilesystem projectFilesystem,
BuildRuleParams params,
ActionGraphBuilder graphBuilder,
CodeSignIdentityStore codeSignIdentityStore,
ProvisioningProfileStore provisioningProfileStore,
Optional<BuildTarget> binary,
Optional<PatternMatchedCollection<BuildTarget>> platformBinary,
Optional<Flavor> defaultPlatform,
Either<AppleBundleExtension, String> extension,
Optional<String> productName,
SourcePath infoPlist,
ImmutableMap<String, String> infoPlistSubstitutions,
ImmutableSortedSet<BuildTarget> deps,
ImmutableSortedSet<BuildTarget> tests,
AppleDebugFormat debugFormat,
boolean dryRunCodeSigning,
boolean cacheable,
boolean verifyResources,
ValidationType assetCatalogValidation,
AppleAssetCatalogsCompilationOptions appleAssetCatalogsCompilationOptions,
ImmutableList<String> codesignFlags,
Optional<String> codesignAdhocIdentity,
Optional<Boolean> ibtoolModuleFlag,
Optional<ImmutableList<String>> ibtoolFlags,
Optional<String> productType,
Duration codesignTimeout,
boolean copySwiftStdlibToFrameworks,
boolean useLipoThin,
boolean cacheStrips,
boolean useEntitlementsWhenAdhocCodeSigning,
Predicate<BuildTarget> filter,
Optional<Boolean> isAppClip) {
AppleCxxPlatform appleCxxPlatform =
ApplePlatforms.getAppleCxxPlatformForBuildTarget(
graphBuilder,
cxxPlatformsProvider,
appleCxxPlatforms,
buildTarget,
defaultPlatform,
MultiarchFileInfos.create(appleCxxPlatforms, buildTarget));
BuildTarget binaryTarget =
getTargetPlatformBinary(binary, platformBinary, appleCxxPlatform.getFlavor());
AppleBundleDestinations destinations;
if (extension.isLeft() && extension.getLeft().equals(AppleBundleExtension.FRAMEWORK)) {
destinations =
AppleBundleDestinations.platformFrameworkDestinations(
appleCxxPlatform.getAppleSdk().getApplePlatform());
} else {
destinations =
AppleBundleDestinations.platformDestinations(
appleCxxPlatform.getAppleSdk().getApplePlatform());
}
AppleBundleResources collectedResources =
AppleResources.collectResourceDirsAndFiles(
xcodeDescriptions,
targetGraph,
graphBuilder,
Optional.empty(),
targetGraph.get(buildTarget),
appleCxxPlatform,
RecursiveDependenciesMode.COPYING,
filter);
ImmutableSet.Builder<SourcePath> frameworksBuilder = ImmutableSet.builder();
if (INCLUDE_FRAMEWORKS.getRequiredValue(buildTarget)) {
for (BuildTarget dep : deps) {
Optional<FrameworkDependencies> frameworkDependencies =
graphBuilder.requireMetadata(
dep.withAppendedFlavors(
FRAMEWORK_FLAVOR,
NO_INCLUDE_FRAMEWORKS_FLAVOR,
appleCxxPlatform.getCxxPlatform().getFlavor()),
FrameworkDependencies.class);
if (frameworkDependencies.isPresent()) {
frameworksBuilder.addAll(frameworkDependencies.get().getSourcePaths());
}
}
}
// TODO(17155714): framework embedding is currently oddly entwined with framework generation.
// This change simply treats all the immediate prebuilt framework dependencies as wishing to be
// embedded, but in the future this should be dealt with with some greater sophistication.
for (BuildTarget dep : deps) {
Optional<TargetNode<PrebuiltAppleFrameworkDescriptionArg>> prebuiltNode =
targetGraph
.getOptional(dep)
.flatMap(
node -> TargetNodes.castArg(node, PrebuiltAppleFrameworkDescriptionArg.class));
if (prebuiltNode.isPresent()
&& !prebuiltNode
.get()
.getConstructorArg()
.getPreferredLinkage()
.equals(NativeLinkableGroup.Linkage.STATIC)) {
frameworksBuilder.add(graphBuilder.requireRule(dep).getSourcePathToOutput());
}
}
ImmutableSet<SourcePath> frameworks = frameworksBuilder.build();
BuildTarget buildTargetWithoutBundleSpecificFlavors = stripBundleSpecificFlavors(buildTarget);
Optional<AppleAssetCatalog> assetCatalog =
createBuildRuleForTransitiveAssetCatalogDependencies(
xcodeDescriptions,
targetGraph,
buildTargetWithoutBundleSpecificFlavors,
projectFilesystem,
graphBuilder,
productType,
appleCxxPlatform.getAppleSdk().getApplePlatform(),
appleCxxPlatform.getMinVersion(),
appleCxxPlatform.getActool(),
assetCatalogValidation,
appleAssetCatalogsCompilationOptions,
filter);
addToIndex(graphBuilder, assetCatalog);
Optional<CoreDataModel> coreDataModel =
createBuildRulesForCoreDataDependencies(
xcodeDescriptions,
targetGraph,
buildTargetWithoutBundleSpecificFlavors,
projectFilesystem,
params,
AppleBundle.getBinaryName(buildTarget, productName),
appleCxxPlatform,
filter);
addToIndex(graphBuilder, coreDataModel);
Optional<SceneKitAssets> sceneKitAssets =
createBuildRulesForSceneKitAssetsDependencies(
xcodeDescriptions,
targetGraph,
buildTargetWithoutBundleSpecificFlavors,
projectFilesystem,
params,
appleCxxPlatform,
filter);
addToIndex(graphBuilder, sceneKitAssets);
// TODO(beng): Sort through the changes needed to make project generation work with
// binary being optional.
FlavorSet flavoredBinaryRuleFlavors = buildTargetWithoutBundleSpecificFlavors.getFlavors();
BuildRule flavoredBinaryRule =
getFlavoredBinaryRule(
cxxPlatformsProvider,
targetGraph,
flavoredBinaryRuleFlavors.getSet(),
defaultPlatform,
graphBuilder,
binaryTarget);
if (!AppleDebuggableBinary.isBuildRuleDebuggable(flavoredBinaryRule)) {
debugFormat = AppleDebugFormat.NONE;
}
BuildTarget unstrippedTarget =
flavoredBinaryRule
.getBuildTarget()
.withoutFlavors(
CxxStrip.RULE_FLAVOR,
AppleDebuggableBinary.RULE_FLAVOR,
AppleBinaryDescription.APP_FLAVOR)
.withoutFlavors(StripStyle.FLAVOR_DOMAIN.getFlavors())
.withoutFlavors(AppleDebugFormat.FLAVOR_DOMAIN.getFlavors())
.withoutFlavors(AppleDebuggableBinary.RULE_FLAVOR)
.withoutFlavors(ImmutableSet.of(AppleBinaryDescription.APP_FLAVOR));
Optional<LinkerMapMode> linkerMapMode = LinkerMapMode.FLAVOR_DOMAIN.getValue(buildTarget);
if (linkerMapMode.isPresent()) {
unstrippedTarget = unstrippedTarget.withAppendedFlavors(linkerMapMode.get().getFlavor());
}
BuildRule unstrippedBinaryRule = graphBuilder.requireRule(unstrippedTarget);
BuildRule targetDebuggableBinaryRule;
Optional<AppleDsym> appleDsym;
if (unstrippedBinaryRule instanceof HasAppleDebugSymbolDeps) {
BuildTarget binaryBuildTarget =
getBinaryFromBuildRuleWithBinary(flavoredBinaryRule)
.getBuildTarget()
.withoutFlavors(AppleDebugFormat.FLAVOR_DOMAIN.getFlavors());
ProjectFilesystem binaryBuildTargetFilesystem =
targetGraph
.get(binaryBuildTarget, DependencyStack.top(binaryBuildTarget))
.getFilesystem();
AppleDebuggableBinary debuggableBinary =
createAppleDebuggableBinary(
binaryBuildTarget,
binaryBuildTargetFilesystem,
graphBuilder,
getBinaryFromBuildRuleWithBinary(flavoredBinaryRule),
(HasAppleDebugSymbolDeps) unstrippedBinaryRule,
debugFormat,
cxxPlatformsProvider,
appleCxxPlatforms,
cacheStrips);
targetDebuggableBinaryRule = debuggableBinary;
appleDsym = debuggableBinary.getAppleDsym();
} else {
targetDebuggableBinaryRule = unstrippedBinaryRule;
appleDsym = Optional.empty();
}
ImmutableList<String> ibtoolFlagsUnwrapped = ibtoolFlags.orElse(ImmutableList.of());
ImmutableSet<BuildRule> extraBinaries =
collectFirstLevelExtraBinariesFromDeps(
appleCxxPlatform.getAppleSdk().getApplePlatform().getType(),
deps,
binaryTarget,
cxxPlatformsProvider,
targetGraph,
flavoredBinaryRuleFlavors.getSet(),
defaultPlatform,
graphBuilder);
BuildRuleParams bundleParamsWithFlavoredBinaryDep =
getBundleParamsWithUpdatedDeps(
params,
binaryTarget,
ImmutableSet.<BuildRule>builder()
.add(targetDebuggableBinaryRule)
.addAll(RichStream.from(assetCatalog).iterator())
.addAll(RichStream.from(coreDataModel).iterator())
.addAll(RichStream.from(sceneKitAssets).iterator())
.addAll(
BuildRules.toBuildRulesFor(
buildTarget,
graphBuilder,
RichStream.from(collectedResources.getAll())
.concat(frameworks.stream())
.filter(BuildTargetSourcePath.class)
.map(BuildTargetSourcePath::getTarget)
.collect(ImmutableSet.toImmutableSet())))
.addAll(RichStream.from(appleDsym).iterator())
.addAll(extraBinaries)
.build());
ImmutableMap<SourcePath, String> extensionBundlePaths =
collectFirstLevelAppleDependencyBundles(params.getBuildDeps(), destinations);
return new AppleBundle(
buildTarget,
projectFilesystem,
bundleParamsWithFlavoredBinaryDep,
graphBuilder,
extension,
productName,
infoPlist,
infoPlistSubstitutions,
Optional.of(getBinaryFromBuildRuleWithBinary(flavoredBinaryRule)),
appleDsym,
extraBinaries,
destinations,
collectedResources,
extensionBundlePaths,
frameworks,
appleCxxPlatform,
assetCatalog,
coreDataModel,
sceneKitAssets,
tests,
codeSignIdentityStore,
provisioningProfileStore,
dryRunCodeSigning,
cacheable,
verifyResources,
codesignFlags,
codesignAdhocIdentity,
ibtoolModuleFlag,
ibtoolFlagsUnwrapped,
codesignTimeout,
copySwiftStdlibToFrameworks,
useLipoThin,
useEntitlementsWhenAdhocCodeSigning,
isAppClip);
}