diff options
author | 2016-03-16 20:33:14 +0000 | |
---|---|---|
committer | 2016-03-17 10:07:55 +0000 | |
commit | 65b91b267d6b5b31437d4f753570121c84c7bc9e (patch) | |
tree | fdbd4c4e5628e702f15afd0d2a94eed2c4e7b39f /src/main/java/com/google/devtools/build/lib/rules/apple | |
parent | 2d9ec94470b5a0026708aa7174f96d1d2645b04d (diff) |
Add default_ios_sdk_version attribute to xcode_version rules.
This will set the default value for the iOS SDK version configuration value. Users can override this by specifying ios_sdk_version themselves.
--
MOS_MIGRATED_REVID=117377043
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/apple')
7 files changed, 145 insertions, 37 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java index 815687c8f0..e85a7f0658 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java @@ -47,8 +47,7 @@ public class AppleCommandLineOptions extends FragmentOptions { @Option( name = "ios_sdk_version", - // TODO(bazel-team): Make this flag optional, and infer SDKROOT based on executor default. - defaultValue = DEFAULT_IOS_SDK_VERSION, + defaultValue = "null", converter = DottedVersionConverter.class, category = "build", help = "Specifies the version of the iOS SDK to use to build iOS applications." @@ -229,6 +228,7 @@ public class AppleCommandLineOptions extends FragmentOptions { // Set options needed in the host configuration. host.xcodeVersionConfig = xcodeVersionConfig; host.xcodeVersion = xcodeVersion; + host.iosSdkVersion = iosSdkVersion; host.appleBitcodeMode = appleBitcodeMode; return host; diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java index 1ce38d3b36..1bd969ed7e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java @@ -67,8 +67,9 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { @Nullable private final Label defaultProvisioningProfileLabel; AppleConfiguration(AppleCommandLineOptions appleOptions, - Optional<DottedVersion> xcodeVersionOverride) { - this.iosSdkVersion = Preconditions.checkNotNull(appleOptions.iosSdkVersion, "iosSdkVersion"); + Optional<DottedVersion> xcodeVersionOverride, + DottedVersion iosSdkVersion) { + this.iosSdkVersion = Preconditions.checkNotNull(iosSdkVersion, "iosSdkVersion"); this.watchOsSdkVersion = Preconditions.checkNotNull(appleOptions.watchOsSdkVersion, "watchOsSdkVersion"); this.tvOsSdkVersion = @@ -261,8 +262,13 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { public AppleConfiguration create(ConfigurationEnvironment env, BuildOptions buildOptions) throws InvalidConfigurationException { AppleCommandLineOptions appleOptions = buildOptions.get(AppleCommandLineOptions.class); - Optional<DottedVersion> xcodeVersionFlag = getXcodeVersion(env, appleOptions); - AppleConfiguration configuration = new AppleConfiguration(appleOptions, xcodeVersionFlag); + XcodeVersionProperties xcodeVersionProperties = getXcodeVersionProperties(env, appleOptions); + + DottedVersion iosSdkVersion = (appleOptions.iosSdkVersion != null) + ? appleOptions.iosSdkVersion : xcodeVersionProperties.getDefaultIosSdkVersion(); + AppleConfiguration configuration = + new AppleConfiguration(appleOptions, xcodeVersionProperties.getXcodeVersion(), + iosSdkVersion); validate(configuration); return configuration; @@ -293,15 +299,15 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { /** * Uses the {@link AppleCommandLineOptions#xcodeVersion} and * {@link AppleCommandLineOptions#xcodeVersionConfig} command line options to determine and - * return the effective xcode version. Returns absent if no explicit xcode version is - * declared, and host system defaults should be used. + * return the effective xcode version properties. Returns absent if no explicit xcode version + * is declared, and host system defaults should be used. * * @param env the current configuration environment * @param appleOptions the command line options * @throws InvalidConfigurationException if the options given (or configuration targets) were * malformed and thus the xcode version could not be determined */ - private Optional<DottedVersion> getXcodeVersion(ConfigurationEnvironment env, + private XcodeVersionProperties getXcodeVersionProperties(ConfigurationEnvironment env, AppleCommandLineOptions appleOptions) throws InvalidConfigurationException { Optional<DottedVersion> xcodeVersionCommandLineFlag = Optional.fromNullable(appleOptions.xcodeVersion); diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfig.java b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfig.java index 101ffad5db..efa07cc3d1 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfig.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfig.java @@ -56,7 +56,7 @@ public class XcodeConfig implements RuleConfiguredTargetFactory { /** * Uses the {@link AppleCommandLineOptions#xcodeVersion} and * {@link AppleCommandLineOptions#xcodeVersionConfig} command line options to determine and - * return the effective xcode version. + * return the effective xcode version and its properties. * * @param env the current configuration environment * @param xcodeConfigLabel the label for the xcode_config target to parse @@ -67,40 +67,46 @@ public class XcodeConfig implements RuleConfiguredTargetFactory { * @throws InvalidConfigurationException if the options given (or configuration targets) were * malformed and thus the xcode version could not be determined */ - public static Optional<DottedVersion> resolveXcodeVersion(ConfigurationEnvironment env, + public static XcodeVersionProperties resolveXcodeVersion(ConfigurationEnvironment env, Label xcodeConfigLabel, Optional<DottedVersion> xcodeVersionOverrideFlag, String errorDescription) throws InvalidConfigurationException { Rule xcodeConfigRule = getRuleForLabel(xcodeConfigLabel, "xcode_config", env, errorDescription); - DottedVersion dottedVersion = + XcodeVersionRuleData xcodeVersion = resolveExplicitlyDefinedVersion(env, xcodeConfigRule, xcodeVersionOverrideFlag); - - if (dottedVersion != null) { - return Optional.of(dottedVersion); + + if (xcodeVersion != null) { + return xcodeVersion.getXcodeVersionProperties(); + } else if (xcodeVersionOverrideFlag.isPresent()) { + return new XcodeVersionProperties(xcodeVersionOverrideFlag.get()); } else { - return xcodeVersionOverrideFlag; + return XcodeVersionProperties.unknownXcodeVersionProperties(); } } /** - * 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. + * Returns the {@link XcodeVersionRuleData} associated with the {@code xcode_version} target + * explicitly defined in the {@code --xcode_version_config} build flag and selected by the + * {@code --xcode_version} flag. If {@code --xcode_version} is unspecified, then this + * will return the default rule data as specified in the {@code --xcode_version_config} target. + * Returns null if either the {@code --xcode_version} did not match any {@code xcode_version} + * target, or if {@code --xcode_version} is unspecified and {@code --xcode_version_config} + * specified no default target. */ - @Nullable private static DottedVersion resolveExplicitlyDefinedVersion( + @Nullable private static XcodeVersionRuleData resolveExplicitlyDefinedVersion( ConfigurationEnvironment env, Rule xcodeConfigTarget, Optional<DottedVersion> versionOverrideFlag) throws InvalidConfigurationException { if (versionOverrideFlag.isPresent()) { // The version override flag is not necessarily an actual version - it may be a version // alias. - DottedVersion explicitVersion = + XcodeVersionRuleData explicitVersion = aliasesToVersionMap(env, xcodeConfigTarget).get(versionOverrideFlag.get().toString()); if (explicitVersion != null) { return explicitVersion; } } else { // No override specified. Use default. - DottedVersion defaultVersion = getDefaultVersion(env, xcodeConfigTarget); + XcodeVersionRuleData defaultVersion = getDefaultVersion(env, xcodeConfigTarget); if (defaultVersion != null) { return defaultVersion; @@ -121,20 +127,20 @@ public class XcodeConfig implements RuleConfiguredTargetFactory { * Returns the default xcode version to use, if no {@code --xcode_version} command line flag * was specified. */ - @Nullable private static DottedVersion getDefaultVersion(ConfigurationEnvironment env, + @Nullable private static XcodeVersionRuleData getDefaultVersion(ConfigurationEnvironment env, Rule xcodeConfigTarget) throws InvalidConfigurationException { Label defaultVersionLabel = NonconfigurableAttributeMapper.of(xcodeConfigTarget) .get(XcodeConfigRule.DEFAULT_ATTR_NAME, BuildType.LABEL); if (defaultVersionLabel != null) { Rule defaultVersionRule = getRuleForLabel( defaultVersionLabel, "xcode_version", env, "default xcode version"); - return new XcodeVersionRuleData(defaultVersionLabel, defaultVersionRule).getVersion(); + return new XcodeVersionRuleData(defaultVersionLabel, defaultVersionRule); } else { return null; } } - private static Map<String, DottedVersion> aliasesToVersionMap(ConfigurationEnvironment env, + private static Map<String, XcodeVersionRuleData> aliasesToVersionMap(ConfigurationEnvironment env, Rule xcodeConfigTarget) throws InvalidConfigurationException { List<Label> xcodeVersionLabels = NonconfigurableAttributeMapper.of(xcodeConfigTarget) .get(XcodeConfigRule.VERSIONS_ATTR_NAME, BuildType.LABEL_LIST); @@ -146,19 +152,19 @@ public class XcodeConfig implements RuleConfiguredTargetFactory { } ImmutableList<XcodeVersionRuleData> xcodeVersionRules = xcodeVersionRuleListBuilder.build(); - Map<String, DottedVersion> aliasesToVersionMap = Maps.newLinkedHashMap(); + Map<String, XcodeVersionRuleData> aliasesToXcodeRules = Maps.newLinkedHashMap(); for (XcodeVersionRuleData xcodeVersionRule : xcodeVersionRules) { for (String alias : xcodeVersionRule.getAliases()) { - if (aliasesToVersionMap.put(alias, xcodeVersionRule.getVersion()) != null) { + if (aliasesToXcodeRules.put(alias, xcodeVersionRule) != null) { configErrorDuplicateAlias(alias, xcodeVersionRules); } } - if (aliasesToVersionMap.put( - xcodeVersionRule.getVersion().toString(), xcodeVersionRule.getVersion()) != null) { + if (aliasesToXcodeRules.put( + xcodeVersionRule.getVersion().toString(), xcodeVersionRule) != null) { configErrorDuplicateAlias(xcodeVersionRule.getVersion().toString(), xcodeVersionRules); } } - return aliasesToVersionMap; + return aliasesToXcodeRules; } /** @@ -211,4 +217,4 @@ public class XcodeConfig implements RuleConfiguredTargetFactory { throw new InvalidConfigurationException(exception); } } -}
\ No newline at end of file +} diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfigRule.java b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfigRule.java index ecfb643458..de5a2bc618 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfigRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfigRule.java @@ -40,7 +40,7 @@ public class XcodeConfigRule implements RuleDefinition { .requiresConfigurationFragments(AppleConfiguration.class) .exemptFromConstraintChecking( "this rule refines configuration variables and does not build actual content") - /* <!-- #BLAZE_RULE(proto_library).ATTRIBUTE(version) --> + /* <!-- #BLAZE_RULE(xcode_config).ATTRIBUTE(version) --> The default official version of xcode to use. The version specified by the provided <code>xcode_version</code> target is to be used if no <code>xcode_version</code> build flag is specified. @@ -49,7 +49,7 @@ public class XcodeConfigRule implements RuleDefinition { .allowedRuleClasses("xcode_version") .allowedFileTypes() .nonconfigurable("this rule determines configuration")) - /* <!-- #BLAZE_RULE(proto_library).ATTRIBUTE(version) --> + /* <!-- #BLAZE_RULE(xcode_config).ATTRIBUTE(version) --> Accepted <code>xcode_version<code> targets that may be used. If the value of the <code>xcode_version</code> build flag matches one of the aliases or version number of any of the given <code>xcode_version</code> targets, the matching @@ -59,7 +59,7 @@ public class XcodeConfigRule implements RuleDefinition { .allowedRuleClasses("xcode_version") .allowedFileTypes() .nonconfigurable("this rule determines configuration")) - /* <!-- #BLAZE_RULE(proto_library).ATTRIBUTE(version) --> + /* <!-- #BLAZE_RULE(xcode_config).ATTRIBUTE(version) --> Whether to require the build's xcode version match one of the declared targets. If true, this will raise an error if either the <code>xcode_version</code> flag value or <code>default</code> attribute value do not match one of the versions declared diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionProperties.java b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionProperties.java new file mode 100644 index 0000000000..9194a33e45 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionProperties.java @@ -0,0 +1,77 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.rules.apple; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Optional; +import com.google.common.base.Strings; + +import javax.annotation.Nullable; + +/** + * A tuple containing information about a version of xcode and its properties. + */ +public class XcodeVersionProperties { + @VisibleForTesting public static final String DEFAULT_IOS_SDK_VERSION = "8.4"; + + private final Optional<DottedVersion> xcodeVersion; + private final DottedVersion defaultIosSdkVersion; + + /** + * Creates and returns a tuple representing no known xcode property information (defaults are + * used where applicable). + */ + // TODO(bazel-team): The xcode version should be a well-defined value, either specified by the + // user, evaluated on the local system, or set to a sensible default. + // Unfortunately, until the local system evaluation hook is created, this constraint would break + // some users. + public static XcodeVersionProperties unknownXcodeVersionProperties() { + return new XcodeVersionProperties(null); + } + + /** + * Constructor for when only the xcode version is specified, but no property information + * is specified. + */ + XcodeVersionProperties(DottedVersion xcodeVersion) { + this(xcodeVersion, null); + } + + /** + * General constructor. Some (nullable) properties may be left unspecified. In these cases, + * a semi-sensible default will be assigned to the property value. + */ + XcodeVersionProperties(DottedVersion xcodeVersion, + @Nullable String defaultIosSdkVersion) { + this.xcodeVersion = Optional.fromNullable(xcodeVersion); + this.defaultIosSdkVersion = (Strings.isNullOrEmpty(defaultIosSdkVersion)) + ? DottedVersion.fromString(DEFAULT_IOS_SDK_VERSION) + : DottedVersion.fromString(defaultIosSdkVersion); + } + + /** + * Returns the xcode version, or {@link Optional#absent} if the xcode version is unknown. + */ + public Optional<DottedVersion> getXcodeVersion() { + return xcodeVersion; + } + + /** + * Returns the default ios sdk version to use if this xcode version is in use. + */ + public DottedVersion getDefaultIosSdkVersion() { + return defaultIosSdkVersion; + } +} diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionRule.java b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionRule.java index f6e8274902..d0ac5b5441 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionRule.java @@ -31,6 +31,7 @@ public class XcodeVersionRule implements RuleDefinition { static final String VERSION_ATTR_NAME = "version"; static final String ALIASES_ATTR_NAME = "aliases"; + static final String DEFAULT_IOS_SDK_VERSION_ATTR_NAME = "default_ios_sdk_version"; @Override public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { @@ -38,19 +39,25 @@ public class XcodeVersionRule implements RuleDefinition { .requiresConfigurationFragments(AppleConfiguration.class) .exemptFromConstraintChecking( "this rule refines configuration variables and does not build actual content") - /* <!-- #BLAZE_RULE(proto_library).ATTRIBUTE(version) --> + /* <!-- #BLAZE_RULE(xcode_version).ATTRIBUTE(version) --> The official version number of a version of Xcode. <!-- #END_BLAZE_RULE.ATTRIBUTE --> */ .add(attr(VERSION_ATTR_NAME, STRING) .mandatory() .nonconfigurable("this rule determines configuration")) - /* <!-- #BLAZE_RULE(proto_library).ATTRIBUTE(version) --> + /* <!-- #BLAZE_RULE(xcode_version).ATTRIBUTE(version) --> Accepted aliases for this version of Xcode. If the value of the <code>xcode_version</code> build flag matches any of the given alias strings, this xcode version will be used. <!-- #END_BLAZE_RULE.ATTRIBUTE --> */ .add(attr(ALIASES_ATTR_NAME, STRING_LIST) .nonconfigurable("this rule determines configuration")) + /* <!-- #BLAZE_RULE(xcode_version).ATTRIBUTE(default_ios_sdk_version) --> + The ios sdk version that is used by default when this version of xcode is being used. + The <code>ios_sdk_version</code> build flag will override the value specified here. + <!-- #END_BLAZE_RULE.ATTRIBUTE --> */ + .add(attr(DEFAULT_IOS_SDK_VERSION_ATTR_NAME, STRING) + .nonconfigurable("this rule determines configuration")) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionRuleData.java b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionRuleData.java index 02bf38dc48..8bc9baeec6 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionRuleData.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionRuleData.java @@ -33,6 +33,7 @@ import java.util.List; public class XcodeVersionRuleData { private final Label label; private final DottedVersion version; + private final XcodeVersionProperties xcodeVersionProperties; private final ImmutableList<String> aliases; XcodeVersionRuleData(Label label, Rule rule) { @@ -40,8 +41,12 @@ public class XcodeVersionRuleData { NonconfigurableAttributeMapper.of(rule); this.label = label; - this.version = DottedVersion.fromString( + DottedVersion xcodeVersion = DottedVersion.fromString( attrMapper.get(XcodeVersionRule.VERSION_ATTR_NAME, Type.STRING)); + String iosSdkVersionString = + attrMapper.get(XcodeVersionRule.DEFAULT_IOS_SDK_VERSION_ATTR_NAME, Type.STRING); + this.version = xcodeVersion; + this.xcodeVersionProperties = new XcodeVersionProperties(xcodeVersion, iosSdkVersionString); this.aliases = ImmutableList.copyOf( attrMapper.get(XcodeVersionRule.ALIASES_ATTR_NAME, Type.STRING_LIST)); } @@ -61,6 +66,13 @@ public class XcodeVersionRuleData { } /** + * Returns the properties of the {@code xcode_version} target's referenced xcode version. + */ + public XcodeVersionProperties getXcodeVersionProperties() { + return xcodeVersionProperties; + } + + /** * Returns the accepted string aliases for this xcode version. */ public List<String> getAliases() { |