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);
}
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."));
}
}
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();
}
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);
}
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);
}
Aggregations