From b8ed52129f6884ca7b7a40b4a6f515797a7f6fa6 Mon Sep 17 00:00:00 2001 From: cparsons Date: Tue, 11 Jul 2017 20:21:23 +0200 Subject: Remove apple_watch1_extension and apple_watch_extension_binary rules RELNOTES: Remove apple_watch1_extension and apple_watch_extension_binary rules. Users should be using the skylark watchos_application and watchos_extension rules. https://github.com/bazelbuild/rules_apple has details. PiperOrigin-RevId: 161555395 --- .../lib/bazel/rules/BazelRuleClassProvider.java | 4 - .../build/lib/rules/apple/AppleConfiguration.java | 2 - .../build/lib/rules/objc/AppleWatch1Extension.java | 220 ------------- .../lib/rules/objc/AppleWatch1ExtensionRule.java | 119 ------- .../lib/rules/objc/AppleWatchExtensionBinary.java | 37 --- .../rules/objc/AppleWatchExtensionBinaryRule.java | 63 ---- .../lib/rules/objc/Watch2ExtensionSupport.java | 205 ------------ .../lib/rules/objc/WatchApplicationSupport.java | 362 --------------------- .../lib/rules/objc/WatchExtensionSupport.java | 269 --------------- .../devtools/build/lib/rules/objc/WatchUtils.java | 149 --------- 10 files changed, 1430 deletions(-) delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch1Extension.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch1ExtensionRule.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinary.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinaryRule.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/objc/Watch2ExtensionSupport.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/objc/WatchApplicationSupport.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/objc/WatchExtensionSupport.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/objc/WatchUtils.java (limited to 'src/main/java/com/google') diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java index 1c01cfae09..429ef08eab 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java @@ -131,8 +131,6 @@ import com.google.devtools.build.lib.rules.objc.AppleBinaryRule; import com.google.devtools.build.lib.rules.objc.AppleSkylarkCommon; import com.google.devtools.build.lib.rules.objc.AppleStaticLibraryRule; import com.google.devtools.build.lib.rules.objc.AppleStubBinaryRule; -import com.google.devtools.build.lib.rules.objc.AppleWatch1ExtensionRule; -import com.google.devtools.build.lib.rules.objc.AppleWatchExtensionBinaryRule; import com.google.devtools.build.lib.rules.objc.IosApplicationRule; import com.google.devtools.build.lib.rules.objc.IosDeviceRule; import com.google.devtools.build.lib.rules.objc.IosExtensionBinaryRule; @@ -589,8 +587,6 @@ public class BazelRuleClassProvider { builder.addRuleDefinition(new AppleCcToolchainRule()); builder.addRuleDefinition(new AppleToolchain.RequiresXcodeConfigRule(toolsRepository)); - builder.addRuleDefinition(new AppleWatch1ExtensionRule()); - builder.addRuleDefinition(new AppleWatchExtensionBinaryRule()); builder.addRuleDefinition(new IosApplicationRule()); builder.addRuleDefinition(new IosDeviceRule()); builder.addRuleDefinition(new IosExtensionBinaryRule()); 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 76ec63ec1c..936a3bb6cf 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 @@ -710,8 +710,6 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { IOS_APPLICATION("ios_application"), /** Split transition distinguisher for {@code ios_framework} rule. */ FRAMEWORK("framework"), - /** Split transition distinguisher for {@code apple_watch1_extension} rule. */ - WATCH_OS1_EXTENSION("watch_os1_extension"), /** Distinguisher for {@code apple_binary} rule with "ios" platform_type. */ APPLEBIN_IOS("applebin_ios"), /** Distinguisher for {@code apple_binary} rule with "watchos" platform_type. */ diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch1Extension.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch1Extension.java deleted file mode 100644 index 3c134e0475..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch1Extension.java +++ /dev/null @@ -1,220 +0,0 @@ -// Copyright 2016 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import static com.google.devtools.build.lib.rules.objc.AppleWatch1ExtensionRule.WATCH_APP_DEPS_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.FLAG; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.Flag.HAS_WATCH1_EXTENSION; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.MERGE_ZIP; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchApplicationBundleRule.WATCH_APP_NAME_ATTR; - -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; -import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.analysis.config.BuildOptions; -import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.packages.Attribute.SplitTransition; -import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher; -import com.google.devtools.build.lib.rules.objc.IosExtension.ExtensionSplitArchTransition; -import com.google.devtools.build.lib.rules.objc.WatchUtils.WatchOSVersion; -import com.google.devtools.build.lib.rules.test.InstrumentedFilesCollector; -import com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider; -import com.google.devtools.build.lib.syntax.Type; - -/** - * Implementation for {@code apple_watch1_extension}. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -@Deprecated -public class AppleWatch1Extension implements RuleConfiguredTargetFactory { - - static final SplitTransition MINIMUM_OS_AND_SPLIT_ARCH_TRANSITION = - new ExtensionSplitArchTransition(WatchUtils.MINIMUM_OS_VERSION, - ConfigurationDistinguisher.WATCH_OS1_EXTENSION); - private static final ImmutableSet extensionDependencyAttributes = - ImmutableSet.of(new Attribute("binary", Mode.SPLIT)); - private static final ImmutableSet applicationDependencyAttributes = - ImmutableSet.of(new Attribute(WATCH_APP_DEPS_ATTR, Mode.SPLIT)); - - @Override - public ConfiguredTarget create(RuleContext ruleContext) - throws InterruptedException, RuleErrorException { - ruleContext.ruleWarning( - "This rule is deprecated. Please use the new Apple build rules " - + "(https://github.com/bazelbuild/rules_apple) to build Apple targets."); - - ObjcProvider.Builder extensionObjcProviderBuilder = new ObjcProvider.Builder(); - NestedSetBuilder applicationFilesToBuild = NestedSetBuilder.stableOrder(); - NestedSetBuilder extensionfilesToBuild = NestedSetBuilder.stableOrder(); - - // 1. Build watch application bundle. - createWatchApplicationBundle( - ruleContext, - applicationFilesToBuild); - - // 2. Build watch extension bundle. - createWatchExtensionBundle(ruleContext, extensionObjcProviderBuilder, extensionfilesToBuild); - - // 3. Extract the watch application bundle into the extension bundle. - registerWatchApplicationUnBundlingAction(ruleContext); - - RuleConfiguredTargetBuilder targetBuilder = - ObjcRuleClasses.ruleConfiguredTarget(ruleContext, extensionfilesToBuild.build()) - .addProvider( - InstrumentedFilesProvider.class, - InstrumentedFilesCollector.forward(ruleContext, "binary")); - - // 4. Exposed {@ObjcProvider} for bundling into final IPA. - exposeObjcProvider(ruleContext, targetBuilder, extensionObjcProviderBuilder); - - return targetBuilder.build(); - } - - /** - * Exposes an {@link ObjcProvider} with the following to create the final IPA: - * 1. Watch extension bundle. - * 2. WatchKitSupport. - * 3. A flag to indicate that watch os 1 extension is included. - */ - private void exposeObjcProvider( - RuleContext ruleContext, - RuleConfiguredTargetBuilder targetBuilder, - ObjcProvider.Builder exposedObjcProviderBuilder) - throws InterruptedException { - exposedObjcProviderBuilder.add(MERGE_ZIP, - ruleContext.getImplicitOutputArtifact(ReleaseBundlingSupport.IPA)); - WatchUtils.registerActionsToAddWatchSupport(ruleContext, exposedObjcProviderBuilder, - WatchOSVersion.OS1); - exposedObjcProviderBuilder.add(FLAG, HAS_WATCH1_EXTENSION); - - targetBuilder.addProvider(ObjcProvider.class, exposedObjcProviderBuilder.build()); - } - - /** - * Creates a watch extension bundle. - * - * @param ruleContext rule context in which to create the bundle - * which is added as a dependency to the extension - * @param objcProviderBuilder {@link ObjcProvider.Builder} for the extension - * @param filesToBuild the list to contain the files to be built for this extension bundle - */ - private void createWatchExtensionBundle(RuleContext ruleContext, - ObjcProvider.Builder objcProviderBuilder, - NestedSetBuilder filesToBuild) throws InterruptedException { - new WatchExtensionSupport( - ruleContext, - extensionDependencyAttributes, - ObjcRuleClasses.intermediateArtifacts(ruleContext), - watchExtensionBundleName(ruleContext), - watchExtensionIpaArtifact(ruleContext), - watchApplicationBundle(ruleContext)) - .createBundle(filesToBuild, objcProviderBuilder); - } - - /** - * Creates a watch application bundle. - * @param ruleContext rule context in which to create the bundle - * @param filesToBuild the list to contain the files to be built for this bundle - */ - private void createWatchApplicationBundle( - RuleContext ruleContext, - NestedSetBuilder filesToBuild) - throws InterruptedException { - new WatchApplicationSupport( - ruleContext, - WatchOSVersion.OS1, - applicationDependencyAttributes, - new IntermediateArtifacts(ruleContext, "", watchApplicationBundleName(ruleContext)), - watchApplicationBundleName(ruleContext), - watchApplicationIpaArtifact(ruleContext), - watchApplicationBundleName(ruleContext)) - .createBundle(ImmutableList.of(), filesToBuild); - } - - /** - * Registers action to extract the watch application ipa (after signing if required) to the - * extension bundle. - * - * For example, TestWatchApp.ipa will be unbundled into, - * PlugIns/TestWatchExtension.appex - * PlugIns/TestWatchExtension.appex/TestWatchApp.app - */ - private void registerWatchApplicationUnBundlingAction(RuleContext ruleContext) { - Artifact watchApplicationIpa = watchApplicationIpaArtifact(ruleContext); - Artifact watchApplicationBundle = watchApplicationBundle(ruleContext); - - String workingDirectory = watchApplicationBundle.getExecPathString().substring(0, - watchApplicationBundle.getExecPathString().lastIndexOf('/')); - - ImmutableList command = ImmutableList.of( - "mkdir -p " + workingDirectory, - "&&", - String.format("/usr/bin/unzip -q -o %s -d %s", - watchApplicationIpa.getExecPathString(), - workingDirectory), - "&&", - String.format("cd %s/Payload", workingDirectory), - "&&", - String.format("/usr/bin/zip -q -r -0 ../%s *", watchApplicationBundle.getFilename())); - ruleContext.registerAction( - ObjcRuleClasses.spawnOnDarwinActionBuilder() - .setProgressMessage("Extracting watch app: " + ruleContext.getLabel()) - .setShellCommand(ImmutableList.of("/bin/bash", "-c", Joiner.on(" ").join(command))) - .addInput(watchApplicationIpa) - .addOutput(watchApplicationBundle) - .build(ruleContext)); - } - - /** - * Returns a zip {@Artifact} containing extracted watch application - "TestWatchApp.app" - * which is to be merged into the extension bundle. - */ - private Artifact watchApplicationBundle(RuleContext ruleContext) { - return ruleContext.getRelatedArtifact(ruleContext.getUniqueDirectory( - "_watch"), String.format("/%s", watchApplicationIpaArtifact(ruleContext) - .getFilename().replace(".ipa", ".zip"))); - } - - /** - * Returns the {@Artifact} containing final watch application bundle. - */ - private Artifact watchApplicationIpaArtifact(RuleContext ruleContext) { - return ruleContext.getRelatedArtifact(ruleContext.getUniqueDirectory("_watch"), - String.format("/%s.ipa", watchApplicationBundleName(ruleContext))); - } - - /** - * Returns the {@Artifact} containing final watch extension bundle. - */ - private Artifact watchExtensionIpaArtifact(RuleContext ruleContext) throws InterruptedException { - return ruleContext.getImplicitOutputArtifact(ReleaseBundlingSupport.IPA); - } - - private String watchApplicationBundleName(RuleContext ruleContext) { - return ruleContext.attributes().get(WATCH_APP_NAME_ATTR, Type.STRING); - } - - private String watchExtensionBundleName(RuleContext ruleContext) { - return ruleContext.getLabel().getName(); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch1ExtensionRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch1ExtensionRule.java deleted file mode 100644 index a4cbcc328e..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatch1ExtensionRule.java +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright 2016 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import static com.google.devtools.build.lib.packages.Attribute.attr; -import static com.google.devtools.build.lib.packages.BuildType.LABEL; -import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; -import static com.google.devtools.build.lib.syntax.Type.STRING_LIST; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.devtools.build.lib.analysis.BaseRuleClasses; -import com.google.devtools.build.lib.analysis.RuleDefinition; -import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; -import com.google.devtools.build.lib.packages.RuleClass; -import com.google.devtools.build.lib.packages.RuleClass.Builder; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration; - -/** - * Rule definition for apple_watch1_extension. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -@Deprecated -public class AppleWatch1ExtensionRule implements RuleDefinition { - - private static final ImmutableSet ALLOWED_DEPS_RULE_CLASSES = - ImmutableSet.of("objc_library", "objc_import"); - static final String WATCH_APP_DEPS_ATTR = "app_deps"; - static final String WATCH_EXT_FAMILIES_ATTR = "ext_families"; - - @Override - public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { - return builder - .requiresConfigurationFragments(ObjcConfiguration.class, AppleConfiguration.class) - /* -
    -
  • name.ipa: the extension bundle as an .ipa - file
  • - */ - .setImplicitOutputsFunction(ReleaseBundlingSupport.IPA) - /* - The binary target containing the logic for the watch extension. This must be an - apple_watch1_extension_binary target. - */ - .add( - attr("binary", LABEL) - .allowedRuleClasses("apple_watch_extension_binary") - .allowedFileTypes() - .mandatory() - .direct_compile_time_input() - .cfg(AppleWatch1Extension.MINIMUM_OS_AND_SPLIT_ARCH_TRANSITION)) - /* - The list of targets whose resources files are bundled together to form final watch - application bundle. - */ - .add( - attr(WATCH_APP_DEPS_ATTR, LABEL_LIST) - .direct_compile_time_input() - .allowedRuleClasses(ALLOWED_DEPS_RULE_CLASSES) - .allowedFileTypes() - .cfg(AppleWatch1Extension.MINIMUM_OS_AND_SPLIT_ARCH_TRANSITION)) - /* - The device families to which the watch extension is targeted. - - This is known as the TARGETED_DEVICE_FAMILY build setting - in Xcode project files. It is a list of one or more of the strings - "iphone" and "ipad". - -

    By default this is set to "iphone". If it is explicitly specified it may not - be empty.

    -

    The watch application is always built for "watch" for device builds and - "iphone, watch" for simulator builds. - */ - .add( - attr(WATCH_EXT_FAMILIES_ATTR, STRING_LIST) - .value(ImmutableList.of(TargetDeviceFamily.IPHONE.getNameInRule()))) - .build(); - } - - @Override - public Metadata getMetadata() { - return RuleDefinition.Metadata.builder() - .name("apple_watch1_extension") - .factoryClass(AppleWatch1Extension.class) - .ancestors(BaseRuleClasses.BaseRule.class, - ObjcRuleClasses.WatchApplicationBundleRule.class, - ObjcRuleClasses.WatchExtensionBundleRule.class) - .build(); - } -} - -/* - -

    This rule is deprecated. Please use the new Apple build rules -(https://github.com/bazelbuild/rules_apple) -to build Apple targets.

    - -

    This rule produces an extension bundle for apple watch OS 1 which also contains the watch -application bundle

    - -${IMPLICIT_OUTPUTS} - -${ATTRIBUTE_DEFINITION} - -*/ diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinary.java deleted file mode 100644 index 24fc54fc18..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinary.java +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2016 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.rules.objc.CompilationSupport.ExtraLinkArgs; - -/** - * Implementation for the "apple_watch_extension_binary" rule. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -@Deprecated -public class AppleWatchExtensionBinary extends BinaryLinkingTargetFactory { - - public AppleWatchExtensionBinary() { - super(HasReleaseBundlingSupport.NO); - } - - @Override - protected ExtraLinkArgs getExtraLinkArgs(RuleContext ruleContext) { - return new ExtraLinkArgs("-fapplication-extension", "-framework", "WatchKit"); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinaryRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinaryRule.java deleted file mode 100644 index d6a5d30e4b..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinaryRule.java +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2016 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import com.google.devtools.build.lib.analysis.BaseRuleClasses; -import com.google.devtools.build.lib.analysis.RuleDefinition; -import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; -import com.google.devtools.build.lib.packages.RuleClass; -import com.google.devtools.build.lib.packages.RuleClass.Builder; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration; -import com.google.devtools.build.lib.rules.cpp.CppConfiguration; - -/** - * Rule definition for apple_watch_extension_binary. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -@Deprecated -public class AppleWatchExtensionBinaryRule implements RuleDefinition { - @Override - public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { - return builder - .requiresConfigurationFragments(ObjcConfiguration.class, J2ObjcConfiguration.class, - AppleConfiguration.class, CppConfiguration.class) - .cfg(AppleCrosstoolTransition.APPLE_CROSSTOOL_TRANSITION) - .build(); - } - - @Override - public Metadata getMetadata() { - return RuleDefinition.Metadata.builder() - .name("apple_watch_extension_binary") - .factoryClass(AppleWatchExtensionBinary.class) - .ancestors(BaseRuleClasses.BaseRule.class, ObjcRuleClasses.LinkingRule.class) - .build(); - } -} - -/* - -

    This rule is deprecated. Please use the new Apple build rules -(https://github.com/bazelbuild/rules_apple) -to build Apple targets.

    - -

    This rule produces a binary for watch extension by linking one or more -Objective-C libraries.

    - -${IMPLICIT_OUTPUTS} - -*/ diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/Watch2ExtensionSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/Watch2ExtensionSupport.java deleted file mode 100644 index a73ecaeafb..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/Watch2ExtensionSupport.java +++ /dev/null @@ -1,205 +0,0 @@ -// Copyright 2016 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.BUNDLE_FILE; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.GENERAL_RESOURCE_DIR; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.GENERAL_RESOURCE_FILE; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.STRINGS; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchExtensionBundleRule.WATCH_EXT_BUNDLE_ID_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchExtensionBundleRule.WATCH_EXT_DEFAULT_PROVISIONING_PROFILE_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchExtensionBundleRule.WATCH_EXT_ENTITLEMENTS_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchExtensionBundleRule.WATCH_EXT_INFOPLISTS_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchExtensionBundleRule.WATCH_EXT_PROVISIONING_PROFILE_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchExtensionBundleRule.WATCH_EXT_RESOURCES_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchExtensionBundleRule.WATCH_EXT_STRINGS_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchExtensionBundleRule.WATCH_EXT_STRUCTURED_RESOURCES_ATTR; - -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; -import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration; -import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType; -import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.LinkedBinary; -import com.google.devtools.build.lib.syntax.Type; -import javax.annotation.Nullable; - -/** - * Contains support methods to build watch extension bundle - does normal bundle processing - - * compiling and linking the binary, resources, plists and creates a final (signed if necessary) - * bundle. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -@Deprecated -public class Watch2ExtensionSupport { - - private final RuleContext ruleContext; - private final IntermediateArtifacts intermediateArtifacts; - private final String bundleName; - private final Attributes attributes; - - /** - * @param ruleContext the current rule context - * @param intermediateArtifacts the utility object to obtain namespacing for intermediate bundling - * artifacts - * @param bundleName the name of the bundle - */ - Watch2ExtensionSupport( - RuleContext ruleContext, IntermediateArtifacts intermediateArtifacts, String bundleName) { - this.ruleContext = ruleContext; - this.intermediateArtifacts = intermediateArtifacts; - this.bundleName = bundleName; - this.attributes = new Attributes(ruleContext); - } - - /** - * Registers actions to create a watchOS2 extension bundle and zip it into an {@code .ipa}. - * - * @param ipaArtifact an .ipa artifact containing to extension bundle; this is the output artifact - * of the bundling - */ - void createBundle(Artifact ipaArtifact, - NestedSetBuilder extensionFilesToBuild, - ObjcProvider.Builder exposedObjcProviderBuilder) throws InterruptedException { - ObjcProvider.Builder releaseBundlingObjcProviderBuilder = new ObjcProvider.Builder(); - releaseBundlingObjcProviderBuilder.addTransitiveAndPropagate(attributes.binaryDependencies()); - releaseBundlingObjcProviderBuilder - .addAll(GENERAL_RESOURCE_FILE, attributes.resources()) - .addAll(GENERAL_RESOURCE_FILE, attributes.strings()) - .addAll( - GENERAL_RESOURCE_DIR, - ObjcCommon.xcodeStructuredResourceDirs(attributes.structuredResources())) - .addAll(BUNDLE_FILE, BundleableFile.flattenedRawResourceFiles(attributes.resources())) - .addAll( - BUNDLE_FILE, - BundleableFile.structuredRawResourceFiles(attributes.structuredResources())) - .addAll(STRINGS, attributes.strings()); - ObjcProvider releaseBundlingObjcProvider = releaseBundlingObjcProviderBuilder.build(); - - ReleaseBundling.Builder releaseBundling = - new ReleaseBundling.Builder() - .setIpaArtifact(ipaArtifact) - .setBundleId(attributes.bundleId()) - .setProvisioningProfile(attributes.provisioningProfile()) - .setProvisioningProfileAttributeName(WATCH_EXT_PROVISIONING_PROFILE_ATTR) - .setTargetDeviceFamilies(ImmutableSet.of(TargetDeviceFamily.WATCH)) - .setIntermediateArtifacts(intermediateArtifacts) - .setInfoPlistsFromRule(attributes.infoPlists()) - .setEntitlements(attributes.entitlements()); - - if (attributes.isBundleIdExplicitySpecified()) { - releaseBundling.setPrimaryBundleId(attributes.bundleId()); - } else { - releaseBundling.setFallbackBundleId(attributes.bundleId()); - } - - AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); - - ReleaseBundlingSupport releaseBundlingSupport = - new ReleaseBundlingSupport( - ruleContext, - releaseBundlingObjcProvider, - LinkedBinary.DEPENDENCIES_ONLY, - ReleaseBundlingSupport.EXTENSION_BUNDLE_DIR_FORMAT, - bundleName, - appleConfiguration.getMinimumOsForPlatformType(PlatformType.WATCHOS), - releaseBundling.build(), - appleConfiguration.getMultiArchPlatform(PlatformType.WATCHOS)); - - releaseBundlingSupport - .registerActions(DsymOutputType.APP) - .addFilesToBuild(extensionFilesToBuild, Optional.of(DsymOutputType.APP)) - .validateResources() - .validateAttributes() - .addExportedDebugArtifacts(exposedObjcProviderBuilder, DsymOutputType.APP); - } - - /** Rule attributes used for creating watch application bundle. */ - private static class Attributes { - private final RuleContext ruleContext; - - private Attributes(RuleContext ruleContext) { - this.ruleContext = ruleContext; - } - - @Nullable - Artifact provisioningProfile() { - Artifact explicitProvisioningProfile = - getPrerequisiteArtifact(WATCH_EXT_PROVISIONING_PROFILE_ATTR); - if (explicitProvisioningProfile != null) { - return explicitProvisioningProfile; - } - return getPrerequisiteArtifact(WATCH_EXT_DEFAULT_PROVISIONING_PROFILE_ATTR); - } - - String bundleId() { - Preconditions.checkState( - !Strings.isNullOrEmpty( - ruleContext.attributes().get(WATCH_EXT_BUNDLE_ID_ATTR, Type.STRING)), - "requires a bundle_id value"); - return ruleContext.attributes().get(WATCH_EXT_BUNDLE_ID_ATTR, Type.STRING); - } - - ImmutableList infoPlists() { - return getPrerequisiteArtifacts(WATCH_EXT_INFOPLISTS_ATTR); - } - - ImmutableList strings() { - return getPrerequisiteArtifacts(WATCH_EXT_STRINGS_ATTR); - } - - ImmutableList resources() { - return getPrerequisiteArtifacts(WATCH_EXT_RESOURCES_ATTR); - } - - ImmutableList structuredResources() { - return getPrerequisiteArtifacts(WATCH_EXT_STRUCTURED_RESOURCES_ATTR); - } - - Iterable binaryDependencies() { - TransitiveInfoCollection info = ruleContext.getPrerequisite("binary", Mode.TARGET); - AppleExecutableBinaryProvider binaryProvider = - info.get(AppleExecutableBinaryProvider.SKYLARK_CONSTRUCTOR); - return ImmutableList.of(binaryProvider.getDepsObjcProvider()); - } - - @Nullable - Artifact entitlements() { - return getPrerequisiteArtifact(WATCH_EXT_ENTITLEMENTS_ATTR); - } - - private boolean isBundleIdExplicitySpecified() { - return ruleContext.attributes().isAttributeValueExplicitlySpecified(WATCH_EXT_BUNDLE_ID_ATTR); - } - - private ImmutableList getPrerequisiteArtifacts(String attribute) { - return ruleContext.getPrerequisiteArtifacts(attribute, Mode.TARGET).list(); - } - - @Nullable - private Artifact getPrerequisiteArtifact(String attribute) { - return ruleContext.getPrerequisiteArtifact(attribute, Mode.TARGET); - } - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/WatchApplicationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/WatchApplicationSupport.java deleted file mode 100644 index 888dac5c22..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/WatchApplicationSupport.java +++ /dev/null @@ -1,362 +0,0 @@ -// Copyright 2016 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.ASSET_CATALOG; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.BUNDLE_FILE; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.GENERAL_RESOURCE_DIR; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.GENERAL_RESOURCE_FILE; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.MERGE_ZIP; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.STORYBOARD; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.STRINGS; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.XCASSETS_DIR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchApplicationBundleRule.WATCH_APP_ASSET_CATALOGS_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchApplicationBundleRule.WATCH_APP_BUNDLE_ID_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchApplicationBundleRule.WATCH_APP_DEFAULT_PROVISIONING_PROFILE_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchApplicationBundleRule.WATCH_APP_ENTITLEMENTS_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchApplicationBundleRule.WATCH_APP_ICON_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchApplicationBundleRule.WATCH_APP_INFOPLISTS_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchApplicationBundleRule.WATCH_APP_PROVISIONING_PROFILE_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchApplicationBundleRule.WATCH_APP_RESOURCES_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchApplicationBundleRule.WATCH_APP_STORYBOARDS_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchApplicationBundleRule.WATCH_APP_STRINGS_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchApplicationBundleRule.WATCH_APP_STRUCTURED_RESOURCES_ATTR; - -import com.google.common.base.Joiner; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration; -import com.google.devtools.build.lib.rules.apple.ApplePlatform; -import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType; -import com.google.devtools.build.lib.rules.apple.DottedVersion; -import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.LinkedBinary; -import com.google.devtools.build.lib.rules.objc.WatchUtils.WatchOSVersion; -import com.google.devtools.build.lib.syntax.Type; -import javax.annotation.Nullable; - -/** - * Contains support methods to build watch application bundle - does normal bundle processing - - * resources, plists and creates a final (signed if necessary) bundle. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -@Deprecated -final class WatchApplicationSupport { - - private final RuleContext ruleContext; - private final WatchOSVersion watchOSVersion; - private final ImmutableSet dependencyAttributes; - private final String bundleName; - private final IntermediateArtifacts intermediateArtifacts; - private final Attributes attributes; - private final Artifact ipaArtifact; - private final String artifactPrefix; - - /** - * @param ruleContext the current rule context - * @param watchOSVersion the version of watchOS for which to create an application bundle - * @param dependencyAttributes attributes on the current rule context to obtain transitive - * resources from - * @param intermediateArtifacts the utility object to obtain namespacing for intermediate bundling - * artifacts - * @param bundleName the name of the bundle - * @param ipaArtifact the output ipa created by this application bundling - * @param artifactPrefix the string prefix to prepend to bundling artifacts for the application -- - * this prevents intermediate artifacts under this same rule context (such as watch extension - * bundling) from conflicting - */ - WatchApplicationSupport( - RuleContext ruleContext, - WatchOSVersion watchOSVersion, - ImmutableSet dependencyAttributes, - IntermediateArtifacts intermediateArtifacts, - String bundleName, - Artifact ipaArtifact, - String artifactPrefix) { - this.ruleContext = ruleContext; - this.watchOSVersion = watchOSVersion; - this.dependencyAttributes = dependencyAttributes; - this.intermediateArtifacts = intermediateArtifacts; - this.bundleName = bundleName; - this.ipaArtifact = ipaArtifact; - this.artifactPrefix = artifactPrefix; - this.attributes = new Attributes(ruleContext); - } - - /** - * Registers actions to create a watch application bundle. - * - * @param innerBundleZips any zip files to be unzipped and merged into the application bundle - * @param filesToBuild files to build for the rule; the watchOS application .ipa is added to this - * set - */ - void createBundle( - Iterable innerBundleZips, - NestedSetBuilder filesToBuild) - throws InterruptedException { - - ObjcProvider objcProvider = objcProvider(innerBundleZips); - - registerActions(); - - ReleaseBundling.Builder releaseBundling = new ReleaseBundling.Builder() - .setIpaArtifact(ipaArtifact) - .setBundleId(attributes.bundleId()) - .setAppIcon(attributes.appIcon()) - .setProvisioningProfile(attributes.provisioningProfile()) - .setProvisioningProfileAttributeName(WATCH_APP_PROVISIONING_PROFILE_ATTR) - .setTargetDeviceFamilies(families()) - .setIntermediateArtifacts(intermediateArtifacts) - .setInfoPlistsFromRule(attributes.infoPlists()) - .setArtifactPrefix(artifactPrefix) - .setEntitlements(attributes.entitlements()); - - if (attributes.isBundleIdExplicitySpecified()) { - releaseBundling.setPrimaryBundleId(attributes.bundleId()); - } else { - releaseBundling.setFallbackBundleId(attributes.bundleId()); - } - - AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); - - PlatformType appPlatformType = watchOSVersion == WatchOSVersion.OS1 - ? PlatformType.IOS : PlatformType.WATCHOS; - DottedVersion minimumOsVersion = appPlatformType == PlatformType.IOS - ? WatchUtils.determineMinimumIosVersion( - appleConfiguration.getMinimumOsForPlatformType(PlatformType.IOS)) - : appleConfiguration.getMinimumOsForPlatformType(PlatformType.WATCHOS); - - ReleaseBundlingSupport releaseBundlingSupport = - new ReleaseBundlingSupport( - ruleContext, - objcProvider, - LinkedBinary.DEPENDENCIES_ONLY, - watchOSVersion.getApplicationBundleDirFormat(), - bundleName, - minimumOsVersion, - releaseBundling.build(), - appleConfiguration.getMultiArchPlatform(appPlatformType)) - .registerActions(DsymOutputType.APP); - - releaseBundlingSupport - .addFilesToBuild(filesToBuild, Optional.absent()) - .validateResources() - .validateAttributes(); - } - - /** - * Returns the {@link TargetDeviceFamily} that the watch application bundle is targeting. This - * is always {@code TargetDeviceFamily.WATCH}, except for WatchOS1, which has the following - * special rules: - * - * For simulator builds, this returns a set of {@code TargetDeviceFamily.IPHONE} and - * {@code TargetDeviceFamily.WATCH} and for non-simulator builds, this returns - * {@code TargetDeviceFamily.WATCH}. - */ - private ImmutableSet families() { - ApplePlatform platform = - ruleContext.getFragment(AppleConfiguration.class).getMultiArchPlatform(PlatformType.IOS); - if (watchOSVersion != WatchOSVersion.OS1 || platform == ApplePlatform.IOS_DEVICE) { - return ImmutableSet.of(TargetDeviceFamily.WATCH); - } else { - return ImmutableSet.of(TargetDeviceFamily.IPHONE, TargetDeviceFamily.WATCH); - } - } - - /** - * Registers actions to copy WatchKit stub binary at - * $(SDK_ROOT)/Library/Application Support/WatchKit/WK as bundle binary and as stub resource. - * - * For example, for a bundle named "Foo.app", the contents will be, - * - Foo.app/Foo (WK stub as binary) - * - Foo.app/_WatchKitStub/WK (WK stub as resource) - */ - private void registerActions() { - Artifact watchKitStubZip = watchKitStubZip(); - String workingDirectory = watchKitStubZip.getExecPathString() - .substring(0, watchKitStubZip.getExecPathString().lastIndexOf('/')); - String watchKitStubBinaryPath = workingDirectory + "/" + bundleName; - String watchKitStubResourcePath = workingDirectory + "/_WatchKitStub"; - - ImmutableList command = ImmutableList.of( - // 1. Copy WK stub as binary - String.format("cp -f %s %s", WatchUtils.WATCH_KIT_STUB_PATH, watchKitStubBinaryPath), - "&&", - // 2. Copy WK stub as bundle resource. - "mkdir -p " + watchKitStubResourcePath, - "&&", - String.format("cp -f %s %s", WatchUtils.WATCH_KIT_STUB_PATH, watchKitStubResourcePath), - // 3. Zip them. - "&&", - "cd " + workingDirectory, - "&&", - String.format( - "/usr/bin/zip -q -r -0 %s %s", - watchKitStubZip.getFilename(), - Joiner.on(" ").join(ImmutableList.of("_WatchKitStub", bundleName)))); - - AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); - ruleContext.registerAction( - ObjcRuleClasses.spawnAppleEnvActionBuilder( - appleConfiguration, - appleConfiguration.getMultiArchPlatform(PlatformType.WATCHOS)) - .setProgressMessage( - "Copying WatchKit binary and stub resource: " + ruleContext.getLabel()) - .setShellCommand(ImmutableList.of("/bin/bash", "-c", Joiner.on(" ").join(command))) - .addOutput(watchKitStubZip) - .build(ruleContext)); - } - - private ObjcProvider objcProvider(Iterable innerBundleZips) { - ObjcProvider.Builder objcProviderBuilder = new ObjcProvider.Builder(); - if (watchOSVersion != WatchOSVersion.OS1) { - objcProviderBuilder.addAll(MERGE_ZIP, innerBundleZips); - } - - // Add all resource files applicable to watch application from dependency providers. - for (Attribute attribute : dependencyAttributes) { - Iterable dependencyObjcProviders = ruleContext.getPrerequisites( - attribute.getName(), attribute.getAccessMode(), ObjcProvider.class); - for (ObjcProvider dependencyObjcProvider : dependencyObjcProviders) { - objcProviderBuilder.addTransitiveAndPropagate(GENERAL_RESOURCE_FILE, - dependencyObjcProvider); - objcProviderBuilder.addTransitiveAndPropagate(GENERAL_RESOURCE_DIR, - dependencyObjcProvider); - objcProviderBuilder.addTransitiveAndPropagate(BUNDLE_FILE, - dependencyObjcProvider); - objcProviderBuilder.addTransitiveAndPropagate(XCASSETS_DIR, - dependencyObjcProvider); - objcProviderBuilder.addTransitiveAndPropagate(ASSET_CATALOG, - dependencyObjcProvider); - objcProviderBuilder.addTransitiveAndPropagate(STRINGS, - dependencyObjcProvider); - objcProviderBuilder.addTransitiveAndPropagate(STORYBOARD, - dependencyObjcProvider); - } - } - // Add zip containing WatchKit stubs. - objcProviderBuilder.add(ObjcProvider.MERGE_ZIP, watchKitStubZip()); - - // Add resource files. - objcProviderBuilder.addAll(GENERAL_RESOURCE_FILE, attributes.storyboards()) - .addAll(GENERAL_RESOURCE_FILE, attributes.resources()) - .addAll(GENERAL_RESOURCE_FILE, attributes.strings()) - .addAll(GENERAL_RESOURCE_DIR, - ObjcCommon.xcodeStructuredResourceDirs(attributes.structuredResources())) - .addAll(BUNDLE_FILE, BundleableFile.flattenedRawResourceFiles(attributes.resources())) - .addAll( - BUNDLE_FILE, - BundleableFile.structuredRawResourceFiles(attributes.structuredResources())) - .addAll(XCASSETS_DIR, ObjcCommon.uniqueContainers(attributes.assetCatalogs(), - ObjcCommon.ASSET_CATALOG_CONTAINER_TYPE)) - .addAll(ASSET_CATALOG, attributes.assetCatalogs()) - .addAll(STRINGS, attributes.strings()) - .addAll(STORYBOARD, attributes.storyboards()); - - return objcProviderBuilder.build(); - } - - /** - * Returns a zip {@link Artifact} containing stub binary and stub resource that are to be added - * to the bundle. - */ - private Artifact watchKitStubZip() { - return ruleContext.getRelatedArtifact( - ruleContext.getUniqueDirectory("_watch"), "/WatchKitStub.zip"); - } - - /** - * Rule attributes used for creating watch application bundle. - */ - private static class Attributes { - private final RuleContext ruleContext; - - private Attributes(RuleContext ruleContext) { - this.ruleContext = ruleContext; - } - - @Nullable - String appIcon() { - return Strings.emptyToNull(ruleContext.attributes().get(WATCH_APP_ICON_ATTR, Type.STRING)); - } - - @Nullable - Artifact provisioningProfile() { - Artifact explicitProvisioningProfile = - getPrerequisiteArtifact(WATCH_APP_PROVISIONING_PROFILE_ATTR); - if (explicitProvisioningProfile != null) { - return explicitProvisioningProfile; - } - return getPrerequisiteArtifact(WATCH_APP_DEFAULT_PROVISIONING_PROFILE_ATTR); - } - - String bundleId() { - Preconditions.checkState(!Strings.isNullOrEmpty( - ruleContext.attributes().get(WATCH_APP_BUNDLE_ID_ATTR, Type.STRING)), - "requires a bundle_id value"); - return ruleContext.attributes().get(WATCH_APP_BUNDLE_ID_ATTR, Type.STRING); - } - - ImmutableList infoPlists() { - return getPrerequisiteArtifacts(WATCH_APP_INFOPLISTS_ATTR); - } - - ImmutableList assetCatalogs() { - return getPrerequisiteArtifacts(WATCH_APP_ASSET_CATALOGS_ATTR); - } - - ImmutableList strings() { - return getPrerequisiteArtifacts(WATCH_APP_STRINGS_ATTR); - } - - ImmutableList storyboards() { - return getPrerequisiteArtifacts(WATCH_APP_STORYBOARDS_ATTR); - } - - ImmutableList resources() { - return getPrerequisiteArtifacts(WATCH_APP_RESOURCES_ATTR); - } - - ImmutableList structuredResources() { - return getPrerequisiteArtifacts(WATCH_APP_STRUCTURED_RESOURCES_ATTR); - } - - @Nullable - Artifact entitlements() { - return getPrerequisiteArtifact(WATCH_APP_ENTITLEMENTS_ATTR); - } - - private boolean isBundleIdExplicitySpecified() { - return ruleContext.attributes().isAttributeValueExplicitlySpecified(WATCH_APP_BUNDLE_ID_ATTR); - } - - private ImmutableList getPrerequisiteArtifacts(String attribute) { - return ruleContext.getPrerequisiteArtifacts(attribute, Mode.TARGET).list(); - } - - @Nullable - private Artifact getPrerequisiteArtifact(String attribute) { - return ruleContext.getPrerequisiteArtifact(attribute, Mode.TARGET); - } - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/WatchExtensionSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/WatchExtensionSupport.java deleted file mode 100644 index 675682c150..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/WatchExtensionSupport.java +++ /dev/null @@ -1,269 +0,0 @@ -// Copyright 2016 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.BUNDLE_FILE; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.GENERAL_RESOURCE_DIR; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.GENERAL_RESOURCE_FILE; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.MERGE_ZIP; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.STRINGS; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.BundlingRule.FAMILIES_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchExtensionBundleRule.WATCH_EXT_BUNDLE_ID_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchExtensionBundleRule.WATCH_EXT_DEFAULT_PROVISIONING_PROFILE_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchExtensionBundleRule.WATCH_EXT_ENTITLEMENTS_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchExtensionBundleRule.WATCH_EXT_INFOPLISTS_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchExtensionBundleRule.WATCH_EXT_PROVISIONING_PROFILE_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchExtensionBundleRule.WATCH_EXT_RESOURCES_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchExtensionBundleRule.WATCH_EXT_STRINGS_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.WatchExtensionBundleRule.WATCH_EXT_STRUCTURED_RESOURCES_ATTR; - -import com.dd.plist.NSDictionary; -import com.dd.plist.NSObject; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.analysis.actions.FileWriteAction; -import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration; -import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType; -import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.LinkedBinary; -import com.google.devtools.build.lib.rules.objc.TargetDeviceFamily.InvalidFamilyNameException; -import com.google.devtools.build.lib.rules.objc.TargetDeviceFamily.RepeatedFamilyNameException; -import com.google.devtools.build.lib.syntax.Type; -import java.util.List; -import javax.annotation.Nullable; - -/** - * Contains support methods to build WatchOS1 extension bundles - does normal bundle processing - - * compiling and linking the binary, resources, plists and creates a final (signed if necessary) - * bundle. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -@Deprecated -public class WatchExtensionSupport { - - private final RuleContext ruleContext; - private final ImmutableSet dependencyAttributes; - private final IntermediateArtifacts intermediateArtifacts; - private final String bundleName; - private final Artifact ipaArtifact; - private final Artifact watchApplicationBundle; - private final Attributes attributes; - - WatchExtensionSupport( - RuleContext ruleContext, - ImmutableSet dependencyAttributes, - IntermediateArtifacts intermediateArtifacts, - String bundleName, - Artifact ipaArtifact, - @Nullable Artifact watchApplicationBundle) { - this.ruleContext = ruleContext; - this.dependencyAttributes = dependencyAttributes; - this.intermediateArtifacts = intermediateArtifacts; - this.bundleName = bundleName; - this.ipaArtifact = ipaArtifact; - this.attributes = new Attributes(ruleContext); - this.watchApplicationBundle = checkNotNull(watchApplicationBundle); - } - - void createBundle( - NestedSetBuilder filesToBuild, ObjcProvider.Builder exposedObjcProviderBuilder) - throws InterruptedException { - - ObjcProvider releaseBundlingObjcProvider = releaseBundlingObjcProvider(); - - registerWatchExtensionAutomaticPlistAction(); - - ImmutableSet families = attributes.families(); - - if (families.isEmpty()) { - ruleContext.attributeError(FAMILIES_ATTR, ReleaseBundling.INVALID_FAMILIES_ERROR); - } - - ReleaseBundling.Builder releaseBundling = new ReleaseBundling.Builder() - .setIpaArtifact(ipaArtifact) - .setBundleId(attributes.bundleId()) - .setProvisioningProfile(attributes.provisioningProfile()) - .setProvisioningProfileAttributeName(WATCH_EXT_PROVISIONING_PROFILE_ATTR) - .setTargetDeviceFamilies(families) - .setIntermediateArtifacts(intermediateArtifacts) - .setInfoPlistsFromRule(attributes.infoPlists()) - .addInfoplistInput(watchExtensionAutomaticPlist()) - .setEntitlements(attributes.entitlements()); - - if (attributes.isBundleIdExplicitySpecified()) { - releaseBundling.setPrimaryBundleId(attributes.bundleId()); - } else { - releaseBundling.setFallbackBundleId(attributes.bundleId()); - } - - AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); - - ReleaseBundlingSupport releaseBundlingSupport = - new ReleaseBundlingSupport( - ruleContext, - releaseBundlingObjcProvider, - LinkedBinary.DEPENDENCIES_ONLY, - ReleaseBundlingSupport.EXTENSION_BUNDLE_DIR_FORMAT, - bundleName, - WatchUtils.determineMinimumIosVersion( - appleConfiguration.getMinimumOsForPlatformType(PlatformType.IOS)), - releaseBundling.build(), - appleConfiguration.getMultiArchPlatform(PlatformType.IOS)); - - releaseBundlingSupport.registerActions(DsymOutputType.APP); - - releaseBundlingSupport - .addFilesToBuild(filesToBuild, Optional.of(DsymOutputType.APP)) - .validateResources() - .validateAttributes() - .addExportedDebugArtifacts(exposedObjcProviderBuilder, DsymOutputType.APP); - } - - /** - * Registers an action to generate a plist containing entries required for watch extension that - * should be added to the merged plist. - */ - private void registerWatchExtensionAutomaticPlistAction() { - List uiRequiredDeviceCapabilities = ImmutableList.of("watch-companion"); - NSDictionary watchExtensionAutomaticEntries = new NSDictionary(); - watchExtensionAutomaticEntries.put("UIRequiredDeviceCapabilities", - NSObject.wrap(uiRequiredDeviceCapabilities.toArray())); - - ruleContext.registerAction( - FileWriteAction.create( - ruleContext, - watchExtensionAutomaticPlist(), - watchExtensionAutomaticEntries.toGnuStepASCIIPropertyList(), - /*makeExecutable=*/ false)); - } - - private Artifact watchExtensionAutomaticPlist() { - return ruleContext.getRelatedArtifact( - ruleContext.getUniqueDirectory("plists"), "-automatic-watchExtensionInfo.plist"); - } - - private ObjcProvider releaseBundlingObjcProvider() { - ObjcProvider.Builder objcProviderBuilder = new ObjcProvider.Builder(); - // Add dependency providers. - for (Attribute attribute : dependencyAttributes) { - objcProviderBuilder.addTransitiveAndPropagate( - ruleContext.getPrerequisites( - attribute.getName(), attribute.getAccessMode(), ObjcProvider.class)); - } - - // Expose the generated watch application bundle to the extension bundle. - objcProviderBuilder.add(MERGE_ZIP, watchApplicationBundle); - - // Add resource files. - objcProviderBuilder.addAll(GENERAL_RESOURCE_FILE, attributes.resources()) - .addAll(GENERAL_RESOURCE_FILE, attributes.strings()) - .addAll(GENERAL_RESOURCE_DIR, ObjcCommon.xcodeStructuredResourceDirs( - attributes.structuredResources())) - .addAll(BUNDLE_FILE, BundleableFile.flattenedRawResourceFiles(attributes.resources())) - .addAll( - BUNDLE_FILE, - BundleableFile.structuredRawResourceFiles(attributes.structuredResources())) - .addAll(STRINGS, attributes.strings()); - - return objcProviderBuilder.build(); - } - - /** - * Rule attributes used for creating watch application bundle. - */ - private static class Attributes { - private final RuleContext ruleContext; - - private Attributes(RuleContext ruleContext) { - this.ruleContext = ruleContext; - } - - /** - * Returns the value of the {@code families} attribute in a form - * that is more useful than a list of strings. Returns an empty - * set for any invalid {@code families} attribute value, including - * an empty list. - */ - ImmutableSet families() { - List rawFamilies = ruleContext.attributes().get( - AppleWatch1ExtensionRule.WATCH_EXT_FAMILIES_ATTR, Type.STRING_LIST); - try { - return ImmutableSet.copyOf(TargetDeviceFamily.fromNamesInRule(rawFamilies)); - } catch (InvalidFamilyNameException | RepeatedFamilyNameException e) { - return ImmutableSet.of(); - } - } - - @Nullable - Artifact provisioningProfile() { - Artifact explicitProvisioningProfile = - getPrerequisiteArtifact(WATCH_EXT_PROVISIONING_PROFILE_ATTR); - if (explicitProvisioningProfile != null) { - return explicitProvisioningProfile; - } - return getPrerequisiteArtifact(WATCH_EXT_DEFAULT_PROVISIONING_PROFILE_ATTR); - } - - String bundleId() { - Preconditions.checkState(!Strings.isNullOrEmpty( - ruleContext.attributes().get(WATCH_EXT_BUNDLE_ID_ATTR, Type.STRING)), - "requires a bundle_id value"); - return ruleContext.attributes().get(WATCH_EXT_BUNDLE_ID_ATTR, Type.STRING); - } - - ImmutableList infoPlists() { - return getPrerequisiteArtifacts(WATCH_EXT_INFOPLISTS_ATTR); - } - - ImmutableList strings() { - return getPrerequisiteArtifacts(WATCH_EXT_STRINGS_ATTR); - } - - ImmutableList resources() { - return getPrerequisiteArtifacts(WATCH_EXT_RESOURCES_ATTR); - } - - ImmutableList structuredResources() { - return getPrerequisiteArtifacts(WATCH_EXT_STRUCTURED_RESOURCES_ATTR); - } - - @Nullable - Artifact entitlements() { - return getPrerequisiteArtifact(WATCH_EXT_ENTITLEMENTS_ATTR); - } - - private boolean isBundleIdExplicitySpecified() { - return ruleContext.attributes().isAttributeValueExplicitlySpecified(WATCH_EXT_BUNDLE_ID_ATTR); - } - - private ImmutableList getPrerequisiteArtifacts(String attribute) { - return ruleContext.getPrerequisiteArtifacts(attribute, Mode.TARGET).list(); - } - - @Nullable - private Artifact getPrerequisiteArtifact(String attribute) { - return ruleContext.getPrerequisiteArtifact(attribute, Mode.TARGET); - } - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/WatchUtils.java b/src/main/java/com/google/devtools/build/lib/rules/objc/WatchUtils.java deleted file mode 100644 index 28d888c021..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/WatchUtils.java +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright 2016 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.ROOT_MERGE_ZIP; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Ordering; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration; -import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType; -import com.google.devtools.build.lib.rules.apple.DottedVersion; - -/** - * Contains support methods for common processing and generating of watch extension and application - * bundles. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -// TODO(b/30503590): Refactor this into a support class -- such classes are better than this static -// utility. -@Deprecated -final class WatchUtils { - - @VisibleForTesting - /** Bundle directory format for watch applications for watch OS 2. */ - static final String WATCH2_APP_BUNDLE_DIR_FORMAT = "Watch/%s.app"; - - /** - * Supported Apple watch OS versions. - */ - enum WatchOSVersion { - OS1( - ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT, - "WatchKitSupport"), - OS2( - WATCH2_APP_BUNDLE_DIR_FORMAT, - "WatchKitSupport2"); - - private final String applicationBundleDirFormat; - private final String watchKitSupportDirName; - - WatchOSVersion( - String applicationBundleDirFormat, - String watchKitSupportDirName) { - this.applicationBundleDirFormat = applicationBundleDirFormat; - this.watchKitSupportDirName = watchKitSupportDirName; - } - - /** Returns the bundle directory format of the watch application relative to its container. */ - String getApplicationBundleDirFormat() { - return applicationBundleDirFormat; - } - - /** - * Returns the name of the directory in the final iOS bundle which should contain the WatchKit - * support stub. - */ - String getWatchKitSupportDirName() { - return watchKitSupportDirName; - } - } - - @VisibleForTesting - static final String WATCH_KIT_STUB_PATH = - "${SDKROOT}/Library/Application\\ Support/WatchKit/WK"; - - // Apple only accepts watch extension and application starting at 8.2. - @VisibleForTesting - static final DottedVersion MINIMUM_OS_VERSION = DottedVersion.fromString("8.2"); - - /** - * Watch Extension are not accepted by Apple below iOS version 8.2. While applications built with - * a minimum iOS version of less than 8.2 may contain watch extension in their bundle, the - * extension itself needs to be built with 8.2 or higher. This logic overrides (if necessary) - * any flag-set minimum iOS version for extensions only so that this requirement is not - * violated. - */ - static DottedVersion determineMinimumIosVersion(DottedVersion fromFlag) { - return Ordering.natural().max(fromFlag, MINIMUM_OS_VERSION); - } - - /** - * Adds WatchKitSupport stub to the final ipa and exposes it to given @{link ObjcProvider.Builder} - * based on watch OS version. - * - * For example, for watch OS 1, the resulting ipa will have: - * Payload/TestApp.app - * WatchKitSupport - * WatchKitSupport/WK - */ - static void registerActionsToAddWatchSupport( - RuleContext ruleContext, ObjcProvider.Builder objcProviderBuilder, - WatchOSVersion watchOSVersion) { - Artifact watchSupportZip = watchSupportZip(ruleContext); - String workingDirectory = watchSupportZip.getExecPathString() - .substring(0, watchSupportZip.getExecPathString().lastIndexOf('/')); - String watchKitSupportDirName = watchOSVersion.getWatchKitSupportDirName(); - String watchKitSupportPath = workingDirectory + "/" + watchKitSupportDirName; - - ImmutableList command = ImmutableList.of( - // 1. Copy WK stub binary to watchKitSupportPath. - "mkdir -p " + watchKitSupportPath, - "&&", - String.format("cp -f %s %s", WATCH_KIT_STUB_PATH, watchKitSupportPath), - // 2. cd to working directory. - "&&", - "cd " + workingDirectory, - // 3. Zip watchSupport. - "&&", - String.format( - "/usr/bin/zip -q -r -0 %s %s", - watchSupportZip.getFilename(), - watchKitSupportDirName)); - - AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); - ruleContext.registerAction( - ObjcRuleClasses.spawnAppleEnvActionBuilder( - appleConfiguration, - appleConfiguration.getMultiArchPlatform(PlatformType.WATCHOS)) - .setProgressMessage("Copying Watchkit support to app bundle") - .setShellCommand(ImmutableList.of("/bin/bash", "-c", Joiner.on(" ").join(command))) - .addOutput(watchSupportZip) - .build(ruleContext)); - - objcProviderBuilder.add(ROOT_MERGE_ZIP, watchSupportZip(ruleContext)); - } - - private static Artifact watchSupportZip(RuleContext ruleContext) { - return ruleContext.getRelatedArtifact( - ruleContext.getUniqueDirectory("_watch"), "/WatchKitSupport.zip"); - } -} -- cgit v1.2.3