Search in sources :

Example 6 with UnflavoredBuildTarget

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();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Example 7 with UnflavoredBuildTarget

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);
    }
}
Also used : UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) IOException(java.io.IOException) Flavored(com.facebook.buck.model.Flavored) VisibilityPattern(com.facebook.buck.rules.VisibilityPattern) ParamInfoException(com.facebook.buck.rules.ParamInfoException) Hasher(com.google.common.hash.Hasher) ImmutableSet(com.google.common.collect.ImmutableSet) HumanReadableException(com.facebook.buck.util.HumanReadableException) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRuleType(com.facebook.buck.rules.BuildRuleType) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent) Cell(com.facebook.buck.rules.Cell)

Example 8 with UnflavoredBuildTarget

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());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) SourcePath(com.facebook.buck.rules.SourcePath) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BuildRule(com.facebook.buck.rules.BuildRule) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ImmutableMap(com.google.common.collect.ImmutableMap) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) HumanReadableException(com.facebook.buck.util.HumanReadableException) MergeAndroidResourceSources(com.facebook.buck.android.aapt.MergeAndroidResourceSources)

Example 9 with UnflavoredBuildTarget

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;
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 10 with UnflavoredBuildTarget

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();
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) Flavor(com.facebook.buck.model.Flavor) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) ImmutableSet(com.google.common.collect.ImmutableSet) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)19 BuildTarget (com.facebook.buck.model.BuildTarget)9 ImmutableSet (com.google.common.collect.ImmutableSet)7 HumanReadableException (com.facebook.buck.util.HumanReadableException)6 Path (java.nio.file.Path)6 BuildRule (com.facebook.buck.rules.BuildRule)4 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)4 SourcePath (com.facebook.buck.rules.SourcePath)4 Flavor (com.facebook.buck.model.Flavor)3 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 SimplePerfEvent (com.facebook.buck.event.SimplePerfEvent)2 MavenPublishable (com.facebook.buck.jvm.java.MavenPublishable)2 Flavored (com.facebook.buck.model.Flavored)2 BuildRuleType (com.facebook.buck.rules.BuildRuleType)2 Cell (com.facebook.buck.rules.Cell)2 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)2 ParamInfoException (com.facebook.buck.rules.ParamInfoException)2 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)2