use of com.facebook.buck.model.Flavor in project buck by facebook.
the class AndroidBinaryDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
try (SimplePerfEvent.Scope ignored = SimplePerfEvent.scope(Optional.ofNullable(resolver.getEventBus()), PerfEventId.of("AndroidBinaryDescription"), "target", params.getBuildTarget().toString())) {
ResourceCompressionMode compressionMode = getCompressionMode(args);
BuildTarget target = params.getBuildTarget();
boolean isFlavored = target.isFlavored();
if (isFlavored) {
if (target.getFlavors().contains(PACKAGE_STRING_ASSETS_FLAVOR) && !compressionMode.isStoreStringsAsAssets()) {
throw new HumanReadableException("'package_string_assets' flavor does not exist for %s.", target.getUnflavoredBuildTarget());
}
params = params.withBuildTarget(BuildTarget.of(target.getUnflavoredBuildTarget()));
}
BuildRule keystore = resolver.getRule(args.keystore);
if (!(keystore instanceof Keystore)) {
throw new HumanReadableException("In %s, keystore='%s' must be a keystore() but was %s().", params.getBuildTarget(), keystore.getFullyQualifiedName(), keystore.getType());
}
APKModuleGraph apkModuleGraph = new APKModuleGraph(targetGraph, target, Optional.of(args.applicationModuleTargets));
ProGuardObfuscateStep.SdkProguardType androidSdkProguardConfig = args.androidSdkProguardConfig.orElse(ProGuardObfuscateStep.SdkProguardType.DEFAULT);
// was not specified, and allow the old form to override the default.
if (args.useAndroidProguardConfigWithOptimizations.isPresent()) {
Preconditions.checkArgument(!args.androidSdkProguardConfig.isPresent(), "The deprecated use_android_proguard_config_with_optimizations parameter" + " cannot be used with android_sdk_proguard_config.");
LOG.error("Target %s specified use_android_proguard_config_with_optimizations, " + "which is deprecated. Use android_sdk_proguard_config.", params.getBuildTarget());
androidSdkProguardConfig = args.useAndroidProguardConfigWithOptimizations.orElse(false) ? ProGuardObfuscateStep.SdkProguardType.OPTIMIZED : ProGuardObfuscateStep.SdkProguardType.DEFAULT;
}
EnumSet<ExopackageMode> exopackageModes = EnumSet.noneOf(ExopackageMode.class);
if (!args.exopackageModes.isEmpty()) {
exopackageModes = EnumSet.copyOf(args.exopackageModes);
} else if (args.exopackage.orElse(false)) {
LOG.error("Target %s specified exopackage=True, which is deprecated. Use exopackage_modes.", params.getBuildTarget());
exopackageModes = EnumSet.of(ExopackageMode.SECONDARY_DEX);
}
DexSplitMode dexSplitMode = createDexSplitMode(args, exopackageModes);
PackageType packageType = getPackageType(args);
boolean shouldPreDex = !args.disablePreDex && PackageType.DEBUG.equals(packageType) && !args.preprocessJavaClassesBash.isPresent();
ResourceFilter resourceFilter = new ResourceFilter(args.resourceFilter);
AndroidBinaryGraphEnhancer graphEnhancer = new AndroidBinaryGraphEnhancer(params, resolver, compressionMode, resourceFilter, args.getBannedDuplicateResourceTypes(), args.resourceUnionPackage, addFallbackLocales(args.locales), args.manifest, packageType, ImmutableSet.copyOf(args.cpuFilters), args.buildStringSourceMap, shouldPreDex, AndroidBinary.getPrimaryDexPath(params.getBuildTarget(), params.getProjectFilesystem()), dexSplitMode, ImmutableSet.copyOf(args.noDx.orElse(ImmutableSet.of())), /* resourcesToExclude */
ImmutableSet.of(), args.skipCrunchPngs, args.includesVectorDrawables, javacOptions, exopackageModes, args.buildConfigValues, args.buildConfigValuesFile, Optional.empty(), args.trimResourceIds, args.keepResourcePattern, nativePlatforms, Optional.of(args.nativeLibraryMergeMap), args.nativeLibraryMergeGlue, args.nativeLibraryMergeCodeGenerator, args.enableRelinker ? RelinkerMode.ENABLED : RelinkerMode.DISABLED, dxExecutorService, args.manifestEntries, cxxBuckConfig, apkModuleGraph, dxConfig);
AndroidGraphEnhancementResult result = graphEnhancer.createAdditionalBuildables();
if (target.getFlavors().contains(PACKAGE_STRING_ASSETS_FLAVOR)) {
Optional<PackageStringAssets> packageStringAssets = result.getPackageStringAssets();
Preconditions.checkState(packageStringAssets.isPresent());
return packageStringAssets.get();
}
// Build rules added to "no_dx" are only hints, not hard dependencies. Therefore, although a
// target may be mentioned in that parameter, it may not be present as a build rule.
ImmutableSortedSet.Builder<BuildRule> builder = ImmutableSortedSet.naturalOrder();
for (BuildTarget noDxTarget : args.noDx.orElse(ImmutableSet.of())) {
Optional<BuildRule> ruleOptional = resolver.getRuleOptional(noDxTarget);
if (ruleOptional.isPresent()) {
builder.add(ruleOptional.get());
} else {
LOG.info("%s: no_dx target not a dependency: %s", target, noDxTarget);
}
}
ImmutableSortedSet<BuildRule> buildRulesToExcludeFromDex = builder.build();
ImmutableSortedSet<JavaLibrary> rulesToExcludeFromDex = RichStream.from(buildRulesToExcludeFromDex).filter(JavaLibrary.class).collect(MoreCollectors.toImmutableSortedSet(Ordering.natural()));
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
Optional<RedexOptions> redexOptions = getRedexOptions(params, resolver, args);
ImmutableSortedSet<BuildRule> redexExtraDeps = redexOptions.map(a -> a.getRedexExtraArgs().stream().flatMap(arg -> arg.getDeps(ruleFinder).stream()).collect(MoreCollectors.toImmutableSortedSet(Ordering.natural()))).orElse(ImmutableSortedSet.of());
return new AndroidBinary(params.copyReplacingExtraDeps(Suppliers.ofInstance(result.getFinalDeps())).copyAppendingExtraDeps(ruleFinder.filterBuildRuleInputs(result.getPackageableCollection().getProguardConfigs())).copyAppendingExtraDeps(rulesToExcludeFromDex).copyAppendingExtraDeps(redexExtraDeps), ruleFinder, proGuardConfig.getProguardJarOverride(), proGuardConfig.getProguardMaxHeapSize(), Optional.of(args.proguardJvmArgs), proGuardConfig.getProguardAgentPath(), (Keystore) keystore, packageType, dexSplitMode, args.noDx.orElse(ImmutableSet.of()), androidSdkProguardConfig, args.optimizationPasses, args.proguardConfig, args.skipProguard, redexOptions, compressionMode, args.cpuFilters, resourceFilter, exopackageModes, MACRO_HANDLER.getExpander(params.getBuildTarget(), params.getCellRoots(), resolver), args.preprocessJavaClassesBash, rulesToExcludeFromDex, result, args.reorderClassesIntraDex, args.dexReorderToolFile, args.dexReorderDataDumpFile, args.xzCompressionLevel, dxExecutorService, args.packageAssetLibraries, args.compressAssetLibraries, args.manifestEntries, javaOptions.getJavaRuntimeLauncher(), dxConfig.getDxMaxHeapSize());
}
}
use of com.facebook.buck.model.Flavor in project buck by facebook.
the class InstallCommand method getInstallHelperTargets.
private ImmutableSet<String> getInstallHelperTargets(CommandRunnerParams params, ListeningExecutorService executor) throws IOException, InterruptedException, BuildTargetException, BuildFileParseException {
ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
ImmutableSet.Builder<String> installHelperTargets = ImmutableSet.builder();
for (int index = 0; index < getArguments().size(); index++) {
// TODO(ryu2): Cache argument parsing
TargetNodeSpec spec = parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), getArguments()).get(index);
BuildTarget target = FluentIterable.from(params.getParser().resolveTargetSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, ImmutableList.of(spec), SpeculativeParsing.of(false), parserConfig.getDefaultFlavorsMode())).transformAndConcat(Functions.identity()).first().get();
TargetNode<?, ?> node = params.getParser().getTargetNode(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, target);
if (node != null && Description.getBuildRuleType(node.getDescription()).equals(Description.getBuildRuleType(AppleBundleDescription.class))) {
for (Flavor flavor : node.getBuildTarget().getFlavors()) {
if (ApplePlatform.needsInstallHelper(flavor.getName())) {
AppleConfig appleConfig = new AppleConfig(params.getBuckConfig());
Optional<BuildTarget> deviceHelperTarget = appleConfig.getAppleDeviceHelperTarget();
Optionals.addIfPresent(Optionals.bind(deviceHelperTarget, input -> !input.toString().isEmpty() ? Optional.of(input.toString()) : Optional.empty()), installHelperTargets);
}
}
}
}
return installHelperTargets.build();
}
use of com.facebook.buck.model.Flavor in project buck by facebook.
the class KotlinLibraryDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
BuildTarget target = params.getBuildTarget();
// creating the action graph from the target graph.
if (CalculateAbi.isAbiTarget(target)) {
BuildTarget libraryTarget = CalculateAbi.getLibraryTarget(params.getBuildTarget());
BuildRule libraryRule = resolver.requireRule(libraryTarget);
return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, Preconditions.checkNotNull(libraryRule.getSourcePathToOutput()));
}
ImmutableSortedSet<Flavor> flavors = target.getFlavors();
BuildRuleParams paramsWithMavenFlavor = null;
if (flavors.contains(JavaLibrary.MAVEN_JAR)) {
paramsWithMavenFlavor = params;
// Maven rules will depend upon their vanilla versions, so the latter have to be constructed
// without the maven flavor to prevent output-path conflict
params = params.withoutFlavor(JavaLibrary.MAVEN_JAR);
}
if (flavors.contains(JavaLibrary.SRC_JAR)) {
args.mavenCoords = args.mavenCoords.map(input -> AetherUtil.addClassifier(input, AetherUtil.CLASSIFIER_SOURCES));
if (!flavors.contains(JavaLibrary.MAVEN_JAR)) {
return new JavaSourceJar(params, args.srcs, args.mavenCoords);
} else {
return MavenUberJar.SourceJar.create(Preconditions.checkNotNull(paramsWithMavenFlavor), args.srcs, args.mavenCoords, args.mavenPomTemplate);
}
}
JavacOptions javacOptions = JavacOptionsFactory.create(defaultOptions, params, resolver, ruleFinder, args);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ImmutableSortedSet<BuildRule> exportedDeps = resolver.getAllRules(args.exportedDeps);
BuildRuleParams javaLibraryParams = params.copyAppendingExtraDeps(Iterables.concat(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), exportedDeps, resolver.getAllRules(args.providedDeps))), ruleFinder.filterBuildRuleInputs(javacOptions.getInputs(ruleFinder))));
DefaultKotlinLibrary defaultKotlinLibrary = new DefaultKotlinLibrary(javaLibraryParams, pathResolver, ruleFinder, args.srcs, validateResources(pathResolver, params.getProjectFilesystem(), args.resources), Optional.empty(), Optional.empty(), ImmutableList.of(), exportedDeps, resolver.getAllRules(args.providedDeps), JavaLibraryRules.getAbiInputs(resolver, javaLibraryParams.getDeps()), false, ImmutableSet.of(), new KotlincToJarStepFactory(kotlinBuckConfig.getKotlinCompiler().get(), args.extraKotlincArguments), args.resourcesRoot, args.manifestFile, args.mavenCoords, args.tests, args.removeClasses);
if (!flavors.contains(JavaLibrary.MAVEN_JAR)) {
return defaultKotlinLibrary;
} else {
return MavenUberJar.create(defaultKotlinLibrary, Preconditions.checkNotNull(paramsWithMavenFlavor), args.mavenCoords, args.mavenPomTemplate);
}
}
use of com.facebook.buck.model.Flavor in project buck by facebook.
the class AbstractFlavorSearchTargetNodeFinder method getBaseTargetFlavorMap.
// Build the flavor map, which maps all unflavored targets to the flavors they have in the
// graph. We sort the list of flavor sets from largest to smallest, so that look ups pick the
// more flavored sets first.
@Value.Derived
ImmutableMap<UnflavoredBuildTarget, ImmutableSet<ImmutableSet<Flavor>>> getBaseTargetFlavorMap() {
Map<UnflavoredBuildTarget, List<ImmutableSet<Flavor>>> flavorMapRawBuilder = new LinkedHashMap<>();
for (Map.Entry<BuildTarget, TargetNode<?, ?>> ent : getBaseTargetIndex().entrySet()) {
BuildTarget baseTarget = ent.getKey();
UnflavoredBuildTarget unflavoredTarget = baseTarget.getUnflavoredBuildTarget();
if (!flavorMapRawBuilder.containsKey(unflavoredTarget)) {
flavorMapRawBuilder.put(unflavoredTarget, new ArrayList<>());
}
flavorMapRawBuilder.get(unflavoredTarget).add(baseTarget.getFlavors());
}
ImmutableMap.Builder<UnflavoredBuildTarget, ImmutableSet<ImmutableSet<Flavor>>> flavorMapBuilder = ImmutableMap.builder();
for (Map.Entry<UnflavoredBuildTarget, List<ImmutableSet<Flavor>>> ent : flavorMapRawBuilder.entrySet()) {
ent.getValue().sort((o1, o2) -> Integer.compare(o2.size(), o1.size()));
flavorMapBuilder.put(ent.getKey(), ImmutableSet.copyOf(ent.getValue()));
}
return flavorMapBuilder.build();
}
use of com.facebook.buck.model.Flavor in project buck by facebook.
the class ProjectGenerator method getBuildWithBuckShellScript.
private String getBuildWithBuckShellScript(TargetNode<?, ?> targetNode) {
ST template;
try {
template = new ST(Resources.toString(Resources.getResource(ProjectGenerator.class, BUILD_WITH_BUCK_TEMPLATE), Charsets.UTF_8));
} catch (IOException e) {
throw new RuntimeException("There was an error loading '" + BUILD_WITH_BUCK_TEMPLATE + "' template", e);
}
String buildFlags = getBuildFlags();
String escapedBuildTarget = Escaper.escapeAsBashString(targetNode.getBuildTarget().getFullyQualifiedName());
Optional<String> productName = getProductNameForTargetNode(targetNode);
String binaryName = AppleBundle.getBinaryName(targetNode.getBuildTarget(), productName);
Path bundleDestination = getScratchPathForAppBundle(projectFilesystem, targetNode.getBuildTarget(), binaryName);
Path dsymDestination = getScratchPathForDsymBundle(projectFilesystem, targetNode.getBuildTarget(), binaryName);
Path resolvedBundleDestination = projectFilesystem.resolve(bundleDestination);
Path resolvedDsymDestination = projectFilesystem.resolve(dsymDestination);
ImmutableSet<Flavor> flavors = ImmutableSet.copyOf(targetNode.getBuildTarget().getFlavors());
CxxPlatform cxxPlatform = cxxPlatforms.getValue(flavors).orElse(defaultCxxPlatform);
String oldCompDir = cxxPlatform.getCompilerDebugPathSanitizer().getCompilationDirectory();
// Use the hostname for padding instead of the directory, this way the directory matches without
// having to resolve it.
String dsymPaddedCompDirWithHost = Strings.padStart(":" + projectFilesystem.getRootPath().toString(), oldCompDir.length(), 'f');
template.add("path_to_build_with_buck_py", getBuildWithBuckPythonScriptPath(projectFilesystem));
template.add("path_to_fix_uuid_script", getFixUUIDScriptPath(projectFilesystem));
template.add("repo_root", projectFilesystem.getRootPath());
template.add("path_to_buck", getPathToBuck(executableFinder, environment));
template.add("build_flags", buildFlags);
template.add("escaped_build_target", escapedBuildTarget);
template.add("buck_dwarf_flavor", (appleConfig.forceDsymModeInBuildWithBuck() ? AppleDebugFormat.DWARF_AND_DSYM : AppleDebugFormat.DWARF).getFlavor().getName());
template.add("buck_dsym_flavor", AppleDebugFormat.DWARF_AND_DSYM.getFlavor().getName());
template.add("binary_name", binaryName);
template.add("comp_dir", oldCompDir);
template.add("new_comp_dir", projectFilesystem.getRootPath().toString());
template.add("padded_source_dir", dsymPaddedCompDirWithHost);
template.add("resolved_bundle_destination", resolvedBundleDestination);
template.add("resolved_bundle_destination_parent", resolvedBundleDestination.getParent());
template.add("resolved_dsym_destination", resolvedDsymDestination);
template.add("force_dsym", appleConfig.forceDsymModeInBuildWithBuck() ? "true" : "false");
return template.render();
}
Aggregations