Search in sources :

Example 1 with TouchStep

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

the class AndroidResource method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
    buildableContext.recordArtifact(Preconditions.checkNotNull(pathToTextSymbolsFile));
    buildableContext.recordArtifact(Preconditions.checkNotNull(pathToRDotJavaPackageFile));
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), Preconditions.checkNotNull(pathToTextSymbolsDir)));
    if (getRes() == null) {
        return steps.add(new TouchStep(getProjectFilesystem(), pathToTextSymbolsFile)).add(new WriteFileStep(getProjectFilesystem(), rDotJavaPackageArgument == null ? "" : rDotJavaPackageArgument, pathToRDotJavaPackageFile, false)).build();
    }
    // from the AndroidManifest.xml.
    if (rDotJavaPackageArgument == null) {
        Preconditions.checkNotNull(manifestFile, "manifestFile cannot be null when res is non-null and rDotJavaPackageArgument is " + "null. This should already be enforced by the constructor.");
        steps.add(new ExtractFromAndroidManifestStep(context.getSourcePathResolver().getAbsolutePath(manifestFile), getProjectFilesystem(), buildableContext, METADATA_KEY_FOR_R_DOT_JAVA_PACKAGE, Preconditions.checkNotNull(pathToRDotJavaPackageFile)));
    } else {
        steps.add(new WriteFileStep(getProjectFilesystem(), rDotJavaPackageArgument, pathToRDotJavaPackageFile, false));
    }
    ImmutableSet<Path> pathsToSymbolsOfDeps = symbolsOfDeps.get().stream().map(context.getSourcePathResolver()::getAbsolutePath).collect(MoreCollectors.toImmutableSet());
    steps.add(new MiniAapt(context.getSourcePathResolver(), getProjectFilesystem(), Preconditions.checkNotNull(res), Preconditions.checkNotNull(pathToTextSymbolsFile), pathsToSymbolsOfDeps, resourceUnion, isGrayscaleImageProcessingEnabled));
    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) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) TouchStep(com.facebook.buck.step.fs.TouchStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep) TouchStep(com.facebook.buck.step.fs.TouchStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep) MiniAapt(com.facebook.buck.android.aapt.MiniAapt)

Example 2 with TouchStep

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

the class GoCompile method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    buildableContext.recordArtifact(output);
    ImmutableList.Builder<Path> compileSrcListBuilder = ImmutableList.builder();
    ImmutableList.Builder<Path> headerSrcListBuilder = ImmutableList.builder();
    ImmutableList.Builder<Path> asmSrcListBuilder = ImmutableList.builder();
    for (SourcePath path : srcs) {
        Path srcPath = context.getSourcePathResolver().getAbsolutePath(path);
        String extension = MorePaths.getFileExtension(srcPath).toLowerCase();
        if (extension.equals("s")) {
            asmSrcListBuilder.add(srcPath);
        } else if (extension.equals("go")) {
            compileSrcListBuilder.add(srcPath);
        } else {
            headerSrcListBuilder.add(srcPath);
        }
    }
    ImmutableList<Path> compileSrcs = compileSrcListBuilder.build();
    ImmutableList<Path> headerSrcs = headerSrcListBuilder.build();
    ImmutableList<Path> asmSrcs = asmSrcListBuilder.build();
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
    Optional<Path> asmHeaderPath;
    if (!asmSrcs.isEmpty()) {
        asmHeaderPath = Optional.of(BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s/" + getBuildTarget().getShortName() + "__asm_hdr").resolve("go_asm.h"));
        steps.add(new MkdirStep(getProjectFilesystem(), asmHeaderPath.get().getParent()));
    } else {
        asmHeaderPath = Optional.empty();
    }
    boolean allowExternalReferences = !asmSrcs.isEmpty();
    if (compileSrcs.isEmpty()) {
        steps.add(new TouchStep(getProjectFilesystem(), output));
    } else {
        steps.add(new GoCompileStep(getProjectFilesystem().getRootPath(), compiler.getEnvironment(context.getSourcePathResolver()), compiler.getCommandPrefix(context.getSourcePathResolver()), compilerFlags, packageName, compileSrcs, importPathMap, ImmutableList.of(symlinkTree.getRoot()), asmHeaderPath, allowExternalReferences, platform, output));
    }
    if (!asmSrcs.isEmpty()) {
        Path asmIncludeDir = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s/" + getBuildTarget().getShortName() + "__asm_includes");
        steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), asmIncludeDir));
        if (!headerSrcs.isEmpty()) {
            // TODO(mikekap): Allow header-map style input.
            for (Path header : FluentIterable.from(headerSrcs).append(asmSrcs)) {
                steps.add(new SymlinkFileStep(getProjectFilesystem(), header, asmIncludeDir.resolve(header.getFileName()), /* useAbsolutePaths */
                true));
            }
        }
        Path asmOutputDir = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s/" + getBuildTarget().getShortName() + "__asm_compile");
        steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), asmOutputDir));
        ImmutableList.Builder<Path> asmOutputs = ImmutableList.builder();
        for (Path asmSrc : asmSrcs) {
            Path outputPath = asmOutputDir.resolve(asmSrc.getFileName().toString().replaceAll("\\.[sS]$", ".o"));
            steps.add(new GoAssembleStep(getProjectFilesystem().getRootPath(), assembler.getEnvironment(context.getSourcePathResolver()), assembler.getCommandPrefix(context.getSourcePathResolver()), assemblerFlags, asmSrc, ImmutableList.<Path>builder().addAll(assemblerIncludeDirs).add(asmHeaderPath.get().getParent()).add(asmIncludeDir).build(), platform, outputPath));
            asmOutputs.add(outputPath);
        }
        steps.add(new GoPackStep(getProjectFilesystem().getRootPath(), packer.getEnvironment(context.getSourcePathResolver()), packer.getCommandPrefix(context.getSourcePathResolver()), GoPackStep.Operation.APPEND, asmOutputs.build(), output));
    }
    return steps.build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) SymlinkFileStep(com.facebook.buck.step.fs.SymlinkFileStep) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) SymlinkFileStep(com.facebook.buck.step.fs.SymlinkFileStep) TouchStep(com.facebook.buck.step.fs.TouchStep) TouchStep(com.facebook.buck.step.fs.TouchStep) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep)

Example 3 with TouchStep

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

the class UnzipAar method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), unpackDirectory));
    steps.add(new UnzipStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(aarFile), unpackDirectory));
    steps.add(new TouchStep(getProjectFilesystem(), getProguardConfig()));
    steps.add(new MkdirStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(getAssetsDirectory())));
    steps.add(new MkdirStep(getProjectFilesystem(), getNativeLibsDirectory()));
    steps.add(new TouchStep(getProjectFilesystem(), getTextSymbolsFile()));
    // We take the classes.jar file that is required to exist in an .aar and merge it with any
    // .jar files under libs/ into an "uber" jar. We do this for simplicity because we do not know
    // how many entries there are in libs/ at graph enhancement time, but we need to make sure
    // that all of the .class files in the .aar get packaged. As it is implemented today, an
    // android_library that depends on an android_prebuilt_aar can compile against anything in the
    // .aar's classes.jar or libs/.
    steps.add(new MkdirStep(getProjectFilesystem(), uberClassesJar.getParent()));
    steps.add(new AbstractExecutionStep("create_uber_classes_jar") {

        @Override
        public StepExecutionResult execute(ExecutionContext context) {
            Path libsDirectory = unpackDirectory.resolve("libs");
            boolean dirDoesNotExistOrIsEmpty;
            if (!getProjectFilesystem().exists(libsDirectory)) {
                dirDoesNotExistOrIsEmpty = true;
            } else {
                try {
                    dirDoesNotExistOrIsEmpty = getProjectFilesystem().getDirectoryContents(libsDirectory).isEmpty();
                } catch (IOException e) {
                    context.logError(e, "Failed to get directory contents of %s", libsDirectory);
                    return StepExecutionResult.ERROR;
                }
            }
            Path classesJar = unpackDirectory.resolve("classes.jar");
            JavacEventSinkToBuckEventBusBridge eventSink = new JavacEventSinkToBuckEventBusBridge(context.getBuckEventBus());
            if (!getProjectFilesystem().exists(classesJar)) {
                try {
                    JarDirectoryStepHelper.createEmptyJarFile(getProjectFilesystem(), classesJar, eventSink, context.getStdErr());
                } catch (IOException e) {
                    context.logError(e, "Failed to create empty jar %s", classesJar);
                    return StepExecutionResult.ERROR;
                }
            }
            if (dirDoesNotExistOrIsEmpty) {
                try {
                    getProjectFilesystem().copy(classesJar, uberClassesJar, ProjectFilesystem.CopySourceMode.FILE);
                } catch (IOException e) {
                    context.logError(e, "Failed to copy from %s to %s", classesJar, uberClassesJar);
                    return StepExecutionResult.ERROR;
                }
            } else {
                // Glob all of the contents from classes.jar and the entries in libs/ into a single JAR.
                ImmutableSortedSet.Builder<Path> entriesToJarBuilder = ImmutableSortedSet.naturalOrder();
                entriesToJarBuilder.add(classesJar);
                try {
                    entriesToJarBuilder.addAll(getProjectFilesystem().getDirectoryContents(libsDirectory));
                } catch (IOException e) {
                    context.logError(e, "Failed to get directory contents of %s", libsDirectory);
                    return StepExecutionResult.ERROR;
                }
                ImmutableSortedSet<Path> entriesToJar = entriesToJarBuilder.build();
                try {
                    JarDirectoryStepHelper.createJarFile(getProjectFilesystem(), uberClassesJar, entriesToJar, /* mainClass */
                    Optional.empty(), /* manifestFile */
                    Optional.empty(), /* mergeManifests */
                    true, /* blacklist */
                    ImmutableSet.of(), eventSink, context.getStdErr());
                } catch (IOException e) {
                    context.logError(e, "Failed to jar %s into %s", entriesToJar, uberClassesJar);
                    return StepExecutionResult.ERROR;
                }
            }
            return StepExecutionResult.SUCCESS;
        }
    });
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTextSymbolsDir));
    steps.add(new ExtractFromAndroidManifestStep(getAndroidManifest(), getProjectFilesystem(), buildableContext, METADATA_KEY_FOR_R_DOT_JAVA_PACKAGE, pathToRDotJavaPackageFile));
    steps.add(CopyStep.forFile(getProjectFilesystem(), getTextSymbolsFile(), pathToTextSymbolsFile));
    buildableContext.recordArtifact(unpackDirectory);
    buildableContext.recordArtifact(uberClassesJar);
    buildableContext.recordArtifact(pathToTextSymbolsFile);
    buildableContext.recordArtifact(pathToRDotJavaPackageFile);
    return steps.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) UnzipStep(com.facebook.buck.zip.UnzipStep) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) Step(com.facebook.buck.step.Step) CopyStep(com.facebook.buck.step.fs.CopyStep) UnzipStep(com.facebook.buck.zip.UnzipStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) TouchStep(com.facebook.buck.step.fs.TouchStep) TouchStep(com.facebook.buck.step.fs.TouchStep) IOException(java.io.IOException) JavacEventSinkToBuckEventBusBridge(com.facebook.buck.jvm.java.JavacEventSinkToBuckEventBusBridge) ExecutionContext(com.facebook.buck.step.ExecutionContext) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep)

Example 4 with TouchStep

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

the class AaptPackageResources method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    // Copy manifest to a path named AndroidManifest.xml after replacing the manifest placeholders
    // if needed. Do this before running any other commands to ensure that it is available at the
    // desired path.
    steps.add(new MkdirStep(getProjectFilesystem(), getAndroidManifestXml().getParent()));
    Optional<ImmutableMap<String, String>> placeholders = manifestEntries.getPlaceholders();
    if (placeholders.isPresent() && !placeholders.get().isEmpty()) {
        steps.add(new ReplaceManifestPlaceholdersStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(manifest), getAndroidManifestXml(), placeholders.get()));
    } else {
        steps.add(CopyStep.forFile(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(manifest), getAndroidManifestXml()));
    }
    steps.add(new MkdirStep(getProjectFilesystem(), getResourceApkPath().getParent()));
    Path rDotTxtDir = getPathToRDotTxtDir();
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), rDotTxtDir));
    Path pathToGeneratedProguardConfig = getPathToGeneratedProguardConfigFile();
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToGeneratedProguardConfig.getParent()));
    buildableContext.recordArtifact(pathToGeneratedProguardConfig);
    steps.add(new AaptStep(getProjectFilesystem().getRootPath(), getAndroidManifestXml(), filteredResourcesProvider.getResDirectories(), context.getSourcePathResolver().getAllAbsolutePaths(assetsDirectories), getResourceApkPath(), rDotTxtDir, pathToGeneratedProguardConfig, /*
             * In practice, it appears that if --no-crunch is used, resources will occasionally
             * appear distorted in the APK produced by this command (and what's worse, a clean
             * reinstall does not make the problem go away). This is not reliably reproducible, so
             * for now, we categorically outlaw the use of --no-crunch so that developers do not get
             * stuck in the distorted image state. One would expect the use of --no-crunch to allow
             * for faster build times, so it would be nice to figure out a way to leverage it in
             * debug mode that never results in distorted images.
             */
    !skipCrunchPngs, /* && packageType.isCrunchPngFiles() */
    includesVectorDrawables, manifestEntries), new ZipScrubberStep(getProjectFilesystem(), getResourceApkPath()));
    // If we had an empty res directory, we won't generate an R.txt file.  This ensures that it
    // always exists.
    steps.add(new TouchStep(getProjectFilesystem(), getPathToRDotTxtFile()));
    if (hasRDotJava()) {
        generateRDotJavaFiles(steps, buildableContext, context);
    }
    // Record the filtered resources dirs, since when we initialize ourselves from disk, we'll
    // need to test whether this is empty or not without requiring the `ResourcesFilter` rule to
    // be available.
    buildableContext.addMetadata(FILTERED_RESOURCE_DIRS_KEY, FluentIterable.from(filteredResourcesProvider.getResDirectories()).transform(Object::toString).toSortedList(Ordering.natural()));
    buildableContext.recordArtifact(getAndroidManifestXml());
    buildableContext.recordArtifact(getResourceApkPath());
    steps.add(new RecordFileSha1Step(getProjectFilesystem(), getResourceApkPath(), RESOURCE_PACKAGE_HASH_KEY, buildableContext));
    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) Step(com.facebook.buck.step.Step) CopyStep(com.facebook.buck.step.fs.CopyStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) RecordFileSha1Step(com.facebook.buck.rules.RecordFileSha1Step) ZipScrubberStep(com.facebook.buck.zip.ZipScrubberStep) TouchStep(com.facebook.buck.step.fs.TouchStep) TouchStep(com.facebook.buck.step.fs.TouchStep) ImmutableMap(com.google.common.collect.ImmutableMap) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) RecordFileSha1Step(com.facebook.buck.rules.RecordFileSha1Step) ZipScrubberStep(com.facebook.buck.zip.ZipScrubberStep)

Example 5 with TouchStep

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

the class ProGuardObfuscateStep method create.

/**
   * Create steps that write out ProGuard's command line arguments to a text file and then run
   * ProGuard using those arguments. We write the arguments to a file to avoid blowing out
   * exec()'s ARG_MAX limit.
   *
   * @param steps Where to append the generated steps.
   */
public static void create(JavaRuntimeLauncher javaRuntimeLauncher, ProjectFilesystem filesystem, Optional<Path> proguardJarOverride, String proguardMaxHeapSize, Optional<String> proguardAgentPath, Path generatedProGuardConfig, Set<Path> customProguardConfigs, SdkProguardType sdkProguardConfig, Optional<Integer> optimizationPasses, Optional<List<String>> proguardJvmArgs, Map<Path, Path> inputAndOutputEntries, Set<Path> additionalLibraryJarsForProguard, Path proguardDirectory, BuildableContext buildableContext, boolean skipProguard, ImmutableList.Builder<Step> steps) {
    steps.add(new MakeCleanDirectoryStep(filesystem, proguardDirectory));
    Path pathToProGuardCommandLineArgsFile = proguardDirectory.resolve("command-line.txt");
    CommandLineHelperStep commandLineHelperStep = new CommandLineHelperStep(filesystem, generatedProGuardConfig, customProguardConfigs, sdkProguardConfig, optimizationPasses, inputAndOutputEntries, additionalLibraryJarsForProguard, proguardDirectory, pathToProGuardCommandLineArgsFile);
    if (skipProguard) {
        steps.add(commandLineHelperStep, new TouchStep(filesystem, commandLineHelperStep.getMappingTxt()));
    } else {
        ProGuardObfuscateStep proGuardStep = new ProGuardObfuscateStep(javaRuntimeLauncher, filesystem, inputAndOutputEntries, pathToProGuardCommandLineArgsFile, skipProguard, proguardJarOverride, proguardMaxHeapSize, proguardJvmArgs, proguardAgentPath);
        buildableContext.recordArtifact(commandLineHelperStep.getConfigurationTxt());
        buildableContext.recordArtifact(commandLineHelperStep.getMappingTxt());
        buildableContext.recordArtifact(commandLineHelperStep.getSeedsTxt());
        steps.add(commandLineHelperStep, proGuardStep, // here to guarantee it's around when we go to cache this rule.
        new TouchStep(filesystem, commandLineHelperStep.getMappingTxt()));
    }
}
Also used : Path(java.nio.file.Path) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) TouchStep(com.facebook.buck.step.fs.TouchStep)

Aggregations

MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)5 TouchStep (com.facebook.buck.step.fs.TouchStep)5 Path (java.nio.file.Path)5 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)4 SourcePath (com.facebook.buck.rules.SourcePath)4 Step (com.facebook.buck.step.Step)4 ImmutableList (com.google.common.collect.ImmutableList)4 MkdirStep (com.facebook.buck.step.fs.MkdirStep)3 CopyStep (com.facebook.buck.step.fs.CopyStep)2 MiniAapt (com.facebook.buck.android.aapt.MiniAapt)1 JavacEventSinkToBuckEventBusBridge (com.facebook.buck.jvm.java.JavacEventSinkToBuckEventBusBridge)1 RecordFileSha1Step (com.facebook.buck.rules.RecordFileSha1Step)1 AbstractExecutionStep (com.facebook.buck.step.AbstractExecutionStep)1 ExecutionContext (com.facebook.buck.step.ExecutionContext)1 StepExecutionResult (com.facebook.buck.step.StepExecutionResult)1 SymlinkFileStep (com.facebook.buck.step.fs.SymlinkFileStep)1 WriteFileStep (com.facebook.buck.step.fs.WriteFileStep)1 UnzipStep (com.facebook.buck.zip.UnzipStep)1 ZipScrubberStep (com.facebook.buck.zip.ZipScrubberStep)1 ImmutableMap (com.google.common.collect.ImmutableMap)1