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