use of com.facebook.buck.rules.BuildContext in project buck by facebook.
the class JavaSourceJarTest method shouldOnlyIncludePathBasedSources.
@Test
public void shouldOnlyIncludePathBasedSources() {
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
SourcePath fileBased = new FakeSourcePath("some/path/File.java");
SourcePath ruleBased = new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//cheese:cake"));
JavaPackageFinder finderStub = createNiceMock(JavaPackageFinder.class);
expect(finderStub.findJavaPackageFolder((Path) anyObject())).andStubReturn(Paths.get("cheese"));
expect(finderStub.findJavaPackage((Path) anyObject())).andStubReturn("cheese");
// No need to verify. It's a stub. I don't care about the interactions.
EasyMock.replay(finderStub);
JavaSourceJar rule = new JavaSourceJar(new FakeBuildRuleParamsBuilder("//example:target").build(), ImmutableSortedSet.of(fileBased, ruleBased), Optional.empty());
BuildContext buildContext = BuildContext.builder().setActionGraph(new ActionGraph(ImmutableList.of())).setSourcePathResolver(pathResolver).setJavaPackageFinder(finderStub).setEventBus(BuckEventBusFactory.newInstance()).build();
ImmutableList<Step> steps = rule.getBuildSteps(buildContext, new FakeBuildableContext());
// There should be a CopyStep per file being copied. Count 'em.
int copyStepsCount = FluentIterable.from(steps).filter(CopyStep.class::isInstance).size();
assertEquals(1, copyStepsCount);
}
use of com.facebook.buck.rules.BuildContext 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.BuildContext 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.BuildContext 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.BuildContext in project buck by facebook.
the class DefaultJavaLibraryTest method testStepsPresenceForForDirectJarSpooling.
@Test
public void testStepsPresenceForForDirectJarSpooling() {
BuildTarget buildTarget = BuildTargetFactory.newInstance("//:lib");
BuildRule javaLibraryBuildRule = createDefaultJavaLibraryRuleWithAbiKey(buildTarget, /* srcs */
ImmutableSortedSet.of("foo/Bar.java"), /* deps */
ImmutableSortedSet.of(), /* exportedDeps */
ImmutableSortedSet.of(), Optional.of(AbstractJavacOptions.SpoolMode.DIRECT_TO_JAR), /* postprocessClassesCommands */
ImmutableList.of());
BuildContext buildContext = createBuildContext(javaLibraryBuildRule, /* bootclasspath */
null);
ImmutableList<Step> steps = javaLibraryBuildRule.getBuildSteps(buildContext, new FakeBuildableContext());
assertThat(steps, Matchers.hasItem(Matchers.instanceOf(JavacDirectToJarStep.class)));
assertThat(steps, Matchers.not(Matchers.hasItem(Matchers.instanceOf(JavacStep.class))));
assertThat(steps, Matchers.not(Matchers.hasItem(Matchers.instanceOf(JarDirectoryStep.class))));
}
Aggregations