Search in sources :

Example 1 with JavacStep

use of com.facebook.buck.jvm.java.JavacStep 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)

Aggregations

CalculateAbiStep (com.facebook.buck.jvm.java.CalculateAbiStep)1 JarDirectoryStep (com.facebook.buck.jvm.java.JarDirectoryStep)1 JavacStep (com.facebook.buck.jvm.java.JavacStep)1 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)1 SourcePath (com.facebook.buck.rules.SourcePath)1 Step (com.facebook.buck.step.Step)1 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)1 MkdirStep (com.facebook.buck.step.fs.MkdirStep)1 WriteFileStep (com.facebook.buck.step.fs.WriteFileStep)1 ImmutableList (com.google.common.collect.ImmutableList)1 Path (java.nio.file.Path)1