Search in sources :

Example 16 with BuildRuleResolver

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

the class AndroidBinaryTest method testGetProguardOutputFromInputClasspath.

@Test
public void testGetProguardOutputFromInputClasspath() throws Exception {
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    BuildTarget target = BuildTargetFactory.newInstance("//:fbandroid_with_dash_debug_fbsign");
    AndroidBinary rule = AndroidBinaryBuilder.createBuilder(target).setManifest(new FakeSourcePath("AndroidManifest.xml")).setKeystore(addKeystoreRule(ruleResolver).getBuildTarget()).build(ruleResolver);
    BuildTarget libBaseTarget = BuildTargetFactory.newInstance("//first-party/orca/lib-base:lib-base");
    Path proguardConfigDir = BuildTargets.getGenPath(rule.getProjectFilesystem(), target.withFlavors(AndroidBinaryGraphEnhancer.AAPT_PACKAGE_FLAVOR), "__%s__proguard__/.proguard");
    Path proguardDir = AndroidBinary.getProguardOutputFromInputClasspath(proguardConfigDir, BuildTargets.getScratchPath(rule.getProjectFilesystem(), libBaseTarget, "lib__%s__classes"));
    assertEquals(proguardConfigDir.resolve(BuildTargets.getScratchPath(rule.getProjectFilesystem(), libBaseTarget, "lib__%s__classes-obfuscated.jar")), proguardDir);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 17 with BuildRuleResolver

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

the class AndroidBinaryTest method testCreateFilterResourcesStep.

@Test
public void testCreateFilterResourcesStep() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRule keystoreRule = addKeystoreRule(resolver);
    BuildTarget target = BuildTargetFactory.newInstance("//:target");
    AndroidBinaryBuilder builder = AndroidBinaryBuilder.createBuilder(target).setManifest(new FakeSourcePath("AndroidManifest.xml")).setKeystore(keystoreRule.getBuildTarget()).setResourceFilter(new ResourceFilter(ImmutableList.of("mdpi"))).setResourceCompressionMode(ResourceCompressionMode.ENABLED_WITH_STRINGS_AS_ASSETS);
    AndroidBinary buildRule = builder.build(resolver);
    ImmutableList<Path> resourceDirectories = ImmutableList.of(Paths.get("one"), Paths.get("two"));
    FilteredResourcesProvider resourcesProvider = buildRule.getEnhancementResult().getAaptPackageResources().getFilteredResourcesProvider();
    assertTrue(resourcesProvider instanceof ResourcesFilter);
    ImmutableList.Builder<Path> filteredDirs = ImmutableList.builder();
    ((ResourcesFilter) resourcesProvider).createFilterResourcesStep(resourceDirectories, /* whitelistedStringsDir */
    ImmutableSet.of(), /* locales */
    ImmutableSet.of(), filteredDirs);
    assertEquals(ImmutableList.of(BuildTargets.getScratchPath(buildRule.getProjectFilesystem(), target.withFlavors(AndroidBinaryGraphEnhancer.RESOURCES_FILTER_FLAVOR), "__filtered__%s__/0"), BuildTargets.getScratchPath(buildRule.getProjectFilesystem(), target.withFlavors(AndroidBinaryGraphEnhancer.RESOURCES_FILTER_FLAVOR), "__filtered__%s__/1")), filteredDirs.build());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ResourceFilter(com.facebook.buck.android.FilterResourcesStep.ResourceFilter) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 18 with BuildRuleResolver

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

the class AndroidBinaryTest method noDxParametersAreHintsAndNotHardDependencies.

@Test
public void noDxParametersAreHintsAndNotHardDependencies() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRule keystoreRule = addKeystoreRule(resolver);
    AndroidBinaryBuilder.createBuilder(BuildTargetFactory.newInstance("//:target")).setBuildTargetsToExcludeFromDex(ImmutableSet.of(BuildTargetFactory.newInstance("//missing:dep"))).setKeystore(keystoreRule.getBuildTarget()).setManifest(new FakeSourcePath("AndroidManifest.xml")).build(resolver);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 19 with BuildRuleResolver

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

the class AndroidBinaryDescriptionTest method testNoDxRulesBecomeFirstOrderDeps.

@Test
public void testNoDxRulesBecomeFirstOrderDeps() throws Exception {
    TargetNode<?, ?> transitiveDepNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//exciting:dep")).addSrc(Paths.get("Dep.java")).build();
    TargetNode<?, ?> depNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//exciting:target")).addSrc(Paths.get("Other.java")).addDep(transitiveDepNode.getBuildTarget()).build();
    TargetNode<?, ?> keystoreNode = KeystoreBuilder.createBuilder(BuildTargetFactory.newInstance("//:keystore")).setStore(new FakeSourcePath("store")).setProperties(new FakeSourcePath("properties")).build();
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    TargetNode<?, ?> androidBinaryNode = AndroidBinaryBuilder.createBuilder(target).setManifest(new FakeSourcePath("manifest.xml")).setKeystore(BuildTargetFactory.newInstance("//:keystore")).setNoDx(ImmutableSet.of(transitiveDepNode.getBuildTarget())).setOriginalDeps(ImmutableSortedSet.of(depNode.getBuildTarget())).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(transitiveDepNode, depNode, keystoreNode, androidBinaryNode);
    BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRule transitiveDep = ruleResolver.requireRule(transitiveDepNode.getBuildTarget());
    AndroidBinary androidBinary = (AndroidBinary) ruleResolver.requireRule(target);
    assertThat(androidBinary.getDeps(), Matchers.hasItem(transitiveDep));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 20 with BuildRuleResolver

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

the class AndroidBuildConfigJavaLibraryTest method testBuildConfigHasCorrectProperties.

@Test
public void testBuildConfigHasCorrectProperties() throws NoSuchBuildTargetException {
    BuildRuleParams params = new FakeBuildRuleParamsBuilder("//foo:bar").build();
    BuildConfigFields fields = BuildConfigFields.fromFieldDeclarations(Collections.singleton("String KEY = \"value\""));
    BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    AndroidBuildConfigJavaLibrary buildConfigJavaLibrary = AndroidBuildConfigDescription.createBuildRule(params, "com.example.buck", /* values */
    fields, /* valuesFile */
    Optional.empty(), /* useConstantExpressions */
    false, DEFAULT_JAVAC_OPTIONS, buildRuleResolver);
    AndroidBuildConfig buildConfig = buildConfigJavaLibrary.getAndroidBuildConfig();
    assertEquals("com.example.buck", buildConfig.getJavaPackage());
    assertEquals(fields, buildConfig.getBuildConfigFields());
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildConfigFields(com.facebook.buck.rules.coercer.BuildConfigFields) Test(org.junit.Test)

Aggregations

BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)622 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)578 Test (org.junit.Test)540 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)402 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)376 BuildTarget (com.facebook.buck.model.BuildTarget)287 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)240 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)211 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)211 TargetGraph (com.facebook.buck.rules.TargetGraph)196 BuildRule (com.facebook.buck.rules.BuildRule)185 Path (java.nio.file.Path)136 SourcePath (com.facebook.buck.rules.SourcePath)133 PathSourcePath (com.facebook.buck.rules.PathSourcePath)104 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)101 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)83 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)75 RuleKey (com.facebook.buck.rules.RuleKey)71 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)62 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)54