Search in sources :

Example 1 with JarDirectoryStep

use of com.facebook.buck.jvm.java.JarDirectoryStep in project buck by facebook.

the class AndroidAar method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> commands = ImmutableList.builder();
    // Create temp folder to store the files going to be zipped
    commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), temp));
    // Remove the output .aar file
    commands.add(new RmStep(getProjectFilesystem(), pathToOutputFile));
    // put manifest into tmp folder
    commands.add(CopyStep.forFile(getProjectFilesystem(), context.getSourcePathResolver().getRelativePath(manifest.getSourcePathToOutput()), temp.resolve("AndroidManifest.xml")));
    // put R.txt into tmp folder
    commands.add(CopyStep.forFile(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(Preconditions.checkNotNull(androidResource.getPathToTextSymbolsFile())), temp.resolve("R.txt")));
    // put res/ and assets/ into tmp folder
    commands.add(CopyStep.forDirectory(getProjectFilesystem(), context.getSourcePathResolver().getRelativePath(assembledResourceDirectory), temp.resolve("res"), CopyStep.DirectoryMode.CONTENTS_ONLY));
    commands.add(CopyStep.forDirectory(getProjectFilesystem(), context.getSourcePathResolver().getRelativePath(assembledAssetsDirectory), temp.resolve("assets"), CopyStep.DirectoryMode.CONTENTS_ONLY));
    // Create our Uber-jar, and place it in the tmp folder.
    commands.add(new JarDirectoryStep(getProjectFilesystem(), temp.resolve("classes.jar"), context.getSourcePathResolver().getAllAbsolutePaths(classpathsToIncludeInJar), /* mainClass */
    null, /* manifestFile */
    null));
    // move native libs into tmp folder under jni/
    if (assembledNativeLibs.isPresent()) {
        commands.add(CopyStep.forDirectory(getProjectFilesystem(), assembledNativeLibs.get(), temp.resolve("jni"), CopyStep.DirectoryMode.CONTENTS_ONLY));
    }
    // move native assets into tmp folder under assets/lib/
    for (SourcePath dir : nativeLibAssetsDirectories) {
        CopyNativeLibraries.copyNativeLibrary(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(dir), temp.resolve("assets").resolve("lib"), ImmutableSet.of(), commands);
    }
    // do the zipping
    commands.add(new MkdirStep(getProjectFilesystem(), pathToOutputFile.getParent()));
    commands.add(new ZipStep(getProjectFilesystem(), pathToOutputFile, ImmutableSet.of(), false, ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, temp));
    buildableContext.recordArtifact(pathToOutputFile);
    return commands.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ZipStep(com.facebook.buck.zip.ZipStep) RmStep(com.facebook.buck.step.fs.RmStep) ImmutableList(com.google.common.collect.ImmutableList) JarDirectoryStep(com.facebook.buck.jvm.java.JarDirectoryStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) 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) ZipStep(com.facebook.buck.zip.ZipStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) JarDirectoryStep(com.facebook.buck.jvm.java.JarDirectoryStep)

Example 2 with JarDirectoryStep

use of com.facebook.buck.jvm.java.JarDirectoryStep 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 3 with JarDirectoryStep

use of com.facebook.buck.jvm.java.JarDirectoryStep in project buck by facebook.

the class GwtModule method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    Path workingDirectory = outputFile.getParent();
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), workingDirectory));
    // A CopyResourcesStep is needed so that a file that is at java/com/example/resource.txt in the
    // repository will be added as com/example/resource.txt in the resulting JAR (assuming that
    // "/java/" is listed under src_roots in .buckconfig).
    Path tempJarFolder = workingDirectory.resolve("tmp");
    steps.add(new CopyResourcesStep(getProjectFilesystem(), context.getSourcePathResolver(), ruleFinder, getBuildTarget(), filesForGwtModule, tempJarFolder, context.getJavaPackageFinder()));
    steps.add(new JarDirectoryStep(getProjectFilesystem(), outputFile, /* entriesToJar */
    ImmutableSortedSet.of(tempJarFolder), /* mainClass */
    null, /* manifestFile */
    null));
    buildableContext.recordArtifact(outputFile);
    return steps.build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) JarDirectoryStep(com.facebook.buck.jvm.java.JarDirectoryStep) CopyResourcesStep(com.facebook.buck.jvm.java.CopyResourcesStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) JarDirectoryStep(com.facebook.buck.jvm.java.JarDirectoryStep) CopyResourcesStep(com.facebook.buck.jvm.java.CopyResourcesStep)

Example 4 with JarDirectoryStep

use of com.facebook.buck.jvm.java.JarDirectoryStep in project buck by facebook.

the class GenAidl method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> commands = ImmutableList.builder();
    commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), genPath));
    BuildTarget target = getBuildTarget();
    Path outputDirectory = BuildTargets.getScratchPath(getProjectFilesystem(), target, "__%s.aidl");
    commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDirectory));
    AidlStep command = new AidlStep(getProjectFilesystem(), target, context.getSourcePathResolver().getAbsolutePath(aidlFilePath), ImmutableSet.of(importPath), outputDirectory);
    commands.add(command);
    // Files must ultimately be written to GEN_DIR to be used as source paths.
    Path genDirectory = getProjectFilesystem().getBuckPaths().getGenDir().resolve(importPath);
    // Warn the user if the genDirectory is not under the output directory.
    if (!importPath.startsWith(target.getBasePath().toString())) {
        // TODO(shs96c): Make this fatal. Give people some time to clean up their rules.
        context.getEventBus().post(ConsoleEvent.warning("%s, gen_aidl import path (%s) should be a child of %s", target, importPath, target.getBasePath()));
    }
    commands.add(new MkdirStep(getProjectFilesystem(), genDirectory));
    commands.add(new JarDirectoryStep(getProjectFilesystem(), output, ImmutableSortedSet.of(outputDirectory), /* main class */
    null, /* manifest */
    null));
    buildableContext.recordArtifact(output);
    return commands.build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) BuildTarget(com.facebook.buck.model.BuildTarget) MkdirStep(com.facebook.buck.step.fs.MkdirStep) JarDirectoryStep(com.facebook.buck.jvm.java.JarDirectoryStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) JarDirectoryStep(com.facebook.buck.jvm.java.JarDirectoryStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep)

Aggregations

JarDirectoryStep (com.facebook.buck.jvm.java.JarDirectoryStep)4 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)4 SourcePath (com.facebook.buck.rules.SourcePath)4 Step (com.facebook.buck.step.Step)4 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)4 ImmutableList (com.google.common.collect.ImmutableList)4 MkdirStep (com.facebook.buck.step.fs.MkdirStep)3 Path (java.nio.file.Path)3 CalculateAbiStep (com.facebook.buck.jvm.java.CalculateAbiStep)1 CopyResourcesStep (com.facebook.buck.jvm.java.CopyResourcesStep)1 JavacStep (com.facebook.buck.jvm.java.JavacStep)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 CopyStep (com.facebook.buck.step.fs.CopyStep)1 RmStep (com.facebook.buck.step.fs.RmStep)1 WriteFileStep (com.facebook.buck.step.fs.WriteFileStep)1 ZipStep (com.facebook.buck.zip.ZipStep)1