diff options
Diffstat (limited to 'src/main')
29 files changed, 1417 insertions, 784 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD index 7e4b7e0ca4..1c037a0f57 100644 --- a/src/main/java/com/google/devtools/build/lib/BUILD +++ b/src/main/java/com/google/devtools/build/lib/BUILD @@ -57,6 +57,7 @@ filegroup( "//src/main/java/com/google/devtools/build/lib/skyframe/packages:srcs", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:srcs", "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi:srcs", + "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple:srcs", "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp:srcs", "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi/java:srcs", "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi/platform:srcs", diff --git a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java index 0bc32e4291..038f2a7837 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java @@ -38,6 +38,7 @@ import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassNamePredicate; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import com.google.devtools.build.lib.skylarkbuildapi.SplitTransitionProviderApi; import com.google.devtools.build.lib.syntax.ClassObject; import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.EvalUtils; @@ -276,7 +277,7 @@ public final class Attribute implements Comparable<Attribute> { * based on attributes of that rule. For instance, a split transition on a rule's deps may differ * depending on the 'platform' attribute of the rule. */ - public interface SplitTransitionProvider { + public interface SplitTransitionProvider extends SplitTransitionProviderApi { /** * Returns the {@link SplitTransition} given the attribute mapper of the originating rule. */ 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 da57b6ae74..42f6949455 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 @@ -29,10 +29,8 @@ import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec; import com.google.devtools.build.lib.skyframe.serialization.SerializationContext; import com.google.devtools.build.lib.skyframe.serialization.SerializationException; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; +import com.google.devtools.build.lib.skylarkbuildapi.apple.AppleBitcodeModeApi; import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter; -import com.google.devtools.build.lib.skylarkinterface.SkylarkValue; import com.google.devtools.common.options.Converters.CommaSeparatedOptionListConverter; import com.google.devtools.common.options.EnumConverter; import com.google.devtools.common.options.Option; @@ -402,19 +400,8 @@ public class AppleCommandLineOptions extends FragmentOptions { * <p>This is a build-wide value, as bitcode mode needs to be consistent among a target and its * compiled dependencies. */ - @SkylarkModule( - name = "apple_bitcode_mode", - category = SkylarkModuleCategory.NONE, - doc = - "The Bitcode mode to use when compiling Objective-C and Swift code on Apple platforms. " - + "Possible values are:<br><ul>" - + "<li><code>'none'</code></li>" - + "<li><code>'embedded'</code></li>" - + "<li><code>'embedded_markers'</code></li>" - + "</ul>" - ) @Immutable - public enum AppleBitcodeMode implements SkylarkValue { + public enum AppleBitcodeMode implements AppleBitcodeModeApi { /** Do not compile bitcode. */ NONE("none", ImmutableList.<String>of()), 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 55b9b01a1e..22333bb41a 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 @@ -32,22 +32,16 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.rules.apple.AppleCommandLineOptions.AppleBitcodeMode; import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; -import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; +import com.google.devtools.build.lib.skylarkbuildapi.apple.AppleConfigurationApi; import java.util.ArrayList; import java.util.List; import javax.annotation.Nullable; /** A configuration containing flags required for Apple platforms and tools. */ @AutoCodec -@SkylarkModule( - name = "apple", - doc = "A configuration fragment for Apple platforms.", - category = SkylarkModuleCategory.CONFIGURATION_FRAGMENT -) @Immutable -public class AppleConfiguration extends BuildConfiguration.Fragment { +public class AppleConfiguration extends BuildConfiguration.Fragment + implements AppleConfigurationApi<PlatformType> { /** * Environment variable name for the xcode version. The value of this environment variable should * be set to the version (for example, "7.2") of xcode to use when invoking part of the apple @@ -165,10 +159,7 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { * platform or cpu for all actions spawned in this configuration; it is appropriate for * identifying the target cpu of iOS compile and link actions within this configuration. */ - @SkylarkCallable( - name = "ios_cpu", - doc = "<b>Deprecated. Use <a href='#single_arch_cpu'>single_arch_cpu</a> instead.</b> " - + "The value of ios_cpu for this configuration.") + @Override public String getIosCpu() { return iosCpu; } @@ -190,15 +181,7 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { * <li>Use the default. * </ol> */ - @SkylarkCallable( - name = "single_arch_cpu", - structField = true, - doc = - "The single \"effective\" architecture for this configuration (e.g., <code>i386</code> or " - + "<code>arm64</code>) in the context of rule logic that is only concerned with a " - + "single architecture (such as <code>objc_library</code>, which registers " - + "single-architecture compile actions)." - ) + @Override public String getSingleArchitecture() { if (!Strings.isNullOrEmpty(appleSplitCpu)) { return appleSplitCpu; @@ -272,13 +255,7 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { * the context of rule logic which is only concerned with a single architecture (such as in {@code * objc_library}, which registers single-architecture compile actions). */ - @SkylarkCallable( - name = "single_arch_platform", - doc = "The platform of the current configuration. This should only be invoked in a context " - + "where only a single architecture may be supported; consider " - + "<a href='#multi_arch_platform'>multi_arch_platform</a> for other cases.", - structField = true - ) + @Override public ApplePlatform getSingleArchPlatform() { return ApplePlatform.forTarget(applePlatformType, getSingleArchitecture()); } @@ -296,12 +273,7 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { * Otherwise, this will return a simulator platform. */ // TODO(bazel-team): This should support returning multiple platforms. - @SkylarkCallable( - name = "multi_arch_platform", - doc = "The platform of the current configuration for the given platform type. This should only " - + "be invoked in a context where multiple architectures may be supported; consider " - + "<a href='#single_arch_platform'>single_arch_platform</a> for other cases." - ) + @Override public ApplePlatform getMultiArchPlatform(PlatformType platformType) { List<String> architectures = getMultiArchitectures(platformType); switch (platformType) { @@ -342,11 +314,7 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { * #getMultiArchPlatform(PlatformType)}. */ // TODO(b/28754442): Deprecate for more general skylark-exposed platform retrieval. - @SkylarkCallable( - name = "ios_cpu_platform", - doc = "<b>Deprecated. Use <a href='#single_arch_platform'>single_arch_platform</a> or " - + "<a href='#multi_arch_platform'>multi_arch_platform</a> instead.</b> " - + "The platform given by the ios_cpu flag.") + @Override public ApplePlatform getIosCpuPlatform() { return ApplePlatform.forTarget(PlatformType.IOS, iosCpu); } @@ -393,13 +361,7 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { * * @see AppleBitcodeMode */ - @SkylarkCallable( - name = "bitcode_mode", - doc = "Returns the Bitcode mode to use for compilation steps.<p>" - + "This field is only valid for device builds; for simulator builds, it always returns " - + "<code>'none'</code>.", - structField = true - ) + @Override public AppleBitcodeMode getBitcodeMode() { if (hasValidSingleArchPlatform() && getSingleArchPlatform().isDevice()) { return bitcodeMode; diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/ApplePlatform.java b/src/main/java/com/google/devtools/build/lib/rules/apple/ApplePlatform.java index cc8fb96b30..561843acb0 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/ApplePlatform.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/ApplePlatform.java @@ -22,45 +22,16 @@ import com.google.devtools.build.lib.packages.Info; import com.google.devtools.build.lib.packages.NativeProvider; import com.google.devtools.build.lib.packages.Provider; import com.google.devtools.build.lib.packages.SkylarkInfo; -import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; +import com.google.devtools.build.lib.skylarkbuildapi.apple.ApplePlatformApi; +import com.google.devtools.build.lib.skylarkbuildapi.apple.ApplePlatformTypeApi; import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter; -import com.google.devtools.build.lib.skylarkinterface.SkylarkValue; import java.util.HashMap; import java.util.Locale; import javax.annotation.Nullable; /** An enum that can be used to distinguish between various apple platforms. */ -@SkylarkModule( - name = "apple_platform", - category = SkylarkModuleCategory.NONE, - doc = "Corresponds to Xcode's notion of a platform as would be found in " - + "<code>Xcode.app/Contents/Developer/Platforms</code>. Each platform represents an Apple " - + "platform type (such as iOS or tvOS) combined with one or more related CPU " - + "architectures. For example, the iOS simulator platform supports <code>x86_64</code> and " - + "<code>i386</code> architectures.<p>" - + "Specific instances of this type can be retrieved from the fields of the " - + "<a href='apple_common.html#platform'>apple_common.platform</a> struct:<br><ul>" - + "<li><code>apple_common.platform.ios_device</code></li>" - + "<li><code>apple_common.platform.ios_simulator</code></li>" - + "<li><code>apple_common.platform.macos</code></li>" - + "<li><code>apple_common.platform.tvos_device</code></li>" - + "<li><code>apple_common.platform.tvos_simulator</code></li>" - + "<li><code>apple_common.platform.watchos_device</code></li>" - + "<li><code>apple_common.platform.watchos_simulator</code></li>" - + "</ul><p>" - + "More commonly, however, the <a href='apple.html'>apple</a> configuration fragment has " - + "fields/methods that allow rules to determine the platform for which a target is being " - + "built.<p>" - + "Example:<br>" - + "<pre class='language-python'>\n" - + "p = apple_common.platform.ios_device\n" - + "print(p.name_in_plist) # 'iPhoneOS'\n" - + "</pre>" -) @Immutable -public enum ApplePlatform implements SkylarkValue { +public enum ApplePlatform implements ApplePlatformApi { IOS_DEVICE("ios_device", "iPhoneOS", PlatformType.IOS, true), IOS_SIMULATOR("ios_simulator", "iPhoneSimulator", PlatformType.IOS, false), MACOS("macos", "MacOSX", PlatformType.MACOS, true), @@ -100,40 +71,17 @@ public enum ApplePlatform implements SkylarkValue { this.isDevice = isDevice; } - /** Returns the platform type of this platform. */ - @SkylarkCallable( - name = "platform_type", - doc = "Returns the platform type of this platform.", - structField = true - ) + @Override public PlatformType getType() { return platformType; } - /** - * Returns true if this platform is a device platform, or false if this is a simulator platform. - */ - @SkylarkCallable( - name = "is_device", - doc = "Returns <code>True</code> if this platform is a device platform or <code>False</code> " - + "if it is a simulator platform.", - structField = true - ) + @Override public boolean isDevice() { return isDevice; } - /** - * Returns the name of the "platform" as it appears in the CFBundleSupportedPlatforms plist - * setting. - */ - @SkylarkCallable(name = "name_in_plist", structField = true, - doc = "The name of the platform as it appears in the <code>CFBundleSupportedPlatforms</code> " - + "entry of an Info.plist file and in Xcode's platforms directory, without the extension " - + "(for example, <code>iPhoneOS</code> or <code>iPhoneSimulator</code>).<br>" - + "This name, when converted to lowercase (e.g., <code>iphoneos</code>, " - + "<code>iphonesimulator</code>), can be passed to Xcode's command-line tools like " - + "<code>ibtool</code> and <code>actool</code> when they expect a platform name.") + @Override public String getNameInPlist() { return nameInPlist; } @@ -246,26 +194,8 @@ public enum ApplePlatform implements SkylarkValue { * platform type (for example, watchOS) together with a cpu value (for example, armv7). */ // TODO(cparsons): Use these values in static retrieval methods in this class. - @SkylarkModule( - name = "apple_platform_type", - category = SkylarkModuleCategory.NONE, - doc = "Describes an Apple \"platform type\", such as iOS, macOS, tvOS, or watchOS. This is " - + "distinct from a \"platform\", which is the platform type combined with one or more CPU " - + "architectures.<p>" - + "Specific instances of this type can be retrieved by accessing the fields of the " - + "<a href='apple_common.html#platform_type'>apple_common.platform_type</a>:<br><ul>" - + "<li><code>apple_common.platform_type.ios</code></li>" - + "<li><code>apple_common.platform_type.macos</code></li>" - + "<li><code>apple_common.platform_type.tvos</code></li>" - + "<li><code>apple_common.platform_type.watchos</code></li>" - + "</ul><p>" - + "Likewise, the platform type of an existing platform value can be retrieved using its " - + "<code>platform_type</code> field.<p>" - + "Platform types can be converted to a lowercase string (e.g., <code>ios</code> or " - + "<code>macos</code>) using the <a href='globals.html#str'>str</a> function." - ) @Immutable - public enum PlatformType implements SkylarkValue { + public enum PlatformType implements ApplePlatformTypeApi { IOS("ios"), WATCHOS("watchos"), TVOS("tvos"), 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 cf6cbf5be6..21e3ffba45 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 @@ -27,18 +27,13 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.packages.Attribute.LabelLateBoundDefault; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType; -import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkbuildapi.apple.AppleToolchainApi; /** * Utility class for resolving items for the Apple toolchain (such as common tool flags, and paths). */ -@SkylarkModule( - name = "apple_toolchain", - doc = "Utilities for resolving items from the Apple toolchain." -) @Immutable -public class AppleToolchain { +public class AppleToolchain implements AppleToolchainApi<AppleConfiguration> { // These next two strings are shared secrets with the xcrunwrapper.sh to allow // expansion of DeveloperDir and SDKRoot and runtime, since they aren't known @@ -82,10 +77,6 @@ public class AppleToolchain { /** * Returns the platform directory inside of Xcode for a given configuration. */ - @SkylarkCallable( - name = "sdk_dir", - doc = "Returns the platform directory inside of Xcode for a given configuration." - ) public static String sdkDir() { return SDKROOT_DIR; } @@ -93,31 +84,23 @@ public class AppleToolchain { /** * Returns the Developer directory inside of Xcode for a given configuration. */ - @SkylarkCallable( - name = "developer_dir", - doc = "Returns the Developer directory inside of Xcode for a given configuration." - ) public static String developerDir() { return DEVELOPER_DIR; } /** - * Returns the platform frameworks directory inside of Xcode for a given {@link ApplePlatform}. + * Returns the platform frameworks directory inside of Xcode for a given configuration. */ - public static String platformDeveloperFrameworkDir(ApplePlatform platform) { - String platformDir = platformDir(platform.getNameInPlist()); - return platformDir + "/Developer/Library/Frameworks"; + public static String platformDeveloperFrameworkDir(AppleConfiguration configuration) { + return platformDeveloperFrameworkDir(configuration.getSingleArchPlatform()); } /** - * Returns the platform frameworks directory inside of Xcode for a given configuration. + * Returns the platform frameworks directory inside of Xcode for a given {@link ApplePlatform}. */ - @SkylarkCallable( - name = "platform_developer_framework_dir", - doc = "Returns the platform frameworks directory inside of Xcode for a given configuration." - ) - public static String platformFrameworkDirFromConfig(AppleConfiguration configuration) { - return platformDeveloperFrameworkDir(configuration.getSingleArchPlatform()); + public static String platformDeveloperFrameworkDir(ApplePlatform platform) { + String platformDir = platformDir(platform.getNameInPlist()); + return platformDir + "/Developer/Library/Frameworks"; } /** Returns the SDK frameworks directory inside of Xcode for a given configuration. */ @@ -157,6 +140,30 @@ public class AppleToolchain { } /** + * Returns the platform directory inside of Xcode for a given configuration. + */ + @Override + public String sdkDirConstant() { + return sdkDir(); + } + + /** + * Returns the Developer directory inside of Xcode for a given configuration. + */ + @Override + public String developerDirConstant() { + return developerDir(); + } + + /** + * Returns the platform frameworks directory inside of Xcode for a given configuration. + */ + @Override + public String platformFrameworkDirFromConfig(AppleConfiguration configuration) { + return platformDeveloperFrameworkDir(configuration); + } + + /** * Base rule definition to be ancestor for rules which may require an xcode toolchain. */ public static class RequiresXcodeConfigRule implements RuleDefinition { diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/BUILD b/src/main/java/com/google/devtools/build/lib/rules/apple/BUILD index 4ad39bc4f1..d03e842b13 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/BUILD +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/BUILD @@ -23,6 +23,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/concurrent", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", + "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple", "//src/main/java/com/google/devtools/common/options", "//third_party:guava", "//third_party:jsr305", 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 189462e947..9919ff757d 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 @@ -22,11 +22,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Ordering; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; -import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; +import com.google.devtools.build.lib.skylarkbuildapi.apple.DottedVersionApi; import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter; -import com.google.devtools.build.lib.skylarkinterface.SkylarkValue; import java.util.ArrayList; import java.util.Objects; import java.util.regex.Matcher; @@ -72,16 +69,9 @@ import javax.annotation.Nullable; * * <p>This class is immutable and can safely be shared among threads. */ -@SkylarkModule( - name = "DottedVersion", - category = SkylarkModuleCategory.NONE, - doc = - "A value representing a version with multiple components, separated by periods, such as " - + "1.2.3.4." -) @Immutable @AutoCodec -public final class DottedVersion implements Comparable<DottedVersion>, SkylarkValue { +public final class DottedVersion implements DottedVersionApi<DottedVersion> { private static final Splitter DOT_SPLITTER = Splitter.on('.'); private static final Pattern COMPONENT_PATTERN = Pattern.compile("(\\d+)(?:([a-z]+)(\\d*))?"); private static final String ILLEGAL_VERSION = @@ -173,12 +163,7 @@ public final class DottedVersion implements Comparable<DottedVersion>, SkylarkVa return 0; } - @SkylarkCallable( - name = "compare_to", - doc = - "Compares based on most significant (first) not-matching version component. " - + "So, for example, 1.2.3 < 1.2.4" - ) + @Override public int compareTo_skylark(DottedVersion other) { return compareTo(other); } 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 index 50db482da5..589d6599e4 100644 --- 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 @@ -19,18 +19,15 @@ import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTa import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.packages.NativeInfo; import com.google.devtools.build.lib.packages.NativeProvider; -import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkbuildapi.apple.XcodeConfigProviderApi; import javax.annotation.Nullable; /** * The set of Apple versions computed from command line options and the {@code xcode_config} rule. */ @Immutable -@SkylarkModule( - name = XcodeConfigProvider.SKYLARK_NAME, - doc = "The set of Apple versions computed from command line options and the xcode_config rule.") -public class XcodeConfigProvider extends NativeInfo { +public class XcodeConfigProvider extends NativeInfo + implements XcodeConfigProviderApi<ApplePlatform, ApplePlatform.PlatformType> { /** Skylark name for this provider. */ public static final String SKYLARK_NAME = "XcodeVersionConfig"; @@ -66,18 +63,12 @@ public class XcodeConfigProvider extends NativeInfo { this.xcodeVersion = xcodeVersion; } - @SkylarkCallable(name = "xcode_version", - doc = "Returns the Xcode version that is being used to build.<p>" - + "This will return <code>None</code> if no Xcode versions are available.", - allowReturnNones = true) + @Override public DottedVersion getXcodeVersion() { return xcodeVersion; } - @SkylarkCallable( - name = "minimum_os_for_platform_type", - doc = "The minimum compatible OS version for target simulator and devices for a particular " - + "platform type.") + @Override 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. @@ -95,10 +86,7 @@ public class XcodeConfigProvider extends NativeInfo { } } - @SkylarkCallable( - name = "sdk_version_for_platform", - doc = "The version of the platform SDK that will be used to build targets for the given " - + "platform.") + @Override public DottedVersion getSdkVersionForPlatform(ApplePlatform platform) { switch (platform) { case IOS_DEVICE: 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 1f14012e5f..dbe364e662 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 @@ -96,7 +96,7 @@ public class AppleCcToolchain extends CcToolchain { SDK_FRAMEWORK_DIR_KEY, AppleToolchain.sdkFrameworkDir(platform, ruleContext)) .addStringVariable( PLATFORM_DEVELOPER_FRAMEWORK_DIR, - AppleToolchain.platformFrameworkDirFromConfig(appleConfiguration)) + AppleToolchain.platformDeveloperFrameworkDir(appleConfiguration)) .addStringVariable( XCODE_VERISON_OVERRIDE_VALUE_KEY, appleEnv.getOrDefault(AppleConfiguration.XCODE_VERSION_ENV_NAME, "")) diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleDynamicFrameworkInfo.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleDynamicFrameworkInfo.java index 6555f8a951..66011d412d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleDynamicFrameworkInfo.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleDynamicFrameworkInfo.java @@ -19,9 +19,7 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.packages.NativeInfo; import com.google.devtools.build.lib.packages.NativeProvider; -import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; +import com.google.devtools.build.lib.skylarkbuildapi.apple.AppleDynamicFrameworkInfoApi; import com.google.devtools.build.lib.vfs.PathFragment; import javax.annotation.Nullable; @@ -40,12 +38,8 @@ import javax.annotation.Nullable; * </ul> */ @Immutable -@SkylarkModule( - name = "AppleDynamicFramework", - category = SkylarkModuleCategory.PROVIDER, - doc = "A provider containing information about an Apple dynamic framework." -) -public final class AppleDynamicFrameworkInfo extends NativeInfo { +public final class AppleDynamicFrameworkInfo extends NativeInfo + implements AppleDynamicFrameworkInfoApi<PathFragment, Artifact> { /** Skylark name for the AppleDynamicFrameworkInfo. */ public static final String SKYLARK_NAME = "AppleDynamicFramework"; @@ -80,55 +74,22 @@ public final class AppleDynamicFrameworkInfo extends NativeInfo { this.dynamicFrameworkFiles = dynamicFrameworkFiles; } - /** - * Returns the framework path names used as link inputs in order to link against the dynamic - * framework. - */ - @SkylarkCallable(name = "framework_dirs", - structField = true, - doc = "The framework path names used as link inputs in order to link against the dynamic " - + "framework." - ) + @Override public NestedSet<PathFragment> getDynamicFrameworkDirs() { return dynamicFrameworkDirs; } - /** - * Returns the full set of artifacts that should be included as inputs to link against the - * dynamic framework. - */ - @SkylarkCallable(name = "framework_files", - structField = true, - doc = "The full set of files that should be included as inputs to link against the " - + "dynamic framework." - ) + @Override public NestedSet<Artifact> getDynamicFrameworkFiles() { return dynamicFrameworkFiles; } - /** - * Returns the multi-architecture dylib binary of the dynamic framework. May return null if - * the rule providing the framework only specified framework imports. - */ - @Nullable - @SkylarkCallable(name = "binary", - structField = true, - doc = "The multi-architecture dylib binary of the dynamic framework. May be null if " - + "the rule providing the framework only specified framework imports." - ) + @Override public Artifact getAppleDylibBinary() { return dylibBinary; } - /** - * Returns the {@link ObjcProvider} which contains information about the transitive dependencies - * linked into the dylib. - */ - @SkylarkCallable(name = "objc", - structField = true, - doc = "A provider which contains information about the transitive dependencies linked into " - + "the dynamic framework." - ) + @Override public ObjcProvider getDepsObjcProvider() { return depsObjcProvider; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java index efec1c23ad..9e4daaddb1 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java @@ -39,9 +39,8 @@ import com.google.devtools.build.lib.rules.apple.XcodeConfigProvider; import com.google.devtools.build.lib.rules.apple.XcodeVersionProperties; import com.google.devtools.build.lib.rules.objc.AppleBinary.AppleBinaryOutput; import com.google.devtools.build.lib.rules.objc.ObjcProvider.Key; -import com.google.devtools.build.lib.skylarkinterface.Param; -import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkbuildapi.SkylarkRuleContextApi; +import com.google.devtools.build.lib.skylarkbuildapi.apple.AppleCommonApi; import com.google.devtools.build.lib.syntax.Environment; import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.Runtime; @@ -55,11 +54,8 @@ import javax.annotation.Nullable; /** * A class that exposes apple rule implementation internals to skylark. */ -@SkylarkModule( - name = "apple_common", - doc = "Functions for skylark to access internals of the apple rule implementations." -) -public class AppleSkylarkCommon { +public class AppleSkylarkCommon + implements AppleCommonApi<Artifact, ObjcProvider, XcodeConfigProvider, ApplePlatform> { @VisibleForTesting public static final String BAD_KEY_ERROR = "Argument %s not a recognized key, 'providers'," @@ -93,33 +89,12 @@ public class AppleSkylarkCommon { this.objcProtoAspect = objcProtoAspect; } - @SkylarkCallable( - name = "apple_toolchain", - doc = "Utilities for resolving items from the apple toolchain." - ) + @Override public AppleToolchain getAppleToolchain() { return new AppleToolchain(); } - @SkylarkCallable( - name = "platform_type", - doc = - "An enum-like struct that contains the following fields corresponding to Apple platform " - + "types:<br><ul>" - + "<li><code>ios</code></li>" - + "<li><code>macos</code></li>" - + "<li><code>tvos</code></li>" - + "<li><code>watchos</code></li>" - + "</ul><p>" - + "These values can be passed to methods that expect a platform type, like the 'apple' " - + "configuration fragment's " - + "<a href='apple.html#multi_arch_platform'>multi_arch_platform</a> method.<p>" - + "Example:<p>" - + "<pre class='language-python'>\n" - + "ctx.fragments.apple.multi_arch_platform(apple_common.platform_type.ios)\n" - + "</pre>", - structField = true - ) + @Override public Info getPlatformTypeStruct() { if (platformType == null) { platformType = PlatformType.getSkylarkStruct(); @@ -127,23 +102,7 @@ public class AppleSkylarkCommon { return platformType; } - @SkylarkCallable( - name = "platform", - doc = - "An enum-like struct that contains the following fields corresponding to Apple " - + "platforms:<br><ul>" - + "<li><code>ios_device</code></li>" - + "<li><code>ios_simulator</code></li>" - + "<li><code>macos</code></li>" - + "<li><code>tvos_device</code></li>" - + "<li><code>tvos_simulator</code></li>" - + "<li><code>watchos_device</code></li>" - + "<li><code>watchos_device</code></li>" - + "</ul><p>" - + "These values can be passed to methods that expect a platform, like " - + "<a href='apple.html#sdk_version_for_platform'>apple.sdk_version_for_platform</a>.", - structField = true - ) + @Override public Info getPlatformStruct() { if (platform == null) { platform = ApplePlatform.getSkylarkStruct(); @@ -151,218 +110,71 @@ public class AppleSkylarkCommon { return platform; } - @SkylarkCallable( - name = XcodeVersionProperties.SKYLARK_NAME, - doc = - "The constructor/key for the <code>XcodeVersionProperties</code> provider.<p>" - + "If a target propagates the <code>XcodeVersionProperties</code> provider," - + " use this as the key with which to retrieve it. Example:<br>" - + "<pre class='language-python'>\n" - + "dep = ctx.attr.deps[0]\n" - + "p = dep[apple_common.XcodeVersionProperties]\n" - + "</pre>", - structField = true - ) + @Override public Provider getXcodeVersionPropertiesConstructor() { return XcodeVersionProperties.SKYLARK_CONSTRUCTOR; } - @SkylarkCallable( - name = XcodeConfigProvider.SKYLARK_NAME, - doc = "The constructor/key for the <code>XcodeVersionConfig</code> provider.", - structField = true - ) + @Override public Provider getXcodeVersionConfigConstructor() { return XcodeConfigProvider.PROVIDER; } - @SkylarkCallable( - // TODO(b/63899207): This currently does not match ObjcProvider.SKYLARK_NAME as it requires - // a migration of existing skylark rules. - name = "Objc", - doc = - "The constructor/key for the <code>Objc</code> provider.<p>" - + "If a target propagates the <code>Objc</code> provider, use this as the " - + "key with which to retrieve it. Example:<br>" - + "<pre class='language-python'>\n" - + "dep = ctx.attr.deps[0]\n" - + "p = dep[apple_common.Objc]\n" - + "</pre>", - structField = true - ) + @Override public Provider getObjcProviderConstructor() { return ObjcProvider.SKYLARK_CONSTRUCTOR; } - @SkylarkCallable( - name = AppleDynamicFrameworkInfo.SKYLARK_NAME, - doc = - "The constructor/key for the <code>AppleDynamicFramework</code> provider.<p>" - + "If a target propagates the <code>AppleDynamicFramework</code> provider, use this " - + "as the key with which to retrieve it. Example:<br>" - + "<pre class='language-python'>\n" - + "dep = ctx.attr.deps[0]\n" - + "p = dep[apple_common.AppleDynamicFramework]\n" - + "</pre>", - structField = true - ) + @Override public Provider getAppleDynamicFrameworkConstructor() { return AppleDynamicFrameworkInfo.SKYLARK_CONSTRUCTOR; } - @SkylarkCallable( - name = AppleDylibBinaryInfo.SKYLARK_NAME, - doc = - "The constructor/key for the <code>AppleDylibBinary</code> provider.<p>" - + "If a target propagates the <code>AppleDylibBinary</code> provider, use this as the " - + "key with which to retrieve it. Example:<br>" - + "<pre class='language-python'>\n" - + "dep = ctx.attr.deps[0]\n" - + "p = dep[apple_common.AppleDylibBinary]\n" - + "</pre>", - structField = true - ) + @Override public Provider getAppleDylibBinaryConstructor() { return AppleDylibBinaryInfo.SKYLARK_CONSTRUCTOR; } - @SkylarkCallable( - name = AppleExecutableBinaryInfo.SKYLARK_NAME, - doc = - "The constructor/key for the <code>AppleExecutableBinary</code> provider.<p>" - + "If a target propagates the <code>AppleExecutableBinary</code> provider," - + " use this as the key with which to retrieve it. Example:<br>" - + "<pre class='language-python'>\n" - + "dep = ctx.attr.deps[0]\n" - + "p = dep[apple_common.AppleExecutableBinary]\n" - + "</pre>", - structField = true - ) + @Override public Provider getAppleExecutableBinaryConstructor() { return AppleExecutableBinaryInfo.SKYLARK_CONSTRUCTOR; } - @SkylarkCallable( - name = AppleStaticLibraryInfo.SKYLARK_NAME, - doc = - "The constructor/key for the <code>AppleStaticLibrary</code> provider.<p>" - + "If a target propagates the <code>AppleStaticLibrary</code> provider, use " - + "this as the key with which to retrieve it. Example:<br>" - + "<pre class='language-python'>\n" - + "dep = ctx.attr.deps[0]\n" - + "p = dep[apple_common.AppleStaticLibrary]\n" - + "</pre>", - structField = true - ) + @Override public AppleStaticLibraryInfo.Provider getAppleStaticLibraryProvider() { return AppleStaticLibraryInfo.SKYLARK_CONSTRUCTOR; } - @SkylarkCallable( - name = AppleDebugOutputsInfo.SKYLARK_NAME, - doc = - "The constructor/key for the <code>AppleDebugOutputs</code> provider.<p>" - + "If a target propagates the <code>AppleDebugOutputs</code> provider, use this as the " - + "key with which to retrieve it. Example:<br>" - + "<pre class='language-python'>\n" - + "dep = ctx.attr.deps[0]\n" - + "p = dep[apple_common.AppleDebugOutputs]\n" - + "</pre>", - structField = true - ) + @Override public Provider getAppleDebugOutputsConstructor() { return AppleDebugOutputsInfo.SKYLARK_CONSTRUCTOR; } - @SkylarkCallable( - name = AppleLoadableBundleBinaryInfo.SKYLARK_NAME, - doc = - "The constructor/key for the <code>AppleLoadableBundleBinary</code> provider.<p>" - + "If a target propagates the <code>AppleLoadableBundleBinary</code> provider, " - + "use this as the key with which to retrieve it. Example:<br>" - + "<pre class='language-python'>\n" - + "dep = ctx.attr.deps[0]\n" - + "p = dep[apple_common.AppleLoadableBundleBinary]\n" - + "</pre>", - structField = true - ) + @Override public Provider getAppleLoadableBundleBinaryConstructor() { return AppleLoadableBundleBinaryInfo.SKYLARK_CONSTRUCTOR; } - @SkylarkCallable( - name = "apple_host_system_env", - doc = - "Returns a <a href='dict.html'>dict</a> of environment variables that should be set " - + "for actions that need to run build tools on an Apple host system, such as the " - + " version of Xcode that should be used. The keys are variable names and the values " - + " are their corresponding values." - ) + @Override public ImmutableMap<String, String> getAppleHostSystemEnv(XcodeConfigProvider xcodeConfig) { return AppleConfiguration.getXcodeVersionEnv(xcodeConfig.getXcodeVersion()); } - @SkylarkCallable( - name = "target_apple_env", - doc = - "Returns a <code>dict</code> of environment variables that should be set for actions " - + "that build targets of the given Apple platform type. For example, this dictionary " - + "contains variables that denote the platform name and SDK version with which to " - + "build. The keys are variable names and the values are their corresponding values." - ) + @Override public ImmutableMap<String, String> getTargetAppleEnvironment( - XcodeConfigProvider xcodeConfig, ApplePlatform platform) { + XcodeConfigProvider xcodeConfigApi, ApplePlatform platformApi) { + XcodeConfigProvider xcodeConfig = (XcodeConfigProvider) xcodeConfigApi; + ApplePlatform platform = (ApplePlatform) platformApi; return AppleConfiguration.appleTargetPlatformEnv( platform, xcodeConfig.getSdkVersionForPlatform(platform)); } - @SkylarkCallable( - name = "multi_arch_split", - doc = "A configuration transition for rule attributes to build dependencies in one or" - + " more Apple platforms. " - + "<p>Use of this transition requires that the 'platform_type' and 'minimum_os_version'" - + " string attributes are defined and mandatory on the rule.</p>" - + "<p>The value of the platform_type attribute will dictate the target architectures " - + " for which dependencies along this configuration transition will be built.</p>" - + "<p>Options are:</p>" - + "<ul>" - + "<li><code>ios</code>: architectures gathered from <code>--ios_multi_cpus</code>.</li>" - + "<li><code>macos</code>: architectures gathered from <code>--macos_cpus</code>.</li>" - + "<li><code>tvos</code>: architectures gathered from <code>--tvos_cpus</code>.</li>" - + "<li><code>watchos</code>: architectures gathered from <code>--watchos_cpus</code>." - + "</li></ul>" - + "<p>minimum_os_version should be a dotted version string such as '7.3', and is used to" - + " set the minimum operating system on the configuration similarly based on platform" - + " type. For example, specifying platform_type 'ios' and minimum_os_version '8.0' will" - + " ensure that dependencies are built with minimum iOS version '8.0'.", - structField = true - ) + @Override public SplitTransitionProvider getMultiArchSplitProvider() { return new MultiArchSplitTransitionProvider(); } - @SkylarkCallable( - name = "new_objc_provider", - doc = "Creates a new ObjcProvider instance.", - parameters = { - @Param( - name = "uses_swift", - type = Boolean.class, - defaultValue = "False", - named = true, - positional = false, - doc = "Whether this provider should enable Swift support." - ) - }, - extraKeywords = - @Param( - name = "kwargs", - type = SkylarkDict.class, - defaultValue = "{}", - doc = "Dictionary of arguments." - ), - useEnvironment = true - ) + @Override // This method is registered statically for skylark, and never called directly. public ObjcProvider newObjcProvider( Boolean usesSwift, @@ -392,52 +204,7 @@ public class AppleSkylarkCommon { return resultBuilder.build(); } - @SkylarkCallable( - name = "new_dynamic_framework_provider", - doc = "Creates a new AppleDynamicFramework provider instance.", - parameters = { - @Param( - name = AppleDynamicFrameworkInfo.DYLIB_BINARY_FIELD_NAME, - type = Artifact.class, - named = true, - positional = false, - doc = "The dylib binary artifact of the dynamic framework." - ), - @Param( - name = AppleDynamicFrameworkInfo.OBJC_PROVIDER_FIELD_NAME, - type = ObjcProvider.class, - named = true, - positional = false, - doc = - "An ObjcProvider which contains information about the transitive " - + "dependencies linked into the binary." - ), - @Param( - name = AppleDynamicFrameworkInfo.FRAMEWORK_DIRS_FIELD_NAME, - type = SkylarkNestedSet.class, - generic1 = String.class, - named = true, - noneable = true, - positional = false, - defaultValue = "None", - doc = - "The framework path names used as link inputs in order to link against the dynamic " - + "framework." - ), - @Param( - name = AppleDynamicFrameworkInfo.FRAMEWORK_FILES_FIELD_NAME, - type = SkylarkNestedSet.class, - generic1 = Artifact.class, - named = true, - noneable = true, - positional = false, - defaultValue = "None", - doc = - "The full set of artifacts that should be included as inputs to link against the " - + "dynamic framework" - ) - } - ) + @Override public AppleDynamicFrameworkInfo newDynamicFrameworkProvider( Artifact dylibBinary, ObjcProvider depsObjcProvider, @@ -462,18 +229,10 @@ public class AppleSkylarkCommon { dylibBinary, depsObjcProvider, frameworkDirs, frameworkFiles); } - @SkylarkCallable( - name = "link_multi_arch_binary", - doc = "Links a (potentially multi-architecture) binary targeting Apple platforms. This " - + "method comprises a bulk of the logic of the <code>apple_binary</code> rule, and is " - + "exposed as an API to iterate on migration of <code>apple_binary</code> to skylark.\n" - + "<p>This API is <b>highly experimental</b> and subject to change at any time. Do not " - + "depend on the stability of this function at this time.", - mandatoryPositionals = 1 // The SkylarkRuleContext. - ) - // TODO(b/70937317): Iterate on, improve, and solidify this API. - public NativeInfo linkMultiArchBinary(SkylarkRuleContext skylarkRuleContext) + @Override + public NativeInfo linkMultiArchBinary(SkylarkRuleContextApi skylarkRuleContextApi) throws EvalException, InterruptedException { + SkylarkRuleContext skylarkRuleContext = (SkylarkRuleContext) skylarkRuleContextApi; try { RuleContext ruleContext = skylarkRuleContext.getRuleContext(); AppleBinaryOutput appleBinaryOutput = AppleBinary.linkMultiArchBinary(ruleContext); @@ -483,28 +242,12 @@ public class AppleSkylarkCommon { } } - @SkylarkCallable( - name = "dotted_version", - doc = "Creates a new <a href=\"DottedVersion.html\">DottedVersion</a> instance.", - parameters = { - @Param( - name = "version", - type = String.class, - doc = "The string representation of the DottedVersion." - ) - } - ) + @Override public DottedVersion dottedVersion(String version) { return DottedVersion.fromString(version); } - @SkylarkCallable( - name = "objc_proto_aspect", - doc = - "objc_proto_aspect gathers the proto dependencies of the attached rule target," - + "and propagates the proto values of its dependencies through the ObjcProto provider.", - structField = true - ) + @Override public SkylarkAspect getObjcProtoAspect() { return objcProtoAspect; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibraryInfo.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibraryInfo.java index 6515719243..bfa557e29b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibraryInfo.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibraryInfo.java @@ -17,11 +17,7 @@ package com.google.devtools.build.lib.rules.objc; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.packages.BuiltinProvider; import com.google.devtools.build.lib.packages.NativeInfo; -import com.google.devtools.build.lib.skylarkinterface.Param; -import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; -import com.google.devtools.build.lib.skylarkinterface.SkylarkConstructor; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; +import com.google.devtools.build.lib.skylarkbuildapi.apple.AppleStaticLibraryInfoApi; import com.google.devtools.build.lib.syntax.EvalException; /** @@ -37,16 +33,7 @@ import com.google.devtools.build.lib.syntax.EvalException; * included in this archive multiple times). * </ul> */ -@SkylarkModule( - name = "AppleStaticLibrary", - category = SkylarkModuleCategory.PROVIDER, - doc = "A provider containing information regarding multi-architecture Apple static libraries, " - + "as is propagated by the apple_static_library rule." -) -public final class AppleStaticLibraryInfo extends NativeInfo { - - /** Skylark name for the AppleStaticLibraryInfo. */ - public static final String SKYLARK_NAME = "AppleStaticLibrary"; +public final class AppleStaticLibraryInfo extends NativeInfo implements AppleStaticLibraryInfoApi { /** Skylark constructor and identifier for AppleStaticLibraryInfo. */ public static final Provider SKYLARK_CONSTRUCTOR = new Provider(); @@ -65,26 +52,12 @@ public final class AppleStaticLibraryInfo extends NativeInfo { this.depsObjcProvider = depsObjcProvider; } - /** - * Returns the multi-architecture archive that {@code apple_static_library} created. - */ - @SkylarkCallable(name = "archive", - structField = true, - doc = "The multi-arch archive (.a) output by apple_static_library." - ) + @Override public Artifact getMultiArchArchive() { return multiArchArchive; } - /** - * Returns the {@link ObjcProvider} which contains information about the transitive dependencies - * linked into the archive. - */ - @SkylarkCallable(name = "objc", - structField = true, - doc = "A provider which contains information about the transitive dependencies linked into " - + "the archive." - ) + @Override public ObjcProvider getDepsObjcProvider() { return depsObjcProvider; } @@ -92,33 +65,13 @@ public final class AppleStaticLibraryInfo extends NativeInfo { /** * Provider class for {@link AppleStaticLibraryInfo} objects. */ - public static class Provider extends BuiltinProvider<AppleStaticLibraryInfo> { + public static class Provider extends BuiltinProvider<AppleStaticLibraryInfo> + implements AppleStaticLibraryInfoApi.AppleStaticLibraryInfoProvider<Artifact, ObjcProvider> { private Provider() { super(SKYLARK_NAME, AppleStaticLibraryInfo.class); } - @SkylarkCallable( - name = SKYLARK_NAME, - doc = "The <code>AppleStaticLibrary</code> constructor.", - parameters = { - @Param( - name = "archive", - type = Artifact.class, - named = true, - positional = false, - doc = "Multi-architecture archive (.a) representing a static library"), - @Param( - name = "objc", - type = ObjcProvider.class, - named = true, - positional = false, - doc = "A provider which contains information about the transitive dependencies " - + "linked into the archive."), - }, - selfCall = true) - @SkylarkConstructor( - objectType = AppleStaticLibraryInfo.class, - receiverNameForDoc = "apple_common.AppleStaticLibrary") + @Override public AppleStaticLibraryInfo appleStaticLibrary( Artifact archive, ObjcProvider objcProvider) throws EvalException { return new AppleStaticLibraryInfo(archive, objcProvider); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BUILD b/src/main/java/com/google/devtools/build/lib/rules/objc/BUILD index 371c58903a..5a2c8ca33d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/BUILD +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BUILD @@ -33,6 +33,8 @@ java_library( "//src/main/java/com/google/devtools/build/lib/rules/cpp", "//src/main/java/com/google/devtools/build/lib/shell", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", + "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi", + "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple", "//src/main/java/com/google/devtools/build/lib/vfs", "//src/main/java/com/google/devtools/common/options", "//src/main/protobuf:bundlemerge_java_proto", diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java index 127e5030a9..e4c13b0d58 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java @@ -38,9 +38,7 @@ import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo; import com.google.devtools.build.lib.rules.cpp.CppModuleMap; import com.google.devtools.build.lib.rules.cpp.LinkerInputs; import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink; -import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; +import com.google.devtools.build.lib.skylarkbuildapi.apple.ObjcProviderApi; import com.google.devtools.build.lib.syntax.EvalUtils; import com.google.devtools.build.lib.syntax.SkylarkNestedSet; import com.google.devtools.build.lib.syntax.SkylarkSemantics; @@ -54,12 +52,7 @@ import java.util.Map; * deps that are needed for building Objective-C rules. */ @Immutable -@SkylarkModule( - name = "ObjcProvider", - category = SkylarkModuleCategory.PROVIDER, - doc = "A provider for compilation and linking of objc." -) -public final class ObjcProvider extends NativeInfo { +public final class ObjcProvider extends NativeInfo implements ObjcProviderApi<Artifact> { /** Skylark name for the ObjcProvider. */ public static final String SKYLARK_NAME = "objc"; @@ -427,341 +420,201 @@ public final class ObjcProvider extends NativeInfo { XCDATAMODEL, XIB); - @SkylarkCallable(name = "asset_catalog", - structField = true, - doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " - + "Asset catalog resource files." - ) + @Override public NestedSet<Artifact> assetCatalog() { return get(ASSET_CATALOG); } - @SkylarkCallable(name = "bundle_file", - structField = true, - doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " - + "Files that are plopped into the final bundle at some arbitrary bundle path." - ) + @Override public SkylarkNestedSet bundleFile() { return (SkylarkNestedSet) ObjcProviderSkylarkConverters.convertToSkylark( BUNDLE_FILE, get(BUNDLE_FILE)); } - @SkylarkCallable(name = "define", - structField = true, - doc = "A set of strings from 'defines' attributes. These are to be passed as '-D' flags to " - + "all invocations of the compiler for this target and all depending targets." - ) + @Override public NestedSet<String> define() { return get(DEFINE); } - @SkylarkCallable(name = "dynamic_framework_dir", - structField = true, - doc = "Exec paths of .framework directories corresponding to dynamic frameworks to link." - ) + @Override public SkylarkNestedSet dynamicFrameworkDir() { return ObjcProviderSkylarkConverters.convertPathFragmentsToSkylark(get(DYNAMIC_FRAMEWORK_DIR)); } - @SkylarkCallable(name = "dynamic_framework_file", - structField = true, - doc = "Files in .framework directories belonging to a dynamically linked framework." - ) + @Override public NestedSet<Artifact> dynamicFrameworkFile() { return get(DYNAMIC_FRAMEWORK_FILE); } - @SkylarkCallable(name = "debug_symbols", - structField = true, - doc = "Files containing information on debug symbols." - ) + @Override public NestedSet<Artifact> debugSymbols() { return get(DEBUG_SYMBOLS); } - @SkylarkCallable(name = "debug_symbols_plist", - structField = true, - doc = "Files containing the plist of the debug symbols." - ) + @Override public NestedSet<Artifact> debugSymbolsPlist() { return get(DEBUG_SYMBOLS_PLIST); } - @SkylarkCallable(name = "exported_debug_artifacts", - structField = true, - doc = "Debug files that should be exported by the top-level target." - ) + @Override public NestedSet<Artifact> exportedDebugArtifacts() { return get(EXPORTED_DEBUG_ARTIFACTS); } - @SkylarkCallable(name = "framework_search_path_only", - structField = true, - doc = "Exec paths of .framework directories corresponding to frameworks to include " - + "in search paths, but not to link." - ) + @Override public SkylarkNestedSet frameworkSearchPathOnly() { return ObjcProviderSkylarkConverters.convertPathFragmentsToSkylark( get(FRAMEWORK_SEARCH_PATH_ONLY)); } - @SkylarkCallable(name = "force_load_library", - structField = true, - doc = "Libraries to load with -force_load." - ) + @Override public NestedSet<Artifact> forceLoadLibrary() { return get(FORCE_LOAD_LIBRARY); } - @SkylarkCallable(name = "header", - structField = true, - doc = "All header files. These may be either public or private headers." - ) + @Override public NestedSet<Artifact> header() { return get(HEADER); } - @SkylarkCallable(name = "imported_library", - structField = true, - doc = "Imported precompiled static libraries (.a files) to be linked into the binary." - ) + @Override public NestedSet<Artifact> importedLibrary() { return get(IMPORTED_LIBRARY); } - @SkylarkCallable(name = "include", - structField = true, - doc = "Include search paths specified with '-I' on the command line. Also known as " - + "header search paths (and distinct from <em>user</em> header search paths)." - ) + @Override public SkylarkNestedSet include() { return ObjcProviderSkylarkConverters.convertPathFragmentsToSkylark(get(INCLUDE)); } - @SkylarkCallable(name = "include_system", - structField = true, - doc = "System include search paths (typically specified with -isystem)." - ) + @Override public SkylarkNestedSet includeSystem() { return ObjcProviderSkylarkConverters.convertPathFragmentsToSkylark(get(INCLUDE_SYSTEM)); } - @SkylarkCallable(name = "iquote", - structField = true, - doc = "User header search paths (typically specified with -iquote)." - ) + @Override public SkylarkNestedSet iquote() { return ObjcProviderSkylarkConverters.convertPathFragmentsToSkylark(get(IQUOTE)); } - @SkylarkCallable(name = "j2objc_library", - structField = true, - doc = "Static libraries that are built from J2ObjC-translated Java code." - ) + @Override public NestedSet<Artifact> j2objcLibrary() { return get(J2OBJC_LIBRARY); } - @SkylarkCallable(name = "jre_library", - structField = true, - doc = "J2ObjC JRE emulation libraries and their dependencies." - ) + @Override public NestedSet<Artifact> jreLibrary() { return get(JRE_LIBRARY); } - @SkylarkCallable(name = "library", - structField = true, - doc = "Library (.a) files compiled by dependencies of the current target." - ) + @Override public NestedSet<Artifact> library() { return get(LIBRARY); } - @SkylarkCallable(name = "link_inputs", - structField = true, - doc = "Link time artifacts from dependencies that do not fall into any other category such " - + "as libraries or archives. This catch-all provides a way to add arbitrary data (e.g. " - + "Swift AST files) to the linker. The rule that adds these is also responsible to " - + "add the necessary linker flags to 'linkopt'." - ) + @Override public NestedSet<Artifact> linkInputs() { return get(LINK_INPUTS); } - @SkylarkCallable(name = "linked_binary", - structField = true, - doc = "Single-architecture linked binaries to be combined for the final multi-architecture " - + "binary." - ) + @Override public NestedSet<Artifact> linkedBinary() { return get(LINKED_BINARY); } - @SkylarkCallable(name = "linkmap_file", - structField = true, - doc = "Single-architecture link map for a binary." - ) + @Override public NestedSet<Artifact> linkmapFile() { return get(LINKMAP_FILE); } - @SkylarkCallable(name = "linkopt", - structField = true, - doc = "Linking options." - ) + @Override public NestedSet<String> linkopt() { return get(LINKOPT); } - @SkylarkCallable(name = "merge_zip", - structField = true, - doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " - + "Merge zips to include in the bundle. The entries of these zip files are included in " - + "the final bundle with the same path. The entries in the merge zips should not include " - + "the bundle root path (e.g. 'Foo.app')." - ) + @Override public NestedSet<Artifact> mergeZip() { return get(MERGE_ZIP); } - @SkylarkCallable(name = "module_map", - structField = true, - doc = "Clang module maps, used to enforce proper use of private header files." - ) + @Override public NestedSet<Artifact> moduleMap() { return get(MODULE_MAP); } - @SkylarkCallable(name = "multi_arch_dynamic_libraries", - structField = true, - doc = "Combined-architecture dynamic libraries to include in the final bundle." - ) + @Override public NestedSet<Artifact> multiArchDynamicLibraries() { return get(MULTI_ARCH_DYNAMIC_LIBRARIES); } - @SkylarkCallable(name = "multi_arch_linked_archives", - structField = true, - doc = "Combined-architecture archives to include in the final bundle." - ) + @Override public NestedSet<Artifact> multiArchLinkedArchives() { return get(MULTI_ARCH_LINKED_ARCHIVES); } - @SkylarkCallable(name = "multi_arch_linked_binaries", - structField = true, - doc = "Combined-architecture binaries to include in the final bundle." - ) + @Override public NestedSet<Artifact> multiArchLinkedBinaries() { return get(MULTI_ARCH_LINKED_BINARIES); } - @SkylarkCallable(name = "root_merge_zip", - structField = true, - doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " - + "Merge zips to include in the ipa and outside the bundle root." - ) + @Override public NestedSet<Artifact> rootMergeZip() { return get(ROOT_MERGE_ZIP); } - @SkylarkCallable(name = "sdk_dylib", - structField = true, - doc = "Names of SDK .dylib libraries to link with. For instance, 'libz' or 'libarchive'." - ) + @Override public NestedSet<String> sdkDylib() { return get(SDK_DYLIB); } - @SkylarkCallable(name = "sdk_framework", - structField = true, - doc = "Names of SDK frameworks to link with (e.g. 'AddressBook', 'QuartzCore')." - ) + @Override public SkylarkNestedSet sdkFramework() { return (SkylarkNestedSet) ObjcProviderSkylarkConverters.convertToSkylark(SDK_FRAMEWORK, get(SDK_FRAMEWORK)); } - @SkylarkCallable(name = "source", - structField = true, - doc = "All transitive source files." - ) + @Override public NestedSet<Artifact> source() { return get(SOURCE); } - @SkylarkCallable(name = "static_framework_file", - structField = true, - doc = "Files in .framework directories that should be statically included as inputs " - + "when compiling and linking." - ) + @Override public NestedSet<Artifact> staticFrameworkFile() { return get(STATIC_FRAMEWORK_FILE); } - @SkylarkCallable(name = "storyboard", - structField = true, - doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " - + "Files for storyboard sources." - ) + @Override public NestedSet<Artifact> storyboard() { return get(STORYBOARD); } - @SkylarkCallable(name = "strings", - structField = true, - doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " - + "Files for strings source files." - ) + @Override public NestedSet<Artifact> strings() { return get(STRINGS); } - @SkylarkCallable(name = "umbrella_header", - structField = true, - doc = "Clang umbrella header. Public headers are #included in umbrella headers to be " - + "compatible with J2ObjC segmented headers." - ) + @Override public NestedSet<Artifact> umbrellaHeader() { return get(UMBRELLA_HEADER); } - @SkylarkCallable(name = "weak_sdk_framework", - structField = true, - doc = "Names of SDK frameworks to weakly link with. For instance, 'MediaAccessibility'. " - + "In difference to regularly linked SDK frameworks, symbols from weakly linked " - + "frameworks do not cause an error if they are not present at runtime." - ) + @Override public SkylarkNestedSet weakSdkFramework() { return (SkylarkNestedSet) ObjcProviderSkylarkConverters.convertToSkylark(WEAK_SDK_FRAMEWORK, get(WEAK_SDK_FRAMEWORK)); } - @SkylarkCallable(name = "xcassets_dir", - structField = true, - doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " - + "The set of all unique asset catalog directories (*.xcassets) containing files " - + "in 'asset_catalogs'." - ) + @Override public SkylarkNestedSet xcassetsDir() { return ObjcProviderSkylarkConverters.convertPathFragmentsToSkylark(get(XCASSETS_DIR)); } - @SkylarkCallable(name = "xcdatamodel", - structField = true, - doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " - + "Files that comprise the data models of the final linked binary." - ) + @Override public NestedSet<Artifact> xcdatamodel() { return get(XCDATAMODEL); } - @SkylarkCallable(name = "xib", - structField = true, - doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " - + ".xib resource files" - ) + @Override public NestedSet<Artifact> xib() { return get(XIB); } @@ -1073,12 +926,7 @@ public final class ObjcProvider extends NativeInfo { * Returns all unique static framework directories (directories ending in '.framework') for all * static framework files in this provider. */ - @SkylarkCallable( - name = "framework_dir", - structField = true, - doc = "Returns all unique static framework directories (directories ending in '.framework') " - + "for all static framework files in this provider." - ) + @Override public SkylarkNestedSet getStaticFrameworkDirsForSkylark() { return ObjcProviderSkylarkConverters.convertPathFragmentsToSkylark(getStaticFrameworkDirs()); } diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/BUILD b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/BUILD index 85c2f407e3..000ac59e48 100644 --- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/BUILD +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/BUILD @@ -3,7 +3,7 @@ # (but not the implementation of that API). Ultimately, this package # may be broken out of the Bazel package hierarchy to be standalone. # Thus, this package should not depend on Bazel-specific packages (only -# those which contain pure-Skylark concepts, such as the interpretter or +# those which contain pure-Skylark concepts, such as the interpreter or # annotation interfaces). package(default_visibility = ["//src:__subpackages__"]) diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SplitTransitionProviderApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SplitTransitionProviderApi.java new file mode 100644 index 0000000000..4d32910345 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SplitTransitionProviderApi.java @@ -0,0 +1,22 @@ +// Copyright 2018 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.skylarkbuildapi; + +/** + * Interface for a type representing a split configuration transition. + */ +public interface SplitTransitionProviderApi { + // TODO(cparsons): Expose this explicitly to the build API. +} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleBitcodeModeApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleBitcodeModeApi.java new file mode 100644 index 0000000000..4a70e110d2 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleBitcodeModeApi.java @@ -0,0 +1,36 @@ +// Copyright 2018 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.skylarkbuildapi.apple; + +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; +import com.google.devtools.build.lib.skylarkinterface.SkylarkValue; + +/** + * Interface for an enum describing the bitcode mode to use when compiling Objective-C and Swift + * code on Apple platforms. + */ +@SkylarkModule( + name = "apple_bitcode_mode", + category = SkylarkModuleCategory.NONE, + doc = + "The Bitcode mode to use when compiling Objective-C and Swift code on Apple platforms. " + + "Possible values are:<br><ul>" + + "<li><code>'none'</code></li>" + + "<li><code>'embedded'</code></li>" + + "<li><code>'embedded_markers'</code></li>" + + "</ul>" +) +public interface AppleBitcodeModeApi extends SkylarkValue {} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleCommonApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleCommonApi.java new file mode 100644 index 0000000000..6f547e4bf4 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleCommonApi.java @@ -0,0 +1,371 @@ +// Copyright 2018 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.skylarkbuildapi.apple; + +import com.google.common.collect.ImmutableMap; +import com.google.devtools.build.lib.skylarkbuildapi.FileApi; +import com.google.devtools.build.lib.skylarkbuildapi.ProviderApi; +import com.google.devtools.build.lib.skylarkbuildapi.SkylarkAspectApi; +import com.google.devtools.build.lib.skylarkbuildapi.SkylarkRuleContextApi; +import com.google.devtools.build.lib.skylarkbuildapi.SplitTransitionProviderApi; +import com.google.devtools.build.lib.skylarkbuildapi.StructApi; +import com.google.devtools.build.lib.skylarkbuildapi.apple.AppleStaticLibraryInfoApi.AppleStaticLibraryInfoProvider; +import com.google.devtools.build.lib.skylarkinterface.Param; +import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.syntax.Environment; +import com.google.devtools.build.lib.syntax.EvalException; +import com.google.devtools.build.lib.syntax.SkylarkDict; +import com.google.devtools.build.lib.syntax.SkylarkNestedSet; + +/** + * Interface for a module with useful functions for creating apple-related rule implementations. + */ +@SkylarkModule( + name = "apple_common", + doc = "Functions for skylark to access internals of the apple rule implementations." +) +public interface AppleCommonApi<FileApiT extends FileApi, + ObjcProviderApiT extends ObjcProviderApi<?>, + XcodeConfigProviderApiT extends XcodeConfigProviderApi<?, ?>, + ApplePlatformApiT extends ApplePlatformApi> { + + @SkylarkCallable( + name = "apple_toolchain", + doc = "Utilities for resolving items from the apple toolchain." + ) + public AppleToolchainApi<?> getAppleToolchain(); + + @SkylarkCallable( + name = "platform_type", + doc = + "An enum-like struct that contains the following fields corresponding to Apple platform " + + "types:<br><ul>" + + "<li><code>ios</code></li>" + + "<li><code>macos</code></li>" + + "<li><code>tvos</code></li>" + + "<li><code>watchos</code></li>" + + "</ul><p>" + + "These values can be passed to methods that expect a platform type, like the 'apple' " + + "configuration fragment's " + + "<a href='apple.html#multi_arch_platform'>multi_arch_platform</a> method.<p>" + + "Example:<p>" + + "<pre class='language-python'>\n" + + "ctx.fragments.apple.multi_arch_platform(apple_common.platform_type.ios)\n" + + "</pre>", + structField = true + ) + public StructApi getPlatformTypeStruct(); + + @SkylarkCallable( + name = "platform", + doc = + "An enum-like struct that contains the following fields corresponding to Apple " + + "platforms:<br><ul>" + + "<li><code>ios_device</code></li>" + + "<li><code>ios_simulator</code></li>" + + "<li><code>macos</code></li>" + + "<li><code>tvos_device</code></li>" + + "<li><code>tvos_simulator</code></li>" + + "<li><code>watchos_device</code></li>" + + "<li><code>watchos_device</code></li>" + + "</ul><p>" + + "These values can be passed to methods that expect a platform, like " + + "<a href='apple.html#sdk_version_for_platform'>apple.sdk_version_for_platform</a>.", + structField = true + ) + public StructApi getPlatformStruct(); + + @SkylarkCallable( + name = "XcodeProperties", + doc = + "The constructor/key for the <code>XcodeVersionProperties</code> provider.<p>" + + "If a target propagates the <code>XcodeVersionProperties</code> provider," + + " use this as the key with which to retrieve it. Example:<br>" + + "<pre class='language-python'>\n" + + "dep = ctx.attr.deps[0]\n" + + "p = dep[apple_common.XcodeVersionProperties]\n" + + "</pre>", + structField = true + ) + public ProviderApi getXcodeVersionPropertiesConstructor(); + + @SkylarkCallable( + name = "XcodeVersionConfig", + doc = "The constructor/key for the <code>XcodeVersionConfig</code> provider.", + structField = true + ) + public ProviderApi getXcodeVersionConfigConstructor(); + + @SkylarkCallable( + // TODO(b/63899207): This currently does not match ObjcProvider.SKYLARK_NAME as it requires + // a migration of existing skylark rules. + name = "Objc", + doc = + "The constructor/key for the <code>Objc</code> provider.<p>" + + "If a target propagates the <code>Objc</code> provider, use this as the " + + "key with which to retrieve it. Example:<br>" + + "<pre class='language-python'>\n" + + "dep = ctx.attr.deps[0]\n" + + "p = dep[apple_common.Objc]\n" + + "</pre>", + structField = true + ) + public ProviderApi getObjcProviderConstructor(); + + @SkylarkCallable( + name = "AppleDynamicFramework", + doc = + "The constructor/key for the <code>AppleDynamicFramework</code> provider.<p>" + + "If a target propagates the <code>AppleDynamicFramework</code> provider, use this " + + "as the key with which to retrieve it. Example:<br>" + + "<pre class='language-python'>\n" + + "dep = ctx.attr.deps[0]\n" + + "p = dep[apple_common.AppleDynamicFramework]\n" + + "</pre>", + structField = true + ) + public ProviderApi getAppleDynamicFrameworkConstructor(); + + @SkylarkCallable( + name = "AppleDylibBinary", + doc = + "The constructor/key for the <code>AppleDylibBinary</code> provider.<p>" + + "If a target propagates the <code>AppleDylibBinary</code> provider, use this as the " + + "key with which to retrieve it. Example:<br>" + + "<pre class='language-python'>\n" + + "dep = ctx.attr.deps[0]\n" + + "p = dep[apple_common.AppleDylibBinary]\n" + + "</pre>", + structField = true + ) + public ProviderApi getAppleDylibBinaryConstructor(); + + @SkylarkCallable( + name = "AppleExecutableBinary", + doc = + "The constructor/key for the <code>AppleExecutableBinary</code> provider.<p>" + + "If a target propagates the <code>AppleExecutableBinary</code> provider," + + " use this as the key with which to retrieve it. Example:<br>" + + "<pre class='language-python'>\n" + + "dep = ctx.attr.deps[0]\n" + + "p = dep[apple_common.AppleExecutableBinary]\n" + + "</pre>", + structField = true + ) + public ProviderApi getAppleExecutableBinaryConstructor(); + + @SkylarkCallable( + name = "AppleStaticLibrary", + doc = + "The constructor/key for the <code>AppleStaticLibrary</code> provider.<p>" + + "If a target propagates the <code>AppleStaticLibrary</code> provider, use " + + "this as the key with which to retrieve it. Example:<br>" + + "<pre class='language-python'>\n" + + "dep = ctx.attr.deps[0]\n" + + "p = dep[apple_common.AppleStaticLibrary]\n" + + "</pre>", + structField = true + ) + public AppleStaticLibraryInfoProvider<?, ?> getAppleStaticLibraryProvider(); + + @SkylarkCallable( + name = "AppleDebugOutputs", + doc = + "The constructor/key for the <code>AppleDebugOutputs</code> provider.<p>" + + "If a target propagates the <code>AppleDebugOutputs</code> provider, use this as the " + + "key with which to retrieve it. Example:<br>" + + "<pre class='language-python'>\n" + + "dep = ctx.attr.deps[0]\n" + + "p = dep[apple_common.AppleDebugOutputs]\n" + + "</pre>", + structField = true + ) + public ProviderApi getAppleDebugOutputsConstructor(); + + @SkylarkCallable( + name = "AppleLoadableBundleBinary", + doc = + "The constructor/key for the <code>AppleLoadableBundleBinary</code> provider.<p>" + + "If a target propagates the <code>AppleLoadableBundleBinary</code> provider, " + + "use this as the key with which to retrieve it. Example:<br>" + + "<pre class='language-python'>\n" + + "dep = ctx.attr.deps[0]\n" + + "p = dep[apple_common.AppleLoadableBundleBinary]\n" + + "</pre>", + structField = true + ) + public ProviderApi getAppleLoadableBundleBinaryConstructor(); + + @SkylarkCallable( + name = "apple_host_system_env", + doc = + "Returns a <a href='dict.html'>dict</a> of environment variables that should be set " + + "for actions that need to run build tools on an Apple host system, such as the " + + " version of Xcode that should be used. The keys are variable names and the values " + + " are their corresponding values." + ) + public ImmutableMap<String, String> getAppleHostSystemEnv( + XcodeConfigProviderApiT xcodeConfig); + + @SkylarkCallable( + name = "target_apple_env", + doc = + "Returns a <code>dict</code> of environment variables that should be set for actions " + + "that build targets of the given Apple platform type. For example, this dictionary " + + "contains variables that denote the platform name and SDK version with which to " + + "build. The keys are variable names and the values are their corresponding values." + ) + public ImmutableMap<String, String> getTargetAppleEnvironment( + XcodeConfigProviderApiT xcodeConfig, ApplePlatformApiT platform); + + @SkylarkCallable( + name = "multi_arch_split", + doc = "A configuration transition for rule attributes to build dependencies in one or" + + " more Apple platforms. " + + "<p>Use of this transition requires that the 'platform_type' and 'minimum_os_version'" + + " string attributes are defined and mandatory on the rule.</p>" + + "<p>The value of the platform_type attribute will dictate the target architectures " + + " for which dependencies along this configuration transition will be built.</p>" + + "<p>Options are:</p>" + + "<ul>" + + "<li><code>ios</code>: architectures gathered from <code>--ios_multi_cpus</code>.</li>" + + "<li><code>macos</code>: architectures gathered from <code>--macos_cpus</code>.</li>" + + "<li><code>tvos</code>: architectures gathered from <code>--tvos_cpus</code>.</li>" + + "<li><code>watchos</code>: architectures gathered from <code>--watchos_cpus</code>." + + "</li></ul>" + + "<p>minimum_os_version should be a dotted version string such as '7.3', and is used to" + + " set the minimum operating system on the configuration similarly based on platform" + + " type. For example, specifying platform_type 'ios' and minimum_os_version '8.0' will" + + " ensure that dependencies are built with minimum iOS version '8.0'.", + structField = true + ) + public SplitTransitionProviderApi getMultiArchSplitProvider(); + + @SkylarkCallable( + name = "new_objc_provider", + doc = "Creates a new ObjcProvider instance.", + parameters = { + @Param( + name = "uses_swift", + type = Boolean.class, + defaultValue = "False", + named = true, + positional = false, + doc = "Whether this provider should enable Swift support." + ) + }, + extraKeywords = + @Param( + name = "kwargs", + type = SkylarkDict.class, + defaultValue = "{}", + doc = "Dictionary of arguments." + ), + useEnvironment = true + ) + // This method is registered statically for skylark, and never called directly. + public ObjcProviderApi<?> newObjcProvider( + Boolean usesSwift, + SkylarkDict<?, ?> kwargs, + Environment environment); + + @SkylarkCallable( + name = "new_dynamic_framework_provider", + doc = "Creates a new AppleDynamicFramework provider instance.", + parameters = { + @Param( + name = "binary", + type = FileApi.class, + named = true, + positional = false, + doc = "The dylib binary artifact of the dynamic framework." + ), + @Param( + name = "objc", + type = ObjcProviderApi.class, + named = true, + positional = false, + doc = + "An ObjcProvider which contains information about the transitive " + + "dependencies linked into the binary." + ), + @Param( + name = "framework_dirs", + type = SkylarkNestedSet.class, + generic1 = String.class, + named = true, + noneable = true, + positional = false, + defaultValue = "None", + doc = + "The framework path names used as link inputs in order to link against the dynamic " + + "framework." + ), + @Param( + name = "framework_files", + type = SkylarkNestedSet.class, + generic1 = FileApi.class, + named = true, + noneable = true, + positional = false, + defaultValue = "None", + doc = + "The full set of artifacts that should be included as inputs to link against the " + + "dynamic framework" + ) + } + ) + public AppleDynamicFrameworkInfoApi<?, ?> newDynamicFrameworkProvider( + FileApiT dylibBinary, + ObjcProviderApiT depsObjcProvider, + Object dynamicFrameworkDirs, + Object dynamicFrameworkFiles); + + @SkylarkCallable( + name = "link_multi_arch_binary", + doc = "Links a (potentially multi-architecture) binary targeting Apple platforms. This " + + "method comprises a bulk of the logic of the <code>apple_binary</code> rule, and is " + + "exposed as an API to iterate on migration of <code>apple_binary</code> to skylark.\n" + + "<p>This API is <b>highly experimental</b> and subject to change at any time. Do not " + + "depend on the stability of this function at this time.", + mandatoryPositionals = 1 // The SkylarkRuleContext. + ) + // TODO(b/70937317): Iterate on, improve, and solidify this API. + public StructApi linkMultiArchBinary(SkylarkRuleContextApi skylarkRuleContext) + throws EvalException, InterruptedException; + + @SkylarkCallable( + name = "dotted_version", + doc = "Creates a new <a href=\"DottedVersion.html\">DottedVersion</a> instance.", + parameters = { + @Param( + name = "version", + type = String.class, + doc = "The string representation of the DottedVersion." + ) + } + ) + public DottedVersionApi<?> dottedVersion(String version); + + @SkylarkCallable( + name = "objc_proto_aspect", + doc = + "objc_proto_aspect gathers the proto dependencies of the attached rule target," + + "and propagates the proto values of its dependencies through the ObjcProto provider.", + structField = true + ) + public SkylarkAspectApi getObjcProtoAspect(); +} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleConfigurationApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleConfigurationApi.java new file mode 100644 index 0000000000..03fac8476e --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleConfigurationApi.java @@ -0,0 +1,78 @@ +// Copyright 2018 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.skylarkbuildapi.apple; + +import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; + +/** An interface for a configuration type containing info for Apple platforms and tools. */ +@SkylarkModule( + name = "apple", + doc = "A configuration fragment for Apple platforms.", + category = SkylarkModuleCategory.CONFIGURATION_FRAGMENT +) +public interface AppleConfigurationApi<ApplePlatformTypeApiT extends ApplePlatformTypeApi> { + + @SkylarkCallable( + name = "ios_cpu", + doc = "<b>Deprecated. Use <a href='#single_arch_cpu'>single_arch_cpu</a> instead.</b> " + + "The value of ios_cpu for this configuration.") + public String getIosCpu(); + + @SkylarkCallable( + name = "single_arch_cpu", + structField = true, + doc = + "The single \"effective\" architecture for this configuration (e.g., <code>i386</code> or " + + "<code>arm64</code>) in the context of rule logic that is only concerned with a " + + "single architecture (such as <code>objc_library</code>, which registers " + + "single-architecture compile actions)." + ) + public String getSingleArchitecture(); + + @SkylarkCallable( + name = "single_arch_platform", + doc = "The platform of the current configuration. This should only be invoked in a context " + + "where only a single architecture may be supported; consider " + + "<a href='#multi_arch_platform'>multi_arch_platform</a> for other cases.", + structField = true + ) + public ApplePlatformApi getSingleArchPlatform(); + + @SkylarkCallable( + name = "multi_arch_platform", + doc = "The platform of the current configuration for the given platform type. This should only " + + "be invoked in a context where multiple architectures may be supported; consider " + + "<a href='#single_arch_platform'>single_arch_platform</a> for other cases." + ) + public ApplePlatformApi getMultiArchPlatform(ApplePlatformTypeApiT platformType); + + @SkylarkCallable( + name = "ios_cpu_platform", + doc = "<b>Deprecated. Use <a href='#single_arch_platform'>single_arch_platform</a> or " + + "<a href='#multi_arch_platform'>multi_arch_platform</a> instead.</b> " + + "The platform given by the ios_cpu flag.") + public ApplePlatformApi getIosCpuPlatform(); + + @SkylarkCallable( + name = "bitcode_mode", + doc = "Returns the Bitcode mode to use for compilation steps.<p>" + + "This field is only valid for device builds; for simulator builds, it always returns " + + "<code>'none'</code>.", + structField = true + ) + public AppleBitcodeModeApi getBitcodeMode(); +} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleDynamicFrameworkInfoApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleDynamicFrameworkInfoApi.java new file mode 100644 index 0000000000..805b4506fc --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleDynamicFrameworkInfoApi.java @@ -0,0 +1,81 @@ +// Copyright 2018 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.skylarkbuildapi.apple; + +import com.google.devtools.build.lib.collect.nestedset.NestedSet; +import com.google.devtools.build.lib.skylarkbuildapi.FileApi; +import com.google.devtools.build.lib.skylarkbuildapi.StructApi; +import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; +import javax.annotation.Nullable; + +/** + * An interface representing an info type containing information about an Apple dynamic + * framework. + **/ +@SkylarkModule( + name = "AppleDynamicFramework", + category = SkylarkModuleCategory.PROVIDER, + doc = "A provider containing information about an Apple dynamic framework." +) +public interface AppleDynamicFrameworkInfoApi<PathFragmentT, FileApiT extends FileApi> + extends StructApi { + + /** + * Returns the framework path names used as link inputs in order to link against the dynamic + * framework. + */ + @SkylarkCallable(name = "framework_dirs", + structField = true, + doc = "The framework path names used as link inputs in order to link against the dynamic " + + "framework." + ) + public NestedSet<PathFragmentT> getDynamicFrameworkDirs(); + + /** + * Returns the full set of artifacts that should be included as inputs to link against the + * dynamic framework. + */ + @SkylarkCallable(name = "framework_files", + structField = true, + doc = "The full set of files that should be included as inputs to link against the " + + "dynamic framework." + ) + public NestedSet<FileApiT> getDynamicFrameworkFiles(); + + /** + * Returns the multi-architecture dylib binary of the dynamic framework. May return null if + * the rule providing the framework only specified framework imports. + */ + @Nullable + @SkylarkCallable(name = "binary", + structField = true, + doc = "The multi-architecture dylib binary of the dynamic framework. May be null if " + + "the rule providing the framework only specified framework imports." + ) + public FileApi getAppleDylibBinary(); + + /** + * Returns the {@link ObjcProviderApi} which contains information about the transitive + * dependencies linked into the dylib. + */ + @SkylarkCallable(name = "objc", + structField = true, + doc = "A provider which contains information about the transitive dependencies linked into " + + "the dynamic framework." + ) + public ObjcProviderApi<FileApiT> getDepsObjcProvider(); +} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/ApplePlatformApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/ApplePlatformApi.java new file mode 100644 index 0000000000..1c4aeae028 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/ApplePlatformApi.java @@ -0,0 +1,83 @@ +// Copyright 2018 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.skylarkbuildapi.apple; + +import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; +import com.google.devtools.build.lib.skylarkinterface.SkylarkValue; + +/** An interface for an object representing an Apple platform. */ +@SkylarkModule( + name = "apple_platform", + category = SkylarkModuleCategory.NONE, + doc = "Corresponds to Xcode's notion of a platform as would be found in " + + "<code>Xcode.app/Contents/Developer/Platforms</code>. Each platform represents an Apple " + + "platform type (such as iOS or tvOS) combined with one or more related CPU " + + "architectures. For example, the iOS simulator platform supports <code>x86_64</code> and " + + "<code>i386</code> architectures.<p>" + + "Specific instances of this type can be retrieved from the fields of the " + + "<a href='apple_common.html#platform'>apple_common.platform</a> struct:<br><ul>" + + "<li><code>apple_common.platform.ios_device</code></li>" + + "<li><code>apple_common.platform.ios_simulator</code></li>" + + "<li><code>apple_common.platform.macos</code></li>" + + "<li><code>apple_common.platform.tvos_device</code></li>" + + "<li><code>apple_common.platform.tvos_simulator</code></li>" + + "<li><code>apple_common.platform.watchos_device</code></li>" + + "<li><code>apple_common.platform.watchos_simulator</code></li>" + + "</ul><p>" + + "More commonly, however, the <a href='apple.html'>apple</a> configuration fragment has " + + "fields/methods that allow rules to determine the platform for which a target is being " + + "built.<p>" + + "Example:<br>" + + "<pre class='language-python'>\n" + + "p = apple_common.platform.ios_device\n" + + "print(p.name_in_plist) # 'iPhoneOS'\n" + + "</pre>" +) +public interface ApplePlatformApi extends SkylarkValue { + + /** Returns the platform type of this platform. */ + @SkylarkCallable( + name = "platform_type", + doc = "Returns the platform type of this platform.", + structField = true + ) + public ApplePlatformTypeApi getType(); + + /** + * Returns true if this platform is a device platform, or false if this is a simulator platform. + */ + @SkylarkCallable( + name = "is_device", + doc = "Returns <code>True</code> if this platform is a device platform or <code>False</code> " + + "if it is a simulator platform.", + structField = true + ) + public boolean isDevice(); + + /** + * Returns the name of the "platform" as it appears in the CFBundleSupportedPlatforms plist + * setting. + */ + @SkylarkCallable(name = "name_in_plist", structField = true, + doc = "The name of the platform as it appears in the <code>CFBundleSupportedPlatforms</code> " + + "entry of an Info.plist file and in Xcode's platforms directory, without the extension " + + "(for example, <code>iPhoneOS</code> or <code>iPhoneSimulator</code>).<br>" + + "This name, when converted to lowercase (e.g., <code>iphoneos</code>, " + + "<code>iphonesimulator</code>), can be passed to Xcode's command-line tools like " + + "<code>ibtool</code> and <code>actool</code> when they expect a platform name.") + public String getNameInPlist(); +} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/ApplePlatformTypeApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/ApplePlatformTypeApi.java new file mode 100644 index 0000000000..f724bdba1e --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/ApplePlatformTypeApi.java @@ -0,0 +1,42 @@ +// Copyright 2018 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.skylarkbuildapi.apple; + +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; +import com.google.devtools.build.lib.skylarkinterface.SkylarkValue; + +/** + * Interface for a descriptor for an Apple platform type, such as such as iOS or macOS. + */ +@SkylarkModule( + name = "apple_platform_type", + category = SkylarkModuleCategory.NONE, + doc = "Describes an Apple \"platform type\", such as iOS, macOS, tvOS, or watchOS. This is " + + "distinct from a \"platform\", which is the platform type combined with one or more CPU " + + "architectures.<p>" + + "Specific instances of this type can be retrieved by accessing the fields of the " + + "<a href='apple_common.html#platform_type'>apple_common.platform_type</a>:<br><ul>" + + "<li><code>apple_common.platform_type.ios</code></li>" + + "<li><code>apple_common.platform_type.macos</code></li>" + + "<li><code>apple_common.platform_type.tvos</code></li>" + + "<li><code>apple_common.platform_type.watchos</code></li>" + + "</ul><p>" + + "Likewise, the platform type of an existing platform value can be retrieved using its " + + "<code>platform_type</code> field.<p>" + + "Platform types can be converted to a lowercase string (e.g., <code>ios</code> or " + + "<code>macos</code>) using the <a href='globals.html#str'>str</a> function." +) +public interface ApplePlatformTypeApi extends SkylarkValue {} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleStaticLibraryInfoApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleStaticLibraryInfoApi.java new file mode 100644 index 0000000000..fdcdb7bf6d --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleStaticLibraryInfoApi.java @@ -0,0 +1,84 @@ +// Copyright 2018 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.skylarkbuildapi.apple; + +import com.google.devtools.build.lib.skylarkbuildapi.FileApi; +import com.google.devtools.build.lib.skylarkbuildapi.ProviderApi; +import com.google.devtools.build.lib.skylarkbuildapi.StructApi; +import com.google.devtools.build.lib.skylarkinterface.Param; +import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; +import com.google.devtools.build.lib.skylarkinterface.SkylarkConstructor; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; +import com.google.devtools.build.lib.syntax.EvalException; + +/** + * Interface for an info type containing information regarding multi-architecture Apple static + * libraries. + */ +@SkylarkModule( + name = "AppleStaticLibrary", + category = SkylarkModuleCategory.PROVIDER, + doc = "A provider containing information regarding multi-architecture Apple static libraries, " + + "as is propagated by the apple_static_library rule." +) +public interface AppleStaticLibraryInfoApi extends StructApi { + + /** Skylark name for this interface. */ + public static final String SKYLARK_NAME = "AppleStaticLibrary"; + + @SkylarkCallable(name = "archive", + structField = true, + doc = "The multi-arch archive (.a) output by apple_static_library." + ) + public FileApi getMultiArchArchive(); + + @SkylarkCallable(name = "objc", + structField = true, + doc = "A provider which contains information about the transitive dependencies linked into " + + "the archive." + ) + public ObjcProviderApi<?> getDepsObjcProvider(); + + /** + * Interface for the provider type for {@link AppleStaticLibraryInfoApi}. + */ + public interface AppleStaticLibraryInfoProvider<FileApiT extends FileApi, + ObjcProviderApiT extends ObjcProviderApi<?>> extends ProviderApi { + + @SkylarkCallable( + name = SKYLARK_NAME, + doc = "The <code>AppleStaticLibrary</code> constructor.", + parameters = { + @Param( + name = "archive", + type = FileApi.class, + named = true, + positional = false, + doc = "Multi-architecture archive (.a) representing a static library"), + @Param( + name = "objc", + type = ObjcProviderApi.class, + named = true, + positional = false, + doc = "A provider which contains information about the transitive dependencies " + + "linked into the archive."), + }, + selfCall = true) + @SkylarkConstructor(objectType = AppleStaticLibraryInfoApi.class) + public AppleStaticLibraryInfoApi appleStaticLibrary( + FileApiT archive, ObjcProviderApiT objcProvider) throws EvalException; + } +} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleToolchainApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleToolchainApi.java new file mode 100644 index 0000000000..7481a97010 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleToolchainApi.java @@ -0,0 +1,46 @@ +// Copyright 2018 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.skylarkbuildapi.apple; + +import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; + +/** + * Interface for a utility module involving the Apple toolchain. + */ +@SkylarkModule( + name = "apple_toolchain", + doc = "Utilities for resolving items from the Apple toolchain." +) +public interface AppleToolchainApi<AppleConfigurationApiT extends AppleConfigurationApi<?>> { + + @SkylarkCallable( + name = "sdk_dir", + doc = "Returns the platform directory inside of Xcode for a given configuration." + ) + public String sdkDirConstant(); + + @SkylarkCallable( + name = "developer_dir", + doc = "Returns the Developer directory inside of Xcode for a given configuration." + ) + public String developerDirConstant(); + + @SkylarkCallable( + name = "platform_developer_framework_dir", + doc = "Returns the platform frameworks directory inside of Xcode for a given configuration." + ) + public String platformFrameworkDirFromConfig(AppleConfigurationApiT configuration); +} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/BUILD b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/BUILD new file mode 100644 index 0000000000..f4cc1b4d93 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/BUILD @@ -0,0 +1,30 @@ +# Description: +# This package contains interfaces representing the skylark "build API" +# (but not the implementation of that API). Ultimately, this package +# may be broken out of the Bazel package hierarchy to be standalone. +# Thus, this package should not depend on Bazel-specific packages (only +# those which contain pure-Skylark concepts, such as the interpreter or +# annotation interfaces). + +package(default_visibility = ["//src:__subpackages__"]) + +licenses(["notice"]) # Apache 2.0 + +filegroup( + name = "srcs", + srcs = glob(["**"]), +) + +java_library( + name = "apple", + srcs = glob(["*.java"]), + deps = [ + "//src/main/java/com/google/devtools/build/lib:skylarkinterface", + "//src/main/java/com/google/devtools/build/lib:syntax", + "//src/main/java/com/google/devtools/build/lib/cmdline", + "//src/main/java/com/google/devtools/build/lib/collect/nestedset", + "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi", + "//third_party:guava", + "//third_party:jsr305", + ], +) diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/DottedVersionApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/DottedVersionApi.java new file mode 100644 index 0000000000..609609d6c6 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/DottedVersionApi.java @@ -0,0 +1,43 @@ +// Copyright 2018 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.skylarkbuildapi.apple; + +import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; +import com.google.devtools.build.lib.skylarkinterface.SkylarkValue; + +/** + * Interface for a value representing a version with multiple components, separated by periods, + * such as "1.2.3.4". + **/ +@SkylarkModule( + name = "DottedVersion", + category = SkylarkModuleCategory.NONE, + doc = + "A value representing a version with multiple components, separated by periods, such as " + + "1.2.3.4." +) +public interface DottedVersionApi<SelfT extends DottedVersionApi<?>> + extends SkylarkValue, Comparable<SelfT> { + + @SkylarkCallable( + name = "compare_to", + doc = + "Compares based on most signifigant (first) not-matching version component. " + + "So, for example, 1.2.3 < 1.2.4" + ) + public int compareTo_skylark(SelfT other); +} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/ObjcProviderApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/ObjcProviderApi.java new file mode 100644 index 0000000000..1d44e3adee --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/ObjcProviderApi.java @@ -0,0 +1,300 @@ +// Copyright 2018 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.skylarkbuildapi.apple; + +import com.google.devtools.build.lib.collect.nestedset.NestedSet; +import com.google.devtools.build.lib.skylarkbuildapi.FileApi; +import com.google.devtools.build.lib.skylarkbuildapi.StructApi; +import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; +import com.google.devtools.build.lib.syntax.SkylarkNestedSet; + +/** + * An interface for an info type that provides all compiling and linking information in the + * transitive closure of its deps that are needed for building Objective-C rules. + */ +@SkylarkModule( + name = "ObjcProvider", + category = SkylarkModuleCategory.PROVIDER, + doc = "A provider for compilation and linking of objc." +) +public interface ObjcProviderApi<FileApiT extends FileApi> extends StructApi { + + @SkylarkCallable(name = "asset_catalog", + structField = true, + doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " + + "Asset catalog resource files." + ) + public NestedSet<FileApiT> assetCatalog(); + + @SkylarkCallable(name = "bundle_file", + structField = true, + doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " + + "Files that are plopped into the final bundle at some arbitrary bundle path." + ) + public SkylarkNestedSet bundleFile(); + + @SkylarkCallable(name = "define", + structField = true, + doc = "A set of strings from 'defines' attributes. These are to be passed as '-D' flags to " + + "all invocations of the compiler for this target and all depending targets." + ) + public NestedSet<String> define(); + + @SkylarkCallable(name = "dynamic_framework_dir", + structField = true, + doc = "Exec paths of .framework directories corresponding to dynamic frameworks to link." + ) + public SkylarkNestedSet dynamicFrameworkDir(); + + @SkylarkCallable(name = "dynamic_framework_file", + structField = true, + doc = "Files in .framework directories belonging to a dynamically linked framework." + ) + public NestedSet<FileApiT> dynamicFrameworkFile(); + + @SkylarkCallable(name = "debug_symbols", + structField = true, + doc = "Files containing information on debug symbols." + ) + public NestedSet<FileApiT> debugSymbols(); + + @SkylarkCallable(name = "debug_symbols_plist", + structField = true, + doc = "Files containing the plist of the debug symbols." + ) + public NestedSet<FileApiT> debugSymbolsPlist(); + + @SkylarkCallable(name = "exported_debug_artifacts", + structField = true, + doc = "Debug files that should be exported by the top-level target." + ) + public NestedSet<FileApiT> exportedDebugArtifacts(); + + @SkylarkCallable(name = "framework_search_path_only", + structField = true, + doc = "Exec paths of .framework directories corresponding to frameworks to include " + + "in search paths, but not to link." + ) + public SkylarkNestedSet frameworkSearchPathOnly(); + + @SkylarkCallable(name = "force_load_library", + structField = true, + doc = "Libraries to load with -force_load." + ) + public NestedSet<FileApiT> forceLoadLibrary(); + + @SkylarkCallable(name = "header", + structField = true, + doc = "All header files. These may be either public or private headers." + ) + public NestedSet<FileApiT> header(); + + @SkylarkCallable(name = "imported_library", + structField = true, + doc = "Imported precompiled static libraries (.a files) to be linked into the binary." + ) + public NestedSet<FileApiT> importedLibrary(); + + @SkylarkCallable(name = "include", + structField = true, + doc = "Include search paths specified with '-I' on the command line. Also known as " + + "header search paths (and distinct from <em>user</em> header search paths)." + ) + public SkylarkNestedSet include(); + + @SkylarkCallable(name = "include_system", + structField = true, + doc = "System include search paths (typically specified with -isystem)." + ) + public SkylarkNestedSet includeSystem(); + + @SkylarkCallable(name = "iquote", + structField = true, + doc = "User header search paths (typically specified with -iquote)." + ) + public SkylarkNestedSet iquote(); + + @SkylarkCallable(name = "j2objc_library", + structField = true, + doc = "Static libraries that are built from J2ObjC-translated Java code." + ) + public NestedSet<FileApiT> j2objcLibrary(); + + @SkylarkCallable(name = "jre_library", + structField = true, + doc = "J2ObjC JRE emulation libraries and their dependencies." + ) + public NestedSet<FileApiT> jreLibrary(); + + @SkylarkCallable(name = "library", + structField = true, + doc = "Library (.a) files compiled by dependencies of the current target." + ) + public NestedSet<FileApiT> library(); + + @SkylarkCallable(name = "link_inputs", + structField = true, + doc = "Link time artifacts from dependencies that do not fall into any other category such " + + "as libraries or archives. This catch-all provides a way to add arbitrary data (e.g. " + + "Swift AST files) to the linker. The rule that adds these is also responsible to " + + "add the necessary linker flags to 'linkopt'." + ) + public NestedSet<FileApiT> linkInputs(); + + @SkylarkCallable(name = "linked_binary", + structField = true, + doc = "Single-architecture linked binaries to be combined for the final multi-architecture " + + "binary." + ) + public NestedSet<FileApiT> linkedBinary(); + + @SkylarkCallable(name = "linkmap_file", + structField = true, + doc = "Single-architecture link map for a binary." + ) + public NestedSet<FileApiT> linkmapFile(); + + @SkylarkCallable(name = "linkopt", + structField = true, + doc = "Linking options." + ) + public NestedSet<String> linkopt(); + + @SkylarkCallable(name = "merge_zip", + structField = true, + doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " + + "Merge zips to include in the bundle. The entries of these zip files are included in " + + "the final bundle with the same path. The entries in the merge zips should not include " + + "the bundle root path (e.g. 'Foo.app')." + ) + public NestedSet<FileApiT> mergeZip(); + + @SkylarkCallable(name = "module_map", + structField = true, + doc = "Clang module maps, used to enforce proper use of private header files." + ) + public NestedSet<FileApiT> moduleMap(); + + @SkylarkCallable(name = "multi_arch_dynamic_libraries", + structField = true, + doc = "Combined-architecture dynamic libraries to include in the final bundle." + ) + public NestedSet<FileApiT> multiArchDynamicLibraries(); + + @SkylarkCallable(name = "multi_arch_linked_archives", + structField = true, + doc = "Combined-architecture archives to include in the final bundle." + ) + public NestedSet<FileApiT> multiArchLinkedArchives(); + + @SkylarkCallable(name = "multi_arch_linked_binaries", + structField = true, + doc = "Combined-architecture binaries to include in the final bundle." + ) + public NestedSet<FileApiT> multiArchLinkedBinaries(); + + @SkylarkCallable(name = "root_merge_zip", + structField = true, + doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " + + "Merge zips to include in the ipa and outside the bundle root." + ) + public NestedSet<FileApiT> rootMergeZip(); + + @SkylarkCallable(name = "sdk_dylib", + structField = true, + doc = "Names of SDK .dylib libraries to link with. For instance, 'libz' or 'libarchive'." + ) + public NestedSet<String> sdkDylib(); + + @SkylarkCallable(name = "sdk_framework", + structField = true, + doc = "Names of SDK frameworks to link with (e.g. 'AddressBook', 'QuartzCore')." + ) + public SkylarkNestedSet sdkFramework(); + + @SkylarkCallable(name = "source", + structField = true, + doc = "All transitive source files." + ) + public NestedSet<FileApiT> source(); + + @SkylarkCallable(name = "static_framework_file", + structField = true, + doc = "Files in .framework directories that should be statically included as inputs " + + "when compiling and linking." + ) + public NestedSet<FileApiT> staticFrameworkFile(); + + @SkylarkCallable(name = "storyboard", + structField = true, + doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " + + "Files for storyboard sources." + ) + public NestedSet<FileApiT> storyboard(); + + @SkylarkCallable(name = "strings", + structField = true, + doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " + + "Files for strings source files." + ) + public NestedSet<FileApiT> strings(); + + @SkylarkCallable(name = "umbrella_header", + structField = true, + doc = "Clang umbrella header. Public headers are #included in umbrella headers to be " + + "compatible with J2ObjC segmented headers." + ) + public NestedSet<FileApiT> umbrellaHeader(); + + @SkylarkCallable(name = "weak_sdk_framework", + structField = true, + doc = "Names of SDK frameworks to weakly link with. For instance, 'MediaAccessibility'. " + + "In difference to regularly linked SDK frameworks, symbols from weakly linked " + + "frameworks do not cause an error if they are not present at runtime." + ) + public SkylarkNestedSet weakSdkFramework(); + + @SkylarkCallable(name = "xcassets_dir", + structField = true, + doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " + + "The set of all unique asset catalog directories (*.xcassets) containing files " + + "in 'asset_catalogs'." + ) + public SkylarkNestedSet xcassetsDir(); + + @SkylarkCallable(name = "xcdatamodel", + structField = true, + doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " + + "Files that comprise the data models of the final linked binary." + ) + public NestedSet<FileApiT> xcdatamodel(); + + @SkylarkCallable(name = "xib", + structField = true, + doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " + + ".xib resource files" + ) + public NestedSet<FileApiT> xib(); + + @SkylarkCallable( + name = "framework_dir", + structField = true, + doc = "Returns all unique static framework directories (directories ending in '.framework') " + + "for all static framework files in this provider." + ) + public SkylarkNestedSet getStaticFrameworkDirsForSkylark(); +} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/XcodeConfigProviderApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/XcodeConfigProviderApi.java new file mode 100644 index 0000000000..0cc4f1e3ce --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/XcodeConfigProviderApi.java @@ -0,0 +1,48 @@ +// Copyright 2018 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.skylarkbuildapi.apple; + +import com.google.devtools.build.lib.skylarkbuildapi.StructApi; +import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; + +/** + * An interface for an info type containing the set of Apple versions computed from command line + * options and the {@code xcode_config} rule. + */ +@SkylarkModule( + name = "XcodeVersionConfig", + doc = "The set of Apple versions computed from command line options and the xcode_config rule.") +public interface XcodeConfigProviderApi<ApplePlatformApiT extends ApplePlatformApi, + ApplePlatformTypeApiT extends ApplePlatformTypeApi> extends StructApi { + + @SkylarkCallable(name = "xcode_version", + doc = "Returns the Xcode version that is being used to build.<p>" + + "This will return <code>None</code> if no Xcode versions are available.", + allowReturnNones = true) + public DottedVersionApi<?> getXcodeVersion(); + + @SkylarkCallable( + name = "minimum_os_for_platform_type", + doc = "The minimum compatible OS version for target simulator and devices for a particular " + + "platform type.") + public DottedVersionApi<?> getMinimumOsForPlatformType(ApplePlatformTypeApiT platformType); + + @SkylarkCallable( + name = "sdk_version_for_platform", + doc = "The version of the platform SDK that will be used to build targets for the given " + + "platform.") + public DottedVersionApi<?> getSdkVersionForPlatform(ApplePlatformApiT platform); +} |