Search in sources :

Example 1 with BuildRuleType

use of com.facebook.buck.rules.BuildRuleType in project buck by facebook.

the class CxxLibraryDescription method addImplicitFlavorsForRuleTypes.

public ImmutableSortedSet<Flavor> addImplicitFlavorsForRuleTypes(ImmutableSortedSet<Flavor> argDefaultFlavors, BuildRuleType... types) {
    Optional<Flavor> typeFlavor = LIBRARY_TYPE.getFlavor(argDefaultFlavors);
    Optional<Flavor> platformFlavor = getCxxPlatforms().getFlavor(argDefaultFlavors);
    LOG.debug("Got arg default type %s platform %s", typeFlavor, platformFlavor);
    for (BuildRuleType type : types) {
        ImmutableMap<String, Flavor> libraryDefaults = cxxBuckConfig.getDefaultFlavorsForRuleType(type);
        if (!typeFlavor.isPresent()) {
            typeFlavor = Optional.ofNullable(libraryDefaults.get(CxxBuckConfig.DEFAULT_FLAVOR_LIBRARY_TYPE));
        }
        if (!platformFlavor.isPresent()) {
            platformFlavor = Optional.ofNullable(libraryDefaults.get(CxxBuckConfig.DEFAULT_FLAVOR_PLATFORM));
        }
    }
    ImmutableSortedSet<Flavor> result = ImmutableSortedSet.of(// Default to static if not otherwise specified.
    typeFlavor.orElse(CxxDescriptionEnhancer.STATIC_FLAVOR), platformFlavor.orElse(defaultCxxPlatform.getFlavor()));
    LOG.debug("Got default flavors %s for rule types %s", result, Arrays.toString(types));
    return result;
}
Also used : BuildRuleType(com.facebook.buck.rules.BuildRuleType) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor)

Example 2 with BuildRuleType

use of com.facebook.buck.rules.BuildRuleType 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 3 with BuildRuleType

use of com.facebook.buck.rules.BuildRuleType in project buck by facebook.

the class TargetsCommand method getDescriptionClassFromParams.

@SuppressWarnings("unchecked")
private Optional<ImmutableSet<Class<? extends Description<?>>>> getDescriptionClassFromParams(CommandRunnerParams params) {
    ImmutableSet<String> types = getTypes();
    ImmutableSet.Builder<Class<? extends Description<?>>> descriptionClassesBuilder = ImmutableSet.builder();
    for (String name : types) {
        try {
            BuildRuleType type = params.getCell().getBuildRuleType(name);
            Description<?> description = params.getCell().getDescription(type);
            descriptionClassesBuilder.add((Class<? extends Description<?>>) description.getClass());
        } catch (IllegalArgumentException e) {
            params.getBuckEventBus().post(ConsoleEvent.severe("Invalid build rule type: " + name));
            return Optional.empty();
        }
    }
    return Optional.of(descriptionClassesBuilder.build());
}
Also used : Description(com.facebook.buck.rules.Description) ImmutableSet(com.google.common.collect.ImmutableSet) BuildRuleType(com.facebook.buck.rules.BuildRuleType)

Example 4 with BuildRuleType

use of com.facebook.buck.rules.BuildRuleType in project buck by facebook.

the class DefaultParserTargetGroupFactory method createTargetNode.

@Override
public TargetGroup createTargetNode(Cell cell, Path buildFile, BuildTarget target, Map<String, Object> rawNode, Function<PerfEventId, SimplePerfEvent.Scope> perfEventScope) {
    Preconditions.checkArgument(!target.isFlavored());
    UnflavoredBuildTarget unflavoredBuildTarget = target.withoutCell().getUnflavoredBuildTarget();
    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)));
    }
    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);
    Cell targetCell = cell.getCell(target);
    TargetGroupDescription.Arg constructorArg = (TargetGroupDescription.Arg) 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);
            TargetGroup node = new TargetGroup(constructorArg.targets, constructorArg.restrictOutboundVisibility, target);
            return node;
        }
    } catch (ParamInfoException e) {
        throw new HumanReadableException("%s: %s", target, e.getMessage());
    }
}
Also used : TargetGroupDescription(com.facebook.buck.groups.TargetGroupDescription) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) VisibilityPattern(com.facebook.buck.rules.VisibilityPattern) ParamInfoException(com.facebook.buck.rules.ParamInfoException) Hasher(com.google.common.hash.Hasher) ImmutableSet(com.google.common.collect.ImmutableSet) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) TargetGroup(com.facebook.buck.rules.TargetGroup) BuildRuleType(com.facebook.buck.rules.BuildRuleType) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent) Cell(com.facebook.buck.rules.Cell)

Aggregations

BuildRuleType (com.facebook.buck.rules.BuildRuleType)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 SimplePerfEvent (com.facebook.buck.event.SimplePerfEvent)2 BuildTarget (com.facebook.buck.model.BuildTarget)2 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)2 Cell (com.facebook.buck.rules.Cell)2 ParamInfoException (com.facebook.buck.rules.ParamInfoException)2 VisibilityPattern (com.facebook.buck.rules.VisibilityPattern)2 HumanReadableException (com.facebook.buck.util.HumanReadableException)2 Hasher (com.google.common.hash.Hasher)2 TargetGroupDescription (com.facebook.buck.groups.TargetGroupDescription)1 Flavor (com.facebook.buck.model.Flavor)1 Flavored (com.facebook.buck.model.Flavored)1 InternalFlavor (com.facebook.buck.model.InternalFlavor)1 Description (com.facebook.buck.rules.Description)1 TargetGroup (com.facebook.buck.rules.TargetGroup)1 IOException (java.io.IOException)1