use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class AndroidManifestDescriptionTest method testGeneratedSkeletonAppearsInDeps.
@Test
public void testGeneratedSkeletonAppearsInDeps() {
BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildRule ruleWithOutput = new FakeBuildRule(BuildTargetFactory.newInstance("//foo:bar"), new SourcePathResolver(new SourcePathRuleFinder(buildRuleResolver))) {
@Override
public SourcePath getSourcePathToOutput() {
return new ExplicitBuildTargetSourcePath(getBuildTarget(), Paths.get("buck-out/gen/foo/bar/AndroidManifest.xml"));
}
};
SourcePath skeleton = ruleWithOutput.getSourcePathToOutput();
buildRuleResolver.addToIndex(ruleWithOutput);
AndroidManifestDescription.Arg arg = new AndroidManifestDescription.Arg();
arg.skeleton = skeleton;
arg.deps = ImmutableSortedSet.of();
BuildRuleParams params = new FakeBuildRuleParamsBuilder("//foo:baz").setDeclaredDeps(buildRuleResolver.getAllRules(arg.deps)).build();
BuildRule androidManifest = new AndroidManifestDescription().createBuildRule(TargetGraph.EMPTY, params, buildRuleResolver, arg);
assertEquals(ImmutableSortedSet.of(ruleWithOutput), androidManifest.getDeps());
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class AndroidManifestTest method createSimpleAndroidManifestRule.
private AndroidManifest createSimpleAndroidManifestRule() {
// First, create the AndroidManifest object.
BuildRuleParams buildRuleParams = new FakeBuildRuleParamsBuilder(MANIFEST_TARGET).build();
AndroidManifestDescription description = new AndroidManifestDescription();
AndroidManifestDescription.Arg arg = description.createUnpopulatedConstructorArg();
arg.skeleton = new FakeSourcePath("java/com/example/AndroidManifestSkeleton.xml");
arg.deps = ImmutableSortedSet.<BuildTarget>of();
return description.createBuildRule(TargetGraph.EMPTY, buildRuleParams, new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()), arg);
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class AndroidNativeLibsPackageableGraphEnhancerTest method testCxxLibrary.
@Test
@SuppressWarnings("unchecked")
public void testCxxLibrary() throws Exception {
NdkCxxPlatform ndkCxxPlatform = NdkCxxPlatform.builder().setCxxPlatform(CxxPlatformUtils.DEFAULT_PLATFORM).setCxxRuntime(NdkCxxPlatforms.CxxRuntime.GNUSTL).setCxxSharedRuntimePath(Paths.get("runtime")).setObjdump(new CommandTool.Builder().addArg("objdump").build()).build();
ImmutableMap<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform> nativePlatforms = ImmutableMap.<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform>builder().put(NdkCxxPlatforms.TargetCpuType.ARMV7, ndkCxxPlatform).put(NdkCxxPlatforms.TargetCpuType.X86, ndkCxxPlatform).build();
CxxLibraryBuilder cxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:cxxlib")).setSoname("somelib.so").setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("test/bar.cpp"))));
TargetNode<CxxLibraryDescription.Arg, ?> cxxLibraryDescription = cxxLibraryBuilder.build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(cxxLibraryDescription);
BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
CxxLibrary cxxLibrary = (CxxLibrary) cxxLibraryBuilder.build(ruleResolver, new FakeProjectFilesystem(), targetGraph);
ruleResolver.addToIndex(cxxLibrary);
BuildTarget target = BuildTargetFactory.newInstance("//:target");
BuildRuleParams originalParams = new FakeBuildRuleParamsBuilder(target).setDeclaredDeps(ImmutableSortedSet.of(cxxLibrary)).build();
APKModuleGraph apkModuleGraph = new APKModuleGraph(TargetGraph.EMPTY, target, Optional.empty());
AndroidNativeLibsPackageableGraphEnhancer enhancer = new AndroidNativeLibsPackageableGraphEnhancer(ruleResolver, originalParams, nativePlatforms, ImmutableSet.of(NdkCxxPlatforms.TargetCpuType.ARMV7), CxxPlatformUtils.DEFAULT_CONFIG, /* nativeLibraryMergeMap */
Optional.empty(), /* nativeLibraryMergeGlue */
Optional.empty(), AndroidBinary.RelinkerMode.DISABLED, apkModuleGraph);
AndroidPackageableCollector collector = new AndroidPackageableCollector(target, ImmutableSet.of(), ImmutableSet.of(), apkModuleGraph);
collector.addPackageables(AndroidPackageableCollector.getPackageableRules(ImmutableSet.of(cxxLibrary)));
AndroidPackageableCollection packageableCollection = collector.build();
Optional<ImmutableMap<APKModule, CopyNativeLibraries>> copyNativeLibrariesOptional = enhancer.enhance(packageableCollection).getCopyNativeLibraries();
CopyNativeLibraries copyNativeLibraries = copyNativeLibrariesOptional.get().get(apkModuleGraph.getRootAPKModule());
assertThat(copyNativeLibraries.getStrippedObjectDescriptions(), Matchers.containsInAnyOrder(Matchers.allOf(Matchers.hasProperty("targetCpuType", Matchers.equalTo(NdkCxxPlatforms.TargetCpuType.ARMV7)), Matchers.hasProperty("strippedObjectName", Matchers.equalTo("somelib.so"))), Matchers.allOf(Matchers.hasProperty("targetCpuType", Matchers.equalTo(NdkCxxPlatforms.TargetCpuType.ARMV7)), Matchers.hasProperty("strippedObjectName", Matchers.equalTo("libgnustl_shared.so")))));
assertThat(copyNativeLibraries.getNativeLibDirectories(), Matchers.empty());
ImmutableCollection<BuildRule> stripRules = ruleFinder.filterBuildRuleInputs(copyNativeLibraries.getStrippedObjectDescriptions().stream().map(StrippedObjectDescription::getSourcePath).collect(MoreCollectors.toImmutableSet()));
assertThat(stripRules, Matchers.contains(Matchers.instanceOf(StripLinkable.class), Matchers.instanceOf(StripLinkable.class)));
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class AaptPackageResourcesTest method setUp.
@Before
public void setUp() throws NoSuchBuildTargetException {
filesystem = new FakeProjectFilesystem();
TargetNode<?, ?> resourceNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:resource1"), filesystem).setRDotJavaPackage("package1").setRes(Paths.get("res1")).setAssets(new PathSourcePath(filesystem, Paths.get("asset1"))).build();
TargetNode<?, ?> resourceNode2 = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:resource2"), filesystem).setRDotJavaPackage("package2").setRes(Paths.get("res2")).setAssets(new PathSourcePath(filesystem, Paths.get("asset2"))).build();
TargetNode<?, ?> assetsNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:assets"), filesystem).setAssets(new PathSourcePath(filesystem, Paths.get("justAssets"))).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(resourceNode, resourceNode2, assetsNode);
ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
resource1 = (AndroidResource) ruleResolver.requireRule(resourceNode.getBuildTarget());
resource2 = (AndroidResource) ruleResolver.requireRule(resourceNode2.getBuildTarget());
justAssets = (AndroidResource) ruleResolver.requireRule(assetsNode.getBuildTarget());
ruleFinder = new SourcePathRuleFinder(ruleResolver);
pathResolver = new SourcePathResolver(ruleFinder);
aaptTarget = BuildTargetFactory.newInstance("//foo:bar");
params = new FakeBuildRuleParamsBuilder(aaptTarget).build();
hashCache = new FakeFileHashCache(new HashMap<>());
createPathSourcePath("res1", "resources1");
createPathSourcePath("res2", "resources2");
createPathSourcePath("res3", "resources3");
createPathSourcePath("asset1", "assets1");
createPathSourcePath("asset2", "assets2");
createPathSourcePath("justAssets", "justAssets");
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class AndroidBuildConfigJavaLibraryTest method testAddToCollector.
@Test
public void testAddToCollector() throws NoSuchBuildTargetException {
BuildTarget buildTarget = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).build();
BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
AndroidBuildConfigJavaLibrary buildConfigJavaLibrary = AndroidBuildConfigDescription.createBuildRule(params, "com.example.buck", /* values */
BuildConfigFields.fromFieldDeclarations(Collections.singleton("String foo = \"bar\"")), /* valuesFile */
Optional.empty(), /* useConstantExpressions */
false, DEFAULT_JAVAC_OPTIONS, buildRuleResolver);
AndroidPackageableCollector collector = new AndroidPackageableCollector(buildTarget);
buildConfigJavaLibrary.addToCollector(collector);
AndroidPackageableCollection collection = collector.build();
assertEquals(ImmutableMap.of("com.example.buck", BuildConfigFields.fromFields(ImmutableList.of(BuildConfigFields.Field.of("String", "foo", "\"bar\"")))), collection.getBuildConfigs());
}
Aggregations