Esempio n. 1
0
  /**
   * Returns the rule class defaults specified for this rule, or null if there are no such defaults.
   */
  @Nullable
  private static EnvironmentCollector maybeGetRuleClassDefaults(RuleContext ruleContext) {
    Rule rule = ruleContext.getRule();
    String restrictionAttr = RuleClass.DEFAULT_RESTRICTED_ENVIRONMENT_ATTR;
    String compatibilityAttr = RuleClass.DEFAULT_COMPATIBLE_ENVIRONMENT_ATTR;

    if (rule.isAttrDefined(restrictionAttr, BuildType.LABEL_LIST)
        || rule.isAttrDefined(compatibilityAttr, BuildType.LABEL_LIST)) {
      return new EnvironmentCollector(
          ruleContext, restrictionAttr, compatibilityAttr, new GroupDefaultsProvider());
    } else {
      return null;
    }
  }
Esempio n. 2
0
 /**
  * Adds new dependencies to the given rule under the given attribute name
  *
  * @param result the builder for the attribute --> dependency labels map
  * @param rule the rule being evaluated
  * @param attrName the name of the attribute to add dependency labels to
  * @param labels the dependencies to add
  * @param configuration the configuration to apply to those dependencies
  */
 private void addExplicitDeps(
     ImmutableSortedKeyListMultimap.Builder<Attribute, LabelAndConfiguration> result,
     Rule rule,
     String attrName,
     Iterable<Label> labels,
     BuildConfiguration configuration) {
   if (!rule.isAttrDefined(attrName, BuildType.LABEL_LIST)
       && !rule.isAttrDefined(attrName, BuildType.NODEP_LABEL_LIST)) {
     return;
   }
   Attribute attribute = rule.getRuleClassObject().getAttributeByName(attrName);
   for (Label label : labels) {
     // The configuration must be the configuration after the first transition step (applying
     // split configurations). The proper configuration (null) for package groups will be set
     // later.
     result.put(attribute, LabelAndConfiguration.of(label, configuration));
   }
 }
Esempio n. 3
0
 @Override
 public AspectParameters apply(Rule rule) {
   if (rule.isAttrDefined("baz", STRING)) {
     String value = rule.getAttributeContainer().getAttr("baz").toString();
     if (!value.equals("")) {
       return new AspectParameters.Builder().addAttribute("baz", value).build();
     }
   }
   return AspectParameters.EMPTY;
 }