Search in sources :

Example 46 with MakeCleanDirectoryStep

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

the class Zip method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    Path output = getOutput();
    Path scratchDir = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s.zip.scratch");
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    steps.add(new RmStep(getProjectFilesystem(), output));
    steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir));
    SrcZipAwareFileBundler bundler = new SrcZipAwareFileBundler(getBuildTarget());
    bundler.copy(getProjectFilesystem(), context.getSourcePathResolver(), steps, scratchDir, sources);
    steps.add(new ZipStep(getProjectFilesystem(), output, ImmutableSortedSet.of(), /* junk paths */
    false, ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, scratchDir));
    buildableContext.recordArtifact(output);
    return steps.build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) RmStep(com.facebook.buck.step.fs.RmStep) ImmutableList(com.google.common.collect.ImmutableList) 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) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep)

Example 47 with MakeCleanDirectoryStep

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

the class CxxLink method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    buildableContext.recordArtifact(output);
    Optional<Path> linkerMapPath = getLinkerMapPath();
    if (linkerMapPath.isPresent() && LinkerMapMode.isLinkerMapEnabledForBuildTarget(getBuildTarget())) {
        buildableContext.recordArtifact(linkerMapPath.get());
    }
    Path scratchDir = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s-tmp");
    Path argFilePath = getProjectFilesystem().getRootPath().resolve(BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s.argsfile"));
    Path fileListPath = getProjectFilesystem().getRootPath().resolve(BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s__filelist.txt"));
    // Try to find all the cell roots used during the link.  This isn't technically correct since,
    // in theory not all inputs need to come from build rules, but it probably works in practice.
    // One way that we know would work is exposing every known cell root paths, since the only rules
    // that we built (and therefore need to scrub) will be in one of those roots.
    ImmutableSet.Builder<Path> cellRoots = ImmutableSet.builder();
    for (BuildRule dep : getDeps()) {
        cellRoots.add(dep.getProjectFilesystem().getRootPath());
    }
    return ImmutableList.of(new MkdirStep(getProjectFilesystem(), output.getParent()), new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir), new RmStep(getProjectFilesystem(), argFilePath), new RmStep(getProjectFilesystem(), fileListPath), CxxPrepareForLinkStep.create(argFilePath, fileListPath, linker.fileList(fileListPath), output, args, linker, getBuildTarget().getCellPath(), context.getSourcePathResolver()), new CxxLinkStep(getProjectFilesystem().getRootPath(), linker.getEnvironment(context.getSourcePathResolver()), linker.getCommandPrefix(context.getSourcePathResolver()), argFilePath, getProjectFilesystem().getRootPath().resolve(scratchDir)), new FileScrubberStep(getProjectFilesystem(), output, linker.getScrubbers(cellRoots.build())), new LogContentsOfFileStep(getProjectFilesystem().resolve(argFilePath), Level.FINEST), new RmStep(getProjectFilesystem(), argFilePath), new LogContentsOfFileStep(getProjectFilesystem().resolve(fileListPath), Level.FINEST), new RmStep(getProjectFilesystem(), fileListPath), new RmStep(getProjectFilesystem(), scratchDir, RmStep.Mode.RECURSIVE));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) RmStep(com.facebook.buck.step.fs.RmStep) ImmutableSet(com.google.common.collect.ImmutableSet) MkdirStep(com.facebook.buck.step.fs.MkdirStep) LogContentsOfFileStep(com.facebook.buck.step.fs.LogContentsOfFileStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) BuildRule(com.facebook.buck.rules.BuildRule) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) FileScrubberStep(com.facebook.buck.step.fs.FileScrubberStep)

Example 48 with MakeCleanDirectoryStep

use of com.facebook.buck.step.fs.MakeCleanDirectoryStep 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 49 with MakeCleanDirectoryStep

use of com.facebook.buck.step.fs.MakeCleanDirectoryStep 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 50 with MakeCleanDirectoryStep

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

the class JavaSourceJar method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    JavaPackageFinder packageFinder = context.getJavaPackageFinder();
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
    steps.add(new RmStep(getProjectFilesystem(), output));
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), temp));
    Set<Path> seenPackages = Sets.newHashSet();
    for (Path source : context.getSourcePathResolver().filterInputsToCompareToOutput(sources)) {
        Path packageFolder = packageFinder.findJavaPackageFolder(source);
        Path packageDir = temp.resolve(packageFolder);
        if (seenPackages.add(packageDir)) {
            steps.add(new MkdirStep(getProjectFilesystem(), packageDir));
        }
        steps.add(CopyStep.forFile(getProjectFilesystem(), source, packageDir.resolve(source.getFileName())));
    }
    steps.add(new ZipStep(getProjectFilesystem(), output, ImmutableSet.of(), /* junk paths */
    false, DEFAULT_COMPRESSION_LEVEL, temp));
    buildableContext.recordArtifact(output);
    return steps.build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) ZipStep(com.facebook.buck.zip.ZipStep) RmStep(com.facebook.buck.step.fs.RmStep) ImmutableList(com.google.common.collect.ImmutableList) 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) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) CopyStep(com.facebook.buck.step.fs.CopyStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) ZipStep(com.facebook.buck.zip.ZipStep)

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