use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class ApkGenruleTest method createSampleAndroidBinaryRule.
private void createSampleAndroidBinaryRule(BuildRuleResolver ruleResolver, ProjectFilesystem filesystem) throws NoSuchBuildTargetException {
// Create a java_binary that depends on a java_library so it is possible to create a
// java_binary rule with a classpath entry and a main class.
BuildTarget libAndroidTarget = BuildTargetFactory.newInstance(filesystem.getRootPath(), "//:lib-android");
BuildRule androidLibRule = JavaLibraryBuilder.createBuilder(libAndroidTarget).addSrc(Paths.get("java/com/facebook/util/Facebook.java")).build(ruleResolver, filesystem);
BuildTarget keystoreTarget = BuildTargetFactory.newInstance(filesystem.getRootPath(), "//keystore:debug");
Keystore keystore = KeystoreBuilder.createBuilder(keystoreTarget).setStore(new FakeSourcePath(filesystem, "keystore/debug.keystore")).setProperties(new FakeSourcePath(filesystem, "keystore/debug.keystore.properties")).build(ruleResolver, filesystem);
AndroidBinaryBuilder.createBuilder(BuildTargetFactory.newInstance(filesystem.getRootPath(), "//:fb4a")).setManifest(new FakeSourcePath("AndroidManifest.xml")).setOriginalDeps(ImmutableSortedSet.of(androidLibRule.getBuildTarget())).setKeystore(keystore.getBuildTarget()).build(ruleResolver, filesystem);
}
use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class DuplicateResourcesTest method makeRules.
/*
* Builds up the following dependency graph, which an android_binary can depend on how it likes:
*
* //main_app:res //direct_dep:library <--------+//direct_dep:res
* ^ ^
* | |
* + +
* //transitive_dep:library<-----+//transitive_dep:res
* ^
* |
* +
* //bottom_dep:res
*/
@Before
public void makeRules() throws Exception {
mainResTarget = BuildTargetFactory.newInstance("//main_app:res");
directDepResTarget = BuildTargetFactory.newInstance("//direct_dep:res");
transitiveDepResTarget = BuildTargetFactory.newInstance("//transitive_dep:res");
transitiveDepLibTarget = BuildTargetFactory.newInstance("//transitive_dep:library");
bottomDepResTarget = BuildTargetFactory.newInstance("//bottom_dep:res");
androidLibraryTarget = BuildTargetFactory.newInstance("//direct_dep:library");
androidBinaryTarget = BuildTargetFactory.newInstance("//main_app:binary");
keystoreTarget = BuildTargetFactory.newInstance("//main_app:keystore");
filesystem = new FakeProjectFilesystem();
mainRes = AndroidResourceBuilder.createBuilder(mainResTarget).setRes(new FakeSourcePath(filesystem, "main_app/res")).setRDotJavaPackage("package").build();
directDepRes = AndroidResourceBuilder.createBuilder(directDepResTarget).setRes(new FakeSourcePath(filesystem, "direct_dep/res")).setRDotJavaPackage("package").setDeps(ImmutableSortedSet.of(transitiveDepResTarget, transitiveDepLibTarget)).build();
transitiveDepLib = AndroidLibraryBuilder.createBuilder(transitiveDepLibTarget).addDep(transitiveDepResTarget).build();
transitiveDepRes = AndroidResourceBuilder.createBuilder(transitiveDepResTarget).setRes(new FakeSourcePath(filesystem, "transitive_dep/res")).setRDotJavaPackage("package").setDeps(ImmutableSortedSet.of(bottomDepResTarget)).build();
bottomDepRes = AndroidResourceBuilder.createBuilder(bottomDepResTarget).setRes(new FakeSourcePath(filesystem, "bottom_dep/res")).setRDotJavaPackage("package").build();
library = AndroidLibraryBuilder.createBuilder(androidLibraryTarget).addDep(directDepResTarget).addDep(transitiveDepLibTarget).build();
keystore = KeystoreBuilder.createBuilder(keystoreTarget).setStore(new FakeSourcePath(filesystem, "store")).setProperties(new FakeSourcePath(filesystem, "properties")).build();
}
use of com.facebook.buck.rules.FakeSourcePath 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"));
}
use of com.facebook.buck.rules.FakeSourcePath 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;"));
}
use of com.facebook.buck.rules.FakeSourcePath 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"));
}
Aggregations