Search in sources :

Example 21 with RmStep

use of com.facebook.buck.step.fs.RmStep in project buck by facebook.

the class DirectHeaderMap method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    LOG.debug("Generating post-build steps to write header map to %s", headerMapPath);
    ImmutableMap.Builder<Path, Path> headerMapEntries = ImmutableMap.builder();
    Path buckOut = getProjectFilesystem().resolve(getProjectFilesystem().getBuckPaths().getBuckOut());
    for (Path key : getLinks().keySet()) {
        Path path = buckOut.relativize(context.getSourcePathResolver().getAbsolutePath(getLinks().get(key)));
        LOG.debug("header map %s -> %s", key, path);
        headerMapEntries.put(key, path);
    }
    return ImmutableList.<Step>builder().add(getVerifyStep()).add(new MkdirStep(getProjectFilesystem(), headerMapPath.getParent())).add(new RmStep(getProjectFilesystem(), headerMapPath)).add(new HeaderMapStep(getProjectFilesystem(), headerMapPath, headerMapEntries.build())).build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) RmStep(com.facebook.buck.step.fs.RmStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 22 with RmStep

use of com.facebook.buck.step.fs.RmStep in project buck by facebook.

the class DirectHeaderMapTest method testBuildSteps.

@Test
public void testBuildSteps() throws IOException {
    BuildContext buildContext = FakeBuildContext.withSourcePathResolver(pathResolver);
    FakeBuildableContext buildableContext = new FakeBuildableContext();
    ImmutableList<Step> expectedBuildSteps = ImmutableList.of(new MkdirStep(projectFilesystem, headerMapPath.getParent()), new RmStep(projectFilesystem, headerMapPath), new HeaderMapStep(projectFilesystem, headerMapPath, ImmutableMap.of(Paths.get("file"), projectFilesystem.resolve(projectFilesystem.getBuckPaths().getBuckOut()).relativize(file1), Paths.get("directory/then/file"), projectFilesystem.resolve(projectFilesystem.getBuckPaths().getBuckOut()).relativize(file2))));
    ImmutableList<Step> actualBuildSteps = buildRule.getBuildSteps(buildContext, buildableContext);
    assertEquals(expectedBuildSteps, actualBuildSteps.subList(1, actualBuildSteps.size()));
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) RmStep(com.facebook.buck.step.fs.RmStep) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) MkdirStep(com.facebook.buck.step.fs.MkdirStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep) Test(org.junit.Test)

Example 23 with RmStep

use of com.facebook.buck.step.fs.RmStep in project buck by facebook.

the class SmartDexingStep method createDxStepForDxPseudoRule.

/**
   * The step to produce the .dex file will be determined by the file extension of outputPath, much
   * as {@code dx} itself chooses whether to embed the dex inside a jar/zip based on the destination
   * file passed to it.  We also create a ".meta" file that contains information about the
   * compressed and uncompressed size of the dex; this information is useful later, in applications,
   * when unpacking.
   */
static Step createDxStepForDxPseudoRule(ProjectFilesystem filesystem, Collection<Path> filesToDex, Path outputPath, EnumSet<Option> dxOptions, Optional<Integer> xzCompressionLevel, Optional<String> dxMaxHeapSize) {
    String output = outputPath.toString();
    List<Step> steps = Lists.newArrayList();
    if (DexStore.XZ.matchesPath(outputPath)) {
        Path tempDexJarOutput = Paths.get(output.replaceAll("\\.jar\\.xz$", ".tmp.jar"));
        steps.add(new DxStep(filesystem, tempDexJarOutput, filesToDex, dxOptions, dxMaxHeapSize));
        // We need to make sure classes.dex is STOREd in the .dex.jar file, otherwise .XZ
        // compression won't be effective.
        Path repackedJar = Paths.get(output.replaceAll("\\.xz$", ""));
        steps.add(new RepackZipEntriesStep(filesystem, tempDexJarOutput, repackedJar, ImmutableSet.of("classes.dex"), ZipCompressionLevel.MIN_COMPRESSION_LEVEL));
        steps.add(new RmStep(filesystem, tempDexJarOutput));
        steps.add(new DexJarAnalysisStep(filesystem, repackedJar, repackedJar.resolveSibling(repackedJar.getFileName() + ".meta")));
        if (xzCompressionLevel.isPresent()) {
            steps.add(new XzStep(filesystem, repackedJar, xzCompressionLevel.get().intValue()));
        } else {
            steps.add(new XzStep(filesystem, repackedJar));
        }
    } else if (DexStore.XZS.matchesPath(outputPath)) {
        // Essentially the same logic as the XZ case above, except we compress later.
        // The differences in output file names make it worth separating into a different case.
        // Ensure classes.dex is stored.
        Path tempDexJarOutput = Paths.get(output.replaceAll("\\.jar\\.xzs\\.tmp~$", ".tmp.jar"));
        steps.add(new DxStep(filesystem, tempDexJarOutput, filesToDex, dxOptions, dxMaxHeapSize));
        steps.add(new RepackZipEntriesStep(filesystem, tempDexJarOutput, outputPath, ImmutableSet.of("classes.dex"), ZipCompressionLevel.MIN_COMPRESSION_LEVEL));
        steps.add(new RmStep(filesystem, tempDexJarOutput));
        // Write a .meta file.
        steps.add(new DexJarAnalysisStep(filesystem, outputPath, outputPath.resolveSibling(outputPath.getFileName() + ".meta")));
    } else if (DexStore.JAR.matchesPath(outputPath) || DexStore.RAW.matchesPath(outputPath) || output.endsWith("classes.dex")) {
        steps.add(new DxStep(filesystem, outputPath, filesToDex, dxOptions, dxMaxHeapSize));
        if (DexStore.JAR.matchesPath(outputPath)) {
            steps.add(new DexJarAnalysisStep(filesystem, outputPath, outputPath.resolveSibling(outputPath.getFileName() + ".meta")));
        }
    } else {
        throw new IllegalArgumentException(String.format("Suffix of %s does not have a corresponding DexStore type.", outputPath));
    }
    return new CompositeStep(steps);
}
Also used : Path(java.nio.file.Path) RmStep(com.facebook.buck.step.fs.RmStep) XzStep(com.facebook.buck.step.fs.XzStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) RepackZipEntriesStep(com.facebook.buck.zip.RepackZipEntriesStep) CompositeStep(com.facebook.buck.step.CompositeStep) XzStep(com.facebook.buck.step.fs.XzStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep) RepackZipEntriesStep(com.facebook.buck.zip.RepackZipEntriesStep) CompositeStep(com.facebook.buck.step.CompositeStep)

Example 24 with RmStep

use of com.facebook.buck.step.fs.RmStep in project buck by facebook.

the class PrebuiltAppleFramework method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    // This file is copied rather than symlinked so that when it is included in an archive zip and
    // unpacked on another machine, it is an ordinary file in both scenarios.
    ImmutableList.Builder<Step> builder = ImmutableList.builder();
    builder.add(new MkdirStep(getProjectFilesystem(), out.getParent()));
    builder.add(new RmStep(getProjectFilesystem(), out, RmStep.Mode.RECURSIVE));
    builder.add(CopyStep.forDirectory(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(frameworkPath), out, CopyStep.DirectoryMode.CONTENTS_ONLY));
    buildableContext.recordArtifact(out);
    return builder.build();
}
Also used : RmStep(com.facebook.buck.step.fs.RmStep) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) CopyStep(com.facebook.buck.step.fs.CopyStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep)

Aggregations

RmStep (com.facebook.buck.step.fs.RmStep)24 Step (com.facebook.buck.step.Step)20 MkdirStep (com.facebook.buck.step.fs.MkdirStep)19 ImmutableList (com.google.common.collect.ImmutableList)18 SourcePath (com.facebook.buck.rules.SourcePath)17 Path (java.nio.file.Path)16 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)15 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)10 CopyStep (com.facebook.buck.step.fs.CopyStep)8 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)7 WriteFileStep (com.facebook.buck.step.fs.WriteFileStep)5 AbstractBuildRule (com.facebook.buck.rules.AbstractBuildRule)4 BuildContext (com.facebook.buck.rules.BuildContext)4 ExecutionContext (com.facebook.buck.step.ExecutionContext)4 ZipStep (com.facebook.buck.zip.ZipStep)4 BuildTargets (com.facebook.buck.model.BuildTargets)3 AddToRuleKey (com.facebook.buck.rules.AddToRuleKey)3 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)3 BuildableContext (com.facebook.buck.rules.BuildableContext)3 ShellStep (com.facebook.buck.shell.ShellStep)3