Beispiel #1
0
  /**
   * Returns the xcode version number corresponding to the {@code --xcode_version} flag, if there is
   * an available {@code xcode_version} target which recognizes the flag value as either an official
   * version or an alias. Returns null if no such target is found.
   */
  @Nullable
  private DottedVersion resolveExplicitlyDefinedVersion(RuleContext ruleContext) {
    AppleConfiguration configuration = ruleContext.getFragment(AppleConfiguration.class);
    Optional<DottedVersion> versionOverrideFlag = configuration.getXcodeVersionOverrideFlag();
    if (versionOverrideFlag.isPresent()) {
      // The version override flag is not necessarily an actual version - it may be a version
      // alias.
      DottedVersion explicitVerison =
          aliasesToVersionMap(ruleContext).get(versionOverrideFlag.get().toString());
      if (explicitVerison != null) {
        return explicitVerison;
      }
    } else { // No override specified. Use default.
      XcodeVersionProvider defaultProvider =
          ruleContext.getPrerequisite(
              XcodeConfigRule.DEFAULT_ATTR_NAME, Mode.TARGET, XcodeVersionProvider.class);

      if (defaultProvider != null) {
        return defaultProvider.getVersion();
      }
    }

    boolean requireDefinedVersions =
        ruleContext.attributes().get(XcodeConfigRule.REQUIRE_DEFINED_VERSIONS_ATTR_NAME, BOOLEAN);
    if (requireDefinedVersions) {
      ruleContext.ruleError(
          "xcode version config required an explicitly defined version, but none was available");
    }

    return null;
  }
Beispiel #2
0
  private static void ruleErrorDuplicateAlias(String alias, RuleContext ruleContext) {
    Iterable<XcodeVersionProvider> xcodeVersionProviders =
        ruleContext.getPrerequisites(
            XcodeConfigRule.VERSIONS_ATTR_NAME, Mode.TARGET, XcodeVersionProvider.class);

    ImmutableList.Builder<Label> labelsContainingAlias = ImmutableList.builder();
    for (XcodeVersionProvider versionProvider : xcodeVersionProviders) {
      if (versionProvider.getAliases().contains(alias)
          || versionProvider.getVersion().toString().equals(alias)) {
        labelsContainingAlias.add(versionProvider.getLabel());
      }
    }
    ruleContext.ruleError(
        String.format(
            "'%s' is registered to multiple labels (%s) in a single xcode version "
                + "configuration",
            alias, Joiner.on(", ").join(labelsContainingAlias.build())));
  }
Beispiel #3
0
  private static Map<String, DottedVersion> aliasesToVersionMap(RuleContext ruleContext) {
    Iterable<XcodeVersionProvider> xcodeVersionProviders =
        ruleContext.getPrerequisites(
            XcodeConfigRule.VERSIONS_ATTR_NAME, Mode.TARGET, XcodeVersionProvider.class);

    Map<String, DottedVersion> aliasesToVersionMap = Maps.newLinkedHashMap();
    for (XcodeVersionProvider versionProvider : xcodeVersionProviders) {
      for (String alias : versionProvider.getAliases()) {
        if (aliasesToVersionMap.put(alias, versionProvider.getVersion()) != null) {
          ruleErrorDuplicateAlias(alias, ruleContext);
        }
      }
      if (aliasesToVersionMap.put(
              versionProvider.getVersion().toString(), versionProvider.getVersion())
          != null) {
        ruleErrorDuplicateAlias(versionProvider.getVersion().toString(), ruleContext);
      }
    }
    return aliasesToVersionMap;
  }