use of com.facebook.buck.model.UnflavoredBuildTarget in project buck by facebook.
the class OcamlStaticLibrary method getLinkableInput.
private NativeLinkableInput getLinkableInput(boolean isBytecode) {
NativeLinkableInput.Builder inputBuilder = NativeLinkableInput.builder();
// Add linker flags.
inputBuilder.addAllArgs(StringArg.from(linkerFlags));
// Add arg and input for static library.
UnflavoredBuildTarget staticBuildTarget = staticLibraryTarget.getUnflavoredBuildTarget();
inputBuilder.addArgs(SourcePathArg.of(new ExplicitBuildTargetSourcePath(ocamlLibraryBuild.getBuildTarget(), isBytecode ? OcamlBuildContext.getBytecodeOutputPath(staticBuildTarget, getProjectFilesystem(), /* isLibrary */
true) : OcamlBuildContext.getNativeOutputPath(staticBuildTarget, getProjectFilesystem(), /* isLibrary */
true))));
// Add args and inputs for C object files.
for (SourcePath objFile : objFiles) {
inputBuilder.addArgs(SourcePathArg.of(objFile));
}
return inputBuilder.build();
}
use of com.facebook.buck.model.UnflavoredBuildTarget in project buck by facebook.
the class DefaultParserTargetNodeFactory method createTargetNode.
@Override
public TargetNode<?, ?> createTargetNode(Cell cell, Path buildFile, BuildTarget target, Map<String, Object> rawNode, Function<PerfEventId, SimplePerfEvent.Scope> perfEventScope) {
BuildRuleType buildRuleType = parseBuildRuleTypeFromRawRule(cell, rawNode);
// Because of the way that the parser works, we know this can never return null.
Description<?> description = cell.getDescription(buildRuleType);
UnflavoredBuildTarget unflavoredBuildTarget = target.withoutCell().getUnflavoredBuildTarget();
if (target.isFlavored()) {
if (description instanceof Flavored) {
if (!((Flavored) description).hasFlavors(ImmutableSet.copyOf(target.getFlavors()))) {
throw UnexpectedFlavorException.createWithSuggestions(cell, target);
}
} else {
LOG.warn("Target %s (type %s) must implement the Flavored interface " + "before we can check if it supports flavors: %s", unflavoredBuildTarget, buildRuleType, target.getFlavors());
throw new HumanReadableException("Target %s (type %s) does not currently support flavors (tried %s)", unflavoredBuildTarget, buildRuleType, target.getFlavors());
}
}
UnflavoredBuildTarget unflavoredBuildTargetFromRawData = RawNodeParsePipeline.parseBuildTargetFromRawRule(cell.getRoot(), rawNode, buildFile);
if (!unflavoredBuildTarget.equals(unflavoredBuildTargetFromRawData)) {
throw new IllegalStateException(String.format("Inconsistent internal state, target from data: %s, expected: %s, raw data: %s", unflavoredBuildTargetFromRawData, unflavoredBuildTarget, Joiner.on(',').withKeyValueSeparator("->").join(rawNode)));
}
Cell targetCell = cell.getCell(target);
Object constructorArg = description.createUnpopulatedConstructorArg();
try {
ImmutableSet.Builder<BuildTarget> declaredDeps = ImmutableSet.builder();
ImmutableSet.Builder<VisibilityPattern> visibilityPatterns = ImmutableSet.builder();
try (SimplePerfEvent.Scope scope = perfEventScope.apply(PerfEventId.of("MarshalledConstructorArg"))) {
marshaller.populate(targetCell.getCellPathResolver(), targetCell.getFilesystem(), target, constructorArg, declaredDeps, visibilityPatterns, rawNode);
}
try (SimplePerfEvent.Scope scope = perfEventScope.apply(PerfEventId.of("CreatedTargetNode"))) {
Hasher hasher = Hashing.sha1().newHasher();
hasher.putString(BuckVersion.getVersion(), UTF_8);
JsonObjectHashing.hashJsonObject(hasher, rawNode);
TargetNode<?, ?> node = targetNodeFactory.createFromObject(hasher.hash(), description, constructorArg, targetCell.getFilesystem(), target, declaredDeps.build(), visibilityPatterns.build(), targetCell.getCellPathResolver());
if (buildFileTrees.isPresent() && cell.isEnforcingBuckPackageBoundaries(target.getBasePath())) {
enforceBuckPackageBoundaries(target, buildFileTrees.get().getUnchecked(targetCell), node.getInputs());
}
nodeListener.onCreate(buildFile, node);
return node;
}
} catch (NoSuchBuildTargetException e) {
throw new HumanReadableException(e);
} catch (ParamInfoException e) {
throw new HumanReadableException(e, "%s: %s", target, e.getMessage());
} catch (IOException e) {
throw new HumanReadableException(e.getMessage(), e);
}
}
use of com.facebook.buck.model.UnflavoredBuildTarget in project buck by facebook.
the class AndroidAarDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams originalBuildRuleParams, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
UnflavoredBuildTarget originalBuildTarget = originalBuildRuleParams.getBuildTarget().checkUnflavored();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
ImmutableList.Builder<BuildRule> aarExtraDepsBuilder = ImmutableList.<BuildRule>builder().addAll(originalBuildRuleParams.getExtraDeps().get());
/* android_manifest */
AndroidManifestDescription.Arg androidManifestArgs = androidManifestDescription.createUnpopulatedConstructorArg();
androidManifestArgs.skeleton = args.manifestSkeleton;
androidManifestArgs.deps = args.deps;
BuildRuleParams androidManifestParams = originalBuildRuleParams.withBuildTarget(BuildTargets.createFlavoredBuildTarget(originalBuildTarget, AAR_ANDROID_MANIFEST_FLAVOR));
AndroidManifest manifest = androidManifestDescription.createBuildRule(targetGraph, androidManifestParams, resolver, androidManifestArgs);
aarExtraDepsBuilder.add(resolver.addToIndex(manifest));
final APKModuleGraph apkModuleGraph = new APKModuleGraph(targetGraph, originalBuildRuleParams.getBuildTarget(), Optional.empty());
/* assemble dirs */
AndroidPackageableCollector collector = new AndroidPackageableCollector(originalBuildRuleParams.getBuildTarget(), /* buildTargetsToExcludeFromDex */
ImmutableSet.of(), /* resourcesToExclude */
ImmutableSet.of(), apkModuleGraph);
collector.addPackageables(AndroidPackageableCollector.getPackageableRules(originalBuildRuleParams.getDeps()));
AndroidPackageableCollection packageableCollection = collector.build();
ImmutableSortedSet<BuildRule> androidResourceDeclaredDeps = AndroidResourceHelper.androidResOnly(originalBuildRuleParams.getDeclaredDeps().get());
ImmutableSortedSet<BuildRule> androidResourceExtraDeps = AndroidResourceHelper.androidResOnly(originalBuildRuleParams.getExtraDeps().get());
BuildRuleParams assembleAssetsParams = originalBuildRuleParams.withBuildTarget(BuildTargets.createFlavoredBuildTarget(originalBuildTarget, AAR_ASSEMBLE_ASSETS_FLAVOR)).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(androidResourceDeclaredDeps), Suppliers.ofInstance(androidResourceExtraDeps));
ImmutableCollection<SourcePath> assetsDirectories = packageableCollection.getAssetsDirectories();
AssembleDirectories assembleAssetsDirectories = new AssembleDirectories(assembleAssetsParams, assetsDirectories);
aarExtraDepsBuilder.add(resolver.addToIndex(assembleAssetsDirectories));
BuildRuleParams assembleResourceParams = originalBuildRuleParams.withBuildTarget(BuildTargets.createFlavoredBuildTarget(originalBuildTarget, AAR_ASSEMBLE_RESOURCE_FLAVOR)).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(androidResourceDeclaredDeps), Suppliers.ofInstance(androidResourceExtraDeps));
ImmutableCollection<SourcePath> resDirectories = packageableCollection.getResourceDetails().getResourceDirectories();
MergeAndroidResourceSources assembleResourceDirectories = new MergeAndroidResourceSources(assembleResourceParams, resDirectories);
aarExtraDepsBuilder.add(resolver.addToIndex(assembleResourceDirectories));
/* android_resource */
BuildRuleParams androidResourceParams = originalBuildRuleParams.withBuildTarget(BuildTargets.createFlavoredBuildTarget(originalBuildTarget, AAR_ANDROID_RESOURCE_FLAVOR)).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(manifest, assembleAssetsDirectories, assembleResourceDirectories)), Suppliers.ofInstance(ImmutableSortedSet.of()));
AndroidResource androidResource = new AndroidResource(androidResourceParams, ruleFinder, /* deps */
ImmutableSortedSet.<BuildRule>naturalOrder().add(assembleAssetsDirectories).add(assembleResourceDirectories).addAll(originalBuildRuleParams.getDeclaredDeps().get()).build(), assembleResourceDirectories.getSourcePathToOutput(), /* resSrcs */
ImmutableSortedMap.of(), /* rDotJavaPackage */
null, assembleAssetsDirectories.getSourcePathToOutput(), /* assetsSrcs */
ImmutableSortedMap.of(), manifest.getSourcePathToOutput(), /* hasWhitelistedStrings */
false);
aarExtraDepsBuilder.add(resolver.addToIndex(androidResource));
ImmutableSortedSet.Builder<SourcePath> classpathToIncludeInAar = ImmutableSortedSet.naturalOrder();
classpathToIncludeInAar.addAll(packageableCollection.getClasspathEntriesToDex());
aarExtraDepsBuilder.addAll(BuildRules.toBuildRulesFor(originalBuildRuleParams.getBuildTarget(), resolver, packageableCollection.getJavaLibrariesToDex()));
if (!args.buildConfigValues.getNameToField().isEmpty() && !args.includeBuildConfigClass) {
throw new HumanReadableException("Rule %s has build_config_values set but does not set " + "include_build_config_class to True. Either indicate you want to include the " + "BuildConfig class in the final .aar or do not specify build config values.", originalBuildRuleParams.getBuildTarget());
}
if (args.includeBuildConfigClass) {
ImmutableSortedSet<JavaLibrary> buildConfigRules = AndroidBinaryGraphEnhancer.addBuildConfigDeps(originalBuildRuleParams, AndroidBinary.PackageType.RELEASE, EnumSet.noneOf(AndroidBinary.ExopackageMode.class), args.buildConfigValues, Optional.empty(), resolver, javacOptions, packageableCollection);
resolver.addAllToIndex(buildConfigRules);
aarExtraDepsBuilder.addAll(buildConfigRules);
classpathToIncludeInAar.addAll(buildConfigRules.stream().map(BuildRule::getSourcePathToOutput).collect(Collectors.toList()));
}
/* native_libraries */
AndroidNativeLibsPackageableGraphEnhancer packageableGraphEnhancer = new AndroidNativeLibsPackageableGraphEnhancer(resolver, originalBuildRuleParams, nativePlatforms, ImmutableSet.of(), cxxBuckConfig, /* nativeLibraryMergeMap */
Optional.empty(), /* nativeLibraryMergeGlue */
Optional.empty(), AndroidBinary.RelinkerMode.DISABLED, apkModuleGraph);
Optional<ImmutableMap<APKModule, CopyNativeLibraries>> nativeLibrariesOptional = packageableGraphEnhancer.enhance(packageableCollection).getCopyNativeLibraries();
if (nativeLibrariesOptional.isPresent() && nativeLibrariesOptional.get().containsKey(apkModuleGraph.getRootAPKModule())) {
aarExtraDepsBuilder.add(resolver.addToIndex(nativeLibrariesOptional.get().get(apkModuleGraph.getRootAPKModule())));
}
Optional<Path> assembledNativeLibsDir = nativeLibrariesOptional.map(input -> {
CopyNativeLibraries copyNativeLibraries = input.get(apkModuleGraph.getRootAPKModule());
if (copyNativeLibraries == null) {
throw new HumanReadableException("Native libraries are present but not in the root application module.");
}
return copyNativeLibraries.getPathToNativeLibsDir();
});
BuildRuleParams androidAarParams = originalBuildRuleParams.copyReplacingExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.copyOf(aarExtraDepsBuilder.build())));
return new AndroidAar(androidAarParams, manifest, androidResource, assembleResourceDirectories.getSourcePathToOutput(), assembleAssetsDirectories.getSourcePathToOutput(), assembledNativeLibsDir, ImmutableSet.copyOf(packageableCollection.getNativeLibAssetsDirectories().values()), classpathToIncludeInAar.build());
}
use of com.facebook.buck.model.UnflavoredBuildTarget in project buck by facebook.
the class PrebuiltJarDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
if (CalculateAbi.isAbiTarget(params.getBuildTarget())) {
return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, args.binaryJar);
}
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildRule prebuilt = new PrebuiltJar(params, pathResolver, args.binaryJar, args.sourceJar, args.gwtJar, args.javadocUrl, args.mavenCoords, args.provided.orElse(false));
UnflavoredBuildTarget prebuiltJarBuildTarget = params.getBuildTarget().checkUnflavored();
BuildTarget flavoredBuildTarget = BuildTargets.createFlavoredBuildTarget(prebuiltJarBuildTarget, JavaLibrary.GWT_MODULE_FLAVOR);
BuildRuleParams gwtParams = params.withBuildTarget(flavoredBuildTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(prebuilt)), Suppliers.ofInstance(ImmutableSortedSet.of()));
BuildRule gwtModule = createGwtModule(gwtParams, args);
resolver.addToIndex(gwtModule);
return prebuilt;
}
use of com.facebook.buck.model.UnflavoredBuildTarget 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();
}
Aggregations