aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/apple/DottedVersion.java35
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java5
2 files changed, 31 insertions, 9 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/DottedVersion.java b/src/main/java/com/google/devtools/build/lib/rules/apple/DottedVersion.java
index 9919ff757d..e063f3e085 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/apple/DottedVersion.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/apple/DottedVersion.java
@@ -15,6 +15,7 @@
package com.google.devtools.build.lib.rules.apple;
import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.ComparisonChain;
@@ -169,6 +170,31 @@ public final class DottedVersion implements DottedVersionApi<DottedVersion> {
}
/**
+ * Returns the string representation of this dotted version, padded or truncated to the specified
+ * number of components.
+ *
+ * <p>For example, a dotted version of "7.3.0" will return "7" if one is requested, "7.3" if two
+ * are requested, "7.3.0" if three are requested, and "7.3.0.0" if four are requested.
+ *
+ * @param numComponents a positive number of dot-separated numbers that should be present in the
+ * returned string representation
+ */
+ public String toStringWithComponents(int numComponents) {
+ Preconditions.checkArgument(numComponents > 0,
+ "Can't serialize as a version with %s components", numComponents);
+ ImmutableList.Builder<Component> stringComponents = ImmutableList.builder();
+ if (numComponents <= components.size()) {
+ stringComponents.addAll(components.subList(0, numComponents));
+ } else {
+ stringComponents.addAll(components);
+ for (int i = components.size(); i < numComponents; i++) {
+ stringComponents.add(ZERO_COMPONENT);
+ }
+ }
+ return Joiner.on('.').join(stringComponents.build());
+ }
+
+ /**
* Returns the string representation of this dotted version, padded to a minimum number of
* components if the string representation does not already contain that many components.
*
@@ -183,14 +209,7 @@ public final class DottedVersion implements DottedVersionApi<DottedVersion> {
* the returned string representation
*/
public String toStringWithMinimumComponents(int numMinComponents) {
- ImmutableList.Builder<Component> stringComponents = ImmutableList.builder();
- stringComponents.addAll(components);
- int numComponents = Math.max(this.numOriginalComponents, numMinComponents);
- int zeroesToPad = numComponents - components.size();
- for (int i = 0; i < zeroesToPad; i++) {
- stringComponents.add(ZERO_COMPONENT);
- }
- return Joiner.on('.').join(stringComponents.build());
+ return toStringWithComponents(Math.max(this.numOriginalComponents, numMinComponents));
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
index f7e7a4a401..40938048a1 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
@@ -553,8 +553,11 @@ public class CompilationSupport {
// next release.
activatedCrosstoolSelectables.add(NO_DSYM_ZIPS_FEATURE_NAME);
+ // Add a feature identifying the Xcode version so CROSSTOOL authors can enable flags for
+ // particular versions of Xcode. To ensure consistency across platforms, use exactly two
+ // components in the version number.
activatedCrosstoolSelectables.add(XCODE_VERSION_FEATURE_NAME_PREFIX
- + XcodeConfig.getXcodeVersion(ruleContext).toStringWithMinimumComponents(2));
+ + XcodeConfig.getXcodeVersion(ruleContext).toStringWithComponents(2));
activatedCrosstoolSelectables.addAll(ruleContext.getFeatures());