|
1 |
| -// Copyright 2015 The Bazel Authors. All rights reserved. |
| 1 | +// Copyright 2017 The Bazel Authors. All rights reserved. |
2 | 2 | //
|
3 | 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
4 | 4 | // you may not use this file except in compliance with the License.
|
|
11 | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 | 12 | // See the License for the specific language governing permissions and
|
13 | 13 | // limitations under the License.
|
14 |
| - |
15 | 14 | package com.google.devtools.build.lib.rules.apple;
|
16 | 15 |
|
17 |
| -import com.google.common.base.Optional; |
18 |
| -import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; |
| 16 | +import com.google.common.base.Preconditions; |
| 17 | +import com.google.devtools.build.lib.analysis.RuleContext; |
| 18 | +import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; |
19 | 19 | import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
|
| 20 | +import com.google.devtools.build.lib.packages.NativeInfo; |
| 21 | +import com.google.devtools.build.lib.packages.NativeProvider; |
| 22 | +import com.google.devtools.build.lib.skylarkbuildapi.apple.XcodeConfigProviderApi; |
| 23 | +import javax.annotation.Nullable; |
20 | 24 |
|
21 | 25 | /**
|
22 |
| - * Provides a version of xcode based on a combination of the {@code --xcode_version} build flag |
23 |
| - * and a {@code xcode_config} target. This version of xcode should be used for selecting apple |
24 |
| - * toolchains and SDKs. |
| 26 | + * The set of Apple versions computed from command line options and the {@code xcode_config} rule. |
25 | 27 | */
|
26 | 28 | @Immutable
|
27 |
| -public final class XcodeConfigProvider implements TransitiveInfoProvider { |
28 |
| - private final Optional<DottedVersion> xcodeVersion; |
29 |
| - |
30 |
| - XcodeConfigProvider(DottedVersion xcodeVersion) { |
31 |
| - this.xcodeVersion = Optional.of(xcodeVersion); |
| 29 | +public class XcodeConfigProvider extends NativeInfo |
| 30 | + implements XcodeConfigProviderApi<ApplePlatform, ApplePlatform.PlatformType> { |
| 31 | + /** Skylark name for this provider. */ |
| 32 | + public static final String SKYLARK_NAME = "XcodeVersionConfig"; |
| 33 | + |
| 34 | + /** Provider identifier for {@link XcodeConfigProvider}. */ |
| 35 | + public static final NativeProvider<XcodeConfigProvider> PROVIDER = |
| 36 | + new NativeProvider<XcodeConfigProvider>(XcodeConfigProvider.class, SKYLARK_NAME) {}; |
| 37 | + |
| 38 | + private final DottedVersion iosSdkVersion; |
| 39 | + private final DottedVersion iosMinimumOsVersion; |
| 40 | + private final DottedVersion watchosSdkVersion; |
| 41 | + private final DottedVersion watchosMinimumOsVersion; |
| 42 | + private final DottedVersion tvosSdkVersion; |
| 43 | + private final DottedVersion tvosMinimumOsVersion; |
| 44 | + private final DottedVersion macosSdkVersion; |
| 45 | + private final DottedVersion macosMinimumOsVersion; |
| 46 | + @Nullable private final DottedVersion xcodeVersion; |
| 47 | + |
| 48 | + public XcodeConfigProvider( |
| 49 | + DottedVersion iosSdkVersion, DottedVersion iosMinimumOsVersion, |
| 50 | + DottedVersion watchosSdkVersion, DottedVersion watchosMinimumOsVersion, |
| 51 | + DottedVersion tvosSdkVersion, DottedVersion tvosMinimumOsVersion, |
| 52 | + DottedVersion macosSdkVersion, DottedVersion macosMinimumOsVersion, |
| 53 | + DottedVersion xcodeVersion) { |
| 54 | + super(PROVIDER); |
| 55 | + this.iosSdkVersion = Preconditions.checkNotNull(iosSdkVersion); |
| 56 | + this.iosMinimumOsVersion = Preconditions.checkNotNull(iosMinimumOsVersion); |
| 57 | + this.watchosSdkVersion = Preconditions.checkNotNull(watchosSdkVersion); |
| 58 | + this.watchosMinimumOsVersion = Preconditions.checkNotNull(watchosMinimumOsVersion); |
| 59 | + this.tvosSdkVersion = Preconditions.checkNotNull(tvosSdkVersion); |
| 60 | + this.tvosMinimumOsVersion = Preconditions.checkNotNull(tvosMinimumOsVersion); |
| 61 | + this.macosSdkVersion = Preconditions.checkNotNull(macosSdkVersion); |
| 62 | + this.macosMinimumOsVersion = Preconditions.checkNotNull(macosMinimumOsVersion); |
| 63 | + this.xcodeVersion = xcodeVersion; |
32 | 64 | }
|
33 |
| - |
34 |
| - private XcodeConfigProvider() { |
35 |
| - this.xcodeVersion = Optional.absent(); |
| 65 | + |
| 66 | + /** |
| 67 | + * Returns the value of the xcode version, if available. This is determined based on a combination |
| 68 | + * of the {@code --xcode_version} build flag and the {@code xcode_config} target defined in the |
| 69 | + * {@code --xcode_version_config} flag. Returns null if no xcode is available. |
| 70 | + */ |
| 71 | + @Override |
| 72 | + public DottedVersion getXcodeVersion() { |
| 73 | + return xcodeVersion; |
36 | 74 | }
|
37 |
| - |
| 75 | + |
38 | 76 | /**
|
39 |
| - * Returns a {@link XcodeConfigProvider} with no xcode version specified. The host system |
40 |
| - * default xcode should be used. See {@link #getXcodeVersion}. |
| 77 | + * Returns the minimum compatible OS version for target simulator and devices for a particular |
| 78 | + * platform type. |
41 | 79 | */
|
42 |
| - static XcodeConfigProvider hostSystemDefault() { |
43 |
| - return new XcodeConfigProvider(); |
| 80 | + @Override |
| 81 | + public DottedVersion getMinimumOsForPlatformType(ApplePlatform.PlatformType platformType) { |
| 82 | + // TODO(b/37240784): Look into using only a single minimum OS flag tied to the current |
| 83 | + // apple_platform_type. |
| 84 | + switch (platformType) { |
| 85 | + case IOS: |
| 86 | + return iosMinimumOsVersion; |
| 87 | + case TVOS: |
| 88 | + return tvosMinimumOsVersion; |
| 89 | + case WATCHOS: |
| 90 | + return watchosMinimumOsVersion; |
| 91 | + case MACOS: |
| 92 | + return macosMinimumOsVersion; |
| 93 | + default: |
| 94 | + throw new IllegalArgumentException("Unhandled platform type: " + platformType); |
| 95 | + } |
44 | 96 | }
|
45 | 97 |
|
46 | 98 | /**
|
47 |
| - * Returns either an explicit xcode version which should be used in actions which require an |
48 |
| - * apple toolchain, or {@link Optional#absent} if the host system default should be used. |
| 99 | + * Returns the SDK version for a platform (whether they be for simulator or device). This is |
| 100 | + * directly derived from command line args. |
49 | 101 | */
|
50 |
| - public Optional<DottedVersion> getXcodeVersion() { |
51 |
| - return xcodeVersion; |
| 102 | + @Override |
| 103 | + public DottedVersion getSdkVersionForPlatform(ApplePlatform platform) { |
| 104 | + switch (platform) { |
| 105 | + case IOS_DEVICE: |
| 106 | + case IOS_SIMULATOR: |
| 107 | + return iosSdkVersion; |
| 108 | + case TVOS_DEVICE: |
| 109 | + case TVOS_SIMULATOR: |
| 110 | + return tvosSdkVersion; |
| 111 | + case WATCHOS_DEVICE: |
| 112 | + case WATCHOS_SIMULATOR: |
| 113 | + return watchosSdkVersion; |
| 114 | + case MACOS: |
| 115 | + return macosSdkVersion; |
| 116 | + default: |
| 117 | + throw new IllegalArgumentException("Unhandled platform: " + platform); |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + public static XcodeConfigProvider fromRuleContext(RuleContext ruleContext) { |
| 122 | + return ruleContext.getPrerequisite( |
| 123 | + XcodeConfigRule.XCODE_CONFIG_ATTR_NAME, Mode.TARGET, XcodeConfigProvider.PROVIDER); |
52 | 124 | }
|
53 | 125 | }
|
0 commit comments