aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar bbaren <bbaren@google.com>2018-08-15 13:58:00 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-08-15 13:59:26 -0700
commitc5442570ecba9a540a552825c8aed7ac9c62c321 (patch)
treec5d3eb1b56ab2b8faa444d130361149c2537ac92 /src/main
parente2f61b197a1375b04222aa99a6bbcb290a19e36c (diff)
Always use exactly two components in Xcode version featureHEADmaster
When setting the standard Xcode version feature (see commit eb952d08f76afa907bb34eaf7e1a69899102c523), always use exactly two components for the version number. Grouping all point releases together simplifies writing CROSSTOOLs. Also fix a bug in MockObjcSupport that prevented Xcode version selection in tests from working properly. RELNOTES: The standard `xcode_VERSION` feature now always uses exactly two components in the version, even if you specify `--xcode_version` with more or fewer than two. PiperOrigin-RevId: 208877588
Diffstat (limited to 'src/main')
-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());