Search in sources :

Example 16 with FakeProjectFilesystem

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", ""));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) RType(com.facebook.buck.android.aapt.RDotTxtEntry.RType) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 17 with FakeProjectFilesystem

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));
}
Also used : Path(java.nio.file.Path) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Test(org.junit.Test)

Example 18 with FakeProjectFilesystem

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));
    }
}
Also used : Path(java.nio.file.Path) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 19 with FakeProjectFilesystem

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()));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 20 with FakeProjectFilesystem

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);
}
Also used : Path(java.nio.file.Path) CxxCompilationDatabaseEntry(com.facebook.buck.cxx.CxxCompilationDatabaseEntry) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Aggregations

FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)438 Test (org.junit.Test)384 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)268 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)189 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)186 Path (java.nio.file.Path)169 BuildTarget (com.facebook.buck.model.BuildTarget)138 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)111 TargetGraph (com.facebook.buck.rules.TargetGraph)107 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)103 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)85 PathSourcePath (com.facebook.buck.rules.PathSourcePath)68 BuildRule (com.facebook.buck.rules.BuildRule)61 SourcePath (com.facebook.buck.rules.SourcePath)56 RuleKey (com.facebook.buck.rules.RuleKey)42 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)40 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)39 ExecutionContext (com.facebook.buck.step.ExecutionContext)38 Before (org.junit.Before)30 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)29