use of com.facebook.buck.step.fs.WriteFileStep in project buck by facebook.
the class DummyRDotJava method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
final Path rDotJavaSrcFolder = getRDotJavaSrcFolder(getBuildTarget(), getProjectFilesystem());
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), rDotJavaSrcFolder));
// Generate the .java files and record where they will be written in javaSourceFilePaths.
ImmutableSortedSet<Path> javaSourceFilePaths;
if (androidResourceDeps.isEmpty()) {
// In this case, the user is likely running a Robolectric test that does not happen to
// depend on any resources. However, if Robolectric doesn't find an R.java file, it flips
// out, so we have to create one, anyway.
// TODO(bolinfest): Stop hardcoding com.facebook. This should match the package in the
// associated TestAndroidManifest.xml file.
Path emptyRDotJava = rDotJavaSrcFolder.resolve("com/facebook/R.java");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), emptyRDotJava.getParent()));
steps.add(new WriteFileStep(getProjectFilesystem(), "package com.facebook;\n public class R {}\n", emptyRDotJava, /* executable */
false));
javaSourceFilePaths = ImmutableSortedSet.of(emptyRDotJava);
} else {
MergeAndroidResourcesStep mergeStep = MergeAndroidResourcesStep.createStepForDummyRDotJava(getProjectFilesystem(), context.getSourcePathResolver(), androidResourceDeps, rDotJavaSrcFolder, forceFinalResourceIds, unionPackage, /* rName */
Optional.empty(), useOldStyleableFormat);
steps.add(mergeStep);
if (!finalRName.isPresent()) {
javaSourceFilePaths = mergeStep.getRDotJavaFiles();
} else {
MergeAndroidResourcesStep mergeFinalRStep = MergeAndroidResourcesStep.createStepForDummyRDotJava(getProjectFilesystem(), context.getSourcePathResolver(), androidResourceDeps, rDotJavaSrcFolder, /* forceFinalResourceIds */
true, unionPackage, finalRName, useOldStyleableFormat);
steps.add(mergeFinalRStep);
javaSourceFilePaths = ImmutableSortedSet.<Path>naturalOrder().addAll(mergeStep.getRDotJavaFiles()).addAll(mergeFinalRStep.getRDotJavaFiles()).build();
}
}
// Clear out the directory where the .class files will be generated.
final Path rDotJavaClassesFolder = getRDotJavaBinFolder();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), rDotJavaClassesFolder));
Path pathToAbiOutputDir = getPathToAbiOutputDir(getBuildTarget(), getProjectFilesystem());
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToAbiOutputDir));
Path pathToAbiOutputFile = pathToAbiOutputDir.resolve("abi.jar");
Path pathToJarOutputDir = outputJar.getParent();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToJarOutputDir));
Path pathToSrcsList = BuildTargets.getGenPath(getProjectFilesystem(), getBuildTarget(), "__%s__srcs");
steps.add(new MkdirStep(getProjectFilesystem(), pathToSrcsList.getParent()));
// Compile the .java files.
final JavacStep javacStep = RDotJava.createJavacStepForDummyRDotJavaFiles(javaSourceFilePaths, pathToSrcsList, rDotJavaClassesFolder, javacOptions, getBuildTarget(), context.getSourcePathResolver(), ruleFinder, getProjectFilesystem());
steps.add(javacStep);
buildableContext.recordArtifact(rDotJavaClassesFolder);
steps.add(new JarDirectoryStep(getProjectFilesystem(), outputJar, ImmutableSortedSet.of(rDotJavaClassesFolder), /* mainClass */
null, /* manifestFile */
null));
buildableContext.recordArtifact(outputJar);
steps.add(new CalculateAbiStep(buildableContext, getProjectFilesystem(), rDotJavaClassesFolder, pathToAbiOutputFile));
return steps.build();
}
use of com.facebook.buck.step.fs.WriteFileStep in project buck by facebook.
the class AndroidResource method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
buildableContext.recordArtifact(Preconditions.checkNotNull(pathToTextSymbolsFile));
buildableContext.recordArtifact(Preconditions.checkNotNull(pathToRDotJavaPackageFile));
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), Preconditions.checkNotNull(pathToTextSymbolsDir)));
if (getRes() == null) {
return steps.add(new TouchStep(getProjectFilesystem(), pathToTextSymbolsFile)).add(new WriteFileStep(getProjectFilesystem(), rDotJavaPackageArgument == null ? "" : rDotJavaPackageArgument, pathToRDotJavaPackageFile, false)).build();
}
// from the AndroidManifest.xml.
if (rDotJavaPackageArgument == null) {
Preconditions.checkNotNull(manifestFile, "manifestFile cannot be null when res is non-null and rDotJavaPackageArgument is " + "null. This should already be enforced by the constructor.");
steps.add(new ExtractFromAndroidManifestStep(context.getSourcePathResolver().getAbsolutePath(manifestFile), getProjectFilesystem(), buildableContext, METADATA_KEY_FOR_R_DOT_JAVA_PACKAGE, Preconditions.checkNotNull(pathToRDotJavaPackageFile)));
} else {
steps.add(new WriteFileStep(getProjectFilesystem(), rDotJavaPackageArgument, pathToRDotJavaPackageFile, false));
}
ImmutableSet<Path> pathsToSymbolsOfDeps = symbolsOfDeps.get().stream().map(context.getSourcePathResolver()::getAbsolutePath).collect(MoreCollectors.toImmutableSet());
steps.add(new MiniAapt(context.getSourcePathResolver(), getProjectFilesystem(), Preconditions.checkNotNull(res), Preconditions.checkNotNull(pathToTextSymbolsFile), pathsToSymbolsOfDeps, resourceUnion, isGrayscaleImageProcessingEnabled));
return steps.build();
}
use of com.facebook.buck.step.fs.WriteFileStep in project buck by facebook.
the class BuiltinApplePackage method appendAdditionalAppleWatchSteps.
private void appendAdditionalAppleWatchSteps(ImmutableList.Builder<Step> commands) {
// 2. WatchKitSupport instead of WatchKitSupport2.
for (BuildRule rule : bundle.getDeps()) {
if (rule instanceof AppleBundle) {
AppleBundle appleBundle = (AppleBundle) rule;
if (appleBundle.getBinary().isPresent()) {
BuildRule binary = appleBundle.getBinary().get();
if (binary instanceof WriteFile && appleBundle.getPlatformName().startsWith("watch")) {
commands.add(new MkdirStep(getProjectFilesystem(), temp.resolve("Symbols")));
Path watchKitSupportDir = temp.resolve("WatchKitSupport2");
commands.add(new MkdirStep(getProjectFilesystem(), watchKitSupportDir));
commands.add(new WriteFileStep(getProjectFilesystem(), ByteSource.wrap(((WriteFile) binary).getFileContents()), watchKitSupportDir.resolve("WK"), true));
} else {
Optional<WriteFile> legacyWatchStub = getLegacyWatchStubFromDeps(appleBundle);
if (legacyWatchStub.isPresent()) {
Path watchKitSupportDir = temp.resolve("WatchKitSupport");
commands.add(new MkdirStep(getProjectFilesystem(), watchKitSupportDir));
commands.add(new WriteFileStep(getProjectFilesystem(), ByteSource.wrap(legacyWatchStub.get().getFileContents()), watchKitSupportDir.resolve("WK"), true));
}
}
}
}
}
}
use of com.facebook.buck.step.fs.WriteFileStep 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.step.fs.WriteFileStep in project buck by facebook.
the class WriteFile method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
buildableContext.recordArtifact(output);
ProjectFilesystem projectFilesystem = getProjectFilesystem();
return ImmutableList.of(new MkdirStep(projectFilesystem, output.getParent()), new WriteFileStep(projectFilesystem, ByteSource.wrap(fileContents), output, executable));
}
Aggregations