aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar lberki <lberki@google.com>2017-07-25 08:47:23 +0200
committerGravatar Jakob Buchgraber <buchgr@google.com>2017-07-25 13:17:42 +0200
commitf929b1a174b535ad6e42bf908879996b77060c31 (patch)
treec49f603c30534b23bf8dc243a9f9781abff317ff /src/main/java
parentef9fe8f3a291e9be3ba2d87ca0310178d0990b84 (diff)
Add a command line option to make the minimum_os_version attribute mandatory on Apple rules.
RELNOTES: None. PiperOrigin-RevId: 163035922
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java11
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/MultiArchSplitTransitionProvider.java13
3 files changed, 27 insertions, 4 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 3b13623b37..36c9449462 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
@@ -42,6 +42,17 @@ import java.util.List;
public class AppleCommandLineOptions extends FragmentOptions {
@Option(
+ name = "experimental_apple_mandatory_minimum_version",
+ defaultValue = "false",
+ category = "experimental",
+ documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
+ effectTags = { OptionEffectTag.LOSES_INCREMENTAL_STATE, OptionEffectTag.BUILD_FILE_SEMANTICS },
+ help = "Whether Apple rules must have a mandatory minimum_os_version attribute."
+ )
+ // TODO(b/37096178): This flag should be default-on and then be removed.
+ public boolean mandatoryMinimumVersion;
+
+ @Option(
name = "xcode_version",
defaultValue = "null",
category = "build",
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 01c5879a22..97027f3d99 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
@@ -95,6 +95,7 @@ public class AppleConfiguration extends BuildConfiguration.Fragment {
private final boolean enableAppleCrosstool;
@Nullable private final String xcodeToolchain;
@Nullable private final Label defaultProvisioningProfileLabel;
+ private final boolean mandatoryMinimumVersion;
AppleConfiguration(
AppleCommandLineOptions appleOptions,
@@ -146,6 +147,7 @@ public class AppleConfiguration extends BuildConfiguration.Fragment {
this.enableAppleCrosstool = appleOptions.enableAppleCrosstoolTransition;
this.defaultProvisioningProfileLabel = appleOptions.defaultProvisioningProfile;
this.xcodeToolchain = appleOptions.xcodeToolchain;
+ this.mandatoryMinimumVersion = appleOptions.mandatoryMinimumVersion;
}
/** Determines cpu value from apple-specific toolchain identifier. */
@@ -616,6 +618,11 @@ public class AppleConfiguration extends BuildConfiguration.Fragment {
return xcodeToolchain;
}
+ /** Returns true if the minimum_os_version attribute should be mandatory on rules with linking. */
+ public boolean isMandatoryMinimumVersion() {
+ return mandatoryMinimumVersion;
+ }
+
/** Returns true if {@link AppleCrosstoolTransition} should be applied to every apple rule. */
public boolean isAppleCrosstoolEnabled() {
return enableAppleCrosstool;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/MultiArchSplitTransitionProvider.java b/src/main/java/com/google/devtools/build/lib/rules/objc/MultiArchSplitTransitionProvider.java
index 5e36fdef53..6a6d19b3d4 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/MultiArchSplitTransitionProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/MultiArchSplitTransitionProvider.java
@@ -83,17 +83,22 @@ public class MultiArchSplitTransitionProvider implements SplitTransitionProvider
*/
public static void validateMinimumOs(RuleContext ruleContext) throws RuleErrorException {
String attributeValue = ruleContext.attributes().get(PlatformRule.MINIMUM_OS_VERSION, STRING);
- // TODO(b/37096178): This should be a mandatory attribute.
- if (!Strings.isNullOrEmpty(attributeValue)) {
+ // TODO(b/37096178): This attribute should always be a version.
+ if (Strings.isNullOrEmpty(attributeValue)) {
+ if (ruleContext.getFragment(AppleConfiguration.class).isMandatoryMinimumVersion()) {
+ ruleContext.throwWithAttributeError(PlatformRule.MINIMUM_OS_VERSION,
+ "This attribute must be explicitly specified");
+ }
+ } else {
try {
DottedVersion minimumOsVersion = DottedVersion.fromString(attributeValue);
if (minimumOsVersion.hasAlphabeticCharacters() || minimumOsVersion.numComponents() > 2) {
- throw ruleContext.throwWithAttributeError(
+ ruleContext.throwWithAttributeError(
PlatformRule.MINIMUM_OS_VERSION,
String.format(INVALID_VERSION_STRING_ERROR_FORMAT, attributeValue));
}
} catch (IllegalArgumentException exception) {
- throw ruleContext.throwWithAttributeError(
+ ruleContext.throwWithAttributeError(
PlatformRule.MINIMUM_OS_VERSION,
String.format(INVALID_VERSION_STRING_ERROR_FORMAT, attributeValue));
}