Search in sources :

Example 21 with MakeCleanDirectoryStep

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

the class DefaultJavaLibrary method getBuildSteps.

/**
   * Building a java_library() rule entails compiling the .java files specified in the srcs
   * attribute. They are compiled into a directory under {@link BuckPaths#getScratchDir()}.
   */
@Override
public final ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    FluentIterable<JavaLibrary> declaredClasspathDeps = JavaLibraryClasspathProvider.getJavaLibraryDeps(getDepsForTransitiveClasspathEntries());
    // Always create the output directory, even if there are no .java files to compile because there
    // might be resources that need to be copied there.
    BuildTarget target = getBuildTarget();
    Path outputDirectory = getClassesDir(target, getProjectFilesystem());
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDirectory));
    SuggestBuildRules suggestBuildRule = DefaultSuggestBuildRules.createSuggestBuildFunction(JAR_RESOLVER, context.getSourcePathResolver(), declaredClasspathDeps.toSet(), ImmutableSet.<JavaLibrary>builder().addAll(getTransitiveClasspathDeps()).add(this).build(), context.getActionGraph().getNodes());
    // We don't want to add these to the declared or transitive deps, since they're only used at
    // compile time.
    Collection<Path> provided = JavaLibraryClasspathProvider.getJavaLibraryDeps(providedDeps).transformAndConcat(JavaLibrary::getOutputClasspaths).filter(Objects::nonNull).transform(context.getSourcePathResolver()::getAbsolutePath).toSet();
    Iterable<Path> declaredClasspaths = declaredClasspathDeps.transformAndConcat(JavaLibrary::getOutputClasspaths).transform(context.getSourcePathResolver()::getAbsolutePath);
    // Only override the bootclasspath if this rule is supposed to compile Android code.
    ImmutableSortedSet<Path> declared = ImmutableSortedSet.<Path>naturalOrder().addAll(declaredClasspaths).addAll(additionalClasspathEntries.stream().map(e -> e.isLeft() ? context.getSourcePathResolver().getAbsolutePath(e.getLeft()) : checkIsAbsolute(e.getRight())).collect(MoreCollectors.toImmutableSet())).addAll(provided).build();
    // Make sure that this directory exists because ABI information will be written here.
    Step mkdir = new MakeCleanDirectoryStep(getProjectFilesystem(), getPathToAbiOutputDir());
    steps.add(mkdir);
    // If there are resources, then link them to the appropriate place in the classes directory.
    JavaPackageFinder finder = context.getJavaPackageFinder();
    if (resourcesRoot.isPresent()) {
        finder = new ResourcesRootPackageFinder(resourcesRoot.get(), finder);
    }
    steps.add(new CopyResourcesStep(getProjectFilesystem(), context.getSourcePathResolver(), ruleFinder, target, resources, outputDirectory, finder));
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), getOutputJarDirPath(target, getProjectFilesystem())));
    // into the built jar.
    if (!getJavaSrcs().isEmpty()) {
        ClassUsageFileWriter usedClassesFileWriter;
        if (trackClassUsage) {
            final Path usedClassesFilePath = getUsedClassesFilePath(getBuildTarget(), getProjectFilesystem());
            depFileOutputPath = getProjectFilesystem().getPathForRelativePath(usedClassesFilePath);
            usedClassesFileWriter = new DefaultClassUsageFileWriter(usedClassesFilePath);
            buildableContext.recordArtifact(usedClassesFilePath);
        } else {
            usedClassesFileWriter = NoOpClassUsageFileWriter.instance();
        }
        // This adds the javac command, along with any supporting commands.
        Path pathToSrcsList = BuildTargets.getGenPath(getProjectFilesystem(), getBuildTarget(), "__%s__srcs");
        steps.add(new MkdirStep(getProjectFilesystem(), pathToSrcsList.getParent()));
        Path scratchDir = BuildTargets.getGenPath(getProjectFilesystem(), target, "lib__%s____working_directory");
        steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir));
        Optional<Path> workingDirectory = Optional.of(scratchDir);
        ImmutableSortedSet<Path> javaSrcs = getJavaSrcs().stream().map(context.getSourcePathResolver()::getRelativePath).collect(MoreCollectors.toImmutableSortedSet());
        compileStepFactory.createCompileToJarStep(context, javaSrcs, target, context.getSourcePathResolver(), ruleFinder, getProjectFilesystem(), declared, outputDirectory, workingDirectory, pathToSrcsList, Optional.of(suggestBuildRule), postprocessClassesCommands, ImmutableSortedSet.of(outputDirectory), /* mainClass */
        Optional.empty(), manifestFile.map(context.getSourcePathResolver()::getAbsolutePath), outputJar.get(), usedClassesFileWriter, /* output params */
        steps, buildableContext, classesToRemoveFromJar);
    }
    if (outputJar.isPresent()) {
        Path output = outputJar.get();
        // No source files, only resources
        if (getJavaSrcs().isEmpty()) {
            steps.add(new JarDirectoryStep(getProjectFilesystem(), output, ImmutableSortedSet.of(outputDirectory), /* mainClass */
            null, manifestFile.map(context.getSourcePathResolver()::getAbsolutePath).orElse(null), true, classesToRemoveFromJar));
        }
        buildableContext.recordArtifact(output);
    }
    JavaLibraryRules.addAccumulateClassNamesStep(this, buildableContext, context.getSourcePathResolver(), steps);
    return steps.build();
}
Also used : ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath) ClassPath(com.google.common.reflect.ClassPath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) BuildTarget(com.facebook.buck.model.BuildTarget) Objects(java.util.Objects) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) SuggestBuildRules(com.facebook.buck.jvm.core.SuggestBuildRules)

Example 22 with MakeCleanDirectoryStep

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

the class ReactNativeBundle method appendWorkerSteps.

private void appendWorkerSteps(ImmutableList.Builder<Step> stepBuilder, SourcePathResolver resolver, Path outputFile, Path sourceMapOutputPath, Path depFile) {
    // Setup the temp dir.
    final Path tmpDir = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s__tmp");
    stepBuilder.add(new MakeCleanDirectoryStep(getProjectFilesystem(), tmpDir));
    // Run the bundler.
    ReactNativeBundleWorkerStep workerStep = new ReactNativeBundleWorkerStep(getProjectFilesystem(), tmpDir, jsPackager.getCommandPrefix(resolver), packagerFlags, platform, isUnbundle, isIndexedUnbundle, getProjectFilesystem().resolve(resolver.getAbsolutePath(entryPath)), isDevMode, getProjectFilesystem().resolve(outputFile), getProjectFilesystem().resolve(resource), getProjectFilesystem().resolve(sourceMapOutputPath));
    stepBuilder.add(workerStep);
    // Run the package to get the used inputs.
    ReactNativeDepsWorkerStep depsWorkerStep = new ReactNativeDepsWorkerStep(getProjectFilesystem(), tmpDir, jsPackager.getCommandPrefix(resolver), packagerFlags, platform, getProjectFilesystem().resolve(resolver.getAbsolutePath(entryPath)), getProjectFilesystem().resolve(depFile));
    stepBuilder.add(depsWorkerStep);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep)

Example 23 with MakeCleanDirectoryStep

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

the class OcamlBuildStep method executeMLNativeCompilation.

private StepExecutionResult executeMLNativeCompilation(ExecutionContext context, Path workingDirectory, ImmutableList<Path> sortedInput, ImmutableList.Builder<Path> linkerInputs) throws IOException, InterruptedException {
    MakeCleanDirectoryStep mkDir = new MakeCleanDirectoryStep(filesystem, ocamlContext.getCompileNativeOutputDir());
    StepExecutionResult mkDirExecutionResult = mkDir.execute(context);
    if (!mkDirExecutionResult.isSuccess()) {
        return mkDirExecutionResult;
    }
    for (Path inputOutput : sortedInput) {
        String inputFileName = inputOutput.getFileName().toString();
        String outputFileName = inputFileName.replaceFirst(OcamlCompilables.OCAML_ML_REGEX, OcamlCompilables.OCAML_CMX).replaceFirst(OcamlCompilables.OCAML_RE_REGEX, OcamlCompilables.OCAML_CMX).replaceFirst(OcamlCompilables.OCAML_MLI_REGEX, OcamlCompilables.OCAML_CMI).replaceFirst(OcamlCompilables.OCAML_REI_REGEX, OcamlCompilables.OCAML_CMI);
        Path outputPath = ocamlContext.getCompileNativeOutputDir().resolve(outputFileName);
        if (!outputFileName.endsWith(OcamlCompilables.OCAML_CMI)) {
            linkerInputs.add(outputPath);
        }
        final ImmutableList<Arg> compileFlags = getCompileFlags(/* isBytecode */
        false, /* excludeDeps */
        false);
        Step compileStep = new OcamlMLCompileStep(workingDirectory, resolver, new OcamlMLCompileStep.Args(filesystem::resolve, cCompilerEnvironment, cCompiler, ocamlContext.getOcamlCompiler().get(), ocamlContext.getOcamlInteropIncludesDir(), outputPath, inputOutput, compileFlags));
        StepExecutionResult compileExecutionResult = compileStep.execute(context);
        if (!compileExecutionResult.isSuccess()) {
            return compileExecutionResult;
        }
    }
    return StepExecutionResult.SUCCESS;
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) Arg(com.facebook.buck.rules.args.Arg) StringArg(com.facebook.buck.rules.args.StringArg) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep)

Example 24 with MakeCleanDirectoryStep

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

the class ShTest method runTests.

@Override
public ImmutableList<Step> runTests(ExecutionContext executionContext, TestRunningOptions options, SourcePathResolver pathResolver, TestReportingCallback testReportingCallback) {
    Step mkdirClean = new MakeCleanDirectoryStep(getProjectFilesystem(), getPathToTestOutputDirectory());
    // Return a single command that runs an .sh file with no arguments.
    Step runTest = new RunShTestAndRecordResultStep(getProjectFilesystem(), pathResolver.getAbsolutePath(test), Arg.stringify(args, pathResolver), Arg.stringify(env, pathResolver), testRuleTimeoutMs, getBuildTarget().getFullyQualifiedName(), getPathToTestOutputResult());
    return ImmutableList.of(mkdirClean, runTest);
}
Also used : MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep)

Example 25 with MakeCleanDirectoryStep

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

the class Genrule method getBuildSteps.

@Override
@VisibleForTesting
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> commands = ImmutableList.builder();
    // Make sure that the directory to contain the output file exists, deleting any pre-existing
    // ones. Rules get output to a directory named after the base path, so we don't want to nuke
    // the entire directory.
    commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToOutDirectory));
    // Delete the old temp directory
    commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTmpDirectory));
    // Create a directory to hold all the source files.
    commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToSrcDirectory));
    addSymlinkCommands(context, commands);
    // Create a shell command that corresponds to this.cmd.
    if (this.isWorkerGenrule) {
        commands.add(createWorkerShellStep(context));
    } else {
        commands.add(createGenruleStep(context));
    }
    if (MorePaths.getFileExtension(pathToOutFile).equals("zip")) {
        commands.add(new ZipScrubberStep(getProjectFilesystem(), pathToOutFile));
    }
    buildableContext.recordArtifact(pathToOutFile);
    return commands.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MkdirAndSymlinkFileStep(com.facebook.buck.step.fs.MkdirAndSymlinkFileStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ZipScrubberStep(com.facebook.buck.zip.ZipScrubberStep) ZipScrubberStep(com.facebook.buck.zip.ZipScrubberStep) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)69 Path (java.nio.file.Path)57 SourcePath (com.facebook.buck.rules.SourcePath)53 Step (com.facebook.buck.step.Step)51 ImmutableList (com.google.common.collect.ImmutableList)47 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)42 MkdirStep (com.facebook.buck.step.fs.MkdirStep)25 ExecutionContext (com.facebook.buck.step.ExecutionContext)18 CopyStep (com.facebook.buck.step.fs.CopyStep)13 RmStep (com.facebook.buck.step.fs.RmStep)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 BuildTarget (com.facebook.buck.model.BuildTarget)10 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)9 BuildContext (com.facebook.buck.rules.BuildContext)9 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)9 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)9 StepExecutionResult (com.facebook.buck.step.StepExecutionResult)9 AbstractBuildRule (com.facebook.buck.rules.AbstractBuildRule)8 ShellStep (com.facebook.buck.shell.ShellStep)8 AbstractExecutionStep (com.facebook.buck.step.AbstractExecutionStep)8