Search in sources :

Example 11 with BuildTarget

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());
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Flavor(com.facebook.buck.model.Flavor)

Example 12 with BuildTarget

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));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget)

Example 13 with BuildTarget

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);
    }
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ExecutionException(java.util.concurrent.ExecutionException) Cell(com.facebook.buck.rules.Cell)

Example 14 with BuildTarget

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);
    }
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) XcodeWorkspaceConfigDescription(com.facebook.buck.apple.XcodeWorkspaceConfigDescription) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap)

Example 15 with BuildTarget

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);
}
Also used : XCBuildConfiguration(com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration) XCConfigurationList(com.facebook.buck.apple.xcode.xcodeproj.XCConfigurationList) NSDictionary(com.dd.plist.NSDictionary) NSString(com.dd.plist.NSString) PBXAggregateTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXAggregateTarget) ImmutableMap(com.google.common.collect.ImmutableMap) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) AppleNativeTargetDescriptionArg(com.facebook.buck.apple.AppleNativeTargetDescriptionArg) StringWithMacrosArg(com.facebook.buck.rules.args.StringWithMacrosArg) AppleWrapperResourceArg(com.facebook.buck.apple.AppleWrapperResourceArg) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) AppleBundleDescription(com.facebook.buck.apple.AppleBundleDescription)

Aggregations

BuildTarget (com.facebook.buck.model.BuildTarget)1045 Test (org.junit.Test)758 Path (java.nio.file.Path)323 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)289 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)254 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)248 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)226 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)216 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)209 BuildRule (com.facebook.buck.rules.BuildRule)196 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)178 SourcePath (com.facebook.buck.rules.SourcePath)163 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)161 TargetGraph (com.facebook.buck.rules.TargetGraph)156 PathSourcePath (com.facebook.buck.rules.PathSourcePath)116 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)108 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)91 ImmutableSet (com.google.common.collect.ImmutableSet)90 ImmutableMap (com.google.common.collect.ImmutableMap)78 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)75