diff options
Diffstat (limited to 'src/main/java/com')
22 files changed, 352 insertions, 89 deletions
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 97027f3d99..3ab182ad59 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 @@ -20,6 +20,7 @@ import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.analysis.config.ConfigurationEnvironment; @@ -93,14 +94,15 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { private final Label xcodeConfigLabel; private final DottedVersion xcodeVersionCommandLineFlag; private final boolean enableAppleCrosstool; + private final AppleCommandLineOptions options; @Nullable private final String xcodeToolchain; @Nullable private final Label defaultProvisioningProfileLabel; private final boolean mandatoryMinimumVersion; AppleConfiguration( - AppleCommandLineOptions appleOptions, + AppleCommandLineOptions options, String cpu, - @Nullable DottedVersion xcodeVersion, + XcodeVersionProperties xcodeVersionProperties, DottedVersion iosSdkVersion, DottedVersion iosMinimumOs, DottedVersion watchosSdkVersion, @@ -109,6 +111,7 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { DottedVersion tvosMinimumOs, DottedVersion macosSdkVersion, DottedVersion macosMinimumOs) { + this.options = options; this.iosSdkVersion = Preconditions.checkNotNull(iosSdkVersion, "iosSdkVersion"); this.iosMinimumOs = Preconditions.checkNotNull(iosMinimumOs, "iosMinimumOs"); this.watchosSdkVersion = @@ -123,31 +126,31 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { Preconditions.checkNotNull(macosSdkVersion, "macOsSdkVersion"); this.macosMinimumOs = Preconditions.checkNotNull(macosMinimumOs, "macOsMinimumOs"); - this.xcodeVersion = xcodeVersion; + this.xcodeVersion = xcodeVersionProperties.getXcodeVersion().orNull(); this.iosCpu = iosCpuFromCpu(cpu); - this.appleSplitCpu = Preconditions.checkNotNull(appleOptions.appleSplitCpu, "appleSplitCpu"); + this.appleSplitCpu = Preconditions.checkNotNull(options.appleSplitCpu, "appleSplitCpu"); this.applePlatformType = - Preconditions.checkNotNull(appleOptions.applePlatformType, "applePlatformType"); - this.configurationDistinguisher = appleOptions.configurationDistinguisher; + Preconditions.checkNotNull(options.applePlatformType, "applePlatformType"); + this.configurationDistinguisher = options.configurationDistinguisher; this.iosMultiCpus = ImmutableList.copyOf( - Preconditions.checkNotNull(appleOptions.iosMultiCpus, "iosMultiCpus")); - this.watchosCpus = (appleOptions.watchosCpus == null || appleOptions.watchosCpus.isEmpty()) + Preconditions.checkNotNull(options.iosMultiCpus, "iosMultiCpus")); + this.watchosCpus = (options.watchosCpus == null || options.watchosCpus.isEmpty()) ? ImmutableList.of(AppleCommandLineOptions.DEFAULT_WATCHOS_CPU) - : ImmutableList.copyOf(appleOptions.watchosCpus); - this.tvosCpus = (appleOptions.tvosCpus == null || appleOptions.tvosCpus.isEmpty()) + : ImmutableList.copyOf(options.watchosCpus); + this.tvosCpus = (options.tvosCpus == null || options.tvosCpus.isEmpty()) ? ImmutableList.of(AppleCommandLineOptions.DEFAULT_TVOS_CPU) - : ImmutableList.copyOf(appleOptions.tvosCpus); - this.macosCpus = (appleOptions.macosCpus == null || appleOptions.macosCpus.isEmpty()) + : ImmutableList.copyOf(options.tvosCpus); + this.macosCpus = (options.macosCpus == null || options.macosCpus.isEmpty()) ? ImmutableList.of(AppleCommandLineOptions.DEFAULT_MACOS_CPU) - : ImmutableList.copyOf(appleOptions.macosCpus); - this.bitcodeMode = appleOptions.appleBitcodeMode; + : ImmutableList.copyOf(options.macosCpus); + this.bitcodeMode = options.appleBitcodeMode; this.xcodeConfigLabel = - Preconditions.checkNotNull(appleOptions.xcodeVersionConfig, "xcodeConfigLabel"); - this.xcodeVersionCommandLineFlag = appleOptions.xcodeVersion; - this.enableAppleCrosstool = appleOptions.enableAppleCrosstoolTransition; - this.defaultProvisioningProfileLabel = appleOptions.defaultProvisioningProfile; - this.xcodeToolchain = appleOptions.xcodeToolchain; - this.mandatoryMinimumVersion = appleOptions.mandatoryMinimumVersion; + Preconditions.checkNotNull(options.xcodeVersionConfig, "xcodeConfigLabel"); + this.xcodeVersionCommandLineFlag = options.xcodeVersion; + this.enableAppleCrosstool = options.enableAppleCrosstoolTransition; + this.defaultProvisioningProfileLabel = options.defaultProvisioningProfile; + this.xcodeToolchain = options.xcodeToolchain; + this.mandatoryMinimumVersion = options.mandatoryMinimumVersion; } /** Determines cpu value from apple-specific toolchain identifier. */ @@ -159,24 +162,37 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { } } + public AppleCommandLineOptions getOptions() { + return options; + } + /** * Returns the minimum iOS version supported by binaries and libraries. Any dependencies on newer * iOS version features or libraries will become weak dependencies which are only loaded if the * runtime OS supports them. + * + * @deprecated use {@link XcodeConfig#getMinimumOsForPlatformType(RuleContext, PlatformType)}. */ @SkylarkCallable(name = "ios_minimum_os", structField = true, doc = "<b>Deprecated. Use <a href='#minimum_os_for_platform_type'>" + "minimum_os_for_platform_type(apple_common.platform_type.ios)</a> instead.</b> " + "The minimum compatible iOS version for target simulators and devices.") + @Deprecated + // Bug tracking the removal of this method: https://github.com/bazelbuild/bazel/issues/3424 public DottedVersion getMinimumOs() { // TODO(bazel-team): Deprecate in favor of getMinimumOsForPlatformType(IOS). return iosMinimumOs; } + /*** + * @deprecated use {@link XcodeConfig#getMinimumOsForPlatformType(RuleContext, PlatformType)}. + */ @SkylarkCallable( name = "minimum_os_for_platform_type", doc = "The minimum compatible OS version for target simulator and devices for a particular " + "platform type.") + @Deprecated + // Bug tracking the removal of this method: https://github.com/bazelbuild/bazel/issues/3424 public DottedVersion getMinimumOsForPlatformType(PlatformType platformType) { // TODO(b/37240784): Look into using only a single minimum OS flag tied to the current // apple_platform_type. @@ -199,8 +215,9 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { * Returns the SDK version for ios SDKs (whether they be for simulator or device). This is * directly derived from --ios_sdk_version. * - * @deprecated - use {@link #getSdkVersionForPlatform()} + * @deprecated use {@link XcodeConfig#getSdkVersionForPlatform(RuleContext, ApplePlatform)} */ + // Bug tracking the removal of this method: https://github.com/bazelbuild/bazel/issues/3424 @Deprecated public DottedVersion getIosSdkVersion() { return getSdkVersionForPlatform(ApplePlatform.IOS_DEVICE); } @@ -208,11 +225,15 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { /** * Returns the SDK version for a platform (whether they be for simulator or device). This is * directly derived from command line args. + * + * @deprecated use {@link XcodeConfig#getSdkVersionForPlatform(RuleContext, ApplePlatform)} */ @SkylarkCallable( name = "sdk_version_for_platform", doc = "The version of the platform SDK that will be used to build targets for the given " + "platform.") + @Deprecated + // Bug tracking the removal of this method: https://github.com/bazelbuild/bazel/issues/3424 public DottedVersion getSdkVersionForPlatform(ApplePlatform platform) { switch (platform) { case IOS_DEVICE: @@ -235,6 +256,8 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { * Returns the value of the xcode version, if available. This is determined based on a combination * of the {@code --xcode_version} build flag and the {@code xcode_config} target defined in the * {@code --xcode_version_config} flag. Returns null if no xcode is available. + * + * @deprecated use {@link XcodeConfig#getXcodeVersion(RuleContext)}. */ @SkylarkCallable( name = "xcode_version", @@ -242,6 +265,8 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { + "This will return <code>None</code> if no Xcode versions are available.", allowReturnNones = true) @Nullable + @Deprecated + // Bug tracking the removal of this method: https://github.com/bazelbuild/bazel/issues/3424 public DottedVersion getXcodeVersion() { return xcodeVersion; } @@ -677,7 +702,7 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { new AppleConfiguration( appleOptions, cpu, - xcodeVersionProperties.getXcodeVersion().orNull(), + xcodeVersionProperties, iosSdkVersion, iosMinimumOsVersion, watchosSdkVersion, diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleToolchain.java b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleToolchain.java index a9c4b49233..35bd1d7991 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleToolchain.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleToolchain.java @@ -14,12 +14,12 @@ package com.google.devtools.build.lib.rules.apple; -import static com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition.HOST; import static com.google.devtools.build.lib.packages.Attribute.attr; import static com.google.devtools.build.lib.packages.BuildType.LABEL; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; +import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; @@ -119,12 +119,12 @@ public class AppleToolchain { /** Returns the SDK frameworks directory inside of Xcode for a given configuration. */ public static String sdkFrameworkDir( - ApplePlatform targetPlatform, AppleConfiguration configuration) { + ApplePlatform targetPlatform, RuleContext ruleContext) { String relativePath; switch (targetPlatform) { case IOS_DEVICE: case IOS_SIMULATOR: - if (configuration.getSdkVersionForPlatform(targetPlatform) + if (XcodeConfig.getSdkVersionForPlatform(ruleContext, targetPlatform) .compareTo(DottedVersion.fromString("9.0")) >= 0) { relativePath = SYSTEM_FRAMEWORK_PATH; } else { @@ -175,11 +175,10 @@ public class AppleToolchain { @Override public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { return builder - .add(attr(":xcode_config", LABEL) + .add(attr(XcodeConfigRule.XCODE_CONFIG_ATTR_NAME, LABEL) .allowedRuleClasses("xcode_config") .checkConstraints() .direct_compile_time_input() - .cfg(HOST) .value(new XcodeConfigLabel(toolsRepository))) .build(); } 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 a486e99c56..e9cfddbf1c 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 @@ -15,10 +15,12 @@ package com.google.devtools.build.lib.rules.apple; import com.google.common.base.Joiner; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.RedirectChaser; +import com.google.devtools.build.lib.analysis.RuleConfiguredTarget; import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.RunfilesProvider; @@ -36,6 +38,7 @@ import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; import com.google.devtools.build.lib.syntax.Type; import java.util.List; import java.util.Map; +import java.util.Objects; import javax.annotation.Nullable; /** @@ -101,8 +104,56 @@ public class XcodeConfig implements RuleConfiguredTargetFactory { @Override public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException { + AppleCommandLineOptions appleOptions = + ruleContext.getFragment(AppleConfiguration.class).getOptions(); + XcodeVersionRuleData defaultVersion = ruleContext.getPrerequisite( + XcodeConfigRule.DEFAULT_ATTR_NAME, RuleConfiguredTarget.Mode.TARGET, + XcodeVersionRuleData.class); + Iterable<XcodeVersionRuleData> availableVersions = ruleContext.getPrerequisites( + XcodeConfigRule.VERSIONS_ATTR_NAME, RuleConfiguredTarget.Mode.TARGET, + XcodeVersionRuleData.class); + boolean requireDefinedVersions = ruleContext.attributes().get( + XcodeConfigRule.REQUIRE_DEFINED_VERSIONS_ATTR_NAME, Type.BOOLEAN); + XcodeVersionProperties xcodeVersionProperties; + try { + xcodeVersionProperties = resolveXcodeVersion( + requireDefinedVersions, + appleOptions.xcodeVersion, + availableVersions, + defaultVersion); + } catch (XcodeConfigException e) { + ruleContext.ruleError(e.getMessage()); + return null; + } + + DottedVersion iosSdkVersion = (appleOptions.iosSdkVersion != null) + ? appleOptions.iosSdkVersion : xcodeVersionProperties.getDefaultIosSdkVersion(); + DottedVersion iosMinimumOsVersion = (appleOptions.iosMinimumOs != null) + ? appleOptions.iosMinimumOs : iosSdkVersion; + DottedVersion watchosSdkVersion = (appleOptions.watchOsSdkVersion != null) + ? appleOptions.watchOsSdkVersion : xcodeVersionProperties.getDefaultWatchosSdkVersion(); + DottedVersion watchosMinimumOsVersion = (appleOptions.watchosMinimumOs != null) + ? appleOptions.watchosMinimumOs : watchosSdkVersion; + DottedVersion tvosSdkVersion = (appleOptions.tvOsSdkVersion != null) + ? appleOptions.tvOsSdkVersion : xcodeVersionProperties.getDefaultTvosSdkVersion(); + DottedVersion tvosMinimumOsVersion = (appleOptions.tvosMinimumOs != null) + ? appleOptions.tvosMinimumOs : tvosSdkVersion; + DottedVersion macosSdkVersion = (appleOptions.macOsSdkVersion != null) + ? appleOptions.macOsSdkVersion : xcodeVersionProperties.getDefaultMacosSdkVersion(); + DottedVersion macosMinimumOsVersion = (appleOptions.macosMinimumOs != null) + ? appleOptions.macosMinimumOs : macosSdkVersion; + + XcodeConfigProvider xcodeVersions = new XcodeConfigProvider( + iosSdkVersion, iosMinimumOsVersion, + watchosSdkVersion, watchosMinimumOsVersion, + tvosSdkVersion, tvosMinimumOsVersion, + macosSdkVersion, macosMinimumOsVersion, + xcodeVersionProperties.getXcodeVersion().orNull()); + return new RuleConfiguredTargetBuilder(ruleContext) .addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY) + .addProvider(xcodeVersions) + .addNativeDeclaredProvider(xcodeVersionProperties) .build(); } @@ -121,7 +172,7 @@ public class XcodeConfig implements RuleConfiguredTargetFactory { static XcodeVersionProperties resolveXcodeVersion( boolean requireDefinedVersions, DottedVersion xcodeVersionOverrideFlag, - ImmutableList<XcodeVersionRuleData> xcodeVersions, + Iterable<XcodeVersionRuleData> xcodeVersions, @Nullable XcodeVersionRuleData defaultVersion) throws XcodeConfigException { XcodeVersionRuleData xcodeVersion = resolveExplicitlyDefinedVersion( @@ -147,7 +198,7 @@ public class XcodeConfig implements RuleConfiguredTargetFactory { @Nullable private static XcodeVersionRuleData resolveExplicitlyDefinedVersion( boolean requireDefinedVersions, - ImmutableList<XcodeVersionRuleData> xcodeVersionRules, + Iterable<XcodeVersionRuleData> xcodeVersionRules, @Nullable XcodeVersionRuleData defaultVersion, DottedVersion versionOverrideFlag) throws XcodeConfigException { @@ -202,7 +253,7 @@ public class XcodeConfig implements RuleConfiguredTargetFactory { * were registered to the same alias) */ private static Map<String, XcodeVersionRuleData> aliasesToVersionMap( - ImmutableList<XcodeVersionRuleData> xcodeVersionRules) + Iterable<XcodeVersionRuleData> xcodeVersionRules) throws XcodeConfigException { Map<String, XcodeVersionRuleData> aliasesToXcodeRules = Maps.newLinkedHashMap(); for (XcodeVersionRuleData xcodeVersionRule : xcodeVersionRules) { @@ -229,7 +280,7 @@ public class XcodeConfig implements RuleConfiguredTargetFactory { * of duplicate aliases in an {@code xcode_config} target definition. */ private static void configErrorDuplicateAlias(String alias, - List<XcodeVersionRuleData> xcodeVersionRules) throws XcodeConfigException { + Iterable<XcodeVersionRuleData> xcodeVersionRules) throws XcodeConfigException { ImmutableList.Builder<Label> labelsContainingAlias = ImmutableList.builder(); for (XcodeVersionRuleData xcodeVersionRule : xcodeVersionRules) { @@ -275,4 +326,59 @@ public class XcodeConfig implements RuleConfiguredTargetFactory { throw new InvalidConfigurationException(exception); } } + + /** + * Returns the minimum compatible OS version for target simulator and devices for a particular + * platform type. + */ + public static DottedVersion getMinimumOsForPlatformType( + RuleContext ruleContext, ApplePlatform.PlatformType platformType) { + AppleConfiguration config = ruleContext.getFragment(AppleConfiguration.class); + XcodeConfigProvider versions = ruleContext.getPrerequisite( + XcodeConfigRule.XCODE_CONFIG_ATTR_NAME, + RuleConfiguredTarget.Mode.TARGET, + XcodeConfigProvider.class); + DottedVersion fromProvider = versions.getMinimumOsForPlatformType(platformType); + DottedVersion fromConfig = config.getMinimumOsForPlatformType(platformType); + // This sanity check is there to keep this provider in sync with AppleConfiguration until the + // latter can be removed. Tracking bug: https://github.com/bazelbuild/bazel/issues/3424 + Preconditions.checkState(fromProvider.equals(fromConfig)); + return fromProvider; + } + + /** + * Returns the SDK version for a platform (whether they be for simulator or device). This is + * directly derived from command line args. + */ + public static DottedVersion getSdkVersionForPlatform( + RuleContext ruleContext, ApplePlatform platform) { + XcodeConfigProvider versions = ruleContext.getPrerequisite( + XcodeConfigRule.XCODE_CONFIG_ATTR_NAME, + RuleConfiguredTarget.Mode.TARGET, + XcodeConfigProvider.class); + DottedVersion fromProvider = versions.getSdkVersionForPlatform(platform); + DottedVersion fromConfig = ruleContext.getFragment(AppleConfiguration.class) + .getSdkVersionForPlatform(platform); + // This sanity check is there to keep this provider in sync with AppleConfiguration until the + // latter can be removed. Tracking bug: https://github.com/bazelbuild/bazel/issues/3424 + Preconditions.checkState(fromProvider.equals(fromConfig)); + return fromProvider; + } + + /** + * Returns the value of the xcode version, if available. This is determined based on a combination + * of the {@code --xcode_version} build flag and the {@code xcode_config} target defined in the + * {@code --xcode_version_config} flag. Returns null if no xcode is available. + */ + public static DottedVersion getXcodeVersion(RuleContext ruleContext) { + XcodeConfigProvider versions = ruleContext.getPrerequisite( + XcodeConfigRule.XCODE_CONFIG_ATTR_NAME, + RuleConfiguredTarget.Mode.TARGET, XcodeConfigProvider.class); + DottedVersion fromProvider = versions.getXcodeVersion(); + DottedVersion fromConfig = ruleContext.getFragment(AppleConfiguration.class).getXcodeVersion(); + // This sanity check is there to keep this provider in sync with AppleConfiguration until the + // latter can be removed. Tracking bug: https://github.com/bazelbuild/bazel/issues/3424 + Preconditions.checkState(Objects.equals(fromProvider, fromConfig)); + return fromProvider; + } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfigProvider.java b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfigProvider.java new file mode 100644 index 0000000000..ce138da4dc --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfigProvider.java @@ -0,0 +1,91 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.rules.apple; + +import com.google.common.base.Preconditions; +import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; +import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; +import javax.annotation.Nullable; + +/** + * The set of Apple versions computed from command line options and the {@code xcode_config} rule. + */ +@Immutable +public class XcodeConfigProvider implements TransitiveInfoProvider { + private final DottedVersion iosSdkVersion; + private final DottedVersion iosMinimumOsVersion; + private final DottedVersion watchosSdkVersion; + private final DottedVersion watchosMinimumOsVersion; + private final DottedVersion tvosSdkVersion; + private final DottedVersion tvosMinimumOsVersion; + private final DottedVersion macosSdkVersion; + private final DottedVersion macosMinimumOsVersion; + @Nullable private final DottedVersion xcodeVersion; + + public XcodeConfigProvider( + DottedVersion iosSdkVersion, DottedVersion iosMinimumOsVersion, + DottedVersion watchosSdkVersion, DottedVersion watchosMinimumOsVersion, + DottedVersion tvosSdkVersion, DottedVersion tvosMinimumOsVersion, + DottedVersion macosSdkVersion, DottedVersion macosMinimumOsVersion, + DottedVersion xcodeVersion) { + this.iosSdkVersion = Preconditions.checkNotNull(iosSdkVersion); + this.iosMinimumOsVersion = Preconditions.checkNotNull(iosMinimumOsVersion); + this.watchosSdkVersion = Preconditions.checkNotNull(watchosSdkVersion); + this.watchosMinimumOsVersion = Preconditions.checkNotNull(watchosMinimumOsVersion); + this.tvosSdkVersion = Preconditions.checkNotNull(tvosSdkVersion); + this.tvosMinimumOsVersion = Preconditions.checkNotNull(tvosMinimumOsVersion); + this.macosSdkVersion = Preconditions.checkNotNull(macosSdkVersion); + this.macosMinimumOsVersion = Preconditions.checkNotNull(macosMinimumOsVersion); + this.xcodeVersion = xcodeVersion; + } + + public DottedVersion getXcodeVersion() { + return xcodeVersion; + } + + public DottedVersion getMinimumOsForPlatformType(ApplePlatform.PlatformType platformType) { + // TODO(b/37240784): Look into using only a single minimum OS flag tied to the current + // apple_platform_type. + switch (platformType) { + case IOS: + return iosMinimumOsVersion; + case TVOS: + return tvosMinimumOsVersion; + case WATCHOS: + return watchosMinimumOsVersion; + case MACOS: + return macosMinimumOsVersion; + default: + throw new IllegalArgumentException("Unhandled platform type: " + platformType); + } + } + + public DottedVersion getSdkVersionForPlatform(ApplePlatform platform) { + switch (platform) { + case IOS_DEVICE: + case IOS_SIMULATOR: + return iosSdkVersion; + case TVOS_DEVICE: + case TVOS_SIMULATOR: + return tvosSdkVersion; + case WATCHOS_DEVICE: + case WATCHOS_SIMULATOR: + return watchosSdkVersion; + case MACOS: + return macosSdkVersion; + default: + throw new IllegalArgumentException("Unhandled platform: " + platform); + } + } +} diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfigRule.java b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfigRule.java index de5a2bc618..1b5a4adf40 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfigRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfigRule.java @@ -30,6 +30,7 @@ import com.google.devtools.build.lib.packages.RuleClass.Builder; */ public class XcodeConfigRule implements RuleDefinition { + public static final String XCODE_CONFIG_ATTR_NAME = ":xcode_config"; static final String DEFAULT_ATTR_NAME = "default"; static final String VERSIONS_ATTR_NAME = "versions"; static final String REQUIRE_DEFINED_VERSIONS_ATTR_NAME = "require_defined_version"; diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersion.java b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersion.java index 7d94b725d8..509588f62d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersion.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersion.java @@ -33,6 +33,7 @@ public class XcodeVersion implements RuleConfiguredTargetFactory { return new RuleConfiguredTargetBuilder(ruleContext) .addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY) + .addProvider(ruleData) .addNativeDeclaredProvider(ruleData.getXcodeVersionProperties()) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionRuleData.java b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionRuleData.java index 7a40726cb5..aa9ad6a5f2 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionRuleData.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionRuleData.java @@ -16,11 +16,12 @@ package com.google.devtools.build.lib.rules.apple; import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.syntax.Type; - import java.util.List; /** @@ -33,7 +34,8 @@ import java.util.List; * "7.0" aliases. This official version of xcode may have a default supported iOS SDK of * 9.0. */ -public class XcodeVersionRuleData { +@Immutable +public class XcodeVersionRuleData implements TransitiveInfoProvider { private final Label label; private final DottedVersion version; private final XcodeVersionProperties xcodeVersionProperties; diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/cpp/AppleCcToolchain.java b/src/main/java/com/google/devtools/build/lib/rules/apple/cpp/AppleCcToolchain.java index dda418e5c2..d7b297cebf 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/cpp/AppleCcToolchain.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/cpp/AppleCcToolchain.java @@ -24,6 +24,7 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.apple.ApplePlatform; import com.google.devtools.build.lib.rules.apple.AppleToolchain; +import com.google.devtools.build.lib.rules.apple.XcodeConfig; import com.google.devtools.build.lib.rules.cpp.CcToolchain; import com.google.devtools.build.lib.rules.cpp.CppConfiguration; import java.util.LinkedHashMap; @@ -58,7 +59,7 @@ public class AppleCcToolchain extends CcToolchain { throws RuleErrorException { AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); - if (appleConfiguration.getXcodeVersion() == null) { + if (XcodeConfig.getXcodeVersion(ruleContext) == null) { ruleContext.throwWithRuleError("Xcode version must be specified to use an Apple CROSSTOOL"); } @@ -69,29 +70,25 @@ public class AppleCcToolchain extends CcToolchain { return ImmutableMap.<String, String>builder() .put( XCODE_VERSION_KEY, - appleConfiguration.getXcodeVersion().toStringWithMinimumComponents(2)) + XcodeConfig.getXcodeVersion(ruleContext).toStringWithMinimumComponents(2)) .put( IOS_SDK_VERSION_KEY, - appleConfiguration - .getSdkVersionForPlatform(ApplePlatform.IOS_SIMULATOR) + XcodeConfig.getSdkVersionForPlatform(ruleContext, ApplePlatform.IOS_SIMULATOR) .toStringWithMinimumComponents(2)) .put( MACOS_SDK_VERSION_KEY, - appleConfiguration - .getSdkVersionForPlatform(ApplePlatform.MACOS) + XcodeConfig.getSdkVersionForPlatform(ruleContext, ApplePlatform.MACOS) .toStringWithMinimumComponents(2)) .put( TVOS_SDK_VERSION_KEY, - appleConfiguration - .getSdkVersionForPlatform(ApplePlatform.TVOS_SIMULATOR) + XcodeConfig.getSdkVersionForPlatform(ruleContext, ApplePlatform.TVOS_SIMULATOR) .toStringWithMinimumComponents(2)) .put( WATCHOS_SDK_VERSION_KEY, - appleConfiguration - .getSdkVersionForPlatform(ApplePlatform.WATCHOS_SIMULATOR) + XcodeConfig.getSdkVersionForPlatform(ruleContext, ApplePlatform.WATCHOS_SIMULATOR) .toStringWithMinimumComponents(2)) .put(SDK_DIR_KEY, AppleToolchain.sdkDir()) - .put(SDK_FRAMEWORK_DIR_KEY, AppleToolchain.sdkFrameworkDir(platform, appleConfiguration)) + .put(SDK_FRAMEWORK_DIR_KEY, AppleToolchain.sdkFrameworkDir(platform, ruleContext)) .put( PLATFORM_DEVELOPER_FRAMEWORK_DIR, AppleToolchain.platformDeveloperFrameworkDir(appleConfiguration)) @@ -106,7 +103,7 @@ public class AppleCcToolchain extends CcToolchain { appleEnv.getOrDefault(AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME, "")) .put( VERSION_MIN_KEY, - appleConfiguration.getMinimumOsForPlatformType(platform.getType()).toString()) + XcodeConfig.getMinimumOsForPlatformType(ruleContext, platform.getType()).toString()) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/cpp/AppleCcToolchainRule.java b/src/main/java/com/google/devtools/build/lib/rules/apple/cpp/AppleCcToolchainRule.java index 2c4d278479..4be2c9e25a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/cpp/AppleCcToolchainRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/cpp/AppleCcToolchainRule.java @@ -19,6 +19,7 @@ import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.packages.RuleClass.Builder; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; +import com.google.devtools.build.lib.rules.apple.AppleToolchain; import com.google.devtools.build.lib.rules.cpp.CcToolchainRule; /** @@ -35,7 +36,8 @@ public class AppleCcToolchainRule implements RuleDefinition { public Metadata getMetadata() { return RuleDefinition.Metadata.builder() .name("apple_cc_toolchain") - .ancestors(BaseRuleClasses.BaseRule.class, CcToolchainRule.class) + .ancestors(BaseRuleClasses.BaseRule.class, CcToolchainRule.class, + AppleToolchain.RequiresXcodeConfigRule.class) .factoryClass(AppleCcToolchain.class) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java index 304930f441..79ae78973a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java @@ -33,6 +33,7 @@ import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.apple.ApplePlatform; import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType; +import com.google.devtools.build.lib.rules.apple.XcodeConfig; import com.google.devtools.build.lib.rules.objc.CompilationSupport.ExtraLinkArgs; import com.google.devtools.build.lib.rules.objc.ObjcCommon.ResourceAttributes; import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.LinkedBinary; @@ -156,7 +157,7 @@ abstract class BinaryLinkingTargetFactory implements RuleConfiguredTargetFactory objcProvider, LinkedBinary.LOCAL_AND_DEPENDENCIES, ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT, - appleConfiguration.getMinimumOsForPlatformType(PlatformType.IOS), + XcodeConfig.getMinimumOsForPlatformType(ruleContext, PlatformType.IOS), appleConfiguration.getSingleArchPlatform()); releaseBundlingSupport .registerActions(DsymOutputType.APP) diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleMergeControlBytes.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BundleMergeControlBytes.java index a89cb98642..0b9f89487b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleMergeControlBytes.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BundleMergeControlBytes.java @@ -16,8 +16,8 @@ package com.google.devtools.build.lib.rules.objc; import com.google.common.io.ByteSource; import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration; -import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType; +import com.google.devtools.build.lib.rules.apple.ApplePlatform; +import com.google.devtools.build.lib.rules.apple.DottedVersion; import com.google.devtools.build.lib.util.Preconditions; import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos; import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos.Control; @@ -34,13 +34,16 @@ import java.io.InputStream; final class BundleMergeControlBytes extends ByteSource { private final Bundling rootBundling; private final Artifact mergedIpa; - private final AppleConfiguration appleConfiguration; + private final DottedVersion iosSdkVersion; + private final ApplePlatform platform; public BundleMergeControlBytes( - Bundling rootBundling, Artifact mergedIpa, AppleConfiguration appleConfiguration) { + Bundling rootBundling, Artifact mergedIpa, DottedVersion iosSdkVersion, + ApplePlatform platform) { this.rootBundling = Preconditions.checkNotNull(rootBundling); this.mergedIpa = Preconditions.checkNotNull(mergedIpa); - this.appleConfiguration = Preconditions.checkNotNull(appleConfiguration); + this.iosSdkVersion = iosSdkVersion; + this.platform = platform; } @Override @@ -56,8 +59,8 @@ final class BundleMergeControlBytes extends ByteSource { .addAllBundleFile(BundleableFile.toBundleFiles(bundling.getBundleFiles())) // TODO(bazel-team): Add rule attribute for specifying targeted device family .setMinimumOsVersion(bundling.getMinimumOsVersion().toString()) - .setSdkVersion(appleConfiguration.getIosSdkVersion().toString()) - .setPlatform(appleConfiguration.getMultiArchPlatform(PlatformType.IOS).name()) + .setSdkVersion(iosSdkVersion.toString()) + .setPlatform(platform.name()) .setBundleRoot(bundling.getBundleDir()); if (bundling.getBundleInfoplist().isPresent()) { 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 39ed3e564c..7e49b8eea3 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 @@ -69,6 +69,7 @@ import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.apple.ApplePlatform; import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType; import com.google.devtools.build.lib.rules.apple.AppleToolchain; +import com.google.devtools.build.lib.rules.apple.XcodeConfig; import com.google.devtools.build.lib.rules.cpp.CcToolchain; import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider; import com.google.devtools.build.lib.rules.cpp.CppFileTypes; @@ -264,18 +265,19 @@ public abstract class CompilationSupport { /** Returns a list of framework search path flags for clang actions. */ static Iterable<String> commonFrameworkFlags( - ObjcProvider provider, AppleConfiguration appleConfiguration) { - return Interspersing.beforeEach("-F", commonFrameworkNames(provider, appleConfiguration)); + ObjcProvider provider, RuleContext ruleContext) { + return Interspersing.beforeEach("-F", commonFrameworkNames(provider, ruleContext)); } /** Returns a list of frameworks for clang actions. */ static Iterable<String> commonFrameworkNames( - ObjcProvider provider, AppleConfiguration appleConfiguration) { + ObjcProvider provider, RuleContext ruleContext) { + AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); ApplePlatform platform = appleConfiguration.getSingleArchPlatform(); ImmutableList.Builder<String> frameworkNames = new ImmutableList.Builder<String>() - .add(AppleToolchain.sdkFrameworkDir(platform, appleConfiguration)); + .add(AppleToolchain.sdkFrameworkDir(platform, ruleContext)); if (platform.getType() == PlatformType.IOS) { // As of sdk8.1, XCTest is in a base Framework dir frameworkNames.add(AppleToolchain.platformDeveloperFrameworkDir(appleConfiguration)); @@ -1413,12 +1415,11 @@ public abstract class CompilationSupport { .add("--platform") .add(appleConfiguration.getSingleArchPlatform().getLowerCaseNameInPlist()) .add("--sdk_version") - .add( - appleConfiguration - .getSdkVersionForPlatform(appleConfiguration.getSingleArchPlatform()) + .add(XcodeConfig.getSdkVersionForPlatform( + ruleContext, appleConfiguration.getSingleArchPlatform()) .toStringWithMinimumComponents(2)) .add("--xcode_version") - .add(appleConfiguration.getXcodeVersion().toStringWithMinimumComponents(2)) + .add(XcodeConfig.getXcodeVersion(ruleContext).toStringWithMinimumComponents(2)) .add("--"); for (ObjcHeaderThinningInfo info : infos) { cmdLine.addJoinPaths( diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosDevice.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosDevice.java index 2a0a2142da..769a3b465b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosDevice.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosDevice.java @@ -23,9 +23,9 @@ import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.RunfilesProvider; import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.apple.ApplePlatform; import com.google.devtools.build.lib.rules.apple.DottedVersion; +import com.google.devtools.build.lib.rules.apple.XcodeConfig; import com.google.devtools.build.lib.rules.apple.XcodeVersionProperties; /** @@ -39,7 +39,6 @@ public final class IosDevice implements RuleConfiguredTargetFactory { "This rule is deprecated. Please use the new Apple build rules " + "(https://github.com/bazelbuild/rules_apple) to build Apple targets."); - AppleConfiguration appleConfiguration = context.getFragment(AppleConfiguration.class); String iosVersionAttribute = context.attributes().get(IosDeviceRule.IOS_VERSION_ATTR_NAME, STRING); XcodeVersionProperties xcodeVersionProperties = @@ -51,8 +50,8 @@ public final class IosDevice implements RuleConfiguredTargetFactory { DottedVersion xcodeVersion = null; if (xcodeVersionProperties != null && xcodeVersionProperties.getXcodeVersion().isPresent()) { xcodeVersion = xcodeVersionProperties.getXcodeVersion().get(); - } else if (appleConfiguration.getXcodeVersion() != null) { - xcodeVersion = appleConfiguration.getXcodeVersion(); + } else if (XcodeConfig.getXcodeVersion(context) != null) { + xcodeVersion = XcodeConfig.getXcodeVersion(context); } DottedVersion iosVersion; @@ -61,7 +60,7 @@ public final class IosDevice implements RuleConfiguredTargetFactory { } else if (xcodeVersionProperties != null) { iosVersion = xcodeVersionProperties.getDefaultIosSdkVersion(); } else { - iosVersion = appleConfiguration.getSdkVersionForPlatform(ApplePlatform.IOS_SIMULATOR); + iosVersion = XcodeConfig.getSdkVersionForPlatform(context, ApplePlatform.IOS_SIMULATOR); } IosDeviceProvider provider = diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceRule.java index 4a20d4a41b..ca8d2809c5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceRule.java @@ -24,6 +24,7 @@ import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.packages.RuleClass.Builder; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; +import com.google.devtools.build.lib.rules.apple.AppleToolchain; /** * Rule definition for ios_device. @@ -69,7 +70,7 @@ public final class IosDeviceRule implements RuleDefinition { return RuleDefinition.Metadata.builder() .name("ios_device") .factoryClass(IosDevice.class) - .ancestors(BaseRuleClasses.BaseRule.class) + .ancestors(BaseRuleClasses.BaseRule.class, AppleToolchain.RequiresXcodeConfigRule.class) .build(); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtension.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtension.java index 897deace6a..8526bbcba2 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtension.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtension.java @@ -25,10 +25,10 @@ import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.packages.Attribute.SplitTransition; import com.google.devtools.build.lib.rules.apple.AppleCommandLineOptions; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher; import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType; import com.google.devtools.build.lib.rules.apple.DottedVersion; +import com.google.devtools.build.lib.rules.apple.XcodeConfig; import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.SplitArchTransition; import java.io.Serializable; import javax.annotation.Nullable; @@ -67,8 +67,7 @@ public class IosExtension extends ReleaseBundlingTargetFactory { @Override protected DottedVersion bundleMinimumOsVersion(RuleContext ruleContext) { return determineMinimumOsVersion( - ruleContext.getFragment(AppleConfiguration.class) - .getMinimumOsForPlatformType(PlatformType.IOS), + XcodeConfig.getMinimumOsForPlatformType(ruleContext, PlatformType.IOS), EXTENSION_MINIMUM_OS_VERSION); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java index 2c9b337c4e..d1ddc215a0 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java @@ -35,6 +35,7 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType; +import com.google.devtools.build.lib.rules.apple.XcodeConfig; import com.google.devtools.build.lib.rules.objc.CompilationSupport.ExtraLinkArgs; import com.google.devtools.build.lib.rules.objc.ObjcCommon.ResourceAttributes; import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.LinkedBinary; @@ -181,7 +182,7 @@ public final class IosTest implements RuleConfiguredTargetFactory { common.getObjcProvider(), LinkedBinary.LOCAL_AND_DEPENDENCIES, bundleFormat, - appleConfiguration.getMinimumOsForPlatformType(PlatformType.IOS), + XcodeConfig.getMinimumOsForPlatformType(ruleContext, PlatformType.IOS), appleConfiguration.getMultiArchPlatform(PlatformType.IOS)) .registerActions(DsymOutputType.TEST) .addFilesToBuild(filesToBuild, Optional.of(DsymOutputType.TEST)) diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java index 60a24514e0..219eaa51c7 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java @@ -50,6 +50,7 @@ import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.apple.AppleToolchain; +import com.google.devtools.build.lib.rules.apple.XcodeConfigRule; import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider; import com.google.devtools.build.lib.rules.cpp.CppConfiguration; import com.google.devtools.build.lib.rules.cpp.CppHelper; @@ -203,11 +204,10 @@ public class J2ObjcAspect extends NativeAspectClass implements ConfiguredAspectF .exec() .value(Label.parseAbsoluteUnchecked(toolsRepository + "//tools/objc:libtool"))) .add( - attr(":xcode_config", LABEL) + attr(XcodeConfigRule.XCODE_CONFIG_ATTR_NAME, LABEL) .allowedRuleClasses("xcode_config") .checkConstraints() .direct_compile_time_input() - .cfg(HOST) .value(new AppleToolchain.XcodeConfigLabel(toolsRepository))) .add( attr("$zipper", LABEL) diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java index 82de6228ac..bfcf03b992 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java @@ -57,11 +57,13 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; +import com.google.devtools.build.lib.rules.apple.AppleCommandLineOptions; import com.google.devtools.build.lib.rules.apple.AppleCommandLineOptions.AppleBitcodeMode; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.apple.ApplePlatform; import com.google.devtools.build.lib.rules.apple.AppleToolchain; import com.google.devtools.build.lib.rules.apple.DottedVersion; +import com.google.devtools.build.lib.rules.apple.XcodeConfig; import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider; import com.google.devtools.build.lib.rules.cpp.CppCompileAction.DotdFile; import com.google.devtools.build.lib.rules.cpp.CppModuleMap; @@ -790,6 +792,34 @@ public class LegacyCompilationSupport extends CompilationSupport { } } + /** + * This method is necessary because + * {@link XcodeConfig#getMinimumOsForPlatformType(RuleContext, ApplePlatform.PlatformType)} uses + * the configuration of whichever rule it was called from; however, we are interested in the + * minimum versions for the dependencies here, which are possibly behind a configuration + * transition. + * + * <p>It's kosher to reach into {@link }AppleConfiguration} this way because we don't touch + * anything that may be tainted by data from BUILD files, only the options, which are directly + * passed into the configuration loader. + */ + private DottedVersion getExplicitMinimumOsVersion( + AppleConfiguration configuration, ApplePlatform.PlatformType platformType) { + AppleCommandLineOptions options = configuration.getOptions(); + switch (platformType) { + case IOS: + return options.iosMinimumOs; + case WATCHOS: + return options.watchosMinimumOs; + case TVOS: + return options.tvosMinimumOs; + case MACOS: + return options.macosMinimumOs; + default: + throw new IllegalStateException("Unhandled platform type: " + platformType); + } + } + /** Returns a list of clang flags used for all link and compile actions executed through clang. */ private List<String> commonLinkAndCompileFlagsForClang( ObjcProvider provider, ObjcConfiguration objcConfiguration, @@ -819,7 +849,11 @@ public class LegacyCompilationSupport extends CompilationSupport { default: throw new IllegalArgumentException("Unhandled platform " + platform); } - DottedVersion minOSVersion = appleConfiguration.getMinimumOsForPlatformType(platform.getType()); + DottedVersion minOSVersion = + getExplicitMinimumOsVersion(appleConfiguration, platform.getType()); + if (minOSVersion == null) { + minOSVersion = XcodeConfig.getMinimumOsForPlatformType(ruleContext, platform.getType()); + } builder.add(minOSVersionArg + "=" + minOSVersion); if (objcConfiguration.generateDsym()) { @@ -830,7 +864,7 @@ public class LegacyCompilationSupport extends CompilationSupport { .add("-arch", appleConfiguration.getSingleArchitecture()) .add("-isysroot", AppleToolchain.sdkDir()) // TODO(bazel-team): Pass framework search paths to Xcodegen. - .addAll(commonFrameworkFlags(provider, appleConfiguration)) + .addAll(commonFrameworkFlags(provider, ruleContext)) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBundleLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBundleLibrary.java index b44cd2dfac..aa6d9b3b01 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBundleLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBundleLibrary.java @@ -26,6 +26,7 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType; +import com.google.devtools.build.lib.rules.apple.XcodeConfig; import com.google.devtools.build.lib.rules.objc.BundleSupport.ExtraActoolArgs; import com.google.devtools.build.lib.rules.objc.ObjcCommon.ResourceAttributes; import com.google.devtools.build.lib.rules.objc.TargetDeviceFamily.InvalidFamilyNameException; @@ -103,7 +104,7 @@ public class ObjcBundleLibrary implements RuleConfiguredTargetFactory { .setObjcProvider(common.getObjcProvider()) .addInfoplistInputFromRule(ruleContext) .setIntermediateArtifacts(intermediateArtifacts) - .setMinimumOsVersion(appleConfiguration.getMinimumOsForPlatformType(PlatformType.IOS)) + .setMinimumOsVersion(XcodeConfig.getMinimumOsForPlatformType(ruleContext, PlatformType.IOS)) .setTargetDeviceFamilies(families) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcVariablesExtension.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcVariablesExtension.java index bf43087e5a..452b2606ea 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcVariablesExtension.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcVariablesExtension.java @@ -25,7 +25,6 @@ import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.packages.BuildType; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.StringSequenceBuilder; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.VariablesExtension; @@ -69,7 +68,6 @@ class ObjcVariablesExtension implements VariablesExtension { private final Artifact fullyLinkArchive; private final IntermediateArtifacts intermediateArtifacts; private final BuildConfiguration buildConfiguration; - private final AppleConfiguration appleConfiguration; private final Set<String> frameworkNames; private final ImmutableList<String> libraryNames; private final ImmutableSet<Artifact> forceLoadArtifacts; @@ -100,7 +98,6 @@ class ObjcVariablesExtension implements VariablesExtension { this.fullyLinkArchive = fullyLinkArchive; this.intermediateArtifacts = intermediateArtifacts; this.buildConfiguration = buildConfiguration; - this.appleConfiguration = buildConfiguration.getFragment(AppleConfiguration.class); this.frameworkNames = frameworkNames; this.libraryNames = libraryNames; this.forceLoadArtifacts = forceLoadArtifacts; @@ -158,7 +155,7 @@ class ObjcVariablesExtension implements VariablesExtension { private void addFrameworkVariables(CcToolchainFeatures.Variables.Builder builder) { StringSequenceBuilder frameworkSequence = new StringSequenceBuilder(); for (String framework : - CompilationSupport.commonFrameworkNames(objcProvider, appleConfiguration)) { + CompilationSupport.commonFrameworkNames(objcProvider, ruleContext)) { frameworkSequence.addValue(framework); } builder.addCustomBuiltVariable(FRAMEWORKS_VARIABLE_NAME, frameworkSequence); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java index 75c4b717d6..6aa8f487bc 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java @@ -58,6 +58,7 @@ import com.google.devtools.build.lib.rules.apple.AppleConfiguration.Configuratio import com.google.devtools.build.lib.rules.apple.ApplePlatform; import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType; import com.google.devtools.build.lib.rules.apple.DottedVersion; +import com.google.devtools.build.lib.rules.apple.XcodeConfig; import com.google.devtools.build.lib.rules.objc.BundleSupport.ExtraActoolArgs; import com.google.devtools.build.lib.rules.objc.Bundling.Builder; import com.google.devtools.build.lib.shell.ShellUtils; @@ -383,7 +384,7 @@ public final class ReleaseBundlingSupport { String.format( "%s%s", platform.getLowerCaseNameInPlist(), - configuration.getSdkVersionForPlatform(platform)); + XcodeConfig.getSdkVersionForPlatform(ruleContext, platform)); ruleContext.registerAction( ObjcRuleClasses.spawnAppleEnvActionBuilder(configuration, platform) .setMnemonic("EnvironmentPlist") @@ -410,8 +411,6 @@ public final class ReleaseBundlingSupport { private NSDictionary automaticEntries() { List<Integer> uiDeviceFamily = TargetDeviceFamily.UI_DEVICE_FAMILY_VALUES.get(bundleSupport.targetDeviceFamilies()); - AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); - NSDictionary result = new NSDictionary(); if (uiDeviceFamily != null) { @@ -420,7 +419,8 @@ public final class ReleaseBundlingSupport { result.put("DTPlatformName", platform.getLowerCaseNameInPlist()); result.put( "DTSDKName", - platform.getLowerCaseNameInPlist() + appleConfiguration.getSdkVersionForPlatform(platform)); + platform.getLowerCaseNameInPlist() + + XcodeConfig.getSdkVersionForPlatform(ruleContext, platform)); result.put("CFBundleSupportedPlatforms", new NSArray(NSObject.wrap(platform.getNameInPlist()))); result.put("MinimumOSVersion", bundling.getMinimumOsVersion().toString()); @@ -511,7 +511,7 @@ public final class ReleaseBundlingSupport { } private ImmutableList<String> getDirsToSign() { - // The order here is important. The innermost code must singed first. + // The order here is important. The innermost code must signed first. ImmutableList.Builder<String> dirsToSign = new ImmutableList.Builder<>(); String bundleDir = ShellUtils.shellEscape(bundling.getBundleDir()); @@ -838,7 +838,9 @@ public final class ReleaseBundlingSupport { new BundleMergeControlBytes( bundling, intermediateArtifacts.unprocessedIpa(), - ruleContext.getFragment(AppleConfiguration.class)); + XcodeConfig.getSdkVersionForPlatform(ruleContext, ApplePlatform.IOS_DEVICE), + ruleContext.getFragment(AppleConfiguration.class) + .getMultiArchPlatform(PlatformType.IOS)); ruleContext.registerAction( new BinaryFileWriteAction( diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingTargetFactory.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingTargetFactory.java index 68acca2432..53820e6281 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingTargetFactory.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingTargetFactory.java @@ -25,6 +25,7 @@ import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType; import com.google.devtools.build.lib.rules.apple.DottedVersion; +import com.google.devtools.build.lib.rules.apple.XcodeConfig; import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.LinkedBinary; import com.google.devtools.build.lib.rules.test.InstrumentedFilesCollector; import com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider; @@ -107,8 +108,7 @@ public abstract class ReleaseBundlingTargetFactory implements RuleConfiguredTarg * configuration). */ protected DottedVersion bundleMinimumOsVersion(RuleContext ruleContext) { - return ruleContext.getFragment(AppleConfiguration.class) - .getMinimumOsForPlatformType(PlatformType.IOS); + return XcodeConfig.getMinimumOsForPlatformType(ruleContext, PlatformType.IOS); } /** |