use of com.facebook.buck.rules.FakeBuildableContext in project buck by facebook.
the class CxxLibraryDescriptionTest method libraryWithoutSourcesDoesntBuildAnything.
@Test
public void libraryWithoutSourcesDoesntBuildAnything() throws Exception {
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar").withFlavors(CxxDescriptionEnhancer.STATIC_FLAVOR, CxxLibraryBuilder.createDefaultPlatform().getFlavor());
ProjectFilesystem filesystem = new FakeProjectFilesystem();
CxxLibraryBuilder libBuilder = new CxxLibraryBuilder(target, cxxBuckConfig);
TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
BuildRule lib = libBuilder.build(resolver, filesystem, targetGraph);
assertThat(lib.getDeps(), is(empty()));
assertThat(lib.getBuildSteps(FakeBuildContext.NOOP_CONTEXT, new FakeBuildableContext()), is(empty()));
}
use of com.facebook.buck.rules.FakeBuildableContext in project buck by facebook.
the class JsBundleWorkerJobArgsTest method setUp.
@Before
public void setUp() throws NoSuchBuildTargetException {
scenario = JsTestScenario.builder().build();
context = FakeBuildContext.withSourcePathResolver(new SourcePathResolver(new SourcePathRuleFinder(scenario.resolver)));
fakeBuildableContext = new FakeBuildableContext();
}
use of com.facebook.buck.rules.FakeBuildableContext in project buck by facebook.
the class DexProducedFromJavaLibraryThatContainsClassFilesTest method testGetBuildStepsWhenThereAreClassesToDex.
@Test
public void testGetBuildStepsWhenThereAreClassesToDex() throws IOException, InterruptedException {
ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
FakeJavaLibrary javaLibraryRule = new FakeJavaLibrary(BuildTargetFactory.newInstance(filesystem.getRootPath(), "//foo:bar"), pathResolver, filesystem, ImmutableSortedSet.of()) {
@Override
public ImmutableSortedMap<String, HashCode> getClassNamesToHashes() {
return ImmutableSortedMap.of("com/example/Foo", HashCode.fromString("cafebabe"));
}
};
resolver.addToIndex(javaLibraryRule);
Path jarOutput = BuildTargets.getGenPath(filesystem, javaLibraryRule.getBuildTarget(), "%s.jar");
javaLibraryRule.setOutputFile(jarOutput.toString());
BuildContext context = FakeBuildContext.withSourcePathResolver(pathResolver);
FakeBuildableContext buildableContext = new FakeBuildableContext();
Path dexOutput = BuildTargets.getGenPath(filesystem, javaLibraryRule.getBuildTarget().withFlavors(AndroidBinaryGraphEnhancer.DEX_FLAVOR), "%s.dex.jar");
createFiles(filesystem, dexOutput.toString(), jarOutput.toString());
BuildTarget buildTarget = BuildTargetFactory.newInstance(filesystem.getRootPath(), "//foo:bar#dex");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).setProjectFilesystem(filesystem).build();
DexProducedFromJavaLibrary preDex = new DexProducedFromJavaLibrary(params, javaLibraryRule);
List<Step> steps = preDex.getBuildSteps(context, buildableContext);
AndroidPlatformTarget androidPlatformTarget = createMock(AndroidPlatformTarget.class);
expect(androidPlatformTarget.getDxExecutable()).andStubReturn(Paths.get("/usr/bin/dx"));
EasyMock.replay(androidPlatformTarget);
ExecutionContext executionContext = TestExecutionContext.newBuilder().setAndroidPlatformTargetSupplier(Suppliers.ofInstance(androidPlatformTarget)).build();
String expectedDxCommand = String.format("%s --dex --no-optimize --force-jumbo --output %s %s", Paths.get("/usr/bin/dx"), filesystem.resolve(dexOutput), filesystem.resolve(jarOutput));
MoreAsserts.assertSteps("Generate bar.dex.jar.", ImmutableList.of(String.format("rm -f %s", filesystem.resolve(dexOutput)), String.format("mkdir -p %s", filesystem.resolve(dexOutput).getParent()), "estimate_dex_weight", "(cd " + filesystem.getRootPath() + " && " + expectedDxCommand + ")", String.format("zip-scrub %s", dexOutput), "record_dx_success"), steps, executionContext);
((EstimateDexWeightStep) steps.get(2)).setWeightEstimateForTesting(250);
Step recordArtifactAndMetadataStep = steps.get(5);
int exitCode = recordArtifactAndMetadataStep.execute(executionContext).getExitCode();
assertEquals(0, exitCode);
assertEquals("The generated .dex.jar file should be in the set of recorded artifacts.", ImmutableSet.of(BuildTargets.getGenPath(filesystem, buildTarget, "%s.dex.jar")), buildableContext.getRecordedArtifacts());
buildableContext.assertContainsMetadataMapping(DexProducedFromJavaLibrary.WEIGHT_ESTIMATE, "250");
}
use of com.facebook.buck.rules.FakeBuildableContext in project buck by facebook.
the class DexProducedFromJavaLibraryThatContainsClassFilesTest method testGetBuildStepsWhenThereAreNoClassesToDex.
@Test
public void testGetBuildStepsWhenThereAreNoClassesToDex() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
DefaultJavaLibrary javaLibrary = JavaLibraryBuilder.createBuilder("//foo:bar").build(resolver);
javaLibrary.getBuildOutputInitializer().setBuildOutput(new JavaLibrary.Data(ImmutableSortedMap.of()));
BuildContext context = FakeBuildContext.NOOP_CONTEXT;
FakeBuildableContext buildableContext = new FakeBuildableContext();
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
BuildTarget buildTarget = BuildTargetFactory.newInstance("//foo:bar#dex");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).setProjectFilesystem(projectFilesystem).build();
DexProducedFromJavaLibrary preDex = new DexProducedFromJavaLibrary(params, javaLibrary);
List<Step> steps = preDex.getBuildSteps(context, buildableContext);
Path dexOutput = BuildTargets.getGenPath(projectFilesystem, buildTarget, "%s.dex.jar");
ExecutionContext executionContext = TestExecutionContext.newBuilder().build();
MoreAsserts.assertSteps("Do not generate a .dex.jar file.", ImmutableList.of(String.format("rm -f %s", projectFilesystem.resolve(dexOutput)), String.format("mkdir -p %s", projectFilesystem.resolve(dexOutput.getParent())), "record_empty_dx"), steps, executionContext);
Step recordArtifactAndMetadataStep = steps.get(2);
assertThat(recordArtifactAndMetadataStep.getShortName(), startsWith("record_"));
int exitCode = recordArtifactAndMetadataStep.execute(executionContext).getExitCode();
assertEquals(0, exitCode);
}
use of com.facebook.buck.rules.FakeBuildableContext in project buck by facebook.
the class DummyRDotJavaTest method testBuildSteps.
@Test
public void testBuildSteps() throws IOException {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildRule resourceRule1 = ruleResolver.addToIndex(AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(BuildTargetFactory.newInstance("//android_res/com/example:res1")).setRDotJavaPackage("com.facebook").setRes(new FakeSourcePath("android_res/com/example/res1")).build());
setAndroidResourceBuildOutput(resourceRule1);
BuildRule resourceRule2 = ruleResolver.addToIndex(AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(BuildTargetFactory.newInstance("//android_res/com/example:res2")).setRDotJavaPackage("com.facebook").setRes(new FakeSourcePath("android_res/com/example/res2")).build());
setAndroidResourceBuildOutput(resourceRule2);
DummyRDotJava dummyRDotJava = new DummyRDotJava(new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//java/base:rule")).setProjectFilesystem(filesystem).build(), ruleFinder, ImmutableSet.of((HasAndroidResourceDeps) resourceRule1, (HasAndroidResourceDeps) resourceRule2), ANDROID_JAVAC_OPTIONS, /* forceFinalResourceIds */
false, Optional.empty(), Optional.of("R2"), false);
FakeBuildableContext buildableContext = new FakeBuildableContext();
List<Step> steps = dummyRDotJava.getBuildSteps(FakeBuildContext.NOOP_CONTEXT, buildableContext);
assertEquals("DummyRDotJava returns an incorrect number of Steps.", 10, steps.size());
String rDotJavaSrcFolder = BuildTargets.getScratchPath(filesystem, dummyRDotJava.getBuildTarget(), "__%s_rdotjava_src__").toString();
String rDotJavaBinFolder = BuildTargets.getScratchPath(filesystem, dummyRDotJava.getBuildTarget(), "__%s_rdotjava_bin__").toString();
String rDotJavaAbiFolder = BuildTargets.getGenPath(filesystem, dummyRDotJava.getBuildTarget(), "__%s_dummyrdotjava_abi__").toString();
String rDotJavaOutputFolder = BuildTargets.getGenPath(filesystem, dummyRDotJava.getBuildTarget(), "__%s_dummyrdotjava_output__").toString();
String rDotJavaOutputJar = MorePaths.pathWithPlatformSeparators(String.format("%s/%s.jar", rDotJavaOutputFolder, dummyRDotJava.getBuildTarget().getShortNameAndFlavorPostfix()));
String genFolder = Paths.get("buck-out/gen/java/base/").toString();
List<String> sortedSymbolsFiles = Stream.of((AndroidResource) resourceRule1, (AndroidResource) resourceRule2).map(Object::toString).collect(MoreCollectors.toImmutableList());
ImmutableSortedSet<Path> javaSourceFiles = ImmutableSortedSet.of(Paths.get(rDotJavaSrcFolder).resolve("com/facebook/R.java"));
List<String> expectedStepDescriptions = Lists.newArrayList(makeCleanDirDescription(filesystem.resolve(rDotJavaSrcFolder)), "android-res-merge " + Joiner.on(' ').join(sortedSymbolsFiles), "android-res-merge " + Joiner.on(' ').join(sortedSymbolsFiles), makeCleanDirDescription(filesystem.resolve(rDotJavaBinFolder)), makeCleanDirDescription(filesystem.resolve(rDotJavaAbiFolder)), makeCleanDirDescription(filesystem.resolve(rDotJavaOutputFolder)), String.format("mkdir -p %s", filesystem.resolve(genFolder)), RDotJava.createJavacStepForDummyRDotJavaFiles(javaSourceFiles, BuildTargets.getGenPath(filesystem, dummyRDotJava.getBuildTarget(), "__%s__srcs"), Paths.get(rDotJavaBinFolder), ANDROID_JAVAC_OPTIONS, /* buildTarget */
null, pathResolver, ruleFinder, new FakeProjectFilesystem()).getDescription(TestExecutionContext.newInstance()), String.format("jar cf %s %s", rDotJavaOutputJar, rDotJavaBinFolder), String.format("calculate_abi %s", rDotJavaBinFolder));
MoreAsserts.assertSteps("DummyRDotJava.getBuildSteps() must return these exact steps.", expectedStepDescriptions, steps, TestExecutionContext.newInstance());
assertEquals(ImmutableSet.of(Paths.get(rDotJavaBinFolder), Paths.get(rDotJavaOutputJar)), buildableContext.getRecordedArtifacts());
}
Aggregations