Search in sources :

Example 1 with WriteFileStep

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();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) JarDirectoryStep(com.facebook.buck.jvm.java.JarDirectoryStep) JavacStep(com.facebook.buck.jvm.java.JavacStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) CalculateAbiStep(com.facebook.buck.jvm.java.CalculateAbiStep) Step(com.facebook.buck.step.Step) JavacStep(com.facebook.buck.jvm.java.JavacStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) CalculateAbiStep(com.facebook.buck.jvm.java.CalculateAbiStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) JarDirectoryStep(com.facebook.buck.jvm.java.JarDirectoryStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep)

Example 2 with WriteFileStep

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();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ImmutableList(com.google.common.collect.ImmutableList) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) TouchStep(com.facebook.buck.step.fs.TouchStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep) TouchStep(com.facebook.buck.step.fs.TouchStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep) MiniAapt(com.facebook.buck.android.aapt.MiniAapt)

Example 3 with WriteFileStep

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));
                    }
                }
            }
        }
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) WriteFile(com.facebook.buck.file.WriteFile) MkdirStep(com.facebook.buck.step.fs.MkdirStep) BuildRule(com.facebook.buck.rules.BuildRule) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep)

Example 4 with WriteFileStep

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);
    }
}
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 5 with WriteFileStep

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));
}
Also used : MkdirStep(com.facebook.buck.step.fs.MkdirStep) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep)

Aggregations

WriteFileStep (com.facebook.buck.step.fs.WriteFileStep)12 Path (java.nio.file.Path)9 SourcePath (com.facebook.buck.rules.SourcePath)7 MkdirStep (com.facebook.buck.step.fs.MkdirStep)7 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)6 ImmutableList (com.google.common.collect.ImmutableList)6 Step (com.facebook.buck.step.Step)5 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)5 RmStep (com.facebook.buck.step.fs.RmStep)3 AbstractBuildRule (com.facebook.buck.rules.AbstractBuildRule)2 PathSourcePath (com.facebook.buck.rules.PathSourcePath)2 ExecutionContext (com.facebook.buck.step.ExecutionContext)2 CopyStep (com.facebook.buck.step.fs.CopyStep)2 HumanReadableException (com.facebook.buck.util.HumanReadableException)2 IOException (java.io.IOException)2 NSDictionary (com.dd.plist.NSDictionary)1 NSString (com.dd.plist.NSString)1 MiniAapt (com.facebook.buck.android.aapt.MiniAapt)1 WriteFile (com.facebook.buck.file.WriteFile)1 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1