use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class MergeAndroidResourcesStepTest method testGenerateRDotJavaForCustomDrawables.
@Test
public void testGenerateRDotJavaForCustomDrawables() throws IOException {
BuildTarget target = BuildTargetFactory.newInstance("//android_res/com/facebook/http:res");
RDotTxtEntryBuilder entriesBuilder = new RDotTxtEntryBuilder();
String symbolsFile = BuildTargets.getGenPath(entriesBuilder.getProjectFilesystem(), target, "__%s_text_symbols__/R.txt").toString();
String rDotJavaPackage = "com.facebook";
final ImmutableList<String> outputTextSymbols = ImmutableList.<String>builder().add("int drawable android_drawable 0x7f010000").add("int drawable fb_drawable 0x7f010001 #").build();
entriesBuilder.add(new RDotTxtFile(rDotJavaPackage, symbolsFile, outputTextSymbols));
FakeProjectFilesystem filesystem = entriesBuilder.getProjectFilesystem();
Path uberRDotTxt = filesystem.resolve("R.txt").toAbsolutePath();
filesystem.writeLinesToPath(outputTextSymbols, uberRDotTxt);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
HasAndroidResourceDeps resource = AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(target).setRes(new FakeSourcePath("res")).setRDotJavaPackage("com.facebook").build();
MergeAndroidResourcesStep mergeStep = new MergeAndroidResourcesStep(filesystem, resolver, ImmutableList.of(resource), Optional.of(uberRDotTxt), Paths.get("output"), /* forceFinalResourceIds */
true, /* bannedDuplicateResourceTypes */
EnumSet.noneOf(RType.class), /* unionPackage */
Optional.empty(), /* rName */
Optional.empty(), /* useOldStyleableFormat */
false);
ExecutionContext executionContext = TestExecutionContext.newInstance();
assertEquals(0, mergeStep.execute(executionContext).getExitCode());
// Verify that the correct Java code is generated.
assertEquals("package com.facebook;\n" + "\n" + "public class R {\n" + " public static class drawable {\n" + " public static final int android_drawable=0x7f010000;\n" + " public static final int fb_drawable=0x7f010001;\n" + " }\n" + "\n" + " public static final int[] custom_drawables = { 0x7f010001 };\n" + "\n" + "}\n", filesystem.readFileIfItExists(Paths.get("output/com/facebook/R.java")).get().replace("\r", ""));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class ResourceFiltersTest method testcreateDensityFilterSkipsDrawables.
@Test
public void testcreateDensityFilterSkipsDrawables() {
Path candidate = Paths.get("drawable-ldpi/somefile");
Predicate<Path> predicate = ResourceFilters.createDensityFilter(new FakeProjectFilesystem(), ImmutableSet.of(Density.MDPI));
assertThat(predicate.apply(candidate), Matchers.is(true));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class ResourceFiltersTest method testCreateDensityFilterIncludesFallbackWhenTargetNotPresent.
@Test
public void testCreateDensityFilterIncludesFallbackWhenTargetNotPresent() throws IOException {
for (String folderName : ResourceFilters.SUPPORTED_RESOURCE_DIRECTORIES) {
if (folderName.equals("drawable")) {
// Drawables are special and we have a different method for them.
continue;
}
ProjectFilesystem filesystem = new FakeProjectFilesystem();
Path include = Paths.get(folderName).resolve("somefile");
filesystem.createNewFile(include);
Path exclude = Paths.get(String.format("%s-ldpi/somefile", folderName));
filesystem.createNewFile(exclude);
Predicate<Path> predicate = ResourceFilters.createDensityFilter(filesystem, ImmutableSet.of(Density.MDPI));
assertThat(predicate.apply(exclude), Matchers.is(false));
assertThat(predicate.apply(include), Matchers.is(true));
}
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class RobolectricTestRuleTest method runtimeDepsIncludeTransitiveResources.
@Test
public void runtimeDepsIncludeTransitiveResources() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem(temporaryFolder.getRoot());
BuildTarget genRuleTarget = BuildTargetFactory.newInstance("//:gen");
TargetNode<?, ?> genRuleNode = GenruleBuilder.newGenruleBuilder(genRuleTarget).setOut("out").build();
BuildTarget res2RuleTarget = BuildTargetFactory.newInstance("//:res2");
TargetNode<?, ?> res2Node = AndroidResourceBuilder.createBuilder(res2RuleTarget).setRes(new DefaultBuildTargetSourcePath(genRuleTarget)).setRDotJavaPackage("foo.bar").build();
BuildTarget robolectricBuildTarget = BuildTargetFactory.newInstance("//java/src/com/facebook/base/robolectricTest:robolectricTest");
TargetNode<?, ?> robolectricTestNode = RobolectricTestBuilder.createBuilder(robolectricBuildTarget, filesystem).addDep(res2RuleTarget).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(genRuleNode, res2Node, robolectricTestNode);
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
BuildRule genRule = resolver.requireRule(genRuleTarget);
RobolectricTest robolectricTest = (RobolectricTest) resolver.requireRule(robolectricBuildTarget);
assertThat(robolectricTest.getRuntimeDeps().collect(MoreCollectors.toImmutableSet()), Matchers.hasItem(genRule.getBuildTarget()));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class CompilationDatabaseIntegrationTest method testCreateCompilationDatabaseForAppleBinaryWithDeps.
@Test
public void testCreateCompilationDatabaseForAppleBinaryWithDeps() throws IOException {
// buck build the #compilation-database.
BuildTarget target = BuildTargetFactory.newInstance("//Apps/Weather:Weather#iphonesimulator-x86_64,compilation-database");
Path compilationDatabase = workspace.buildAndReturnOutput(target.getFullyQualifiedName());
ProjectFilesystem filesystem = new FakeProjectFilesystem();
// Parse the compilation_database.json file.
Map<String, CxxCompilationDatabaseEntry> fileToEntry = CxxCompilationDatabaseUtils.parseCompilationDatabaseJsonFile(compilationDatabase);
ImmutableSet<String> frameworks = ImmutableSet.of(Paths.get("/System/Library/Frameworks/Foundation.framework").getParent().toString(), Paths.get("/System/Library/Frameworks/UIKit.framework").getParent().toString());
String pathToPrivateHeaders = BuildTargets.getGenPath(filesystem, target.withFlavors(InternalFlavor.of("iphonesimulator-x86_64"), CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR), "%s.hmap").toString();
String pathToPublicHeaders = BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance("//Libraries/EXExample:EXExample").withAppendedFlavors(CxxDescriptionEnhancer.EXPORTED_HEADER_SYMLINK_TREE_FLAVOR, CxxPlatformUtils.getHeaderModeForDefaultPlatform(tmp.getRoot()).getFlavor()), "%s.hmap").toString();
Iterable<String> includes = ImmutableList.of(pathToPrivateHeaders, pathToPublicHeaders, filesystem.getBuckPaths().getBuckOut().toString());
assertFlags(filesystem, "Apps/Weather/Weather/EXViewController.m", target.withFlavors(InternalFlavor.of("iphonesimulator-x86_64"), InternalFlavor.of("compile-" + sanitize("Weather/EXViewController.m.o"))), Paths.get("Weather/EXViewController.m.o"), /* isLibrary */
false, fileToEntry, frameworks, includes);
assertFlags(filesystem, "Apps/Weather/Weather/main.m", target.withFlavors(InternalFlavor.of("iphonesimulator-x86_64"), InternalFlavor.of("compile-" + sanitize("Weather/main.m.o"))), Paths.get("Weather/main.m.o"), /* isLibrary */
false, fileToEntry, frameworks, includes);
}
Aggregations