Search in sources :

Example 31 with SourcePathResolver

use of com.facebook.buck.rules.SourcePathResolver in project buck by facebook.

the class NdkLibraryDescriptionTest method transitiveCxxLibraryDepsBecomeFirstOrderDepsOfNdkBuildRule.

@Test
public void transitiveCxxLibraryDepsBecomeFirstOrderDepsOfNdkBuildRule() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    FakeBuildRule transitiveInput = resolver.addToIndex(new FakeBuildRule("//:transitive_input", pathResolver));
    transitiveInput.setOutputFile("out");
    FakeNativeLinkable transitiveDep = resolver.addToIndex(new FakeNativeLinkable("//:transitive_dep", pathResolver, transitiveInput.getSourcePathToOutput()));
    FakeBuildRule firstOrderInput = resolver.addToIndex(new FakeBuildRule("//:first_order_input", pathResolver));
    firstOrderInput.setOutputFile("out");
    FakeNativeLinkable firstOrderDep = resolver.addToIndex(new FakeNativeLinkable("//:first_order_dep", pathResolver, firstOrderInput.getSourcePathToOutput(), transitiveDep));
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    BuildRule ndkLibrary = new NdkLibraryBuilder(target).addDep(firstOrderDep.getBuildTarget()).build(resolver);
    assertThat(ndkLibrary.getDeps(), Matchers.allOf(Matchers.<BuildRule>hasItem(firstOrderInput), Matchers.<BuildRule>hasItem(transitiveInput)));
}
Also used : FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 32 with SourcePathResolver

use of com.facebook.buck.rules.SourcePathResolver in project buck by facebook.

the class MergeAndroidResourcesStepTest method testGenerateRDotJavaWithPreviouslyEmptyResourceUnionPackage.

@Test
public void testGenerateRDotJavaWithPreviouslyEmptyResourceUnionPackage() throws IOException {
    BuildTarget res1Target = BuildTargetFactory.newInstance("//:res1");
    RDotTxtEntryBuilder entriesBuilder = new RDotTxtEntryBuilder();
    entriesBuilder.add(new RDotTxtFile("com.res1", BuildTargets.getGenPath(entriesBuilder.getProjectFilesystem(), res1Target, "__%s_text_symbols__/R.txt").toString(), ImmutableList.of("int id id1 0x7f020000")));
    FakeProjectFilesystem filesystem = entriesBuilder.getProjectFilesystem();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    HasAndroidResourceDeps res1 = AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(res1Target).setRes(new FakeSourcePath("res1")).setRDotJavaPackage("res1").build();
    MergeAndroidResourcesStep mergeStep = MergeAndroidResourcesStep.createStepForDummyRDotJava(filesystem, resolver, ImmutableList.of(res1), Paths.get("output"), /* forceFinalResourceIds */
    false, Optional.of("resM"), /* rName */
    Optional.empty(), /* useOldStyleableFormat */
    false);
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    assertEquals(0, mergeStep.execute(executionContext).getExitCode());
    String res1java = filesystem.readFileIfItExists(Paths.get("output/res1/R.java")).get();
    String resMjava = filesystem.readFileIfItExists(Paths.get("output/resM/R.java")).get();
    assertThat(res1java, StringContains.containsString("id1"));
    assertThat(resMjava, StringContains.containsString("id1"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) 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 33 with SourcePathResolver

use of com.facebook.buck.rules.SourcePathResolver in project buck by facebook.

the class MergeAndroidResourcesStepTest method testGenerateRDotJavaWithRName.

@Test
public void testGenerateRDotJavaWithRName() throws IOException {
    BuildTarget res1Target = BuildTargetFactory.newInstance("//:res1");
    RDotTxtEntryBuilder entriesBuilder = new RDotTxtEntryBuilder();
    entriesBuilder.add(new RDotTxtFile("com.res1", BuildTargets.getGenPath(entriesBuilder.getProjectFilesystem(), res1Target, "__%s_text_symbols__/R.txt").toString(), ImmutableList.of("int id id1 0x7f020000", "int id id2 0x7f020002")));
    FakeProjectFilesystem filesystem = entriesBuilder.getProjectFilesystem();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    HasAndroidResourceDeps res1 = AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(res1Target).setRes(new FakeSourcePath("res1")).setRDotJavaPackage("res1").build();
    MergeAndroidResourcesStep mergeStep = MergeAndroidResourcesStep.createStepForDummyRDotJava(filesystem, resolver, ImmutableList.of(res1), Paths.get("output"), /* forceFinalResourceIds */
    true, Optional.of("res1"), Optional.of("R2"), /* useOldStyleableFormat */
    false);
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    assertEquals(0, mergeStep.execute(executionContext).getExitCode());
    String resR2Java = filesystem.readFileIfItExists(Paths.get("output/res1/R2.java")).get();
    assertThat(resR2Java, StringContains.containsString("static final int id1=0x07f01001;"));
    assertThat(resR2Java, StringContains.containsString("static final int id2=0x07f01002;"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) 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 34 with SourcePathResolver

use of com.facebook.buck.rules.SourcePathResolver in project buck by facebook.

the class MergeAndroidResourcesStepTest method testGenerateRDotJavaWithResourceUnionPackage.

@Test
public void testGenerateRDotJavaWithResourceUnionPackage() throws IOException {
    BuildTarget res1Target = BuildTargetFactory.newInstance("//:res1");
    BuildTarget res2Target = BuildTargetFactory.newInstance("//:res2");
    RDotTxtEntryBuilder entriesBuilder = new RDotTxtEntryBuilder();
    entriesBuilder.add(new RDotTxtFile("com.res1", BuildTargets.getGenPath(entriesBuilder.getProjectFilesystem(), res1Target, "__%s_text_symbols__/R.txt").toString(), ImmutableList.of("int id id1 0x7f020000")));
    entriesBuilder.add(new RDotTxtFile("com.res2", BuildTargets.getGenPath(entriesBuilder.getProjectFilesystem(), res2Target, "__%s_text_symbols__/R.txt").toString(), ImmutableList.of("int id id2 0x7f020000")));
    FakeProjectFilesystem filesystem = entriesBuilder.getProjectFilesystem();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    HasAndroidResourceDeps res1 = AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(res1Target).setRes(new FakeSourcePath("res1")).setRDotJavaPackage("res1").build();
    HasAndroidResourceDeps res2 = AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(res2Target).setRes(new FakeSourcePath("res2")).setRDotJavaPackage("res2").build();
    MergeAndroidResourcesStep mergeStep = MergeAndroidResourcesStep.createStepForDummyRDotJava(filesystem, resolver, ImmutableList.of(res1, res2), Paths.get("output"), /* forceFinalResourceIds */
    false, Optional.of("res1"), /* rName */
    Optional.empty(), /* useOldStyleableFormat */
    false);
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    assertEquals(0, mergeStep.execute(executionContext).getExitCode());
    String res1java = filesystem.readFileIfItExists(Paths.get("output/res1/R.java")).get();
    String res2java = filesystem.readFileIfItExists(Paths.get("output/res2/R.java")).get();
    assertThat(res1java, StringContains.containsString("id1"));
    assertThat(res1java, StringContains.containsString("id2"));
    assertThat(res2java, CoreMatchers.not(StringContains.containsString("id1")));
    assertThat(res2java, StringContains.containsString("id2"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) 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 35 with SourcePathResolver

use of com.facebook.buck.rules.SourcePathResolver 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)

Aggregations

SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)486 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)468 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)376 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)350 Test (org.junit.Test)330 BuildTarget (com.facebook.buck.model.BuildTarget)228 BuildRule (com.facebook.buck.rules.BuildRule)161 Path (java.nio.file.Path)154 SourcePath (com.facebook.buck.rules.SourcePath)148 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)138 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)126 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)119 PathSourcePath (com.facebook.buck.rules.PathSourcePath)86 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)82 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)79 TargetGraph (com.facebook.buck.rules.TargetGraph)76 RuleKey (com.facebook.buck.rules.RuleKey)72 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)70 ExecutionContext (com.facebook.buck.step.ExecutionContext)57 ImmutableList (com.google.common.collect.ImmutableList)55