use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class Genrule method isWorkerGenrule.
@VisibleForTesting
public boolean isWorkerGenrule() {
Arg cmdArg = cmd.orElse(null);
Arg bashArg = bash.orElse(null);
Arg cmdExeArg = cmdExe.orElse(null);
if ((cmdArg instanceof WorkerMacroArg) || (bashArg instanceof WorkerMacroArg) || (cmdExeArg instanceof WorkerMacroArg)) {
if ((cmdArg != null && !(cmdArg instanceof WorkerMacroArg)) || (bashArg != null && !(bashArg instanceof WorkerMacroArg)) || (cmdExeArg != null && !(cmdExeArg instanceof WorkerMacroArg))) {
throw new HumanReadableException("You cannot use a worker macro in one of the cmd, bash, " + "or cmd_exe properties and not in the others for genrule %s.", getBuildTarget().getFullyQualifiedName());
}
return true;
}
return false;
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class WorkerProcessProtocolZero method receiveCommand.
/*
Expects a message that looks like this:
,{
id: <id>,
type: 'command',
args_path: <argsPath>,
stdout_path: <stdoutPath>,
stderr_path: <stderrPath>,
}
*/
@Override
public WorkerProcessCommand receiveCommand(int messageID) throws IOException {
int id = -1;
String type = "";
String argsPath = "";
String stdoutPath = "";
String stderrPath = "";
try {
processStdoutReader.beginObject();
while (processStdoutReader.hasNext()) {
String property = processStdoutReader.nextName();
if (property.equals("id")) {
id = processStdoutReader.nextInt();
} else if (property.equals("type")) {
type = processStdoutReader.nextString();
} else if (property.equals("args_path")) {
argsPath = processStdoutReader.nextString();
} else if (property.equals("stdout_path")) {
stdoutPath = processStdoutReader.nextString();
} else if (property.equals("stderr_path")) {
stderrPath = processStdoutReader.nextString();
} else {
processStdoutReader.skipValue();
}
}
processStdoutReader.endObject();
} catch (IOException e) {
throw new HumanReadableException(e, "Error receiving command from external process.\nStderr from external process:\n%s", getStdErrorOutput());
}
if (id != messageID) {
throw new HumanReadableException(String.format("Expected command's \"id\" value to be " + "\"%d\", got \"%d\" instead.", messageID, id));
}
if (!type.equals(TYPE_COMMAND)) {
throw new HumanReadableException(String.format("Expected command's \"type\" " + "to be \"%s\", got \"%s\" instead.", TYPE_COMMAND, type));
}
return WorkerProcessCommand.of(Paths.get(argsPath), Paths.get(stdoutPath), Paths.get(stderrPath));
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class MacroArg method getInputs.
@Override
public ImmutableCollection<SourcePath> getInputs() {
ImmutableCollection<BuildRule> rules;
try {
rules = expander.extractBuildTimeDeps(target, cellNames, resolver, unexpanded);
} catch (MacroException e) {
throw new HumanReadableException(e, "%s: %s", target, e.getMessage());
}
ImmutableList.Builder<SourcePath> paths = ImmutableList.builder();
for (BuildRule rule : rules) {
paths.add(Preconditions.checkNotNull(rule.getSourcePathToOutput()));
}
return paths.build();
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class FrameworkPathTypeCoercer method coerce.
@Override
public FrameworkPath coerce(CellPathResolver cellRoots, ProjectFilesystem filesystem, Path pathRelativeToProjectRoot, Object object) throws CoerceFailedException {
if (object instanceof String) {
Path path = Paths.get((String) object);
String firstElement = Preconditions.checkNotNull(Iterables.getFirst(path, Paths.get(""))).toString();
if (firstElement.startsWith("$")) {
// NOPMD - length() > 0 && charAt(0) == '$' is ridiculous
Optional<PBXReference.SourceTree> sourceTree = PBXReference.SourceTree.fromBuildSetting(firstElement);
if (sourceTree.isPresent()) {
int nameCount = path.getNameCount();
if (nameCount < 2) {
throw new HumanReadableException("Invalid source tree path: '%s'. Should have at least one path component after" + "'%s'.", path, firstElement);
}
return FrameworkPath.ofSourceTreePath(new SourceTreePath(sourceTree.get(), path.subpath(1, path.getNameCount()), Optional.empty()));
} else {
throw new HumanReadableException("Unknown SourceTree: '%s'. Should be one of: %s", firstElement, Joiner.on(", ").join(Iterables.transform(ImmutableList.copyOf(PBXReference.SourceTree.values()), input -> "$" + input.toString())));
}
} else {
return FrameworkPath.ofSourcePath(sourcePathTypeCoercer.coerce(cellRoots, filesystem, pathRelativeToProjectRoot, object));
}
}
throw CoerceFailedException.simple(object, getOutputClass(), "input should be either a source tree path or a source path");
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class AppleBundle method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> stepsBuilder = ImmutableList.builder();
stepsBuilder.add(new MakeCleanDirectoryStep(getProjectFilesystem(), bundleRoot));
Path resourcesDestinationPath = bundleRoot.resolve(this.destinations.getResourcesPath());
if (assetCatalog.isPresent()) {
stepsBuilder.add(new MkdirStep(getProjectFilesystem(), resourcesDestinationPath));
Path bundleDir = assetCatalog.get().getOutputDir();
stepsBuilder.add(CopyStep.forDirectory(getProjectFilesystem(), bundleDir, resourcesDestinationPath, CopyStep.DirectoryMode.CONTENTS_ONLY));
}
if (coreDataModel.isPresent()) {
stepsBuilder.add(new MkdirStep(getProjectFilesystem(), resourcesDestinationPath));
stepsBuilder.add(CopyStep.forDirectory(getProjectFilesystem(), context.getSourcePathResolver().getRelativePath(coreDataModel.get().getSourcePathToOutput()), resourcesDestinationPath, CopyStep.DirectoryMode.CONTENTS_ONLY));
}
if (sceneKitAssets.isPresent()) {
stepsBuilder.add(new MkdirStep(getProjectFilesystem(), resourcesDestinationPath));
stepsBuilder.add(CopyStep.forDirectory(getProjectFilesystem(), context.getSourcePathResolver().getRelativePath(sceneKitAssets.get().getSourcePathToOutput()), resourcesDestinationPath, CopyStep.DirectoryMode.CONTENTS_ONLY));
}
Path metadataPath = getMetadataPath();
Path infoPlistInputPath = context.getSourcePathResolver().getAbsolutePath(infoPlist);
Path infoPlistSubstitutionTempPath = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s.plist");
Path infoPlistOutputPath = metadataPath.resolve("Info.plist");
stepsBuilder.add(new MkdirStep(getProjectFilesystem(), metadataPath), // TODO(bhamiltoncx): This is only appropriate for .app bundles.
new WriteFileStep(getProjectFilesystem(), "APPLWRUN", metadataPath.resolve("PkgInfo"), /* executable */
false), new MkdirStep(getProjectFilesystem(), infoPlistSubstitutionTempPath.getParent()), new FindAndReplaceStep(getProjectFilesystem(), infoPlistInputPath, infoPlistSubstitutionTempPath, InfoPlistSubstitution.createVariableExpansionFunction(withDefaults(infoPlistSubstitutions, ImmutableMap.of("EXECUTABLE_NAME", binaryName, "PRODUCT_NAME", binaryName)))), new PlistProcessStep(getProjectFilesystem(), infoPlistSubstitutionTempPath, assetCatalog.isPresent() ? Optional.of(assetCatalog.get().getOutputPlist()) : Optional.empty(), infoPlistOutputPath, getInfoPlistAdditionalKeys(), getInfoPlistOverrideKeys(), PlistProcessStep.OutputFormat.BINARY));
if (hasBinary) {
appendCopyBinarySteps(stepsBuilder, context.getSourcePathResolver());
appendCopyDsymStep(stepsBuilder, buildableContext, context.getSourcePathResolver());
}
if (!Iterables.isEmpty(Iterables.concat(resources.getResourceDirs(), resources.getDirsContainingResourceDirs(), resources.getResourceFiles()))) {
stepsBuilder.add(new MkdirStep(getProjectFilesystem(), resourcesDestinationPath));
for (SourcePath dir : resources.getResourceDirs()) {
stepsBuilder.add(CopyStep.forDirectory(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(dir), resourcesDestinationPath, CopyStep.DirectoryMode.DIRECTORY_AND_CONTENTS));
}
for (SourcePath dir : resources.getDirsContainingResourceDirs()) {
stepsBuilder.add(CopyStep.forDirectory(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(dir), resourcesDestinationPath, CopyStep.DirectoryMode.CONTENTS_ONLY));
}
for (SourcePath file : resources.getResourceFiles()) {
// TODO(shs96c): Check that this work cross-cell
Path resolvedFilePath = context.getSourcePathResolver().getRelativePath(file);
Path destinationPath = resourcesDestinationPath.resolve(resolvedFilePath.getFileName());
addResourceProcessingSteps(context.getSourcePathResolver(), resolvedFilePath, destinationPath, stepsBuilder);
}
}
ImmutableList.Builder<Path> codeSignOnCopyPathsBuilder = ImmutableList.builder();
addStepsToCopyExtensionBundlesDependencies(context.getSourcePathResolver(), stepsBuilder, codeSignOnCopyPathsBuilder);
for (SourcePath variantSourcePath : resources.getResourceVariantFiles()) {
// TODO(shs96c): Ensure this works cross-cell, as relative path begins with "buck-out"
Path variantFilePath = context.getSourcePathResolver().getRelativePath(variantSourcePath);
Path variantDirectory = variantFilePath.getParent();
if (variantDirectory == null || !variantDirectory.toString().endsWith(".lproj")) {
throw new HumanReadableException("Variant files have to be in a directory with name ending in '.lproj', " + "but '%s' is not.", variantFilePath);
}
Path bundleVariantDestinationPath = resourcesDestinationPath.resolve(variantDirectory.getFileName());
stepsBuilder.add(new MkdirStep(getProjectFilesystem(), bundleVariantDestinationPath));
Path destinationPath = bundleVariantDestinationPath.resolve(variantFilePath.getFileName());
addResourceProcessingSteps(context.getSourcePathResolver(), variantFilePath, destinationPath, stepsBuilder);
}
if (!frameworks.isEmpty()) {
Path frameworksDestinationPath = bundleRoot.resolve(this.destinations.getFrameworksPath());
stepsBuilder.add(new MkdirStep(getProjectFilesystem(), frameworksDestinationPath));
for (SourcePath framework : frameworks) {
Path srcPath = context.getSourcePathResolver().getAbsolutePath(framework);
stepsBuilder.add(CopyStep.forDirectory(getProjectFilesystem(), srcPath, frameworksDestinationPath, CopyStep.DirectoryMode.DIRECTORY_AND_CONTENTS));
codeSignOnCopyPathsBuilder.add(frameworksDestinationPath.resolve(srcPath.getFileName()));
}
}
if (needCodeSign()) {
Optional<Path> signingEntitlementsTempPath;
Supplier<CodeSignIdentity> codeSignIdentitySupplier;
if (adHocCodeSignIsSufficient()) {
signingEntitlementsTempPath = Optional.empty();
codeSignIdentitySupplier = () -> CodeSignIdentity.AD_HOC;
} else {
// Copy the .mobileprovision file if the platform requires it, and sign the executable.
Optional<Path> entitlementsPlist = Optional.empty();
final Path srcRoot = getProjectFilesystem().getRootPath().resolve(getBuildTarget().getBasePath());
Optional<String> entitlementsPlistString = InfoPlistSubstitution.getVariableExpansionForPlatform(CODE_SIGN_ENTITLEMENTS, platform.getName(), withDefaults(infoPlistSubstitutions, ImmutableMap.of("SOURCE_ROOT", srcRoot.toString(), "SRCROOT", srcRoot.toString())));
if (entitlementsPlistString.isPresent()) {
entitlementsPlist = Optional.of(srcRoot.resolve(Paths.get(entitlementsPlistString.get())));
}
signingEntitlementsTempPath = Optional.of(BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s.xcent"));
final Path dryRunResultPath = bundleRoot.resolve(PP_DRY_RUN_RESULT_FILE);
final ProvisioningProfileCopyStep provisioningProfileCopyStep = new ProvisioningProfileCopyStep(getProjectFilesystem(), infoPlistOutputPath, platform, // Provisioning profile UUID -- find automatically.
Optional.empty(), entitlementsPlist, provisioningProfileStore, resourcesDestinationPath.resolve("embedded.mobileprovision"), dryRunCodeSigning ? bundleRoot.resolve(CODE_SIGN_DRY_RUN_ENTITLEMENTS_FILE) : signingEntitlementsTempPath.get(), codeSignIdentityStore, dryRunCodeSigning ? Optional.of(dryRunResultPath) : Optional.empty());
stepsBuilder.add(provisioningProfileCopyStep);
codeSignIdentitySupplier = () -> {
// Using getUnchecked here because the previous step should already throw if exception
// occurred, and this supplier would never be evaluated.
Optional<ProvisioningProfileMetadata> selectedProfile = Futures.getUnchecked(provisioningProfileCopyStep.getSelectedProvisioningProfileFuture());
if (!selectedProfile.isPresent()) {
// This should only happen in dry-run codesign mode (since otherwise an exception
// would have been thrown already.) Still, we need to return *something*.
Preconditions.checkState(dryRunCodeSigning);
return CodeSignIdentity.AD_HOC;
}
ImmutableSet<HashCode> fingerprints = selectedProfile.get().getDeveloperCertificateFingerprints();
if (fingerprints.isEmpty()) {
// If no identities are available, use an ad-hoc identity.
return Iterables.getFirst(codeSignIdentityStore.getIdentities(), CodeSignIdentity.AD_HOC);
}
for (CodeSignIdentity identity : codeSignIdentityStore.getIdentities()) {
if (identity.getFingerprint().isPresent() && fingerprints.contains(identity.getFingerprint().get())) {
return identity;
}
}
throw new HumanReadableException("No code sign identity available for provisioning profile: %s\n" + "Profile requires an identity with one of the following SHA1 fingerprints " + "available in your keychain: \n %s", selectedProfile.get().getProfilePath(), Joiner.on("\n ").join(fingerprints));
};
}
addSwiftStdlibStepIfNeeded(context.getSourcePathResolver(), bundleRoot.resolve(Paths.get("Frameworks")), dryRunCodeSigning ? Optional.<Supplier<CodeSignIdentity>>empty() : Optional.of(codeSignIdentitySupplier), stepsBuilder, false);
for (Path codeSignOnCopyPath : codeSignOnCopyPathsBuilder.build()) {
stepsBuilder.add(new CodeSignStep(getProjectFilesystem(), context.getSourcePathResolver(), codeSignOnCopyPath, Optional.empty(), codeSignIdentitySupplier, codesign, codesignAllocatePath, dryRunCodeSigning ? Optional.of(codeSignOnCopyPath.resolve(CODE_SIGN_DRY_RUN_ARGS_FILE)) : Optional.empty()));
}
stepsBuilder.add(new CodeSignStep(getProjectFilesystem(), context.getSourcePathResolver(), bundleRoot, signingEntitlementsTempPath, codeSignIdentitySupplier, codesign, codesignAllocatePath, dryRunCodeSigning ? Optional.of(bundleRoot.resolve(CODE_SIGN_DRY_RUN_ARGS_FILE)) : Optional.empty()));
} else {
addSwiftStdlibStepIfNeeded(context.getSourcePathResolver(), bundleRoot.resolve(Paths.get("Frameworks")), Optional.<Supplier<CodeSignIdentity>>empty(), stepsBuilder, false);
}
// Ensure the bundle directory is archived so we can fetch it later.
buildableContext.recordArtifact(context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()));
return stepsBuilder.build();
}
Aggregations