Search in sources :

Example 41 with Flavor

use of com.facebook.buck.model.Flavor 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 42 with Flavor

use of com.facebook.buck.model.Flavor in project buck by facebook.

the class MultiarchFileTest method ruleWithSpecialBuildActionShouldFail.

@Test
public void ruleWithSpecialBuildActionShouldFail() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    HumanReadableException exception = null;
    Iterable<Flavor> forbiddenFlavors = ImmutableList.<Flavor>builder().addAll(CxxInferEnhancer.InferFlavors.getAll()).add(CxxCompilationDatabase.COMPILATION_DATABASE).build();
    for (Flavor flavor : forbiddenFlavors) {
        try {
            nodeBuilderFactory.getNodeBuilder(BuildTargetFactory.newInstance("//foo:xctest#" + "iphoneos-i386,iphoneos-x86_64," + flavor.toString())).build(resolver);
        } catch (HumanReadableException e) {
            exception = e;
        }
        assertThat(exception, notNullValue());
        assertThat("Should throw exception about special build actions.", exception.getHumanReadableErrorMessage(), endsWith("Fat binaries is only supported when building an actual binary."));
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 43 with Flavor

use of com.facebook.buck.model.Flavor in project buck by facebook.

the class AppleCxxPlatformsTest method constructLinkRuleKeys.

// Create and return some rule keys from a dummy source for the given platforms.
private ImmutableMap<Flavor, RuleKey> constructLinkRuleKeys(ImmutableMap<Flavor, AppleCxxPlatform> cxxPlatforms) throws NoSuchBuildTargetException {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.<String, String>builder().put("input.o", Strings.repeat("a", 40)).build()), pathResolver, ruleFinder);
    BuildTarget target = BuildTargetFactory.newInstance("//:target");
    ImmutableMap.Builder<Flavor, RuleKey> ruleKeys = ImmutableMap.builder();
    for (Map.Entry<Flavor, AppleCxxPlatform> entry : cxxPlatforms.entrySet()) {
        BuildRule rule = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, entry.getValue().getCxxPlatform(), new FakeBuildRuleParamsBuilder(target).build(), resolver, pathResolver, ruleFinder, target, Linker.LinkType.EXECUTABLE, Optional.empty(), Paths.get("output"), Linker.LinkableDepType.SHARED, ImmutableList.of(), Optional.empty(), Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(SourcePathArg.from(new FakeSourcePath("input.o"))).build());
        ruleKeys.put(entry.getKey(), ruleKeyFactory.build(rule));
    }
    return ruleKeys.build();
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) Matchers.containsString(org.hamcrest.Matchers.containsString) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ImmutableMap(com.google.common.collect.ImmutableMap) BuildTarget(com.facebook.buck.model.BuildTarget) BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 44 with Flavor

use of com.facebook.buck.model.Flavor in project buck by facebook.

the class CompDirReplacerIntegrationTest method testCompDirReplacerForIntel32Bit.

@Test
public void testCompDirReplacerForIntel32Bit() throws Exception {
    Flavor platformFlavor = InternalFlavor.of("iphonesimulator-i386");
    runCompDirReplacerWithPlatformFlavor(platformFlavor);
}
Also used : InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) Test(org.junit.Test)

Example 45 with Flavor

use of com.facebook.buck.model.Flavor in project buck by facebook.

the class CompDirReplacerIntegrationTest method testCompDirReplacerForArm64Bit.

@Test
public void testCompDirReplacerForArm64Bit() throws Exception {
    Flavor platformFlavor = InternalFlavor.of("iphoneos-arm64");
    runCompDirReplacerWithPlatformFlavor(platformFlavor);
}
Also used : InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) Test(org.junit.Test)

Aggregations

Flavor (com.facebook.buck.model.Flavor)60 InternalFlavor (com.facebook.buck.model.InternalFlavor)42 BuildTarget (com.facebook.buck.model.BuildTarget)33 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)17 Test (org.junit.Test)17 SourcePath (com.facebook.buck.rules.SourcePath)14 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)14 ImmutableMap (com.google.common.collect.ImmutableMap)14 BuildRule (com.facebook.buck.rules.BuildRule)13 ImmutableSet (com.google.common.collect.ImmutableSet)13 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)12 HumanReadableException (com.facebook.buck.util.HumanReadableException)12 Path (java.nio.file.Path)12 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)11 Optional (java.util.Optional)10 ImmutableList (com.google.common.collect.ImmutableList)9 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)9 Map (java.util.Map)9 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)7 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)6