Search in sources :

Example 1 with ProjectFilesystem

use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.

the class AndroidBinary method getStepsForNativeAssets.

private void getStepsForNativeAssets(SourcePathResolver resolver, ImmutableList.Builder<Step> steps, Optional<ImmutableCollection<SourcePath>> nativeLibDirs, final Path libSubdirectory, final String metadataFilename, final APKModule module) {
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), libSubdirectory));
    // Filter, rename and copy the ndk libraries marked as assets.
    if (nativeLibDirs.isPresent()) {
        for (SourcePath nativeLibDir : nativeLibDirs.get()) {
            CopyNativeLibraries.copyNativeLibrary(getProjectFilesystem(), resolver.getAbsolutePath(nativeLibDir), libSubdirectory, cpuFilters, steps);
        }
    }
    // Input asset libraries are sorted in descending filesize order.
    final ImmutableSortedSet.Builder<Path> inputAssetLibrariesBuilder = ImmutableSortedSet.orderedBy((libPath1, libPath2) -> {
        try {
            ProjectFilesystem filesystem = getProjectFilesystem();
            int filesizeResult = -Long.compare(filesystem.getFileSize(libPath1), filesystem.getFileSize(libPath2));
            int pathnameResult = libPath1.compareTo(libPath2);
            return filesizeResult != 0 ? filesizeResult : pathnameResult;
        } catch (IOException e) {
            return 0;
        }
    });
    if (packageAssetLibraries || !module.isRootModule()) {
        if (enhancementResult.getCopyNativeLibraries().isPresent() && enhancementResult.getCopyNativeLibraries().get().containsKey(module)) {
            // Copy in cxx libraries marked as assets. Filtering and renaming was already done
            // in CopyNativeLibraries.getBuildSteps().
            Path cxxNativeLibsSrc = enhancementResult.getCopyNativeLibraries().get().get(module).getPathToNativeLibsAssetsDir();
            steps.add(CopyStep.forDirectory(getProjectFilesystem(), cxxNativeLibsSrc, libSubdirectory, CopyStep.DirectoryMode.CONTENTS_ONLY));
        }
        steps.add(// Step that populates a list of libraries and writes a metadata.txt to decompress.
        new AbstractExecutionStep("write_metadata_for_asset_libraries_" + module.getName()) {

            @Override
            public StepExecutionResult execute(ExecutionContext context) {
                ProjectFilesystem filesystem = getProjectFilesystem();
                try {
                    // Walk file tree to find libraries
                    filesystem.walkRelativeFileTree(libSubdirectory, new SimpleFileVisitor<Path>() {

                        @Override
                        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                            if (!file.toString().endsWith(".so")) {
                                throw new IOException("unexpected file in lib directory");
                            }
                            inputAssetLibrariesBuilder.add(file);
                            return FileVisitResult.CONTINUE;
                        }
                    });
                    // Write a metadata
                    ImmutableList.Builder<String> metadataLines = ImmutableList.builder();
                    Path metadataOutput = libSubdirectory.resolve(metadataFilename);
                    for (Path libPath : inputAssetLibrariesBuilder.build()) {
                        // Should return something like x86/libfoo.so
                        Path relativeLibPath = libSubdirectory.relativize(libPath);
                        long filesize = filesystem.getFileSize(libPath);
                        String desiredOutput = relativeLibPath.toString();
                        String checksum = filesystem.computeSha256(libPath);
                        metadataLines.add(desiredOutput + ' ' + filesize + ' ' + checksum);
                    }
                    ImmutableList<String> metadata = metadataLines.build();
                    if (!metadata.isEmpty()) {
                        filesystem.writeLinesToPath(metadata, metadataOutput);
                    }
                } catch (IOException e) {
                    context.logError(e, "Writing metadata for asset libraries failed.");
                    return StepExecutionResult.ERROR;
                }
                return StepExecutionResult.SUCCESS;
            }
        });
    }
    if (compressAssetLibraries || !module.isRootModule()) {
        final ImmutableList.Builder<Path> outputAssetLibrariesBuilder = ImmutableList.builder();
        steps.add(new AbstractExecutionStep("rename_asset_libraries_as_temp_files_" + module.getName()) {

            @Override
            public StepExecutionResult execute(ExecutionContext context) {
                try {
                    ProjectFilesystem filesystem = getProjectFilesystem();
                    for (Path libPath : inputAssetLibrariesBuilder.build()) {
                        Path tempPath = libPath.resolveSibling(libPath.getFileName() + "~");
                        filesystem.move(libPath, tempPath);
                        outputAssetLibrariesBuilder.add(tempPath);
                    }
                    return StepExecutionResult.SUCCESS;
                } catch (IOException e) {
                    context.logError(e, "Renaming asset libraries failed");
                    return StepExecutionResult.ERROR;
                }
            }
        });
        // Concat and xz compress.
        Path libOutputBlob = libSubdirectory.resolve("libraries.blob");
        steps.add(new ConcatStep(getProjectFilesystem(), outputAssetLibrariesBuilder, libOutputBlob));
        int compressionLevel = xzCompressionLevel.orElse(XzStep.DEFAULT_COMPRESSION_LEVEL).intValue();
        steps.add(new XzStep(getProjectFilesystem(), libOutputBlob, libSubdirectory.resolve(SOLID_COMPRESSED_ASSET_LIBRARY_FILENAME), compressionLevel));
    }
}
Also used : Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) ImmutableList(com.google.common.collect.ImmutableList) XzStep(com.facebook.buck.step.fs.XzStep) IOException(java.io.IOException) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ExecutionContext(com.facebook.buck.step.ExecutionContext) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 2 with ProjectFilesystem

use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.

the class AppleResources method collectResourceDirsAndFiles.

public static <T> AppleBundleResources collectResourceDirsAndFiles(final TargetGraph targetGraph, final Optional<AppleDependenciesCache> cache, TargetNode<T, ?> targetNode) {
    AppleBundleResources.Builder builder = AppleBundleResources.builder();
    Iterable<TargetNode<?, ?>> resourceNodes = AppleBuildRules.getRecursiveTargetNodeDependenciesOfTypes(targetGraph, cache, AppleBuildRules.RecursiveDependenciesMode.COPYING, targetNode, Optional.of(APPLE_RESOURCE_DESCRIPTION_CLASSES));
    ProjectFilesystem filesystem = targetNode.getFilesystem();
    for (TargetNode<?, ?> resourceNode : resourceNodes) {
        Object constructorArg = resourceNode.getConstructorArg();
        if (constructorArg instanceof AppleResourceDescription.Arg) {
            AppleResourceDescription.Arg appleResource = (AppleResourceDescription.Arg) constructorArg;
            builder.addAllResourceDirs(appleResource.dirs);
            builder.addAllResourceFiles(appleResource.files);
            builder.addAllResourceVariantFiles(appleResource.variants);
        } else {
            Preconditions.checkState(constructorArg instanceof ReactNativeLibraryArgs);
            BuildTarget buildTarget = resourceNode.getBuildTarget();
            builder.addDirsContainingResourceDirs(new ExplicitBuildTargetSourcePath(buildTarget, ReactNativeBundle.getPathToJSBundleDir(buildTarget, filesystem)), new ExplicitBuildTargetSourcePath(buildTarget, ReactNativeBundle.getPathToResources(buildTarget, filesystem)));
        }
    }
    return builder.build();
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) ReactNativeLibraryArgs(com.facebook.buck.js.ReactNativeLibraryArgs) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Example 3 with ProjectFilesystem

use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.

the class RageCommand method runWithoutHelp.

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    ProjectFilesystem filesystem = params.getCell().getFilesystem();
    BuckConfig buckConfig = params.getBuckConfig();
    RageConfig rageConfig = RageConfig.of(buckConfig);
    ProcessExecutor processExecutor = new DefaultProcessExecutor(params.getConsole());
    VersionControlCmdLineInterfaceFactory vcsFactory = new DefaultVersionControlCmdLineInterfaceFactory(params.getCell().getFilesystem().getRootPath(), new PrintStreamProcessExecutorFactory(), new VersionControlBuckConfig(buckConfig), buckConfig.getEnvironment());
    Optional<VcsInfoCollector> vcsInfoCollector = VcsInfoCollector.create(vcsFactory.createCmdLineInterface());
    ExtraInfoCollector extraInfoCollector = new DefaultExtraInfoCollector(rageConfig, filesystem, processExecutor);
    Optional<WatchmanDiagReportCollector> watchmanDiagReportCollector = WatchmanDiagReportCollector.newInstanceIfWatchmanUsed(params.getCell(), filesystem, processExecutor, new ExecutableFinder(), params.getEnvironment());
    AbstractReport report;
    DefaultDefectReporter reporter = new DefaultDefectReporter(filesystem, params.getObjectMapper(), rageConfig, params.getBuckEventBus(), params.getClock());
    if (params.getConsole().getAnsi().isAnsiTerminal() && !nonInteractive) {
        report = new InteractiveReport(reporter, filesystem, params.getObjectMapper(), params.getConsole(), params.getStdIn(), params.getBuildEnvironmentDescription(), vcsInfoCollector, rageConfig, extraInfoCollector, watchmanDiagReportCollector);
    } else {
        report = new AutomatedReport(reporter, filesystem, params.getObjectMapper(), params.getConsole(), params.getBuildEnvironmentDescription(), gatherVcsInfo ? vcsInfoCollector : Optional.empty(), rageConfig, extraInfoCollector);
    }
    Optional<DefectSubmitResult> defectSubmitResult = report.collectAndSubmitResult();
    report.presentDefectSubmitResult(defectSubmitResult, showJson);
    return 0;
}
Also used : ExecutableFinder(com.facebook.buck.io.ExecutableFinder) VcsInfoCollector(com.facebook.buck.rage.VcsInfoCollector) AutomatedReport(com.facebook.buck.rage.AutomatedReport) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) DefaultExtraInfoCollector(com.facebook.buck.rage.DefaultExtraInfoCollector) ExtraInfoCollector(com.facebook.buck.rage.ExtraInfoCollector) RageConfig(com.facebook.buck.rage.RageConfig) DefaultVersionControlCmdLineInterfaceFactory(com.facebook.buck.util.versioncontrol.DefaultVersionControlCmdLineInterfaceFactory) VersionControlBuckConfig(com.facebook.buck.util.versioncontrol.VersionControlBuckConfig) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) DefaultVersionControlCmdLineInterfaceFactory(com.facebook.buck.util.versioncontrol.DefaultVersionControlCmdLineInterfaceFactory) VersionControlCmdLineInterfaceFactory(com.facebook.buck.util.versioncontrol.VersionControlCmdLineInterfaceFactory) DefectSubmitResult(com.facebook.buck.rage.DefectSubmitResult) VersionControlBuckConfig(com.facebook.buck.util.versioncontrol.VersionControlBuckConfig) WatchmanDiagReportCollector(com.facebook.buck.rage.WatchmanDiagReportCollector) AbstractReport(com.facebook.buck.rage.AbstractReport) InteractiveReport(com.facebook.buck.rage.InteractiveReport) DefaultDefectReporter(com.facebook.buck.rage.DefaultDefectReporter) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) PrintStreamProcessExecutorFactory(com.facebook.buck.util.PrintStreamProcessExecutorFactory) DefaultExtraInfoCollector(com.facebook.buck.rage.DefaultExtraInfoCollector)

Example 4 with ProjectFilesystem

use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.

the class GwtBinary method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    // Create a clean directory where the .zip file will be written.
    Path workingDirectory = context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()).getParent();
    ProjectFilesystem projectFilesystem = getProjectFilesystem();
    steps.add(new MakeCleanDirectoryStep(projectFilesystem, workingDirectory));
    // Write the deploy files into a separate directory so that the generated .zip is smaller.
    final Path deployDirectory = workingDirectory.resolve("deploy");
    steps.add(new MkdirStep(projectFilesystem, deployDirectory));
    Step javaStep = new ShellStep(projectFilesystem.getRootPath()) {

        @Override
        public String getShortName() {
            return "gwt-compile";
        }

        @Override
        protected ImmutableList<String> getShellCommandInternal(ExecutionContext executionContext) {
            ImmutableList.Builder<String> javaArgsBuilder = ImmutableList.builder();
            javaArgsBuilder.add(javaRuntimeLauncher.getCommand());
            javaArgsBuilder.add("-Dgwt.normalizeTimestamps=true");
            javaArgsBuilder.addAll(vmArgs);
            javaArgsBuilder.add("-classpath", Joiner.on(File.pathSeparator).join(Iterables.transform(getClasspathEntries(context.getSourcePathResolver()), getProjectFilesystem()::resolve)), GWT_COMPILER_CLASS, "-war", context.getSourcePathResolver().getAbsolutePath(getSourcePathToOutput()).toString(), "-style", style.name(), "-optimize", String.valueOf(optimize), "-localWorkers", String.valueOf(localWorkers), "-deploy", getProjectFilesystem().resolve(deployDirectory).toString());
            if (draftCompile) {
                javaArgsBuilder.add("-draftCompile");
            }
            if (strict) {
                javaArgsBuilder.add("-strict");
            }
            javaArgsBuilder.addAll(experimentalArgs);
            javaArgsBuilder.addAll(modules);
            final ImmutableList<String> javaArgs = javaArgsBuilder.build();
            return javaArgs;
        }
    };
    steps.add(javaStep);
    buildableContext.recordArtifact(context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()));
    return steps.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ExecutionContext(com.facebook.buck.step.ExecutionContext) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) ShellStep(com.facebook.buck.shell.ShellStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ShellStep(com.facebook.buck.shell.ShellStep) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem)

Example 5 with ProjectFilesystem

use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.

the class HalideCompile method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    Path outputDir = context.getSourcePathResolver().getRelativePath(getSourcePathToOutput());
    buildableContext.recordArtifact(objectOutputPath(getBuildTarget(), getProjectFilesystem(), functionNameOverride));
    buildableContext.recordArtifact(headerOutputPath(getBuildTarget(), getProjectFilesystem(), functionNameOverride));
    ImmutableList.Builder<Step> commands = ImmutableList.builder();
    ProjectFilesystem projectFilesystem = getProjectFilesystem();
    commands.add(new MakeCleanDirectoryStep(projectFilesystem, outputDir));
    commands.add(new HalideCompilerStep(projectFilesystem.getRootPath(), halideCompiler.getEnvironment(context.getSourcePathResolver()), halideCompiler.getCommandPrefix(context.getSourcePathResolver()), outputDir, fileOutputName(getBuildTarget(), functionNameOverride), targetPlatform, compilerInvocationFlags));
    return commands.build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) 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) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem)

Aggregations

ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)654 Test (org.junit.Test)542 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)401 Path (java.nio.file.Path)324 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)207 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)204 BuildTarget (com.facebook.buck.model.BuildTarget)203 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)126 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)121 TargetGraph (com.facebook.buck.rules.TargetGraph)119 PathSourcePath (com.facebook.buck.rules.PathSourcePath)96 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)92 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)90 SourcePath (com.facebook.buck.rules.SourcePath)79 ExecutionContext (com.facebook.buck.step.ExecutionContext)67 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)67 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)63 BuildRule (com.facebook.buck.rules.BuildRule)56 RuleKey (com.facebook.buck.rules.RuleKey)43 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)42