From 65b91b267d6b5b31437d4f753570121c84c7bc9e Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Wed, 16 Mar 2016 20:33:14 +0000 Subject: 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 --- .../lib/rules/apple/AppleCommandLineOptions.java | 4 +- .../build/lib/rules/apple/AppleConfiguration.java | 20 ++++-- .../build/lib/rules/apple/XcodeConfig.java | 50 +++++++------- .../build/lib/rules/apple/XcodeConfigRule.java | 6 +- .../lib/rules/apple/XcodeVersionProperties.java | 77 ++++++++++++++++++++++ .../build/lib/rules/apple/XcodeVersionRule.java | 11 +++- .../lib/rules/apple/XcodeVersionRuleData.java | 14 +++- 7 files changed, 145 insertions(+), 37 deletions(-) create mode 100644 src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionProperties.java (limited to 'src/main/java/com/google/devtools/build/lib/rules/apple') 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 xcodeVersionOverride) { - this.iosSdkVersion = Preconditions.checkNotNull(appleOptions.iosSdkVersion, "iosSdkVersion"); + Optional 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 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 getXcodeVersion(ConfigurationEnvironment env, + private XcodeVersionProperties getXcodeVersionProperties(ConfigurationEnvironment env, AppleCommandLineOptions appleOptions) throws InvalidConfigurationException { Optional 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 resolveXcodeVersion(ConfigurationEnvironment env, + public static XcodeVersionProperties resolveXcodeVersion(ConfigurationEnvironment env, Label xcodeConfigLabel, Optional 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 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 aliasesToVersionMap(ConfigurationEnvironment env, + private static Map aliasesToVersionMap(ConfigurationEnvironment env, Rule xcodeConfigTarget) throws InvalidConfigurationException { List