Search in sources :

Example 1 with StepRunner

use of com.facebook.buck.step.StepRunner in project buck by facebook.

the class SmartDexingStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
    try {
        Multimap<Path, Path> outputToInputs = outputToInputsSupplier.get();
        runDxCommands(context, outputToInputs);
        if (secondaryOutputDir.isPresent()) {
            removeExtraneousSecondaryArtifacts(secondaryOutputDir.get(), outputToInputs.keySet(), filesystem);
            // Concatenate if solid compression is specified.
            // create a mapping of the xzs file target and the dex.jar files that go into it
            ImmutableMultimap.Builder<Path, Path> secondaryDexJarsMultimapBuilder = ImmutableMultimap.builder();
            for (Path p : outputToInputs.keySet()) {
                if (DexStore.XZS.matchesPath(p)) {
                    String[] matches = p.getFileName().toString().split("-");
                    Path output = p.getParent().resolve(matches[0].concat(SECONDARY_SOLID_DEX_EXTENSION));
                    secondaryDexJarsMultimapBuilder.put(output, p);
                }
            }
            ImmutableMultimap<Path, Path> secondaryDexJarsMultimap = secondaryDexJarsMultimapBuilder.build();
            if (!secondaryDexJarsMultimap.isEmpty()) {
                for (Map.Entry<Path, Collection<Path>> entry : secondaryDexJarsMultimap.asMap().entrySet()) {
                    Path store = entry.getKey();
                    Collection<Path> secondaryDexJars = entry.getValue();
                    // Construct the output path for our solid blob and its compressed form.
                    Path secondaryBlobOutput = store.getParent().resolve("uncompressed.dex.blob");
                    Path secondaryCompressedBlobOutput = store;
                    // Concatenate the jars into a blob and compress it.
                    StepRunner stepRunner = new DefaultStepRunner();
                    Step concatStep = new ConcatStep(filesystem, ImmutableList.copyOf(secondaryDexJars), secondaryBlobOutput);
                    Step xzStep;
                    if (xzCompressionLevel.isPresent()) {
                        xzStep = new XzStep(filesystem, secondaryBlobOutput, secondaryCompressedBlobOutput, xzCompressionLevel.get().intValue());
                    } else {
                        xzStep = new XzStep(filesystem, secondaryBlobOutput, secondaryCompressedBlobOutput);
                    }
                    stepRunner.runStepForBuildTarget(context, concatStep, Optional.empty());
                    stepRunner.runStepForBuildTarget(context, xzStep, Optional.empty());
                }
            }
        }
    } catch (StepFailedException | IOException e) {
        context.logError(e, "There was an error in smart dexing step.");
        return StepExecutionResult.ERROR;
    }
    return StepExecutionResult.SUCCESS;
}
Also used : Path(java.nio.file.Path) XzStep(com.facebook.buck.step.fs.XzStep) StepRunner(com.facebook.buck.step.StepRunner) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) 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) IOException(java.io.IOException) StepFailedException(com.facebook.buck.step.StepFailedException) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) Collection(java.util.Collection) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with StepRunner

use of com.facebook.buck.step.StepRunner in project buck by facebook.

the class DefaultJavaLibraryTest method stubOutBuildContext.

@Before
public void stubOutBuildContext() {
    ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot().toPath());
    StepRunner stepRunner = createNiceMock(StepRunner.class);
    JavaPackageFinder packageFinder = createNiceMock(JavaPackageFinder.class);
    replay(packageFinder, stepRunner);
    annotationScenarioGenPath = filesystem.resolve(filesystem.getBuckPaths().getAnnotationDir()).resolve("android/java/src/com/facebook/__fb_gen__").toAbsolutePath().toString();
}
Also used : JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) StepRunner(com.facebook.buck.step.StepRunner) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Before(org.junit.Before)

Aggregations

StepRunner (com.facebook.buck.step.StepRunner)2 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 JavaPackageFinder (com.facebook.buck.jvm.core.JavaPackageFinder)1 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)1 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)1 CompositeStep (com.facebook.buck.step.CompositeStep)1 DefaultStepRunner (com.facebook.buck.step.DefaultStepRunner)1 Step (com.facebook.buck.step.Step)1 StepFailedException (com.facebook.buck.step.StepFailedException)1 RmStep (com.facebook.buck.step.fs.RmStep)1 WriteFileStep (com.facebook.buck.step.fs.WriteFileStep)1 XzStep (com.facebook.buck.step.fs.XzStep)1 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)1 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)1 RepackZipEntriesStep (com.facebook.buck.zip.RepackZipEntriesStep)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Collection (java.util.Collection)1