Search in sources :

Example 1 with FileScrubberStep

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

the class Archive method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    // Cache the archive we built.
    buildableContext.recordArtifact(output);
    SourcePathResolver resolver = context.getSourcePathResolver();
    // paths.
    for (SourcePath input : inputs) {
        Preconditions.checkState(resolver.getFilesystem(input).getRootPath().equals(getProjectFilesystem().getRootPath()));
    }
    ImmutableList.Builder<Step> builder = ImmutableList.builder();
    builder.add(new MkdirStep(getProjectFilesystem(), output.getParent()), new RmStep(getProjectFilesystem(), output), new ArchiveStep(getProjectFilesystem(), archiver.getEnvironment(resolver), archiver.getCommandPrefix(resolver), archiverFlags, archiver.getArchiveOptions(contents == Contents.THIN), output, inputs.stream().map(resolver::getRelativePath).collect(MoreCollectors.toImmutableList()), archiver));
    if (archiver.isRanLibStepRequired()) {
        builder.add(new RanlibStep(getProjectFilesystem(), ranlib.getEnvironment(resolver), ranlib.getCommandPrefix(resolver), ranlibFlags, output));
    }
    if (!archiver.getScrubbers().isEmpty()) {
        builder.add(new FileScrubberStep(getProjectFilesystem(), output, archiver.getScrubbers()));
    }
    return builder.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) RmStep(com.facebook.buck.step.fs.RmStep) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep) FileScrubberStep(com.facebook.buck.step.fs.FileScrubberStep) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) FileScrubberStep(com.facebook.buck.step.fs.FileScrubberStep)

Example 2 with FileScrubberStep

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

the class ArchiveStepIntegrationTest method thatGeneratedArchivesAreDeterministic.

@Test
@SuppressWarnings("PMD.AvoidUsingOctalValues")
public void thatGeneratedArchivesAreDeterministic() throws IOException, InterruptedException {
    assumeTrue(Platform.detect() == Platform.MACOS || Platform.detect() == Platform.LINUX);
    ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot());
    CxxPlatform platform = CxxPlatformUtils.build(new CxxBuckConfig(FakeBuckConfig.builder().build()));
    // Build up the paths to various files the archive step will use.
    SourcePathResolver sourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    Archiver archiver = platform.getAr();
    Path output = filesystem.getPath("output.a");
    Path input = filesystem.getPath("input.dat");
    filesystem.writeContentsToPath("blah", input);
    Preconditions.checkState(filesystem.resolve(input).toFile().setExecutable(true));
    // Build an archive step.
    ArchiveStep archiveStep = new ArchiveStep(filesystem, archiver.getEnvironment(sourcePathResolver), archiver.getCommandPrefix(sourcePathResolver), ImmutableList.of(), getArchiveOptions(false), output, ImmutableList.of(input), archiver);
    FileScrubberStep fileScrubberStep = new FileScrubberStep(filesystem, output, platform.getAr().getScrubbers());
    // Execute the archive step and verify it ran successfully.
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    TestConsole console = (TestConsole) executionContext.getConsole();
    int exitCode = archiveStep.execute(executionContext).getExitCode();
    assertEquals("archive step failed: " + console.getTextWrittenToStdErr(), 0, exitCode);
    exitCode = fileScrubberStep.execute(executionContext).getExitCode();
    assertEquals("archive scrub step failed: " + console.getTextWrittenToStdErr(), 0, exitCode);
    // zero'd out.
    try (ArArchiveInputStream stream = new ArArchiveInputStream(new FileInputStream(filesystem.resolve(output).toFile()))) {
        ArArchiveEntry entry = stream.getNextArEntry();
        assertEquals(ObjectFileCommonModificationDate.COMMON_MODIFICATION_TIME_STAMP, entry.getLastModified());
        assertEquals(0, entry.getUserId());
        assertEquals(0, entry.getGroupId());
        assertEquals(String.format("0%o", entry.getMode()), 0100644, entry.getMode());
    }
}
Also used : Path(java.nio.file.Path) ArArchiveEntry(org.apache.commons.compress.archivers.ar.ArArchiveEntry) ArArchiveInputStream(org.apache.commons.compress.archivers.ar.ArArchiveInputStream) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) FileScrubberStep(com.facebook.buck.step.fs.FileScrubberStep) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FileInputStream(java.io.FileInputStream) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 3 with FileScrubberStep

use of com.facebook.buck.step.fs.FileScrubberStep 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)

Aggregations

FileScrubberStep (com.facebook.buck.step.fs.FileScrubberStep)3 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)2 SourcePath (com.facebook.buck.rules.SourcePath)2 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)2 MkdirStep (com.facebook.buck.step.fs.MkdirStep)2 RmStep (com.facebook.buck.step.fs.RmStep)2 Path (java.nio.file.Path)2 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 AbstractBuildRule (com.facebook.buck.rules.AbstractBuildRule)1 BuildRule (com.facebook.buck.rules.BuildRule)1 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)1 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)1 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)1 ExecutionContext (com.facebook.buck.step.ExecutionContext)1 Step (com.facebook.buck.step.Step)1 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)1 LogContentsOfFileStep (com.facebook.buck.step.fs.LogContentsOfFileStep)1 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)1 TestConsole (com.facebook.buck.testutil.TestConsole)1 ImmutableList (com.google.common.collect.ImmutableList)1