Search in sources :

Example 46 with MkdirStep

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

the class CxxInferComputeReport method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    buildableContext.recordArtifact(reportOutput);
    ImmutableSortedSet<Path> reportsToMergeFromDeps = FluentIterable.from(analysisToReport.getTransitiveAnalyzeRules()).transform(CxxInferAnalyze::getSourcePathToOutput).transform(context.getSourcePathResolver()::getAbsolutePath).toSortedSet(Ordering.natural());
    ImmutableSortedSet<Path> reportsToMerge = ImmutableSortedSet.<Path>naturalOrder().addAll(reportsToMergeFromDeps).add(context.getSourcePathResolver().getAbsolutePath(analysisToReport.getSourcePathToOutput())).build();
    return ImmutableList.<Step>builder().add(new MkdirStep(projectFilesystem, outputDirectory)).add(new JsonConcatenateStep(projectFilesystem, reportsToMerge, reportOutput, "infer-merge-reports", "Merge Infer Reports")).build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) JsonConcatenateStep(com.facebook.buck.json.JsonConcatenateStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep)

Example 47 with MkdirStep

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

the class JarFattener method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    Path outputDir = getOutputDirectory();
    Path fatJarDir = outputDir.resolve("fat-jar-directory");
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDir));
    // Map of the system-specific shared library name to it's resource name as a string.
    ImmutableMap.Builder<String, String> sonameToResourceMapBuilder = ImmutableMap.builder();
    for (Map.Entry<String, SourcePath> entry : nativeLibraries.entrySet()) {
        String resource = FAT_JAR_NATIVE_LIBRARY_RESOURCE_ROOT + "/" + entry.getKey();
        sonameToResourceMapBuilder.put(entry.getKey(), resource);
        steps.add(new MkdirStep(getProjectFilesystem(), fatJarDir.resolve(resource).getParent()));
        steps.add(new SymlinkFileStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(entry.getValue()), fatJarDir.resolve(resource), /* useAbsolutePaths */
        true));
    }
    ImmutableMap<String, String> sonameToResourceMap = sonameToResourceMapBuilder.build();
    // Grab the source path representing the fat jar info resource.
    Path fatJarInfo = fatJarDir.resolve(FatJar.FAT_JAR_INFO_RESOURCE);
    steps.add(writeFatJarInfo(fatJarInfo, sonameToResourceMap));
    // Build up the resource and src collections.
    Set<Path> javaSourceFilePaths = Sets.newHashSet();
    for (String srcResource : FAT_JAR_SRC_RESOURCES) {
        Path fatJarSource = outputDir.resolve(Paths.get(srcResource).getFileName());
        javaSourceFilePaths.add(fatJarSource);
        steps.add(writeFromResource(fatJarSource, srcResource));
    }
    Path fatJarMainSource = outputDir.resolve(Paths.get(FAT_JAR_MAIN_SRC_RESOURCE).getFileName());
    javaSourceFilePaths.add(fatJarMainSource);
    steps.add(writeFromResource(fatJarMainSource, FAT_JAR_MAIN_SRC_RESOURCE));
    // Symlink the inner JAR into it's place in the fat JAR.
    steps.add(new MkdirStep(getProjectFilesystem(), fatJarDir.resolve(FAT_JAR_INNER_JAR).getParent()));
    steps.add(new SymlinkFileStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(innerJar), fatJarDir.resolve(FAT_JAR_INNER_JAR), /* useAbsolutePaths */
    true));
    // Build the final fat JAR from the structure we've layed out above.  We first package the
    // fat jar resources (e.g. native libs) using the "stored" compression level, to avoid
    // expensive compression on builds and decompression on startup.
    Path zipped = outputDir.resolve("contents.zip");
    Step zipStep = new ZipStep(getProjectFilesystem(), zipped, ImmutableSet.of(), false, ZipCompressionLevel.MIN_COMPRESSION_LEVEL, fatJarDir);
    Path pathToSrcsList = BuildTargets.getGenPath(getProjectFilesystem(), getBuildTarget(), "__%s__srcs");
    steps.add(new MkdirStep(getProjectFilesystem(), pathToSrcsList.getParent()));
    CompileToJarStepFactory compileStepFactory = new JavacToJarStepFactory(javacOptions, JavacOptionsAmender.IDENTITY);
    compileStepFactory.createCompileStep(context, ImmutableSortedSet.copyOf(javaSourceFilePaths), getBuildTarget(), context.getSourcePathResolver(), ruleFinder, getProjectFilesystem(), /* classpathEntries */
    ImmutableSortedSet.of(), fatJarDir, /* workingDir */
    Optional.empty(), pathToSrcsList, /* suggestBuildRule */
    Optional.empty(), NoOpClassUsageFileWriter.instance(), steps, buildableContext);
    steps.add(zipStep);
    steps.add(new JarDirectoryStep(getProjectFilesystem(), output, ImmutableSortedSet.of(zipped), /* mainClass */
    FatJarMain.class.getName(), /* manifestFile */
    null));
    return steps.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ZipStep(com.facebook.buck.zip.ZipStep) 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) MkdirStep(com.facebook.buck.step.fs.MkdirStep) ZipStep(com.facebook.buck.zip.ZipStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) SymlinkFileStep(com.facebook.buck.step.fs.SymlinkFileStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep) ImmutableMap(com.google.common.collect.ImmutableMap) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 48 with MkdirStep

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

the class JavaBinary method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> commands = ImmutableList.builder();
    Path outputDirectory = getOutputDirectory();
    Step mkdir = new MkdirStep(getProjectFilesystem(), outputDirectory);
    commands.add(mkdir);
    ImmutableSortedSet<Path> includePaths;
    if (metaInfDirectory != null) {
        Path stagingRoot = outputDirectory.resolve("meta_inf_staging");
        Path stagingTarget = stagingRoot.resolve("META-INF");
        MakeCleanDirectoryStep createStagingRoot = new MakeCleanDirectoryStep(getProjectFilesystem(), stagingRoot);
        commands.add(createStagingRoot);
        MkdirAndSymlinkFileStep link = new MkdirAndSymlinkFileStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(metaInfDirectory), stagingTarget);
        commands.add(link);
        includePaths = ImmutableSortedSet.<Path>naturalOrder().add(stagingRoot).addAll(context.getSourcePathResolver().getAllAbsolutePaths(getTransitiveClasspaths())).build();
    } else {
        includePaths = context.getSourcePathResolver().getAllAbsolutePaths(getTransitiveClasspaths());
    }
    Path outputFile = context.getSourcePathResolver().getRelativePath(getSourcePathToOutput());
    Path manifestPath = manifestFile == null ? null : context.getSourcePathResolver().getAbsolutePath(manifestFile);
    Step jar = new JarDirectoryStep(getProjectFilesystem(), outputFile, includePaths, mainClass, manifestPath, mergeManifests, blacklist);
    commands.add(jar);
    buildableContext.recordArtifact(outputFile);
    return commands.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MkdirAndSymlinkFileStep(com.facebook.buck.step.fs.MkdirAndSymlinkFileStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) MkdirAndSymlinkFileStep(com.facebook.buck.step.fs.MkdirAndSymlinkFileStep)

Example 49 with MkdirStep

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

the class JavaTest method getPostBuildSteps.

@Override
public ImmutableList<Step> getPostBuildSteps(BuildContext buildContext) {
    return ImmutableList.<Step>builder().add(new MkdirStep(getProjectFilesystem(), getClassPathFile().getParent())).add(new AbstractExecutionStep("write classpath file") {

        @Override
        public StepExecutionResult execute(ExecutionContext context) throws IOException {
            ImmutableSet<Path> classpathEntries = ImmutableSet.<Path>builder().addAll(compiledTestsLibrary.getTransitiveClasspaths().stream().map(buildContext.getSourcePathResolver()::getAbsolutePath).collect(MoreCollectors.toImmutableSet())).addAll(additionalClasspathEntries.stream().map(e -> e.isLeft() ? buildContext.getSourcePathResolver().getAbsolutePath(e.getLeft()) : e.getRight()).collect(MoreCollectors.toImmutableSet())).addAll(getBootClasspathEntries(context)).build();
            getProjectFilesystem().writeLinesToPath(Iterables.transform(classpathEntries, Object::toString), getClassPathFile());
            return StepExecutionResult.SUCCESS;
        }
    }).build();
}
Also used : Path(java.nio.file.Path) ForwardingBuildTargetSourcePath(com.facebook.buck.rules.ForwardingBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExecutionContext(com.facebook.buck.step.ExecutionContext) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep)

Example 50 with MkdirStep

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

the class JavaLibraryRules method addAccumulateClassNamesStep.

static void addAccumulateClassNamesStep(JavaLibrary javaLibrary, BuildableContext buildableContext, SourcePathResolver pathResolver, ImmutableList.Builder<Step> steps) {
    Path pathToClassHashes = JavaLibraryRules.getPathToClassHashes(javaLibrary.getBuildTarget(), javaLibrary.getProjectFilesystem());
    steps.add(new MkdirStep(javaLibrary.getProjectFilesystem(), pathToClassHashes.getParent()));
    steps.add(new AccumulateClassNamesStep(javaLibrary.getProjectFilesystem(), Optional.ofNullable(javaLibrary.getSourcePathToOutput()).map(pathResolver::getRelativePath), pathToClassHashes));
    buildableContext.recordArtifact(pathToClassHashes);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) MkdirStep(com.facebook.buck.step.fs.MkdirStep)

Aggregations

MkdirStep (com.facebook.buck.step.fs.MkdirStep)61 Path (java.nio.file.Path)44 SourcePath (com.facebook.buck.rules.SourcePath)43 Step (com.facebook.buck.step.Step)41 ImmutableList (com.google.common.collect.ImmutableList)38 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)34 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)27 RmStep (com.facebook.buck.step.fs.RmStep)20 CopyStep (com.facebook.buck.step.fs.CopyStep)14 ExecutionContext (com.facebook.buck.step.ExecutionContext)13 AbstractExecutionStep (com.facebook.buck.step.AbstractExecutionStep)12 WriteFileStep (com.facebook.buck.step.fs.WriteFileStep)10 ImmutableMap (com.google.common.collect.ImmutableMap)10 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)8 IOException (java.io.IOException)7 ImmutableSet (com.google.common.collect.ImmutableSet)6 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)6 BuildTarget (com.facebook.buck.model.BuildTarget)5 AbstractBuildRule (com.facebook.buck.rules.AbstractBuildRule)5 PathSourcePath (com.facebook.buck.rules.PathSourcePath)5