use of com.facebook.buck.rules.BuildableContext in project buck by facebook.
the class NdkLibrary method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
// .so files are written to the libs/ subdirectory of the output directory.
// All of them should be recorded via the BuildableContext.
Path binDirectory = buildArtifactsDirectory.resolve("libs");
steps.add(new RmStep(getProjectFilesystem(), makefile));
steps.add(new MkdirStep(getProjectFilesystem(), makefile.getParent()));
steps.add(new WriteFileStep(getProjectFilesystem(), makefileContents, makefile, false));
steps.add(new NdkBuildStep(getProjectFilesystem(), root, makefile, buildArtifactsDirectory, binDirectory, flags, macroExpander));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), genDirectory));
steps.add(CopyStep.forDirectory(getProjectFilesystem(), binDirectory, genDirectory, CopyStep.DirectoryMode.CONTENTS_ONLY));
buildableContext.recordArtifact(genDirectory);
// Some tools need to inspect .so files whose symbols haven't been stripped, so cache these too.
// However, the intermediate object files are huge and we have no interest in them, so filter
// them out.
steps.add(new AbstractExecutionStep("cache_unstripped_so") {
@Override
public StepExecutionResult execute(ExecutionContext context) {
try {
Set<Path> unstrippedSharedObjs = getProjectFilesystem().getFilesUnderPath(buildArtifactsDirectory, input -> input.toString().endsWith(".so"));
for (Path path : unstrippedSharedObjs) {
buildableContext.recordArtifact(path);
}
} catch (IOException e) {
context.logError(e, "Failed to cache intermediate artifacts of %s.", getBuildTarget());
return StepExecutionResult.ERROR;
}
return StepExecutionResult.SUCCESS;
}
});
return steps.build();
}
use of com.facebook.buck.rules.BuildableContext in project buck by facebook.
the class PackageStringAssets method getBuildSteps.
// TODO(russellporter): Add an integration test for packaging string assets
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
if (filteredResourcesProvider.getResDirectories().isEmpty()) {
// There is no zip file, but we still need to provide a consistent hash to
// ComputeExopackageDepsAbi in this case.
buildableContext.addMetadata(STRING_ASSETS_ZIP_HASH, Hashing.sha1().hashInt(0).toString());
return ImmutableList.of();
}
ImmutableList.Builder<Step> steps = ImmutableList.builder();
// We need to generate a zip file with the following dir structure:
// /assets/strings/*.fbstr
Path pathToBaseDir = getPathToStringAssetsDir();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToBaseDir));
Path pathToDirContainingAssetsDir = pathToBaseDir.resolve("string_assets");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToDirContainingAssetsDir));
final Path pathToStrings = pathToDirContainingAssetsDir.resolve("assets").resolve("strings");
Function<String, Path> assetPathBuilder = locale -> pathToStrings.resolve(locale + STRING_ASSET_FILE_EXTENSION);
Path pathToStringAssetsZip = getPathToStringAssetsZip();
Path pathToAllLocalesStringAssetsZip = getPathToAllLocalesStringAssetsZip();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToStrings));
steps.add(new CompileStringsStep(getProjectFilesystem(), filteredResourcesProvider.getStringFiles(), aaptPackageResources.getPathToRDotTxtDir(), assetPathBuilder));
steps.add(new ZipStep(getProjectFilesystem(), pathToAllLocalesStringAssetsZip, ImmutableSet.of(), false, ZipCompressionLevel.MAX_COMPRESSION_LEVEL, pathToDirContainingAssetsDir));
steps.add(new ZipStep(getProjectFilesystem(), pathToStringAssetsZip, locales.stream().map(assetPathBuilder::apply).collect(MoreCollectors.toImmutableSet()), false, ZipCompressionLevel.MAX_COMPRESSION_LEVEL, pathToDirContainingAssetsDir));
steps.add(new RecordFileSha1Step(getProjectFilesystem(), pathToStringAssetsZip, STRING_ASSETS_ZIP_HASH, buildableContext));
buildableContext.recordArtifact(pathToAllLocalesStringAssetsZip);
buildableContext.recordArtifact(pathToStringAssetsZip);
return steps.build();
}
use of com.facebook.buck.rules.BuildableContext in project buck by facebook.
the class PrebuiltJarDescription method createGwtModule.
@VisibleForTesting
static BuildRule createGwtModule(BuildRuleParams params, Arg arg) {
// Because a PrebuiltJar rarely requires any building whatsoever (it could if the source_jar
// is a BuildTargetSourcePath), we make the PrebuiltJar a dependency of the GWT module. If this
// becomes a performance issue in practice, then we will explore reducing the dependencies of
// the GWT module.
final SourcePath input;
if (arg.gwtJar.isPresent()) {
input = arg.gwtJar.get();
} else if (arg.sourceJar.isPresent()) {
input = arg.sourceJar.get();
} else {
input = arg.binaryJar;
}
class ExistingOuputs extends AbstractBuildRule {
@AddToRuleKey
private final SourcePath source;
private final Path output;
protected ExistingOuputs(BuildRuleParams params, SourcePath source) {
super(params);
this.source = source;
BuildTarget target = params.getBuildTarget();
this.output = BuildTargets.getGenPath(getProjectFilesystem(), target, String.format("%s/%%s-gwt.jar", target.getShortName()));
}
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
buildableContext.recordArtifact(context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()));
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), output.getParent()));
steps.add(CopyStep.forFile(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(source), output));
return steps.build();
}
@Override
public SourcePath getSourcePathToOutput() {
return new ExplicitBuildTargetSourcePath(getBuildTarget(), output);
}
}
return new ExistingOuputs(params, input);
}
use of com.facebook.buck.rules.BuildableContext in project buck by facebook.
the class JsBundle method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
final SourcePathResolver sourcePathResolver = context.getSourcePathResolver();
final SourcePath jsOutputDir = getSourcePathToOutput();
final SourcePath sourceMapFile = getSourcePathToSourceMap();
String jobArgs = Stream.concat(Stream.of("bundle", JsFlavors.bundleJobArgs(getBuildTarget().getFlavors()), JsUtil.resolveMapJoin(libraries, sourcePathResolver, p -> "--lib " + p), String.format("--sourcemap %s", sourcePathResolver.getAbsolutePath(sourceMapFile)), String.format("--out %s/%s", sourcePathResolver.getAbsolutePath(jsOutputDir), bundleName)), entryPoints.stream()).filter(s -> !s.isEmpty()).collect(Collectors.joining(" "));
buildableContext.recordArtifact(sourcePathResolver.getRelativePath(jsOutputDir));
buildableContext.recordArtifact(sourcePathResolver.getRelativePath(sourceMapFile));
return ImmutableList.of(new RmStep(getProjectFilesystem(), sourcePathResolver.getAbsolutePath(getOutputRoot())), new MkdirStep(getProjectFilesystem(), sourcePathResolver.getAbsolutePath(jsOutputDir)), new MkdirStep(getProjectFilesystem(), sourcePathResolver.getAbsolutePath(sourceMapFile).getParent()), JsUtil.workerShellStep(worker, jobArgs, getBuildTarget(), sourcePathResolver, getProjectFilesystem()));
}
use of com.facebook.buck.rules.BuildableContext in project buck by facebook.
the class JsLibrary method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
final SourcePathResolver sourcePathResolver = context.getSourcePathResolver();
final Path outputPath = sourcePathResolver.getAbsolutePath(getSourcePathToOutput());
final String jobArgs = String.format("library %s --out %s %s", JsUtil.resolveMapJoin(libraryDependencies, sourcePathResolver, p -> "--lib " + p), outputPath, JsUtil.resolveMapJoin(sources, sourcePathResolver, Path::toString));
return ImmutableList.of(new RmStep(getProjectFilesystem(), outputPath), JsUtil.workerShellStep(worker, jobArgs, getBuildTarget(), sourcePathResolver, getProjectFilesystem()));
}
Aggregations