use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class NdkLibraryTest method testSimpleNdkLibraryRule.
@Test
public void testSimpleNdkLibraryRule() throws Exception {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildContext context = FakeBuildContext.NOOP_CONTEXT;
String basePath = "java/src/com/facebook/base";
BuildTarget target = BuildTargetFactory.newInstance(String.format("//%s:base", basePath));
NdkLibrary ndkLibrary = new NdkLibraryBuilder(target).setFlags(ImmutableList.of("flag1", "flag2")).setIsAsset(true).build(ruleResolver, projectFilesystem);
assertEquals("ndk_library", ndkLibrary.getType());
assertTrue(ndkLibrary.getProperties().is(ANDROID));
assertTrue(ndkLibrary.isAsset());
assertEquals(projectFilesystem.getBuckPaths().getGenDir().resolve(basePath).resolve("__libbase"), ndkLibrary.getLibraryPath());
List<Step> steps = ndkLibrary.getBuildSteps(context, new FakeBuildableContext());
String libbase = projectFilesystem.getBuckPaths().getScratchDir().resolve(basePath).resolve("__libbase").toString();
MoreAsserts.assertShellCommands("ndk_library() should invoke ndk-build on the given path with some -j value", ImmutableList.of(String.format("%s -j %d -C %s flag1 flag2 " + "APP_PROJECT_PATH=%s " + "APP_BUILD_SCRIPT=%s " + "NDK_OUT=%s " + "NDK_LIBS_OUT=%s " + "BUCK_PROJECT_DIR=../../../../.. " + "host-echo-build-step=%s " + "--silent", ndkBuildCommand, Runtime.getRuntime().availableProcessors(), Paths.get(basePath).toString(), /* APP_PROJECT_PATH */
projectFilesystem.resolve(libbase) + File.separator, /* APP_BUILD_SCRIPT */
projectFilesystem.resolve(NdkLibraryDescription.getGeneratedMakefilePath(target, projectFilesystem)), /* NDK_OUT */
projectFilesystem.resolve(libbase) + File.separator, /* NDK_LIBS_OUT */
projectFilesystem.resolve(Paths.get(libbase, "libs")), /* host-echo-build-step */
Platform.detect() == Platform.WINDOWS ? "@REM" : "@#")), steps.subList(3, 4), executionContext);
}
use of com.facebook.buck.model.BuildTarget 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.model.BuildTarget 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.model.BuildTarget 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"));
}
use of com.facebook.buck.model.BuildTarget 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", ""));
}
Aggregations