Search in sources :

Example 11 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class ProjectGenerator method resolveSourcePath.

private Path resolveSourcePath(SourcePath sourcePath) {
    if (sourcePath instanceof PathSourcePath) {
        return ((PathSourcePath) sourcePath).getRelativePath();
    }
    Preconditions.checkArgument(sourcePath instanceof BuildTargetSourcePath);
    BuildTargetSourcePath<?> buildTargetSourcePath = (BuildTargetSourcePath<?>) sourcePath;
    BuildTarget buildTarget = buildTargetSourcePath.getTarget();
    TargetNode<?, ?> node = targetGraph.get(buildTarget);
    Optional<TargetNode<ExportFileDescription.Arg, ?>> exportFileNode = node.castArg(ExportFileDescription.Arg.class);
    if (!exportFileNode.isPresent()) {
        BuildRuleResolver resolver = buildRuleResolverForNode.apply(node);
        SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
        SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
        Path output = pathResolver.getRelativePath(sourcePath);
        if (output == null) {
            throw new HumanReadableException("The target '%s' does not have an output.", node.getBuildTarget());
        }
        requiredBuildTargetsBuilder.add(buildTarget);
        return output;
    }
    Optional<SourcePath> src = exportFileNode.get().getConstructorArg().src;
    if (!src.isPresent()) {
        return buildTarget.getBasePath().resolve(buildTarget.getShortNameAndFlavorPostfix());
    }
    return resolveSourcePath(src.get());
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) TargetNode(com.facebook.buck.rules.TargetNode) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) ExportFileDescription(com.facebook.buck.shell.ExportFileDescription)

Example 12 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException 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 13 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class ProvisioningProfileCopyStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
    final String bundleID;
    try {
        bundleID = AppleInfoPlistParsing.getBundleIdFromPlistStream(filesystem.getInputStreamForRelativePath(infoPlist)).get();
    } catch (IOException e) {
        throw new HumanReadableException("Unable to get bundle ID from info.plist: " + infoPlist);
    }
    final Optional<ImmutableMap<String, NSObject>> entitlements;
    final String prefix;
    if (entitlementsPlist.isPresent()) {
        try {
            NSDictionary entitlementsPlistDict = (NSDictionary) PropertyListParser.parse(entitlementsPlist.get().toFile());
            entitlements = Optional.of(ImmutableMap.copyOf(entitlementsPlistDict.getHashMap()));
            prefix = ProvisioningProfileMetadata.prefixFromEntitlements(entitlements.get()).orElse("*");
        } catch (IOException e) {
            throw new HumanReadableException("Unable to find entitlement .plist: " + entitlementsPlist.get());
        } catch (Exception e) {
            throw new HumanReadableException("Malformed entitlement .plist: " + entitlementsPlist.get());
        }
    } else {
        entitlements = ProvisioningProfileStore.MATCH_ANY_ENTITLEMENT;
        prefix = "*";
    }
    final Optional<ImmutableList<CodeSignIdentity>> identities;
    if (!codeSignIdentityStore.getIdentities().isEmpty()) {
        identities = Optional.of(codeSignIdentityStore.getIdentities());
    } else {
        identities = ProvisioningProfileStore.MATCH_ANY_IDENTITY;
    }
    Optional<ProvisioningProfileMetadata> bestProfile = provisioningProfileUUID.isPresent() ? provisioningProfileStore.getProvisioningProfileByUUID(provisioningProfileUUID.get()) : provisioningProfileStore.getBestProvisioningProfile(bundleID, platform, entitlements, identities);
    if (dryRunResultsPath.isPresent()) {
        try {
            NSDictionary dryRunResult = new NSDictionary();
            dryRunResult.put(BUNDLE_ID, bundleID);
            dryRunResult.put(ENTITLEMENTS, entitlements.orElse(ImmutableMap.of()));
            if (bestProfile.isPresent()) {
                dryRunResult.put(PROFILE_UUID, bestProfile.get().getUUID());
                dryRunResult.put(PROFILE_FILENAME, bestProfile.get().getProfilePath().getFileName().toString());
                dryRunResult.put(TEAM_IDENTIFIER, bestProfile.get().getEntitlements().get("com.apple.developer.team-identifier"));
            }
            filesystem.writeContentsToPath(dryRunResult.toXMLPropertyList(), dryRunResultsPath.get());
        } catch (IOException e) {
            context.logError(e, "Failed when trying to write dry run results: %s", getDescription(context));
            return StepExecutionResult.ERROR;
        }
    }
    selectedProvisioningProfileFuture.set(bestProfile);
    if (!bestProfile.isPresent()) {
        String message = "No valid non-expired provisioning profiles match for " + prefix + "." + bundleID;
        if (dryRunResultsPath.isPresent()) {
            LOG.warn(message);
            return StepExecutionResult.SUCCESS;
        } else {
            throw new HumanReadableException(message);
        }
    }
    Path provisioningProfileSource = bestProfile.get().getProfilePath();
    // Copy the actual .mobileprovision.
    try {
        filesystem.copy(provisioningProfileSource, provisioningProfileDestination, CopySourceMode.FILE);
    } catch (IOException e) {
        context.logError(e, "Failed when trying to copy: %s", getDescription(context));
        return StepExecutionResult.ERROR;
    }
    // Merge the entitlements with the profile, and write out.
    if (entitlementsPlist.isPresent()) {
        return (new PlistProcessStep(filesystem, entitlementsPlist.get(), Optional.empty(), signingEntitlementsTempPath, bestProfile.get().getMergeableEntitlements(), ImmutableMap.of(), PlistProcessStep.OutputFormat.XML)).execute(context);
    } else {
        // No entitlements.plist explicitly specified; write out the minimal entitlements needed.
        String appID = bestProfile.get().getAppID().getFirst() + "." + bundleID;
        NSDictionary entitlementsPlist = new NSDictionary();
        entitlementsPlist.putAll(bestProfile.get().getMergeableEntitlements());
        entitlementsPlist.put(APPLICATION_IDENTIFIER, appID);
        entitlementsPlist.put(KEYCHAIN_ACCESS_GROUPS, new String[] { appID });
        return (new WriteFileStep(filesystem, entitlementsPlist.toXMLPropertyList(), signingEntitlementsTempPath, /* executable */
        false)).execute(context);
    }
}
Also used : Path(java.nio.file.Path) NSDictionary(com.dd.plist.NSDictionary) ImmutableList(com.google.common.collect.ImmutableList) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) IOException(java.io.IOException) HumanReadableException(com.facebook.buck.util.HumanReadableException) HumanReadableException(com.facebook.buck.util.HumanReadableException) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep)

Example 14 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException 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 HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class WorkspaceGenerator method addFilePath.

/**
   * Adds a reference to a project file to the group hierarchy of the generated workspace.
   *
   * @param path Path to the referenced project file in the repository.
   * @param groupPath Path in the group hierarchy of the generated workspace where
   *                  the reference will be placed.
   *                  If absent, the project reference is placed to the root of the workspace.
   */
public void addFilePath(Path path, Optional<Path> groupPath) {
    Map<String, WorkspaceNode> children = this.children;
    if (groupPath.isPresent()) {
        for (Path groupPathPart : groupPath.get()) {
            String groupName = groupPathPart.toString();
            WorkspaceNode node = children.get(groupName);
            WorkspaceGroup group;
            if (node instanceof WorkspaceFileRef) {
                throw new HumanReadableException("Invalid workspace: a group and a project have the same name: %s", groupName);
            } else if (node == null) {
                group = new WorkspaceGroup();
                children.put(groupName, group);
            } else if (node instanceof WorkspaceGroup) {
                group = (WorkspaceGroup) node;
            } else {
                // Unreachable
                throw new HumanReadableException("Expected a workspace to only contain groups and file references");
            }
            children = group.getChildren();
        }
    }
    children.put(path.toString(), new WorkspaceFileRef(path));
}
Also used : Path(java.nio.file.Path) HumanReadableException(com.facebook.buck.util.HumanReadableException)

Aggregations

HumanReadableException (com.facebook.buck.util.HumanReadableException)195 Path (java.nio.file.Path)79 SourcePath (com.facebook.buck.rules.SourcePath)50 BuildTarget (com.facebook.buck.model.BuildTarget)49 Test (org.junit.Test)46 IOException (java.io.IOException)45 ImmutableList (com.google.common.collect.ImmutableList)39 BuildRule (com.facebook.buck.rules.BuildRule)31 ImmutableSet (com.google.common.collect.ImmutableSet)30 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)29 ImmutableMap (com.google.common.collect.ImmutableMap)26 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)22 Optional (java.util.Optional)21 PathSourcePath (com.facebook.buck.rules.PathSourcePath)20 VisibleForTesting (com.google.common.annotations.VisibleForTesting)18 Map (java.util.Map)18 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)17 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)16 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)15 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)15