use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class AndroidLibraryDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
if (params.getBuildTarget().getFlavors().contains(JavaLibrary.SRC_JAR)) {
return new JavaSourceJar(params, args.srcs, args.mavenCoords);
}
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
JavacOptions javacOptions = JavacOptionsFactory.create(defaultOptions, params, resolver, ruleFinder, args);
final ImmutableSet.Builder<BuildRule> queriedDepsBuilder = ImmutableSet.builder();
if (args.depsQuery.isPresent()) {
queriedDepsBuilder.addAll(QueryUtils.resolveDepQuery(params, args.depsQuery.get(), resolver, targetGraph).collect(Collectors.toList()));
}
final ImmutableSet<BuildRule> queriedDeps = queriedDepsBuilder.build();
AndroidLibraryGraphEnhancer graphEnhancer = new AndroidLibraryGraphEnhancer(params.getBuildTarget(), params.copyReplacingExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(queriedDeps).addAll(resolver.getAllRules(args.exportedDeps)).build())), javacOptions, DependencyMode.FIRST_ORDER, /* forceFinalResourceIds */
false, args.resourceUnionPackage, args.finalRName, false);
boolean hasDummyRDotJavaFlavor = params.getBuildTarget().getFlavors().contains(DUMMY_R_DOT_JAVA_FLAVOR);
if (CalculateAbi.isAbiTarget(params.getBuildTarget())) {
if (hasDummyRDotJavaFlavor) {
return graphEnhancer.getBuildableForAndroidResourcesAbi(resolver, ruleFinder);
}
BuildTarget libraryTarget = CalculateAbi.getLibraryTarget(params.getBuildTarget());
BuildRule libraryRule = resolver.requireRule(libraryTarget);
return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, Preconditions.checkNotNull(libraryRule.getSourcePathToOutput()));
}
Optional<DummyRDotJava> dummyRDotJava = graphEnhancer.getBuildableForAndroidResources(resolver, /* createBuildableIfEmpty */
hasDummyRDotJavaFlavor);
if (hasDummyRDotJavaFlavor) {
return dummyRDotJava.get();
} else {
ImmutableSet<Either<SourcePath, Path>> additionalClasspathEntries = ImmutableSet.of();
if (dummyRDotJava.isPresent()) {
additionalClasspathEntries = ImmutableSet.of(Either.ofLeft(dummyRDotJava.get().getSourcePathToOutput()));
ImmutableSortedSet<BuildRule> newDeclaredDeps = ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getDeclaredDeps().get()).add(dummyRDotJava.get()).build();
params = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(newDeclaredDeps), params.getExtraDeps());
}
AndroidLibraryCompiler compiler = compilerFactory.getCompiler(args.language.orElse(JvmLanguage.JAVA));
ImmutableSortedSet<BuildRule> exportedDeps = resolver.getAllRules(args.exportedDeps);
ImmutableSortedSet.Builder<BuildRule> declaredDepsBuilder = ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getDeclaredDeps().get()).addAll(queriedDeps).addAll(compiler.getDeclaredDeps(args, resolver));
ImmutableSortedSet<BuildRule> declaredDeps = declaredDepsBuilder.build();
ImmutableSortedSet<BuildRule> extraDeps = ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getExtraDeps().get()).addAll(BuildRules.getExportedRules(Iterables.concat(declaredDeps, exportedDeps, resolver.getAllRules(args.providedDeps)))).addAll(ruleFinder.filterBuildRuleInputs(javacOptions.getInputs(ruleFinder))).addAll(compiler.getExtraDeps(args, resolver)).build();
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildRuleParams androidLibraryParams = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(declaredDeps), Suppliers.ofInstance(extraDeps));
return new AndroidLibrary(androidLibraryParams, pathResolver, ruleFinder, args.srcs, ResourceValidator.validateResources(pathResolver, params.getProjectFilesystem(), args.resources), args.proguardConfig, args.postprocessClassesCommands, exportedDeps, resolver.getAllRules(args.providedDeps), JavaLibraryRules.getAbiInputs(resolver, androidLibraryParams.getDeps()), additionalClasspathEntries, javacOptions, compiler.trackClassUsage(javacOptions), compiler.compileToJar(args, javacOptions, resolver), args.resourcesRoot, args.mavenCoords, args.manifest, args.tests);
}
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class AndroidLibraryGraphEnhancer method getBuildableForAndroidResourcesAbi.
public CalculateAbi getBuildableForAndroidResourcesAbi(BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder) throws NoSuchBuildTargetException {
Preconditions.checkState(CalculateAbi.isAbiTarget(dummyRDotJavaBuildTarget));
BuildTarget resourcesTarget = CalculateAbi.getLibraryTarget(dummyRDotJavaBuildTarget);
BuildRule resourcesRule = resolver.requireRule(resourcesTarget);
return CalculateAbi.of(dummyRDotJavaBuildTarget, ruleFinder, originalBuildRuleParams, Preconditions.checkNotNull(resourcesRule.getSourcePathToOutput()));
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class AndroidPackageableCollector method addClasspathEntry.
public AndroidPackageableCollector addClasspathEntry(HasJavaClassHashes hasJavaClassHashes, SourcePath classpathEntry) {
BuildTarget target = hasJavaClassHashes.getBuildTarget();
if (buildTargetsToExcludeFromDex.contains(target)) {
collectionBuilder.addNoDxClasspathEntries(classpathEntry);
} else {
collectionBuilder.addClasspathEntriesToDex(classpathEntry);
APKModule module = apkModuleGraph.findModuleForTarget(target);
collectionBuilder.putModuleMappedClasspathEntriesToDex(module, classpathEntry);
javaClassHashesProviders.add(hasJavaClassHashes);
}
return this;
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class AndroidBinaryGraphEnhancer method createPreDexRulesForLibraries.
@VisibleForTesting
ImmutableMultimap<APKModule, DexProducedFromJavaLibrary> createPreDexRulesForLibraries(Iterable<BuildRule> additionalJavaLibrariesToDex, AndroidPackageableCollection packageableCollection) {
Iterable<BuildTarget> additionalJavaLibraryTargets = FluentIterable.from(additionalJavaLibrariesToDex).transform(BuildRule::getBuildTarget);
ImmutableMultimap.Builder<APKModule, DexProducedFromJavaLibrary> preDexDeps = ImmutableMultimap.builder();
for (BuildTarget buildTarget : Iterables.concat(packageableCollection.getJavaLibrariesToDex(), additionalJavaLibraryTargets)) {
Preconditions.checkState(!buildTargetsToExcludeFromDex.contains(buildTarget), "JavaLibrary should have been excluded from target to dex: %s", buildTarget);
BuildRule libraryRule = ruleResolver.getRule(buildTarget);
Preconditions.checkState(libraryRule instanceof JavaLibrary);
JavaLibrary javaLibrary = (JavaLibrary) libraryRule;
// resources, but export_deps is true), then there will not be anything to dx.
if (javaLibrary.getSourcePathToOutput() == null) {
continue;
}
// See whether the corresponding IntermediateDexRule has already been added to the
// ruleResolver.
BuildTarget originalTarget = javaLibrary.getBuildTarget();
BuildTarget preDexTarget = BuildTarget.builder(originalTarget).addFlavors(DEX_FLAVOR).build();
Optional<BuildRule> preDexRule = ruleResolver.getRuleOptional(preDexTarget);
if (preDexRule.isPresent()) {
preDexDeps.put(apkModuleGraph.findModuleForTarget(buildTarget), (DexProducedFromJavaLibrary) preDexRule.get());
continue;
}
// Create the IntermediateDexRule and add it to both the ruleResolver and preDexDeps.
BuildRuleParams paramsForPreDex = buildRuleParams.withBuildTarget(preDexTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(ruleResolver.getRule(javaLibrary.getBuildTarget()))), Suppliers.ofInstance(ImmutableSortedSet.of()));
DexProducedFromJavaLibrary preDex = new DexProducedFromJavaLibrary(paramsForPreDex, javaLibrary);
ruleResolver.addToIndex(preDex);
preDexDeps.put(apkModuleGraph.findModuleForTarget(buildTarget), preDex);
}
return preDexDeps.build();
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class AndroidBinaryGraphEnhancer method addBuildConfigDeps.
/**
* If the user specified any android_build_config() rules, then we must add some build rules to
* generate the production {@code BuildConfig.class} files and ensure that they are included in
* the list of {@link AndroidPackageableCollection#getClasspathEntriesToDex}.
*/
public static ImmutableSortedSet<JavaLibrary> addBuildConfigDeps(BuildRuleParams originalParams, PackageType packageType, EnumSet<ExopackageMode> exopackageModes, BuildConfigFields buildConfigValues, Optional<SourcePath> buildConfigValuesFile, BuildRuleResolver ruleResolver, JavacOptions javacOptions, AndroidPackageableCollection packageableCollection) throws NoSuchBuildTargetException {
ImmutableSortedSet.Builder<JavaLibrary> result = ImmutableSortedSet.naturalOrder();
BuildConfigFields buildConfigConstants = BuildConfigFields.fromFields(ImmutableList.of(BuildConfigFields.Field.of("boolean", BuildConfigs.DEBUG_CONSTANT, String.valueOf(packageType != AndroidBinary.PackageType.RELEASE)), BuildConfigFields.Field.of("boolean", BuildConfigs.IS_EXO_CONSTANT, String.valueOf(!exopackageModes.isEmpty())), BuildConfigFields.Field.of("int", BuildConfigs.EXOPACKAGE_FLAGS, String.valueOf(ExopackageMode.toBitmask(exopackageModes)))));
for (Map.Entry<String, BuildConfigFields> entry : packageableCollection.getBuildConfigs().entrySet()) {
// Merge the user-defined constants with the APK-specific overrides.
BuildConfigFields totalBuildConfigValues = BuildConfigFields.empty().putAll(entry.getValue()).putAll(buildConfigValues).putAll(buildConfigConstants);
// Each enhanced dep needs a unique build target, so we parameterize the build target by the
// Java package.
String javaPackage = entry.getKey();
Flavor flavor = InternalFlavor.of("buildconfig_" + javaPackage.replace('.', '_'));
BuildTarget buildTargetWithFlavors = BuildTarget.builder(originalParams.getBuildTarget()).addFlavors(flavor).build();
BuildRuleParams buildConfigParams = new BuildRuleParams(buildTargetWithFlavors, /* declaredDeps */
Suppliers.ofInstance(ImmutableSortedSet.of()), /* extraDeps */
Suppliers.ofInstance(ImmutableSortedSet.of()), originalParams.getProjectFilesystem(), originalParams.getCellRoots());
JavaLibrary buildConfigJavaLibrary = AndroidBuildConfigDescription.createBuildRule(buildConfigParams, javaPackage, totalBuildConfigValues, buildConfigValuesFile, /* useConstantExpressions */
true, javacOptions, ruleResolver);
ruleResolver.addToIndex(buildConfigJavaLibrary);
Preconditions.checkNotNull(buildConfigJavaLibrary.getSourcePathToOutput(), "%s must have an output file.", buildConfigJavaLibrary);
result.add(buildConfigJavaLibrary);
}
return result.build();
}
Aggregations