use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class MultiarchFileInfos method create.
/**
* Inspect the given build target and return information about it if its a fat binary.
*
* @return non-empty when the target represents a fat binary.
* @throws com.facebook.buck.util.HumanReadableException
* when the target is a fat binary but has incompatible flavors.
*/
public static Optional<MultiarchFileInfo> create(final FlavorDomain<AppleCxxPlatform> appleCxxPlatforms, BuildTarget target) {
ImmutableList<ImmutableSortedSet<Flavor>> thinFlavorSets = generateThinFlavors(appleCxxPlatforms.getFlavors(), target.getFlavors());
if (thinFlavorSets.size() <= 1) {
// Actually a thin binary
return Optional.empty();
}
if (!Sets.intersection(target.getFlavors(), FORBIDDEN_BUILD_ACTIONS).isEmpty()) {
throw new HumanReadableException("%s: Fat binaries is only supported when building an actual binary.", target);
}
AppleCxxPlatform representativePlatform = null;
AppleSdk sdk = null;
for (SortedSet<Flavor> flavorSet : thinFlavorSets) {
AppleCxxPlatform platform = Preconditions.checkNotNull(appleCxxPlatforms.getValue(flavorSet).orElse(null));
if (sdk == null) {
sdk = platform.getAppleSdk();
representativePlatform = platform;
} else if (sdk != platform.getAppleSdk()) {
throw new HumanReadableException("%s: Fat binaries can only be generated from binaries compiled for the same SDK.", target);
}
}
MultiarchFileInfo.Builder builder = MultiarchFileInfo.builder().setFatTarget(target).setRepresentativePlatform(Preconditions.checkNotNull(representativePlatform));
BuildTarget platformFreeTarget = target.withoutFlavors(appleCxxPlatforms.getFlavors());
for (SortedSet<Flavor> flavorSet : thinFlavorSets) {
builder.addThinTargets(platformFreeTarget.withFlavors(flavorSet));
}
return Optional.of(builder.build());
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class WorkspaceAndProjectGenerator method addWorkspaceScheme.
private static void addWorkspaceScheme(TargetGraph projectGraph, AppleDependenciesCache dependenciesCache, String schemeName, XcodeWorkspaceConfigDescription.Arg schemeArguments, ImmutableMap.Builder<String, XcodeWorkspaceConfigDescription.Arg> schemeConfigsBuilder, ImmutableSetMultimap.Builder<String, Optional<TargetNode<?, ?>>> schemeNameToSrcTargetNodeBuilder, ImmutableSetMultimap.Builder<String, TargetNode<AppleTestDescription.Arg, ?>> extraTestNodesBuilder) {
LOG.debug("Adding scheme %s", schemeName);
schemeConfigsBuilder.put(schemeName, schemeArguments);
if (schemeArguments.srcTarget.isPresent()) {
schemeNameToSrcTargetNodeBuilder.putAll(schemeName, Iterables.transform(AppleBuildRules.getSchemeBuildableTargetNodes(projectGraph, Optional.of(dependenciesCache), projectGraph.get(schemeArguments.srcTarget.get())), Optional::of));
} else {
schemeNameToSrcTargetNodeBuilder.put(XcodeWorkspaceConfigDescription.getWorkspaceNameFromArg(schemeArguments), Optional.empty());
}
for (BuildTarget extraTarget : schemeArguments.extraTargets) {
schemeNameToSrcTargetNodeBuilder.putAll(schemeName, Iterables.transform(AppleBuildRules.getSchemeBuildableTargetNodes(projectGraph, Optional.of(dependenciesCache), Preconditions.checkNotNull(projectGraph.get(extraTarget))), Optional::of));
}
extraTestNodesBuilder.putAll(schemeName, getExtraTestTargetNodes(projectGraph, schemeArguments.extraTests));
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class WorkspaceAndProjectGenerator method generateProject.
private void generateProject(final Map<Path, ProjectGenerator> projectGenerators, ListeningExecutorService listeningExecutorService, WorkspaceGenerator workspaceGenerator, ImmutableSet<BuildTarget> targetsInRequiredProjects, ImmutableMultimap.Builder<BuildTarget, PBXTarget> buildTargetToPbxTargetMapBuilder, ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder, final Optional<BuildTarget> targetToBuildWithBuck) throws IOException, InterruptedException {
ImmutableMultimap.Builder<Cell, BuildTarget> projectCellToBuildTargetsBuilder = ImmutableMultimap.builder();
for (TargetNode<?, ?> targetNode : projectGraph.getNodes()) {
BuildTarget buildTarget = targetNode.getBuildTarget();
projectCellToBuildTargetsBuilder.put(rootCell.getCell(buildTarget), buildTarget);
}
ImmutableMultimap<Cell, BuildTarget> projectCellToBuildTargets = projectCellToBuildTargetsBuilder.build();
List<ListenableFuture<GenerationResult>> projectGeneratorFutures = new ArrayList<>();
for (final Cell projectCell : projectCellToBuildTargets.keySet()) {
ImmutableMultimap.Builder<Path, BuildTarget> projectDirectoryToBuildTargetsBuilder = ImmutableMultimap.builder();
final ImmutableSet<BuildTarget> cellRules = ImmutableSet.copyOf(projectCellToBuildTargets.get(projectCell));
for (BuildTarget buildTarget : cellRules) {
projectDirectoryToBuildTargetsBuilder.put(buildTarget.getBasePath(), buildTarget);
}
ImmutableMultimap<Path, BuildTarget> projectDirectoryToBuildTargets = projectDirectoryToBuildTargetsBuilder.build();
final Path relativeTargetCell = rootCell.getRoot().relativize(projectCell.getRoot());
for (final Path projectDirectory : projectDirectoryToBuildTargets.keySet()) {
final ImmutableSet<BuildTarget> rules = filterRulesForProjectDirectory(projectGraph, ImmutableSet.copyOf(projectDirectoryToBuildTargets.get(projectDirectory)));
if (Sets.intersection(targetsInRequiredProjects, rules).isEmpty()) {
continue;
}
final boolean isMainProject = workspaceArguments.srcTarget.isPresent() && rules.contains(workspaceArguments.srcTarget.get());
projectGeneratorFutures.add(listeningExecutorService.submit(() -> {
GenerationResult result = generateProjectForDirectory(projectGenerators, targetToBuildWithBuck, projectCell, projectDirectory, rules, isMainProject, targetsInRequiredProjects);
// convert the projectPath to relative to the target cell here
result = GenerationResult.of(relativeTargetCell.resolve(result.getProjectPath()), result.isProjectGenerated(), result.getRequiredBuildTargets(), result.getBuildTargetToGeneratedTargetMap());
return result;
}));
}
}
List<GenerationResult> generationResults;
try {
generationResults = Futures.allAsList(projectGeneratorFutures).get();
} catch (ExecutionException e) {
Throwables.throwIfInstanceOf(e.getCause(), IOException.class);
Throwables.throwIfUnchecked(e.getCause());
throw new IllegalStateException("Unexpected exception: ", e);
}
for (GenerationResult result : generationResults) {
if (!result.isProjectGenerated()) {
continue;
}
workspaceGenerator.addFilePath(result.getProjectPath());
processGenerationResult(buildTargetToPbxTargetMapBuilder, targetToProjectPathMapBuilder, result);
}
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class WorkspaceAndProjectGenerator method addExtraWorkspaceSchemes.
private static void addExtraWorkspaceSchemes(TargetGraph projectGraph, AppleDependenciesCache dependenciesCache, ImmutableSortedMap<String, BuildTarget> extraSchemes, ImmutableMap.Builder<String, XcodeWorkspaceConfigDescription.Arg> schemeConfigsBuilder, ImmutableSetMultimap.Builder<String, Optional<TargetNode<?, ?>>> schemeNameToSrcTargetNodeBuilder, ImmutableSetMultimap.Builder<String, TargetNode<AppleTestDescription.Arg, ?>> extraTestNodesBuilder) {
for (Map.Entry<String, BuildTarget> extraSchemeEntry : extraSchemes.entrySet()) {
BuildTarget extraSchemeTarget = extraSchemeEntry.getValue();
Optional<TargetNode<?, ?>> extraSchemeNode = projectGraph.getOptional(extraSchemeTarget);
if (!extraSchemeNode.isPresent() || !(extraSchemeNode.get().getDescription() instanceof XcodeWorkspaceConfigDescription)) {
throw new HumanReadableException("Extra scheme target '%s' should be of type 'xcode_workspace_config'", extraSchemeTarget);
}
XcodeWorkspaceConfigDescription.Arg extraSchemeArg = (XcodeWorkspaceConfigDescription.Arg) extraSchemeNode.get().getConstructorArg();
String schemeName = extraSchemeEntry.getKey();
addWorkspaceScheme(projectGraph, dependenciesCache, schemeName, extraSchemeArg, schemeConfigsBuilder, schemeNameToSrcTargetNodeBuilder, extraTestNodesBuilder);
}
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class ProjectGenerator method generateBuildWithBuckTarget.
private void generateBuildWithBuckTarget(TargetNode<?, ?> targetNode) {
final BuildTarget buildTarget = targetNode.getBuildTarget();
String buckTargetProductName = getXcodeTargetName(buildTarget) + BUILD_WITH_BUCK_POSTFIX;
PBXAggregateTarget buildWithBuckTarget = new PBXAggregateTarget(buckTargetProductName);
buildWithBuckTarget.setProductName(buckTargetProductName);
PBXShellScriptBuildPhase buildShellScriptBuildPhase = new PBXShellScriptBuildPhase();
buildShellScriptBuildPhase.setShellScript(getBuildWithBuckShellScript(targetNode));
buildWithBuckTarget.getBuildPhases().add(buildShellScriptBuildPhase);
// Only add a shell script for fixing UUIDs if it is an AppleBundle
if (targetNode.getDescription() instanceof AppleBundleDescription) {
PBXShellScriptBuildPhase codesignPhase = new PBXShellScriptBuildPhase();
codesignPhase.setShellScript(getCodesignShellScript(targetNode));
buildWithBuckTarget.getBuildPhases().add(codesignPhase);
}
TargetNode<CxxLibraryDescription.Arg, ?> node = getAppleNativeNode(targetGraph, targetNode).get();
ImmutableMap<String, ImmutableMap<String, String>> configs = getXcodeBuildConfigurationsForTargetNode(node, ImmutableMap.of()).get();
XCConfigurationList configurationList = new XCConfigurationList();
PBXGroup group = project.getMainGroup().getOrCreateDescendantGroupByPath(StreamSupport.stream(buildTarget.getBasePath().spliterator(), false).map(Object::toString).collect(MoreCollectors.toImmutableList())).getOrCreateChildGroupByName(getXcodeTargetName(buildTarget));
for (String configurationName : configs.keySet()) {
XCBuildConfiguration configuration = configurationList.getBuildConfigurationsByName().getUnchecked(configurationName);
configuration.setBaseConfigurationReference(getConfigurationFileReference(group, getConfigurationNameToXcconfigPath(buildTarget).apply(configurationName)));
NSDictionary inlineSettings = new NSDictionary();
inlineSettings.put("HEADER_SEARCH_PATHS", "");
inlineSettings.put("LIBRARY_SEARCH_PATHS", "");
inlineSettings.put("FRAMEWORK_SEARCH_PATHS", "");
configuration.setBuildSettings(inlineSettings);
}
buildWithBuckTarget.setBuildConfigurationList(configurationList);
project.getTargets().add(buildWithBuckTarget);
targetNodeToGeneratedProjectTargetBuilder.put(targetNode, buildWithBuckTarget);
}
Aggregations