Search in sources :

Example 1 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.

the class AidlStep method getShellCommandInternal.

@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
    ImmutableList.Builder<String> args = ImmutableList.builder();
    // The arguments passed to aidl are based off of what I observed when running Ant in verbose
    // mode.
    AndroidPlatformTarget androidPlatformTarget = context.getAndroidPlatformTarget();
    verifyImportPaths(filesystem, importDirectoryPaths);
    args.add(androidPlatformTarget.getAidlExecutable().toString());
    // For some reason, all of the flags to aidl do not permit a space between the flag name and
    // the flag value.
    // file created by --preprocess to import
    args.add("-p" + androidPlatformTarget.getAndroidFrameworkIdlFile().toString());
    // search path for import statements
    for (String importDirectoryPath : importDirectoryPaths) {
        Path resolved = filesystem.getPathForRelativePath(Paths.get(importDirectoryPath));
        args.add("-I" + resolved);
    }
    // base output folder for generated files
    args.add("-o" + filesystem.resolve(destinationDirectory));
    // aidl includes this path in the generated file and so it must not be absolute.
    args.add(MorePaths.relativize(workingDirectory, aidlFilePath).toString());
    return args.build();
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList)

Example 2 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList 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 3 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.

the class AndroidBinary method getBuildSteps.

@SuppressWarnings("PMD.PrematureDeclaration")
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    // The `HasInstallableApk` interface needs access to the manifest, so make sure we create our
    // own copy of this so that we don't have a runtime dep on the `AaptPackageResources` step.
    Path manifestPath = context.getSourcePathResolver().getRelativePath(getManifestPath());
    steps.add(new MkdirStep(getProjectFilesystem(), manifestPath.getParent()));
    steps.add(CopyStep.forFile(getProjectFilesystem(), context.getSourcePathResolver().getRelativePath(androidManifestPath), manifestPath));
    buildableContext.recordArtifact(manifestPath);
    // Create the .dex files if we aren't doing pre-dexing.
    DexFilesInfo dexFilesInfo = addFinalDxSteps(buildableContext, context.getSourcePathResolver(), steps);
    ////
    // BE VERY CAREFUL adding any code below here.
    // Any inputs to apkbuilder must be reflected in the hash returned by getAbiKeyForDeps.
    ////
    AndroidPackageableCollection packageableCollection = enhancementResult.getPackageableCollection();
    ImmutableSet.Builder<Path> nativeLibraryDirectoriesBuilder = ImmutableSet.builder();
    // Copy the transitive closure of native-libs-as-assets to a single directory, if any.
    ImmutableSet.Builder<Path> nativeLibraryAsAssetDirectories = ImmutableSet.builder();
    for (final APKModule module : enhancementResult.getAPKModuleGraph().getAPKModules()) {
        boolean shouldPackageAssetLibraries = packageAssetLibraries || !module.isRootModule();
        if (!ExopackageMode.enabledForNativeLibraries(exopackageModes) && enhancementResult.getCopyNativeLibraries().isPresent() && enhancementResult.getCopyNativeLibraries().get().containsKey(module)) {
            CopyNativeLibraries copyNativeLibraries = enhancementResult.getCopyNativeLibraries().get().get(module);
            if (shouldPackageAssetLibraries) {
                nativeLibraryDirectoriesBuilder.add(copyNativeLibraries.getPathToNativeLibsDir());
            } else {
                nativeLibraryDirectoriesBuilder.add(copyNativeLibraries.getPathToNativeLibsDir());
                nativeLibraryDirectoriesBuilder.add(copyNativeLibraries.getPathToNativeLibsAssetsDir());
            }
        }
        if ((!packageableCollection.getNativeLibAssetsDirectories().isEmpty()) || (!packageableCollection.getNativeLinkablesAssets().isEmpty() && shouldPackageAssetLibraries)) {
            Path pathForNativeLibsAsAssets = getPathForNativeLibsAsAssets();
            final Path libSubdirectory = pathForNativeLibsAsAssets.resolve("assets").resolve(module.isRootModule() ? "lib" : module.getName());
            ImmutableCollection<SourcePath> nativeLibDirs = packageableCollection.getNativeLibAssetsDirectories().get(module);
            getStepsForNativeAssets(context.getSourcePathResolver(), steps, nativeLibDirs == null ? Optional.empty() : Optional.of(nativeLibDirs), libSubdirectory, module.isRootModule() ? "metadata.txt" : "libs.txt", module);
            nativeLibraryAsAssetDirectories.add(pathForNativeLibsAsAssets);
        }
    }
    // If non-english strings are to be stored as assets, pass them to ApkBuilder.
    ImmutableSet.Builder<Path> zipFiles = ImmutableSet.builder();
    RichStream.from(primaryApkAssetsZips).map(context.getSourcePathResolver()::getRelativePath).forEach(zipFiles::add);
    if (ExopackageMode.enabledForNativeLibraries(exopackageModes)) {
        // We need to include a few dummy native libraries with our application so that Android knows
        // to run it as 32-bit.  Android defaults to 64-bit when no libraries are provided at all,
        // causing us to fail to load our 32-bit exopackage native libraries later.
        String fakeNativeLibraryBundle = System.getProperty("buck.native_exopackage_fake_path");
        if (fakeNativeLibraryBundle == null) {
            throw new RuntimeException("fake native bundle not specified in properties");
        }
        zipFiles.add(Paths.get(fakeNativeLibraryBundle));
    }
    ImmutableSet<Path> allAssetDirectories = ImmutableSet.<Path>builder().addAll(nativeLibraryAsAssetDirectories.build()).addAll(dexFilesInfo.secondaryDexDirs).build();
    SourcePathResolver resolver = context.getSourcePathResolver();
    Path signedApkPath = getSignedApkPath();
    final Path pathToKeystore = resolver.getAbsolutePath(keystorePath);
    Supplier<KeystoreProperties> keystoreProperties = Suppliers.memoize(() -> {
        try {
            return KeystoreProperties.createFromPropertiesFile(pathToKeystore, resolver.getAbsolutePath(keystorePropertiesPath), getProjectFilesystem());
        } catch (IOException e) {
            throw new RuntimeException();
        }
    });
    ApkBuilderStep apkBuilderCommand = new ApkBuilderStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(resourcesApkPath), getSignedApkPath(), dexFilesInfo.primaryDexPath, allAssetDirectories, nativeLibraryDirectoriesBuilder.build(), zipFiles.build(), packageableCollection.getPathsToThirdPartyJars().stream().map(resolver::getAbsolutePath).collect(MoreCollectors.toImmutableSet()), pathToKeystore, keystoreProperties, /* debugMode */
    false, javaRuntimeLauncher);
    steps.add(apkBuilderCommand);
    // The `ApkBuilderStep` delegates to android tools to build a ZIP with timestamps in it, making
    // the output non-deterministic.  So use an additional scrubbing step to zero these out.
    steps.add(new ZipScrubberStep(getProjectFilesystem(), signedApkPath));
    Path apkToRedexAndAlign;
    // Optionally, compress the resources file in the .apk.
    if (this.isCompressResources()) {
        Path compressedApkPath = getCompressedResourcesApkPath();
        apkToRedexAndAlign = compressedApkPath;
        RepackZipEntriesStep arscComp = new RepackZipEntriesStep(getProjectFilesystem(), signedApkPath, compressedApkPath, ImmutableSet.of("resources.arsc"));
        steps.add(arscComp);
    } else {
        apkToRedexAndAlign = signedApkPath;
    }
    boolean applyRedex = redexOptions.isPresent();
    Path apkPath = context.getSourcePathResolver().getRelativePath(getSourcePathToOutput());
    Path apkToAlign = apkToRedexAndAlign;
    // redex
    if (applyRedex) {
        Path proguardConfigDir = getProguardTextFilesPath();
        Path redexedApk = apkPath.getParent().resolve(apkPath.getFileName().toString() + ".redex");
        apkToAlign = redexedApk;
        ImmutableList<Step> redexSteps = ReDexStep.createSteps(getProjectFilesystem(), resolver, redexOptions.get(), apkToRedexAndAlign, redexedApk, keystoreProperties, proguardConfigDir, context.getSourcePathResolver());
        steps.addAll(redexSteps);
    }
    steps.add(new ZipalignStep(getProjectFilesystem().getRootPath(), apkToAlign, apkPath));
    buildableContext.recordArtifact(apkPath);
    return steps.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) CopyStep(com.facebook.buck.step.fs.CopyStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) SymlinkFilesIntoDirectoryStep(com.facebook.buck.shell.SymlinkFilesIntoDirectoryStep) AccumulateClassNamesStep(com.facebook.buck.jvm.java.AccumulateClassNamesStep) Step(com.facebook.buck.step.Step) RepackZipEntriesStep(com.facebook.buck.zip.RepackZipEntriesStep) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ReDexStep(com.facebook.buck.android.redex.ReDexStep) XzStep(com.facebook.buck.step.fs.XzStep) ZipScrubberStep(com.facebook.buck.zip.ZipScrubberStep) AbstractGenruleStep(com.facebook.buck.shell.AbstractGenruleStep) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ImmutableSet(com.google.common.collect.ImmutableSet) ZipScrubberStep(com.facebook.buck.zip.ZipScrubberStep) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) IOException(java.io.IOException) RepackZipEntriesStep(com.facebook.buck.zip.RepackZipEntriesStep) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 4 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList 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 5 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.

the class DxStep method getShellCommandInternal.

@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    AndroidPlatformTarget androidPlatformTarget = context.getAndroidPlatformTarget();
    String dx = androidPlatformTarget.getDxExecutable().toString();
    if (options.contains(Option.USE_CUSTOM_DX_IF_AVAILABLE)) {
        String customDx = Strings.emptyToNull(System.getProperty("buck.dx"));
        dx = customDx != null ? customDx : dx;
    }
    builder.add(dx);
    // Also, if DX works in-process, it probably wouldn't need an enlarged Xmx.
    if (maxHeapSize.isPresent() && !options.contains(Option.RUN_IN_PROCESS)) {
        builder.add(String.format("-JXmx%s", maxHeapSize.get()));
    }
    builder.add("--dex");
    // --statistics flag, if appropriate.
    if (context.getVerbosity().shouldPrintSelectCommandOutput()) {
        builder.add("--statistics");
    }
    if (options.contains(Option.NO_OPTIMIZE)) {
        builder.add("--no-optimize");
    }
    if (options.contains(Option.FORCE_JUMBO)) {
        builder.add("--force-jumbo");
    }
    // --no-locals flag, if appropriate.
    if (options.contains(Option.NO_LOCALS)) {
        builder.add("--no-locals");
    }
    // verbose flag, if appropriate.
    if (context.getVerbosity().shouldUseVerbosityFlagIfAvailable()) {
        builder.add("--verbose");
    }
    builder.add("--output", filesystem.resolve(outputDexFile).toString());
    for (Path fileToDex : filesToDex) {
        builder.add(filesystem.resolve(fileToDex).toString());
    }
    return builder.build();
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)983 List (java.util.List)256 ArrayList (java.util.ArrayList)148 Test (org.junit.Test)145 Path (java.nio.file.Path)143 Map (java.util.Map)135 ImmutableMap (com.google.common.collect.ImmutableMap)118 IOException (java.io.IOException)103 SourcePath (com.facebook.buck.rules.SourcePath)91 ImmutableSet (com.google.common.collect.ImmutableSet)91 Set (java.util.Set)89 Optional (java.util.Optional)77 Step (com.facebook.buck.step.Step)76 HashMap (java.util.HashMap)74 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)62 File (java.io.File)55 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)52 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)52 HashSet (java.util.HashSet)51 Collectors (java.util.stream.Collectors)50