use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class ExportFileDescription method createBuildRule.
@Override
public <A extends Arg> ExportFile createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) {
BuildTarget target = params.getBuildTarget();
Mode mode = args.mode.orElse(Mode.COPY);
String name;
if (args.out.isPresent()) {
if (mode == ExportFileDescription.Mode.REFERENCE) {
throw new HumanReadableException("%s: must not set `out` for `export_file` when using `REFERENCE` mode", params.getBuildTarget());
}
name = args.out.get();
} else {
name = target.getShortNameAndFlavorPostfix();
}
SourcePath src;
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
if (args.src.isPresent()) {
if (mode == ExportFileDescription.Mode.REFERENCE && !pathResolver.getFilesystem(args.src.get()).equals(params.getProjectFilesystem())) {
throw new HumanReadableException("%s: must use `COPY` mode for `export_file` when source (%s) uses a different cell", target, args.src.get());
}
src = args.src.get();
} else {
src = new PathSourcePath(params.getProjectFilesystem(), target.getBasePath().resolve(target.getShortNameAndFlavorPostfix()));
}
return new ExportFile(params, ruleFinder, pathResolver, name, mode, src);
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class Genrule method addSymlinkCommands.
@VisibleForTesting
void addSymlinkCommands(BuildContext context, ImmutableList.Builder<Step> commands) {
Path basePath = getBuildTarget().getBasePath();
// Symlink all sources into the temp directory so that they can be used in the genrule.
for (SourcePath src : srcs) {
Path relativePath = context.getSourcePathResolver().getRelativePath(src);
Path absolutePath = context.getSourcePathResolver().getAbsolutePath(src);
Path canonicalPath = absolutePath.normalize();
// By the time we get this far, all source paths (the keys in the map) have been converted
// to paths relative to the project root. We want the path relative to the build target, so
// strip the base path.
Path localPath;
if (absolutePath.equals(canonicalPath)) {
if (relativePath.startsWith(basePath) || getBuildTarget().isInCellRoot()) {
localPath = MorePaths.relativize(basePath, relativePath);
} else {
localPath = canonicalPath.getFileName();
}
} else {
localPath = relativePath;
}
Path destination = pathToSrcDirectory.resolve(localPath);
commands.add(new MkdirAndSymlinkFileStep(getProjectFilesystem(), relativePath, destination));
}
}
use of com.facebook.buck.rules.SourcePath 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.rules.SourcePath 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();
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class AppleBundle method addStoryboardProcessingSteps.
private void addStoryboardProcessingSteps(SourcePathResolver resolver, Path sourcePath, Path destinationPath, ImmutableList.Builder<Step> stepsBuilder) {
if (platform.getName().contains("watch") || isLegacyWatchApp()) {
LOG.debug("Compiling storyboard %s to storyboardc %s and linking", sourcePath, destinationPath);
Path compiledStoryboardPath = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s.storyboardc");
stepsBuilder.add(new IbtoolStep(getProjectFilesystem(), ibtool.getEnvironment(resolver), ibtool.getCommandPrefix(resolver), ImmutableList.of("--target-device", "watch", "--compile"), sourcePath, compiledStoryboardPath));
stepsBuilder.add(new IbtoolStep(getProjectFilesystem(), ibtool.getEnvironment(resolver), ibtool.getCommandPrefix(resolver), ImmutableList.of("--target-device", "watch", "--link"), compiledStoryboardPath, destinationPath.getParent()));
} else {
LOG.debug("Compiling storyboard %s to storyboardc %s", sourcePath, destinationPath);
String compiledStoryboardFilename = Files.getNameWithoutExtension(destinationPath.toString()) + ".storyboardc";
Path compiledStoryboardPath = destinationPath.getParent().resolve(compiledStoryboardFilename);
stepsBuilder.add(new IbtoolStep(getProjectFilesystem(), ibtool.getEnvironment(resolver), ibtool.getCommandPrefix(resolver), ImmutableList.of("--compile"), sourcePath, compiledStoryboardPath));
}
}
Aggregations