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));
}
}
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();
}
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;
}
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();
}
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();
}
Aggregations