Search in sources :

Example 61 with FakeBuildRuleParamsBuilder

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());
}
Also used : FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Test(org.junit.Test)

Example 62 with FakeBuildRuleParamsBuilder

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);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver)

Example 63 with FakeBuildRuleParamsBuilder

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)));
}
Also used : CxxLibrary(com.facebook.buck.cxx.CxxLibrary) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ImmutableMap(com.google.common.collect.ImmutableMap) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Test(org.junit.Test)

Example 64 with FakeBuildRuleParamsBuilder

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");
}
Also used : FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) HashMap(java.util.HashMap) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Before(org.junit.Before)

Example 65 with FakeBuildRuleParamsBuilder

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());
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)108 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)102 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)102 Test (org.junit.Test)94 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)87 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)78 BuildTarget (com.facebook.buck.model.BuildTarget)77 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)74 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)50 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)32 SourcePath (com.facebook.buck.rules.SourcePath)30 BuildRule (com.facebook.buck.rules.BuildRule)27 Path (java.nio.file.Path)26 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)25 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)22 PathSourcePath (com.facebook.buck.rules.PathSourcePath)18 Step (com.facebook.buck.step.Step)17 RuleKey (com.facebook.buck.rules.RuleKey)16 FakeBuildableContext (com.facebook.buck.rules.FakeBuildableContext)15 ExecutionContext (com.facebook.buck.step.ExecutionContext)14