Search in sources :

Example 56 with FakeBuildRuleParamsBuilder

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

the class OmnibusTest method commondDepOfIncludedAndExcludedRoots.

@Test
public void commondDepOfIncludedAndExcludedRoots() throws NoSuchBuildTargetException {
    NativeLinkable a = new OmnibusNode("//:a");
    NativeLinkTarget root = new OmnibusRootNode("//:root", ImmutableList.of(a));
    NativeLinkable excludedRoot = new OmnibusNode("//:excluded_root", ImmutableList.of(a));
    // Verify the spec.
    Omnibus.OmnibusSpec spec = Omnibus.buildSpec(CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableList.of(root), ImmutableList.of(excludedRoot));
    assertThat(spec.getGraph().getNodes(), Matchers.empty());
    assertThat(spec.getBody().keySet(), Matchers.empty());
    assertThat(spec.getRoots().keySet(), Matchers.containsInAnyOrder(root.getBuildTarget()));
    assertThat(spec.getDeps().keySet(), Matchers.containsInAnyOrder(a.getBuildTarget()));
    assertThat(spec.getExcluded().keySet(), Matchers.containsInAnyOrder(excludedRoot.getBuildTarget(), a.getBuildTarget()));
    // Verify the libs.
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    ImmutableMap<String, SourcePath> libs = toSonameMap(Omnibus.getSharedLibraries(new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:rule")).build(), resolver, ruleFinder, CxxPlatformUtils.DEFAULT_CONFIG, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableList.of(), ImmutableList.of(root), ImmutableList.of(excludedRoot)));
    assertThat(libs.keySet(), Matchers.containsInAnyOrder(root.getBuildTarget().toString(), excludedRoot.getBuildTarget().toString(), a.getBuildTarget().toString()));
    assertCxxLinkContainsNativeLinkableInput(getCxxLinkRule(ruleFinder, libs.get(root.getBuildTarget().toString())), pathResolver, root.getNativeLinkTargetInput(CxxPlatformUtils.DEFAULT_PLATFORM));
    assertThat(libs.get(excludedRoot.getBuildTarget().toString()), Matchers.not(Matchers.instanceOf(ExplicitBuildTargetSourcePath.class)));
    assertThat(libs.get(a.getBuildTarget().toString()), Matchers.not(Matchers.instanceOf(ExplicitBuildTargetSourcePath.class)));
}
Also used : FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 57 with FakeBuildRuleParamsBuilder

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

the class JavaSourceJarTest method outputNameShouldIndicateThatTheOutputIsASrcJar.

@Test
public void outputNameShouldIndicateThatTheOutputIsASrcJar() {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    JavaSourceJar rule = new JavaSourceJar(new FakeBuildRuleParamsBuilder("//example:target").build(), ImmutableSortedSet.of(), Optional.empty());
    resolver.addToIndex(rule);
    SourcePath output = rule.getSourcePathToOutput();
    assertNotNull(output);
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    assertThat(pathResolver.getRelativePath(output).toString(), endsWith(Javac.SRC_JAR));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 58 with FakeBuildRuleParamsBuilder

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

the class AndroidBinaryGraphEnhancerTest method testAllBuildablesExceptPreDexRule.

@Test
public void testAllBuildablesExceptPreDexRule() throws Exception {
    // Create an android_build_config() as a dependency of the android_binary().
    BuildTarget buildConfigBuildTarget = BuildTargetFactory.newInstance("//java/com/example:cfg");
    BuildRuleParams buildConfigParams = new FakeBuildRuleParamsBuilder(buildConfigBuildTarget).build();
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    AndroidBuildConfigJavaLibrary buildConfigJavaLibrary = AndroidBuildConfigDescription.createBuildRule(buildConfigParams, "com.example.buck", /* values */
    BuildConfigFields.empty(), /* valuesFile */
    Optional.empty(), /* useConstantExpressions */
    false, ANDROID_JAVAC_OPTIONS, ruleResolver);
    BuildTarget apkTarget = BuildTargetFactory.newInstance("//java/com/example:apk");
    BuildRuleParams originalParams = new FakeBuildRuleParamsBuilder(apkTarget).setDeclaredDeps(ImmutableSortedSet.of(buildConfigJavaLibrary)).build();
    // set it up.
    Keystore keystore = createStrictMock(Keystore.class);
    AndroidBinaryGraphEnhancer graphEnhancer = new AndroidBinaryGraphEnhancer(originalParams, ruleResolver, ResourcesFilter.ResourceCompressionMode.ENABLED_WITH_STRINGS_AS_ASSETS, FilterResourcesStep.ResourceFilter.EMPTY_FILTER, /* bannedDuplicateResourceTypes */
    EnumSet.noneOf(RType.class), Optional.empty(), /* locales */
    ImmutableSet.of(), new FakeSourcePath("AndroidManifest.xml"), AndroidBinary.PackageType.DEBUG, /* cpuFilters */
    ImmutableSet.of(), /* shouldBuildStringSourceMap */
    false, /* shouldPreDex */
    false, BuildTargets.getScratchPath(originalParams.getProjectFilesystem(), apkTarget, "%s/classes.dex"), DexSplitMode.NO_SPLIT, /* buildRulesToExcludeFromDex */
    ImmutableSet.of(), /* resourcesToExclude */
    ImmutableSet.of(), /* skipCrunchPngs */
    false, /* includesVectorDrawables */
    false, ANDROID_JAVAC_OPTIONS, EnumSet.of(ExopackageMode.SECONDARY_DEX), /* buildConfigValues */
    BuildConfigFields.empty(), /* buildConfigValuesFiles */
    Optional.empty(), /* xzCompressionLevel */
    Optional.empty(), /* trimResourceIds */
    false, /* keepResourcePattern */
    Optional.empty(), /* nativePlatforms */
    ImmutableMap.of(), /* nativeLibraryMergeMap */
    Optional.empty(), /* nativeLibraryMergeGlue */
    Optional.empty(), /* nativeLibraryMergeCodeGenerator */
    Optional.empty(), AndroidBinary.RelinkerMode.DISABLED, MoreExecutors.newDirectExecutorService(), /* manifestEntries */
    ManifestEntries.empty(), CxxPlatformUtils.DEFAULT_CONFIG, new APKModuleGraph(TargetGraph.EMPTY, originalParams.getBuildTarget(), Optional.empty()), new DxConfig(FakeBuckConfig.builder().build()));
    replay(keystore);
    AndroidGraphEnhancementResult result = graphEnhancer.createAdditionalBuildables();
    // Verify that android_build_config() was processed correctly.
    Flavor flavor = InternalFlavor.of("buildconfig_com_example_buck");
    final SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
    BuildTarget enhancedBuildConfigTarget = BuildTarget.builder(apkTarget).addFlavors(flavor).build();
    assertEquals("The only classpath entry to dex should be the one from the AndroidBuildConfigJavaLibrary" + " created via graph enhancement.", ImmutableSet.of(BuildTargets.getGenPath(originalParams.getProjectFilesystem(), enhancedBuildConfigTarget, "lib__%s__output").resolve(enhancedBuildConfigTarget.getShortNameAndFlavorPostfix() + ".jar")), result.getClasspathEntriesToDex().stream().map(pathResolver::getRelativePath).collect(MoreCollectors.toImmutableSet()));
    BuildRule enhancedBuildConfigRule = ruleResolver.getRule(enhancedBuildConfigTarget);
    assertTrue(enhancedBuildConfigRule instanceof AndroidBuildConfigJavaLibrary);
    AndroidBuildConfigJavaLibrary enhancedBuildConfigJavaLibrary = (AndroidBuildConfigJavaLibrary) enhancedBuildConfigRule;
    AndroidBuildConfig androidBuildConfig = enhancedBuildConfigJavaLibrary.getAndroidBuildConfig();
    assertEquals("com.example.buck", androidBuildConfig.getJavaPackage());
    assertTrue(androidBuildConfig.isUseConstantExpressions());
    assertEquals("IS_EXOPACKAGE defaults to false, but should now be true. DEBUG should still be true.", BuildConfigFields.fromFields(ImmutableList.of(BuildConfigFields.Field.of("boolean", "DEBUG", "true"), BuildConfigFields.Field.of("boolean", "IS_EXOPACKAGE", "true"), BuildConfigFields.Field.of("int", "EXOPACKAGE_FLAGS", "1"))), androidBuildConfig.getBuildConfigFields());
    ImmutableSortedSet<BuildRule> finalDeps = result.getFinalDeps();
    BuildRule computeExopackageDepsAbiRule = findRuleOfType(ruleResolver, ComputeExopackageDepsAbi.class);
    assertThat(finalDeps, Matchers.hasItem(computeExopackageDepsAbiRule));
    FilteredResourcesProvider resourcesProvider = result.getAaptPackageResources().getFilteredResourcesProvider();
    assertTrue(resourcesProvider instanceof ResourcesFilter);
    BuildRule resourcesFilterRule = findRuleOfType(ruleResolver, ResourcesFilter.class);
    BuildRule aaptPackageResourcesRule = findRuleOfType(ruleResolver, AaptPackageResources.class);
    MoreAsserts.assertDepends("AaptPackageResources must depend on ResourcesFilter", aaptPackageResourcesRule, resourcesFilterRule);
    BuildRule packageStringAssetsRule = findRuleOfType(ruleResolver, PackageStringAssets.class);
    MoreAsserts.assertDepends("PackageStringAssets must depend on ResourcesFilter", packageStringAssetsRule, aaptPackageResourcesRule);
    assertFalse(result.getPreDexMerge().isPresent());
    MoreAsserts.assertDepends("ComputeExopackageDepsAbi must depend on ResourcesFilter", computeExopackageDepsAbiRule, resourcesFilterRule);
    MoreAsserts.assertDepends("ComputeExopackageDepsAbi must depend on PackageStringAssets", computeExopackageDepsAbiRule, packageStringAssetsRule);
    MoreAsserts.assertDepends("ComputeExopackageDepsAbi must depend on AaptPackageResources", computeExopackageDepsAbiRule, aaptPackageResourcesRule);
    assertTrue(result.getPackageStringAssets().isPresent());
    assertTrue(result.getComputeExopackageDepsAbi().isPresent());
    verify(keystore);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) RType(com.facebook.buck.android.aapt.RDotTxtEntry.RType) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Keystore(com.facebook.buck.jvm.java.Keystore) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 59 with FakeBuildRuleParamsBuilder

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

the class AndroidBinaryGraphEnhancerTest method testResourceRulesBecomeDepsOfAaptPackageResources.

@Test
public void testResourceRulesBecomeDepsOfAaptPackageResources() throws Exception {
    TargetNode<?, ?> resourceNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:resource")).setRDotJavaPackage("package").setRes(Paths.get("res")).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(resourceNode);
    BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    AndroidResource resource = (AndroidResource) ruleResolver.requireRule(resourceNode.getBuildTarget());
    // set it up.
    BuildTarget target = BuildTargetFactory.newInstance("//:target");
    BuildRuleParams originalParams = new FakeBuildRuleParamsBuilder(target).setDeclaredDeps(ImmutableSortedSet.of(resource)).build();
    AndroidBinaryGraphEnhancer graphEnhancer = new AndroidBinaryGraphEnhancer(originalParams, ruleResolver, ResourcesFilter.ResourceCompressionMode.ENABLED_WITH_STRINGS_AS_ASSETS, FilterResourcesStep.ResourceFilter.EMPTY_FILTER, /* bannedDuplicateResourceTypes */
    EnumSet.noneOf(RType.class), Optional.empty(), /* locales */
    ImmutableSet.of(), new FakeSourcePath("AndroidManifest.xml"), AndroidBinary.PackageType.DEBUG, /* cpuFilters */
    ImmutableSet.of(), /* shouldBuildStringSourceMap */
    false, /* shouldPreDex */
    false, BuildTargets.getScratchPath(originalParams.getProjectFilesystem(), target, "%s/classes.dex"), DexSplitMode.NO_SPLIT, /* buildRulesToExcludeFromDex */
    ImmutableSet.of(), /* resourcesToExclude */
    ImmutableSet.of(), /* skipCrunchPngs */
    false, /* includesVectorDrawables */
    false, ANDROID_JAVAC_OPTIONS, EnumSet.of(ExopackageMode.SECONDARY_DEX), /* buildConfigValues */
    BuildConfigFields.empty(), /* buildConfigValuesFiles */
    Optional.empty(), /* xzCompressionLevel */
    Optional.empty(), /* trimResourceIds */
    false, /* keepResourcePattern */
    Optional.empty(), /* nativePlatforms */
    ImmutableMap.of(), /* nativeLibraryMergeMap */
    Optional.empty(), /* nativeLibraryMergeGlue */
    Optional.empty(), /* nativeLibraryMergeCodeGenerator */
    Optional.empty(), AndroidBinary.RelinkerMode.DISABLED, MoreExecutors.newDirectExecutorService(), /* manifestEntries */
    ManifestEntries.empty(), CxxPlatformUtils.DEFAULT_CONFIG, new APKModuleGraph(TargetGraph.EMPTY, originalParams.getBuildTarget(), Optional.empty()), new DxConfig(FakeBuckConfig.builder().build()));
    graphEnhancer.createAdditionalBuildables();
    BuildRule aaptPackageResourcesRule = findRuleOfType(ruleResolver, AaptPackageResources.class);
    MoreAsserts.assertDepends("AaptPackageResources must depend on resource rules", aaptPackageResourcesRule, resource);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) RType(com.facebook.buck.android.aapt.RDotTxtEntry.RType) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 60 with FakeBuildRuleParamsBuilder

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

the class AndroidBinaryDescriptionTest method turkishCaseRulesDoNotCrashConstructor.

@Test
public void turkishCaseRulesDoNotCrashConstructor() throws Exception {
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    Keystore keystore = ruleResolver.addToIndex(new Keystore(new FakeBuildRuleParamsBuilder("//:keystore").build(), new FakeSourcePath("store"), new FakeSourcePath("properties")));
    Locale originalLocale = Locale.getDefault();
    try {
        Locale.setDefault(new Locale("tr"));
        // Make sure this doesn't crash in Enum.valueOf() when default Turkish locale rules
        // upper-case "instrumented" to "İNSTRUMENTED".
        AndroidBinaryBuilder.createBuilder(BuildTargetFactory.newInstance("//:rule")).setManifest(new FakeSourcePath("manifest.xml")).setKeystore(keystore.getBuildTarget()).setPackageType("instrumented").build(ruleResolver, new FakeProjectFilesystem(), TargetGraph.EMPTY);
    } finally {
        Locale.setDefault(originalLocale);
    }
}
Also used : Keystore(com.facebook.buck.jvm.java.Keystore) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Locale(java.util.Locale) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) 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