diff options
Diffstat (limited to 'src')
35 files changed, 160 insertions, 5749 deletions
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 39f1dcbf93..54bfabc689 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 @@ -130,17 +130,13 @@ 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.IosApplicationRule; import com.google.devtools.build.lib.rules.objc.IosDeviceRule; -import com.google.devtools.build.lib.rules.objc.IosExtensionBinaryRule; -import com.google.devtools.build.lib.rules.objc.IosExtensionRule; import com.google.devtools.build.lib.rules.objc.IosTestRule; import com.google.devtools.build.lib.rules.objc.J2ObjcAspect; import com.google.devtools.build.lib.rules.objc.J2ObjcCommandLineOptions; import com.google.devtools.build.lib.rules.objc.J2ObjcConfiguration; import com.google.devtools.build.lib.rules.objc.J2ObjcLibraryBaseRule; import com.google.devtools.build.lib.rules.objc.J2ObjcLibraryRule; -import com.google.devtools.build.lib.rules.objc.ObjcBinaryRule; import com.google.devtools.build.lib.rules.objc.ObjcBuildInfoFactory; import com.google.devtools.build.lib.rules.objc.ObjcBundleLibraryRule; import com.google.devtools.build.lib.rules.objc.ObjcBundleRule; @@ -576,12 +572,8 @@ public class BazelRuleClassProvider { builder.addRuleDefinition(new AppleCcToolchainRule()); builder.addRuleDefinition(new AppleToolchain.RequiresXcodeConfigRule(toolsRepository)); - builder.addRuleDefinition(new IosApplicationRule()); builder.addRuleDefinition(new IosDeviceRule()); - builder.addRuleDefinition(new IosExtensionBinaryRule()); - builder.addRuleDefinition(new IosExtensionRule()); builder.addRuleDefinition(new IosTestRule()); - builder.addRuleDefinition(new ObjcBinaryRule()); builder.addRuleDefinition(new ObjcBundleRule()); builder.addRuleDefinition(new ObjcBundleLibraryRule()); builder.addRuleDefinition(new ObjcFrameworkRule()); @@ -605,8 +597,6 @@ public class BazelRuleClassProvider { builder.addRuleDefinition(new ObjcRuleClasses.LibtoolRule()); builder.addRuleDefinition(new ObjcRuleClasses.IpaRule()); builder.addRuleDefinition(new ObjcRuleClasses.ReleaseBundlingToolsRule()); - builder.addRuleDefinition(new ObjcRuleClasses.WatchExtensionBundleRule()); - builder.addRuleDefinition(new ObjcRuleClasses.WatchApplicationBundleRule()); builder.addRuleDefinition(new ObjcRuleClasses.CrosstoolRule()); builder.addRuleDefinition(new XcodeConfigRule()); builder.addRuleDefinition(new XcodeConfigAliasRule()); 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 8d5ed3fdf4..1747763a14 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 @@ -838,12 +838,8 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { */ public enum ConfigurationDistinguisher { UNKNOWN("unknown"), - /** Split transition distinguisher for {@code ios_extension} rule. */ - IOS_EXTENSION("ios_extension"), /** Split transition distinguisher for {@code ios_application} rule. */ IOS_APPLICATION("ios_application"), - /** Split transition distinguisher for {@code ios_framework} rule. */ - FRAMEWORK("framework"), /** 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/BinaryLinkingTargetFactory.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java deleted file mode 100644 index 6e60ca84bd..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java +++ /dev/null @@ -1,255 +0,0 @@ -// Copyright 2014 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.IMPORTED_LIBRARY; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.LIBRARY; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; -import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.analysis.RunfilesSupport; -import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; -import com.google.devtools.build.lib.collect.nestedset.NestedSet; -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.XcodeConfig; -import com.google.devtools.build.lib.rules.objc.CompilationSupport.ExtraLinkArgs; -import com.google.devtools.build.lib.rules.objc.ObjcCommon.ResourceAttributes; -import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.LinkedBinary; -import com.google.devtools.build.lib.rules.proto.ProtoSourcesProvider; -import java.util.Map; -import java.util.TreeMap; - -/** - * Implementation for rules that link binaries. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -@Deprecated -abstract class BinaryLinkingTargetFactory implements RuleConfiguredTargetFactory { - /** - * Indicates whether this binary generates an application bundle. If so, it causes the {@code - * infoplist} attribute to be read and a bundle to be added to the files-to-build. - */ - enum HasReleaseBundlingSupport { - YES, - NO; - } - - private final HasReleaseBundlingSupport hasReleaseBundlingSupport; - - protected BinaryLinkingTargetFactory(HasReleaseBundlingSupport hasReleaseBundlingSupport) { - this.hasReleaseBundlingSupport = hasReleaseBundlingSupport; - } - - /** - * Returns extra linker arguments. Default implementation returns empty list. Subclasses can - * override and customize. - */ - protected ExtraLinkArgs getExtraLinkArgs(RuleContext ruleContext) { - return new ExtraLinkArgs(); - } - - @VisibleForTesting - static final String REQUIRES_AT_LEAST_ONE_LIBRARY_OR_SOURCE_FILE = - "At least one library dependency or source file is required."; - - @Override - public final 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."); - - Iterable<ObjcProtoProvider> objcProtoProviders = - ruleContext.getPrerequisites("deps", Mode.TARGET, ObjcProtoProvider.class); - - ProtobufSupport protoSupport = - new ProtobufSupport( - ruleContext, - ruleContext.getConfiguration(), - ImmutableList.<ProtoSourcesProvider>of(), - objcProtoProviders, - ProtobufSupport.getTransitivePortableProtoFilters(objcProtoProviders)) - .registerGenerationActions() - .registerCompilationActions(); - - Optional<ObjcProvider> protosObjcProvider = protoSupport.getObjcProvider(); - - ObjcCommon common = common(ruleContext, protosObjcProvider); - - ObjcProvider objcProvider = common.getObjcProvider(); - assertLibraryOrSources(objcProvider, ruleContext); - - IntermediateArtifacts intermediateArtifacts = - ObjcRuleClasses.intermediateArtifacts(ruleContext); - - NestedSetBuilder<Artifact> filesToBuild = - NestedSetBuilder.<Artifact>stableOrder() - .add(intermediateArtifacts.strippedSingleArchitectureBinary()); - - new ResourceSupport(ruleContext).validateAttributes(); - - ruleContext.assertNoErrors(); - - J2ObjcMappingFileProvider j2ObjcMappingFileProvider = - J2ObjcMappingFileProvider.union( - ruleContext.getPrerequisites("deps", Mode.TARGET, J2ObjcMappingFileProvider.class)); - J2ObjcEntryClassProvider j2ObjcEntryClassProvider = - new J2ObjcEntryClassProvider.Builder() - .addTransitive( - ruleContext.getPrerequisites("deps", Mode.TARGET, J2ObjcEntryClassProvider.class)) - .build(); - - Map<String, NestedSet<Artifact>> outputGroupCollector = new TreeMap<>(); - CompilationSupport compilationSupport = - new CompilationSupport.Builder() - .setRuleContext(ruleContext) - .setOutputGroupCollector(outputGroupCollector) - .build(); - - compilationSupport - .validateAttributes() - .registerCompileAndArchiveActions(common) - .registerFullyLinkAction( - common.getObjcProvider(), - ruleContext.getImplicitOutputArtifact(CompilationSupport.FULLY_LINKED_LIB)) - .registerLinkActions( - objcProvider, - j2ObjcMappingFileProvider, - j2ObjcEntryClassProvider, - getExtraLinkArgs(ruleContext), - ImmutableList.<Artifact>of(), - DsymOutputType.APP); - - Optional<XcTestAppProvider> xcTestAppProvider; - Optional<RunfilesSupport> maybeRunfilesSupport = Optional.absent(); - switch (hasReleaseBundlingSupport) { - case YES: - AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); - // TODO(bazel-team): Remove once all bundle users are migrated to ios_application. - ReleaseBundlingSupport releaseBundlingSupport = - new ReleaseBundlingSupport( - ruleContext, - objcProvider, - LinkedBinary.LOCAL_AND_DEPENDENCIES, - ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT, - XcodeConfig.getMinimumOsForPlatformType(ruleContext, PlatformType.IOS), - appleConfiguration.getSingleArchPlatform()); - releaseBundlingSupport - .registerActions(DsymOutputType.APP) - .addFilesToBuild(filesToBuild, Optional.of(DsymOutputType.APP)) - .validateResources() - .validateAttributes(); - - xcTestAppProvider = Optional.of(releaseBundlingSupport.xcTestAppProvider()); - if (appleConfiguration.getMultiArchPlatform(PlatformType.IOS) - == ApplePlatform.IOS_SIMULATOR) { - Artifact runnerScript = intermediateArtifacts.runnerScript(); - Artifact ipaFile = ruleContext.getImplicitOutputArtifact(ReleaseBundlingSupport.IPA); - releaseBundlingSupport.registerGenerateRunnerScriptAction(runnerScript, ipaFile); - maybeRunfilesSupport = Optional.of(releaseBundlingSupport.runfilesSupport(runnerScript)); - } - break; - case NO: - xcTestAppProvider = Optional.absent(); - break; - default: - throw new AssertionError(); - } - - RuleConfiguredTargetBuilder targetBuilder = - ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build()) - .addNativeDeclaredProvider(objcProvider) - .addNativeDeclaredProvider(objcProvider) - .addProvider( - InstrumentedFilesProvider.class, - compilationSupport.getInstrumentedFilesProvider(common)) - .addOutputGroups(outputGroupCollector); - - if (xcTestAppProvider.isPresent()) { - // TODO(bazel-team): Stop exporting an XcTestAppProvider once objc_binary no longer creates an - // application bundle. - targetBuilder.addNativeDeclaredProvider(xcTestAppProvider.get()); - } - if (maybeRunfilesSupport.isPresent()) { - RunfilesSupport runfilesSupport = maybeRunfilesSupport.get(); - targetBuilder.setRunfilesSupport(runfilesSupport, runfilesSupport.getExecutable()); - } - configureTarget(targetBuilder, ruleContext); - return targetBuilder.build(); - } - - private void assertLibraryOrSources(ObjcProvider objcProvider, RuleContext ruleContext) - throws RuleErrorException { - if (Iterables.isEmpty(objcProvider.get(LIBRARY)) // Includes sources from this target. - && Iterables.isEmpty(objcProvider.get(IMPORTED_LIBRARY))) { - ruleContext.throwWithRuleError(REQUIRES_AT_LEAST_ONE_LIBRARY_OR_SOURCE_FILE); - } - } - - private ObjcCommon common(RuleContext ruleContext, Optional<ObjcProvider> protosObjcProvider) { - IntermediateArtifacts intermediateArtifacts = - ObjcRuleClasses.intermediateArtifacts(ruleContext); - CompilationArtifacts compilationArtifacts = - CompilationSupport.compilationArtifacts(ruleContext); - - ObjcCommon.Builder builder = - new ObjcCommon.Builder(ruleContext) - .setCompilationAttributes( - CompilationAttributes.Builder.fromRuleContext(ruleContext).build()) - .setCompilationArtifacts(compilationArtifacts) - .setResourceAttributes(new ResourceAttributes(ruleContext)) - .addDefines(ruleContext.getTokenizedStringListAttr("defines")) - .addDeps(ruleContext.getPrerequisites("deps", Mode.TARGET)) - .addRuntimeDeps(ruleContext.getPrerequisites("runtime_deps", Mode.TARGET)) - .addDeps(ruleContext.getPrerequisites("bundles", Mode.TARGET)) - .addDepObjcProviders(protosObjcProvider.asSet()) - .addNonPropagatedDepObjcProviders( - ruleContext.getPrerequisites( - "non_propagated_deps", Mode.TARGET, ObjcProvider.SKYLARK_CONSTRUCTOR)) - .setIntermediateArtifacts(intermediateArtifacts) - .setAlwayslink(false) - .setHasModuleMap() - .setLinkedBinary(intermediateArtifacts.strippedSingleArchitectureBinary()); - - if (ObjcRuleClasses.objcConfiguration(ruleContext).generateDsym()) { - builder.addDebugArtifacts(DsymOutputType.APP); - } - - if (ObjcRuleClasses.objcConfiguration(ruleContext).generateLinkmap()) { - builder.setLinkmapFile(intermediateArtifacts.linkmap()); - } - - return builder.build(); - } - - /** - * Performs additional configuration of the target. The default implementation does nothing, but - * subclasses may override it to add logic. - */ - protected void configureTarget(RuleConfiguredTargetBuilder target, RuleContext ruleContext) {}; -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplication.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplication.java deleted file mode 100644 index f0b426569f..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplication.java +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2015 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.common.collect.ImmutableSet; -import com.google.common.collect.Streams; -import com.google.devtools.build.lib.actions.Artifact; -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.analysis.configuredtargets.RuleConfiguredTarget.Mode; -import com.google.devtools.build.lib.packages.Attribute.SplitTransition; -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.objc.ObjcProvider.Flag; -import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.SplitArchTransition; - -/** - * Implementation for {@code ios_application}. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -@Deprecated -public class IosApplication extends ReleaseBundlingTargetFactory { - - /** - * Transition that when applied to a target generates a configured target for each value in - * {@code --ios_multi_cpus}, such that {@code --ios_cpu} is set to a different one of those values - * in the configured targets. - */ - public static final SplitTransition<BuildOptions> SPLIT_ARCH_TRANSITION = - new SplitArchTransition(); - - private static final ImmutableSet<Attribute> DEPENDENCY_ATTRIBUTES = - ImmutableSet.of( - new Attribute("binary", Mode.SPLIT), - new Attribute("extensions", Mode.TARGET)); - - public IosApplication() { - super(ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT, DEPENDENCY_ATTRIBUTES); - } - - /** - * Validates that there is exactly one watch extension for each OS version. - */ - @Override - protected void validateAttributes(RuleContext ruleContext) { - Iterable<ObjcProvider> extensionProviders = ruleContext.getPrerequisites( - "extensions", Mode.TARGET, ObjcProvider.SKYLARK_CONSTRUCTOR); - if (hasMoreThanOneWatchExtension(extensionProviders, Flag.HAS_WATCH1_EXTENSION) - || hasMoreThanOneWatchExtension(extensionProviders, Flag.HAS_WATCH2_EXTENSION)) { - ruleContext.attributeError("extensions", "An iOS application can contain exactly one " - + "watch extension for each watch OS version"); - } - } - - private boolean hasMoreThanOneWatchExtension( - Iterable<ObjcProvider> objcProviders, final Flag watchExtensionVersionFlag) { - return Streams.stream(objcProviders) - .filter(objcProvider -> objcProvider.is(watchExtensionVersionFlag)) - .count() - > 1; - } - - @Override - protected void configureTarget(RuleConfiguredTargetBuilder target, RuleContext ruleContext, - ReleaseBundlingSupport releaseBundlingSupport) throws InterruptedException { - // If this is an application built for the simulator, make it runnable. - AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); - if (appleConfiguration.getMultiArchPlatform(PlatformType.IOS) == ApplePlatform.IOS_SIMULATOR) { - Artifact runnerScript = ObjcRuleClasses.intermediateArtifacts(ruleContext).runnerScript(); - Artifact ipaFile = ruleContext.getImplicitOutputArtifact(ReleaseBundlingSupport.IPA); - releaseBundlingSupport.registerGenerateRunnerScriptAction(runnerScript, ipaFile); - target.setRunfilesSupport(releaseBundlingSupport.runfilesSupport(runnerScript), runnerScript); - } - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplicationRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplicationRule.java deleted file mode 100644 index 7beb9bbde5..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplicationRule.java +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2015 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.ConfigurationTransition.HOST; -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.BOOLEAN; - -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.objc.ObjcRuleClasses.IpaRule; - -/** - * Rule definition for ios_application. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -@Deprecated -public class IosApplicationRule implements RuleDefinition { - - @Override - public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { - return builder - .requiresConfigurationFragments(ObjcConfiguration.class, AppleConfiguration.class) - /*<!-- #BLAZE_RULE(ios_application).IMPLICIT_OUTPUTS --> - <ul> - <li><code><var>name</var>.ipa</code>: the application bundle as an <code>.ipa</code> - file - </ul> - <!-- #END_BLAZE_RULE.IMPLICIT_OUTPUTS -->*/ - .setImplicitOutputsFunction(ReleaseBundlingSupport.IPA) - /* <!-- #BLAZE_RULE(ios_application).ATTRIBUTE(binary) --> - The binary target included in the final bundle. - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add( - attr("binary", LABEL) - .allowedRuleClasses("objc_binary") - .allowedFileTypes() - .mandatory() - .direct_compile_time_input() - .cfg(IosApplication.SPLIT_ARCH_TRANSITION)) - /* <!-- #BLAZE_RULE(ios_application).ATTRIBUTE(extensions) --> - Any extensions to include in the final application. - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add( - attr("extensions", LABEL_LIST) - .allowedRuleClasses( - "ios_extension", "apple_watch1_extension") - .allowedFileTypes() - .direct_compile_time_input()) - .add( - attr("$runner_script_template", LABEL) - .cfg(HOST) - .value(env.getToolsLabel("//tools/objc:ios_runner.sh.mac_template"))) - .add( - attr("$is_executable", BOOLEAN) - .value(true) - .nonconfigurable("Called from RunCommand.isExecutable, which takes a Target")) - .build(); - } - - @Override - public Metadata getMetadata() { - return RuleDefinition.Metadata.builder() - .name("ios_application") - .factoryClass(IosApplication.class) - .ancestors( - BaseRuleClasses.BaseRule.class, - ObjcRuleClasses.ReleaseBundlingRule.class, - ObjcRuleClasses.SimulatorRule.class, - IpaRule.class) - .build(); - } -} - -/*<!-- #BLAZE_RULE (NAME = ios_application, TYPE = BINARY, FAMILY = Objective-C) --> - -<p><strong>This rule is deprecated.</strong> Please use the new Apple build rules -(<a href="https://github.com/bazelbuild/rules_apple">https://github.com/bazelbuild/rules_apple</a>) -to build Apple targets.</p> - -<p>This rule produces an application bundle for iOS.</p> -<p>When running an iOS application using the <code>run</code> command, environment variables that -are prefixed with <code>IOS_</code> will be passed to the launched application, with the prefix -stripped. For example, if you export <code>IOS_ENV=foo</code>, <code>ENV=foo</code> will be -passed to the application.</p> - -${IMPLICIT_OUTPUTS} - -<!-- #END_BLAZE_RULE -->*/ diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtension.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtension.java deleted file mode 100644 index f255e7ec29..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtension.java +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright 2014 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.MERGE_ZIP; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Ordering; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.analysis.config.BuildOptions; -import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; -import com.google.devtools.build.lib.packages.Attribute.SplitTransition; -import com.google.devtools.build.lib.rules.apple.AppleCommandLineOptions; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher; -import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType; -import com.google.devtools.build.lib.rules.apple.DottedVersion; -import com.google.devtools.build.lib.rules.apple.XcodeConfig; -import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.SplitArchTransition; -import java.io.Serializable; -import javax.annotation.Nullable; - -/** - * Implementation for {@code ios_extension}. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -@Deprecated -public class IosExtension extends ReleaseBundlingTargetFactory { - - // Apple only accepts extensions starting at 8.0. - @VisibleForTesting - static final DottedVersion EXTENSION_MINIMUM_OS_VERSION = DottedVersion.fromString("8.0"); - - /** - * Transition that when applied to a target generates a configured target for each value in - * {@code --ios_multi_cpus}, such that {@code --ios_cpu} is set to a different one of those values - * in the configured targets. - * - * <p>Also ensures that, no matter whether {@code --ios_multi_cpus} is set, {@code - * --ios_minimum_os} is at least {@code 8.0} as Apple requires this for extensions. - */ - static final SplitTransition<BuildOptions> MINIMUM_OS_AND_SPLIT_ARCH_TRANSITION = - new ExtensionSplitArchTransition(EXTENSION_MINIMUM_OS_VERSION, - ConfigurationDistinguisher.IOS_EXTENSION); - - public IosExtension() { - super( - ReleaseBundlingSupport.EXTENSION_BUNDLE_DIR_FORMAT, - ImmutableSet.of(new Attribute("binary", Mode.SPLIT))); - } - - @Override - protected DottedVersion bundleMinimumOsVersion(RuleContext ruleContext) { - return determineMinimumOsVersion( - XcodeConfig.getMinimumOsForPlatformType(ruleContext, PlatformType.IOS), - EXTENSION_MINIMUM_OS_VERSION); - } - - @Override - protected ObjcProvider exposedObjcProvider( - RuleContext ruleContext, ReleaseBundlingSupport releaseBundlingSupport) - throws InterruptedException { - ObjcProvider.Builder builder = - new ObjcProvider.Builder() - // Nest this target's bundle under final IPA - .add(MERGE_ZIP, ruleContext.getImplicitOutputArtifact(ReleaseBundlingSupport.IPA)); - - releaseBundlingSupport.addExportedDebugArtifacts(builder, DsymOutputType.APP); - return builder.build(); - } - - /** - * Overrides (if necessary) any flag-set minimum iOS version for extensions only with given - * minimum OS version. - * - * Extensions are not accepted by Apple below given mininumOSVersion. While applications built - * with a minimum iOS version of less than give version may contain extensions in their bundle, - * the extension itself needs to be built with given version or higher. - * - * @param fromFlag the minimum OS version from command line flag - * @param minimumOSVersion the minumum OS version the extension should be built with - */ - private static DottedVersion determineMinimumOsVersion(@Nullable DottedVersion fromFlag, - DottedVersion minimumOSVersion) { - if (fromFlag == null) { - return minimumOSVersion; - } - return Ordering.natural().max(fromFlag, minimumOSVersion); - } - - /** - * Split transition that configures the minimum iOS version in addition to architecture splitting. - */ - static class ExtensionSplitArchTransition extends SplitArchTransition - implements Serializable { - - private final DottedVersion minimumOSVersion; - private final ConfigurationDistinguisher configurationDistinguisher; - - ExtensionSplitArchTransition(DottedVersion minimumOSVersion, - ConfigurationDistinguisher configurationDistinguisher) { - this.minimumOSVersion = minimumOSVersion; - this.configurationDistinguisher = configurationDistinguisher; - } - - @Override - protected ImmutableList<BuildOptions> defaultOptions(BuildOptions originalOptions) { - AppleCommandLineOptions appleOptions = originalOptions.get(AppleCommandLineOptions.class); - DottedVersion newMinimumVersion = determineMinimumOsVersion(appleOptions.iosMinimumOs, - minimumOSVersion); - - if (newMinimumVersion.equals(appleOptions.iosMinimumOs)) { - return ImmutableList.of(); - } - - BuildOptions splitOptions = originalOptions.clone(); - setMinimumOsVersion(splitOptions, newMinimumVersion); - splitOptions.get(AppleCommandLineOptions.class).configurationDistinguisher = - getConfigurationDistinguisher(); - return ImmutableList.of(splitOptions); - } - - @Override - protected void setAdditionalOptions(BuildOptions splitOptions, BuildOptions originalOptions) { - DottedVersion fromFlag = originalOptions.get(AppleCommandLineOptions.class).iosMinimumOs; - setMinimumOsVersion(splitOptions, determineMinimumOsVersion(fromFlag, minimumOSVersion)); - } - - @Override - protected ConfigurationDistinguisher getConfigurationDistinguisher() { - return configurationDistinguisher; - } - - private void setMinimumOsVersion(BuildOptions splitOptions, DottedVersion newMinimumVersion) { - splitOptions.get(AppleCommandLineOptions.class).iosMinimumOs = newMinimumVersion; - } - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinary.java deleted file mode 100644 index d598f6c2c2..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinary.java +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2015 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 "ios_extension_binary" rule. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -@Deprecated -public class IosExtensionBinary extends BinaryLinkingTargetFactory { - public IosExtensionBinary() { - super(HasReleaseBundlingSupport.NO); - } - - @Override - protected ExtraLinkArgs getExtraLinkArgs(RuleContext ruleContext) { - return new ExtraLinkArgs("-e", "_NSExtensionMain", "-fapplication-extension"); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinaryRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinaryRule.java deleted file mode 100644 index 226b98ff2f..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinaryRule.java +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2015 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 ios_extension_binary. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -@Deprecated -public class IosExtensionBinaryRule 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("ios_extension_binary") - .factoryClass(IosExtensionBinary.class) - .ancestors(BaseRuleClasses.BaseRule.class, ObjcRuleClasses.LinkingRule.class) - .build(); - } -} - -/*<!-- #BLAZE_RULE (NAME = ios_extension_binary, TYPE = BINARY, FAMILY = Objective-C) --> - -<p><strong>This rule is deprecated.</strong> Please use the new Apple build rules -(<a href="https://github.com/bazelbuild/rules_apple">https://github.com/bazelbuild/rules_apple</a>) -to build Apple targets.</p> - -<p>This rule produces a binary for an iOS app extension by linking one or more -Objective-C libraries.</p> - -${IMPLICIT_OUTPUTS} - -<!-- #END_BLAZE_RULE -->*/ diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionRule.java deleted file mode 100644 index 62b6374d7e..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionRule.java +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2015 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 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.objc.ObjcRuleClasses.IpaRule; - -/** - * Rule definition for ios_extension. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -@Deprecated -public class IosExtensionRule implements RuleDefinition { - @Override - public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { - return builder - .requiresConfigurationFragments(ObjcConfiguration.class, AppleConfiguration.class) - /*<!-- #BLAZE_RULE(ios_extension).IMPLICIT_OUTPUTS --> - <ul> - <li><code><var>name</var>.ipa</code>: the extension bundle as an <code>.ipa</code> - file</li> - </ul> - <!-- #END_BLAZE_RULE.IMPLICIT_OUTPUTS -->*/ - .setImplicitOutputsFunction(ReleaseBundlingSupport.IPA) - /* <!-- #BLAZE_RULE(ios_extension).ATTRIBUTE(binary) --> - The binary target containing the logic for the extension. - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add( - attr("binary", LABEL) - .allowedRuleClasses("ios_extension_binary") - .allowedFileTypes() - .mandatory() - .direct_compile_time_input() - .cfg(IosExtension.MINIMUM_OS_AND_SPLIT_ARCH_TRANSITION)) - .build(); - } - - @Override - public Metadata getMetadata() { - return RuleDefinition.Metadata.builder() - .name("ios_extension") - .factoryClass(IosExtension.class) - .ancestors( - BaseRuleClasses.BaseRule.class, - ObjcRuleClasses.ReleaseBundlingRule.class, - IpaRule.class) - .build(); - } -} - -/*<!-- #BLAZE_RULE (NAME = ios_extension, TYPE = BINARY, FAMILY = Objective-C) --> - -<p><strong>This rule is deprecated.</strong> Please use the new Apple build rules -(<a href="https://github.com/bazelbuild/rules_apple">https://github.com/bazelbuild/rules_apple</a>) -to build Apple targets.</p> - -<p>This rule produces a bundled binary for an iOS app extension from a compiled binary and bundle -metadata.</p> - -<p>An iOS app extension is a nested bundle that is located inside the application bundle and is -released with it. An iOS app extension cannot be released alone, although this rule allows you to -build an <code>.ipa</code> with only the extension. - -<p>Bundles generated by this rule use a bundle directory called -<code>PlugIns/<var>target-name</var>.appex</code>, while an application bundle uses -<code>Payload/<var>target-name</var>.app</code>. For instance, if an application call Foo has an app -extension called Bar, the Bar extension bundle files will be stored in -<code>Payload/Foo.app/PlugIns/Bar.appex</code> in the final application <code>.ipa</code>. - -<p>There are many similarities between app extensions and applications with little to no difference -between how each thing is processed: -<ul> - <li>both have entitlements and Info.plist files - <li>both are code-signed. Signing and merging happens in this order: the extension is code-signed, - bundles are merged, application is code-signed - <li>both can have an app icon and launch image, and of course asset catalogs and all kinds of - resources - <li>both have linked binaries. The app extension binary is different in that it is linked with - these additional flags: - <ul> - <li><code>-e _NSExtensionMain</code> - sets the entry point to a standard function in the - iOS runtime rather than <code>main()</code> - <li><code>-fapplicationextension</code> - </ul> -</ul> - -${IMPLICIT_OUTPUTS} - -<!-- #END_BLAZE_RULE -->*/ diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinary.java deleted file mode 100644 index 03fdb97f3b..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinary.java +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2014 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; - -/** - * Implementation for the "objc_binary" rule. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -@Deprecated -public class ObjcBinary extends BinaryLinkingTargetFactory { - public ObjcBinary() { - super( - // TODO(bazel-team): Remove the enum and delete all code depending on YES case once all - // bundle users are migrated to ios_application. - HasReleaseBundlingSupport.YES); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java deleted file mode 100644 index 55cde701d5..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2014 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.ConfigurationTransition.HOST; -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.syntax.Type.BOOLEAN; - -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 objc_binary. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -// TODO(bazel-team): Remove bundling functionality (dependency on ApplicationRule, IPA output). -@Deprecated -public class ObjcBinaryRule implements RuleDefinition { - - @Override - public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { - return builder - .requiresConfigurationFragments( - ObjcConfiguration.class, - J2ObjcConfiguration.class, - AppleConfiguration.class, - CppConfiguration.class) - /*<!-- #BLAZE_RULE(objc_binary).IMPLICIT_OUTPUTS --> - <ul> - <li><code><var>name</var>.ipa</code>: the application bundle as an <code>.ipa</code> - file</li> - </ul> - <!-- #END_BLAZE_RULE.IMPLICIT_OUTPUTS -->*/ - .setImplicitOutputsFunction(ReleaseBundlingSupport.IPA) - // TODO(bazel-team): Remove these when this rule no longer produces a bundle. - .add( - attr("$runner_script_template", LABEL) - .cfg(HOST) - .value(env.getToolsLabel("//tools/objc:ios_runner.sh.mac_template"))) - .add( - attr("$is_executable", BOOLEAN) - .value(true) - .nonconfigurable("Called from RunCommand.isExecutable, which takes a Target")) - .cfg(AppleCrosstoolTransition.APPLE_CROSSTOOL_TRANSITION) - .build(); - } - - @Override - public Metadata getMetadata() { - return RuleDefinition.Metadata.builder() - .name("objc_binary") - .factoryClass(ObjcBinary.class) - .ancestors( - BaseRuleClasses.BaseRule.class, - ObjcRuleClasses.LinkingRule.class, - ObjcRuleClasses.ReleaseBundlingRule.class, - ObjcRuleClasses.SimulatorRule.class) - .build(); - } -} - -/*<!-- #BLAZE_RULE (NAME = objc_binary, TYPE = BINARY, FAMILY = Objective-C) --> - -<p><strong>This rule is deprecated.</strong> Please use the new Apple build rules -(<a href="https://github.com/bazelbuild/rules_apple">https://github.com/bazelbuild/rules_apple</a>) -to build Apple targets.</p> - -<p>This rule produces one or more Objective-C libraries for bundling in an -<code>ios_application</code>.</p> - -<p>Any application-related attributes (infoplist, app_icon, resources, xibs, datamodels...) on this -rule are deprecated and you should define them on <code>ios_application</code> instead. They will be -removed from <code>objc_binary</code> soon.</p> - -<p>Until the migration to <code>ios_application</code> is complete, this rule requires at least one -source file to be defined in either <code>srcs</code> or <code>non_arc_srcs</code></p>. - -${IMPLICIT_OUTPUTS} - -<!-- #END_BLAZE_RULE -->*/ diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java index bd4e99087b..e292f000c6 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java @@ -1394,351 +1394,4 @@ public class ObjcRuleClasses { .build(); } } - - /** - * Attributes for {@code apple_watch*} rules that creates a watch extension bundle. - */ - public static class WatchExtensionBundleRule implements RuleDefinition { - static final String WATCH_EXT_BUNDLE_ID_ATTR = "ext_bundle_id"; - static final String WATCH_EXT_DEFAULT_PROVISIONING_PROFILE_ATTR = - ":default_ext_provisioning_profile"; - static final String WATCH_EXT_ENTITLEMENTS_ATTR = "ext_entitlements"; - static final String WATCH_EXT_PROVISIONING_PROFILE_ATTR = "ext_provisioning_profile"; - static final String WATCH_EXT_INFOPLISTS_ATTR = "ext_infoplists"; - static final String WATCH_EXT_RESOURCES_ATTR = "ext_resources"; - static final String WATCH_EXT_STRUCTURED_RESOURCES_ATTR = "ext_structured_resources"; - static final String WATCH_EXT_STRINGS_ATTR = "ext_strings"; - - @Override - public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { - return builder - /* <!-- #BLAZE_RULE($watch_extension_bundle_rule).ATTRIBUTE(ext_bundle_id) --> - The bundle ID (reverse-DNS path followed by app name) of the watch extension binary. - - If specified, it will override the bundle ID specified in the associated plist file. If - no bundle ID is specified on either this attribute or in the plist file, a junk value - will be used. - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add( - attr(WATCH_EXT_BUNDLE_ID_ATTR, STRING) - .value( - new Attribute.ComputedDefault() { - @Override - public Object getDefault(AttributeMap rule) { - // For tests and similar, we don't want to force people to explicitly - // specify throw-away data. - return "example.ext." + rule.getName(); - } - })) - /* <!-- #BLAZE_RULE($watch_extension_bundle_rule).ATTRIBUTE(ext_entitlements) --> - The entitlements file required for device builds of watch extension. - - See - <a href="https://developer.apple.com/library/mac/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/AboutEntitlements.html">the apple documentation</a> - for more information. If absent, the default entitlements from the - provisioning profile will be used. - <p> - The following variables are substituted as per - <a href="https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html">their definitions in Apple's documentation</a>: - $(AppIdentifierPrefix) and $(CFBundleIdentifier). - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add(attr(WATCH_EXT_ENTITLEMENTS_ATTR, LABEL).allowedFileTypes(ENTITLEMENTS_TYPE)) - /* <!-- #BLAZE_RULE($watch_extension_bundle_rule).ATTRIBUTE(ext_infoplists) --> - Infoplist files to be merged. The merged output corresponds to <i>appname</i>-Info.plist - in Xcode projects. Duplicate keys between infoplist files will cause an error if - and only if the values conflict. If both <code>infoplist</code> and - <code>infoplists</code> are specified, the files defined in both attributes will be used. - Blaze will perform variable substitution on the plist files for the following values: - <ul> - <li><code>${EXECUTABLE_NAME}</code>: The name of the executable generated and included - in the bundle by blaze, which can be used as the value for - <code>CFBundleExecutable</code> within the plist. - <li><code>${BUNDLE_NAME}</code>: This target's name and bundle suffix (.bundle or .app) - in the form<code><var>name</var></code>.<code>suffix</code>. - <li><code>${PRODUCT_NAME}</code>: This target's name. - </ul> - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add(attr(WATCH_EXT_INFOPLISTS_ATTR, BuildType.LABEL_LIST).allowedFileTypes(PLIST_TYPE)) - /* <!-- #BLAZE_RULE($watch_extension_bundle_rule).ATTRIBUTE(ext_provisioning_profile) --> - The provisioning profile (.mobileprovision file) to use when bundling - the watch extension. - - This is only used for non-simulator builds. - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add( - attr(WATCH_EXT_PROVISIONING_PROFILE_ATTR, LABEL) - .singleArtifact() - .allowedFileTypes(FileType.of(".mobileprovision"))) - .add( - attr(WATCH_EXT_DEFAULT_PROVISIONING_PROFILE_ATTR, LABEL) - .singleArtifact() - .allowedFileTypes(FileType.of(".mobileprovision")) - .value( - LateBoundDefault.fromTargetConfiguration( - AppleConfiguration.class, - null, - (rule, attributes, appleConfig) -> { - if (appleConfig.getMultiArchPlatform(PlatformType.IOS) - != ApplePlatform.IOS_DEVICE) { - return null; - } - if (attributes.isAttributeValueExplicitlySpecified( - WATCH_EXT_PROVISIONING_PROFILE_ATTR)) { - return null; - } - return appleConfig.getDefaultProvisioningProfileLabel(); - }))) - /* <!-- #BLAZE_RULE($watch_extension_bundle_rule).ATTRIBUTE(ext_resources) --> - Files to include in the final watch extension bundle. - - They are not processed or compiled in any way besides the processing - done by the rules that actually generate them. These files are placed - in the root of the bundle (e.g. Foo.app/...) in most cases. - However, if they appear to be localized (i.e. are contained in a - directory called *.lproj), they will be placed in a directory of the - same name in the app bundle. - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add( - attr(WATCH_EXT_RESOURCES_ATTR, LABEL_LIST) - .legacyAllowAnyFileType() - .direct_compile_time_input()) - /* <!-- #BLAZE_RULE($watch_extension_bundle_rule).ATTRIBUTE(ext_structured_resources)--> - Files to include in the final watch extension bundle. - - They are not processed or compiled in any way besides the processing - done by the rules that actually generate them. In differences to - <code>resources</code> these files are placed in the bundle root in - the same structure passed to this argument, so - <code>["res/foo.png"]</code> will end up in - <code>Foo.app/res/foo.png</code>. - <p>Note that in the generated XCode project file, all files in the top directory of - the specified files will be included in the Xcode-generated app bundle. So - specifying <code>["res/foo.png"]</code> will lead to the inclusion of all files in - directory <code>res</code>. - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add( - attr(WATCH_EXT_STRUCTURED_RESOURCES_ATTR, LABEL_LIST) - .legacyAllowAnyFileType() - .direct_compile_time_input()) - /* <!-- #BLAZE_RULE($watch_extension_bundle_rule).ATTRIBUTE(ext_strings) --> - Files which are plists of strings, often localizable to be added to watch extension. - - These files are converted to binary plists (if they are not already) - and placed in the bundle root of the final package. If this file's - immediate containing directory is named *.lproj (e.g. en.lproj, - Base.lproj), it will be placed under a directory of that name in the - final bundle. This allows for localizable strings. - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add( - attr(WATCH_EXT_STRINGS_ATTR, LABEL_LIST) - .allowedFileTypes(STRINGS_TYPE) - .direct_compile_time_input()) - .build(); - } - - @Override - public Metadata getMetadata() { - return RuleDefinition.Metadata.builder() - .name("$watch_extension_bundle_rule") - .type(RuleClassType.ABSTRACT) - .ancestors( - AppleToolchain.RequiresXcodeConfigRule.class, - ResourceToolsRule.class, - ReleaseBundlingToolsRule.class, - XcrunRule.class) - .build(); - } - } - - /** - * Attributes for {@code apple_watch*} rules that creates a watch application bundle. - */ - public static class WatchApplicationBundleRule implements RuleDefinition { - static final String WATCH_APP_NAME_ATTR = "app_name"; - static final String WATCH_APP_ICON_ATTR = "app_icon"; - static final String WATCH_APP_BUNDLE_ID_ATTR = "app_bundle_id"; - static final String WATCH_APP_DEFAULT_PROVISIONING_PROFILE_ATTR = - ":default_app_provisioning_profile"; - static final String WATCH_APP_ENTITLEMENTS_ATTR = "app_entitlements"; - static final String WATCH_APP_PROVISIONING_PROFILE_ATTR = "app_provisioning_profile"; - static final String WATCH_APP_ASSET_CATALOGS_ATTR = "app_asset_catalogs"; - static final String WATCH_APP_INFOPLISTS_ATTR = "app_infoplists"; - static final String WATCH_APP_STORYBOARDS_ATTR = "app_storyboards"; - static final String WATCH_APP_RESOURCES_ATTR = "app_resources"; - static final String WATCH_APP_STRUCTURED_RESOURCES_ATTR = "app_structured_resources"; - static final String WATCH_APP_STRINGS_ATTR = "app_strings"; - - @Override - public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { - return builder - /* <!-- #BLAZE_RULE($watch_application_bundle_rule).ATTRIBUTE(app_name) --> - Name of the final watch application binary. - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add(attr(WATCH_APP_NAME_ATTR, STRING).mandatory()) - /* <!-- #BLAZE_RULE($watch_application_bundle_rule).ATTRIBUTE(app_icon) --> - The name of the watch application icon. - - The icon should be in one of the asset catalogs of this target or - a (transitive) dependency. In a new project, this is initialized - to "AppIcon" by Xcode. - <p> - If the application icon is not in an asset catalog, do not use this - attribute. Instead, add a CFBundleIcons entry to the Info.plist file. - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add(attr(WATCH_APP_ICON_ATTR, STRING)) - /* <!-- #BLAZE_RULE($watch_application_bundle_rule).ATTRIBUTE(app_entitlements) --> - The entitlements file required for device builds of watch application. - - See - <a href="https://developer.apple.com/library/mac/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/AboutEntitlements.html">the apple documentation</a> - for more information. If absent, the default entitlements from the - provisioning profile will be used. - <p> - The following variables are substituted as per - <a href="https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html">their definitions in Apple's documentation</a>: - $(AppIdentifierPrefix) and $(CFBundleIdentifier). - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add(attr(WATCH_APP_ENTITLEMENTS_ATTR, LABEL).allowedFileTypes(ENTITLEMENTS_TYPE)) - /* <!-- #BLAZE_RULE($watch_application_bundle_rule).ATTRIBUTE(app_asset_catalogs) --> - Files that comprise the asset catalogs of the final linked binary. - - Each file must have a containing directory named *.xcassets. This - containing directory becomes the root of one of the asset catalogs - linked with any binary that depends directly or indirectly on this - target. - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add( - attr(WATCH_APP_ASSET_CATALOGS_ATTR, LABEL_LIST) - .legacyAllowAnyFileType() - .direct_compile_time_input()) - /* <!-- #BLAZE_RULE($watch_application_bundle_rule).ATTRIBUTE(app_bundle_id) --> - The bundle ID (reverse-DNS path followed by app name) of the watch application binary. - - If specified, it will override the bundle ID specified in the associated plist file. If - no bundle ID is specified on either this attribute or in the plist file, a junk value - will be used. - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add( - attr(WATCH_APP_BUNDLE_ID_ATTR, STRING) - .value( - new Attribute.ComputedDefault(WATCH_APP_NAME_ATTR) { - @Override - public Object getDefault(AttributeMap rule) { - // For tests and similar, we don't want to force people to explicitly - // specify throw-away data. - return "example.app." + rule.get(WATCH_APP_NAME_ATTR, STRING); - } - })) - /* <!-- #BLAZE_RULE($watch_application_bundle_rule).ATTRIBUTE(app_infoplists) --> - Infoplist files to be merged. The merged output corresponds to <i>appname</i>-Info.plist - in Xcode projects. Duplicate keys between infoplist files will cause an error if - and only if the values conflict. If both <code>infoplist</code> and - <code>infoplists</code> are specified, the files defined in both attributes will be used. - Blaze will perform variable substitution on the plist files for the following values: - <ul> - <li><code>${EXECUTABLE_NAME}</code>: The name of the executable generated and included - in the bundle by blaze, which can be used as the value for - <code>CFBundleExecutable</code> within the plist. - <li><code>${BUNDLE_NAME}</code>: This target's name and bundle suffix (.bundle or .app) - in the form<code><var>name</var></code>.<code>suffix</code>. - <li><code>${PRODUCT_NAME}</code>: This target's name. - </ul> - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add(attr(WATCH_APP_INFOPLISTS_ATTR, BuildType.LABEL_LIST).allowedFileTypes(PLIST_TYPE)) - /* <!-- #BLAZE_RULE($watch_application_bundle_rule).ATTRIBUTE(app_provisioning_profile)--> - The provisioning profile (.mobileprovision file) to use when bundling - the watch application. - - This is only used for non-simulator builds. - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add( - attr(WATCH_APP_PROVISIONING_PROFILE_ATTR, LABEL) - .singleArtifact() - .allowedFileTypes(FileType.of(".mobileprovision"))) - .add( - attr(WATCH_APP_DEFAULT_PROVISIONING_PROFILE_ATTR, LABEL) - .singleArtifact() - .allowedFileTypes(FileType.of(".mobileprovision")) - .value( - LateBoundDefault.fromTargetConfiguration( - AppleConfiguration.class, - null, - (rule, attributes, appleConfig) -> { - if (appleConfig.getMultiArchPlatform(PlatformType.IOS) - != ApplePlatform.IOS_DEVICE) { - return null; - } - if (attributes.isAttributeValueExplicitlySpecified( - WATCH_APP_PROVISIONING_PROFILE_ATTR)) { - return null; - } - return appleConfig.getDefaultProvisioningProfileLabel(); - }))) - /* <!-- #BLAZE_RULE($objc_resources_rule).ATTRIBUTE(app_storyboards) --> - Files which are .storyboard resources for the watch application, possibly - localizable. - - These files are compiled and placed in the bundle root of the final package. - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add(attr(WATCH_APP_STORYBOARDS_ATTR, LABEL_LIST).allowedFileTypes(STORYBOARD_TYPE)) - /* <!-- #BLAZE_RULE($watch_application_bundle_rule).ATTRIBUTE(app_resources) --> - Files to include in the final watch application bundle. - - They are not processed or compiled in any way besides the processing - done by the rules that actually generate them. These files are placed - in the root of the bundle (e.g. Foo.app/...) in most cases. - However, if they appear to be localized (i.e. are contained in a - directory called *.lproj), they will be placed in a directory of the - same name in the app bundle. - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add( - attr(WATCH_APP_RESOURCES_ATTR, LABEL_LIST) - .legacyAllowAnyFileType() - .direct_compile_time_input()) - /* <!-- #BLAZE_RULE($watch_application_bundle_rule).ATTRIBUTE(app_structured_resources)--> - Files to include in the final watch application bundle. - - They are not processed or compiled in any way besides the processing - done by the rules that actually generate them. In differences to - <code>resources</code> these files are placed in the bundle root in - the same structure passed to this argument, so - <code>["res/foo.png"]</code> will end up in - <code>Foo.app/res/foo.png</code>. - <p>Note that in the generated XCode project file, all files in the top directory of - the specified files will be included in the Xcode-generated app bundle. So - specifying <code>["res/foo.png"]</code> will lead to the inclusion of all files in - directory <code>res</code>. - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add( - attr(WATCH_APP_STRUCTURED_RESOURCES_ATTR, LABEL_LIST) - .legacyAllowAnyFileType() - .direct_compile_time_input()) - /* <!-- #BLAZE_RULE($watch_application_bundle_rule).ATTRIBUTE(app_strings) --> - Files which are plists of strings, often localizable to be added to watch application. - - These files are converted to binary plists (if they are not already) - and placed in the bundle root of the final package. If this file's - immediate containing directory is named *.lproj (e.g. en.lproj, - Base.lproj), it will be placed under a directory of that name in the - final bundle. This allows for localizable strings. - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add( - attr(WATCH_APP_STRINGS_ATTR, LABEL_LIST) - .allowedFileTypes(STRINGS_TYPE) - .direct_compile_time_input()) - .build(); - } - @Override - public Metadata getMetadata() { - return RuleDefinition.Metadata.builder() - .name("$watch_application_bundle_rule") - .type(RuleClassType.ABSTRACT) - .ancestors( - AppleToolchain.RequiresXcodeConfigRule.class, - ResourceToolsRule.class, - ReleaseBundlingToolsRule.class, - XcrunRule.class) - .build(); - } - } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingTargetFactory.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingTargetFactory.java deleted file mode 100644 index 1a5ca6d5e1..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingTargetFactory.java +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright 2014 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.common.base.Optional; -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.RuleConfiguredTargetBuilder; -import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; -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.apple.DottedVersion; -import com.google.devtools.build.lib.rules.apple.XcodeConfig; -import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.LinkedBinary; -import javax.annotation.Nullable; - -/** - * Base class for rules that bundle releases. - * - * @deprecated The native bundling rules have been deprecated. This class will be removed in the - * future. - */ -@Deprecated -public abstract class ReleaseBundlingTargetFactory implements RuleConfiguredTargetFactory { - - private final String bundleDirFormat; - private final ImmutableSet<Attribute> dependencyAttributes; - - /** - * @param bundleDirFormat format string representing the bundle's directory with a single - * placeholder for the target name (e.g. {@code "Payload/%s.app"}) - * @param dependencyAttributes all attributes that contain dependencies of this rule. Any - * dependency so listed must expose {@link ObjcProvider}. - */ - public ReleaseBundlingTargetFactory( - String bundleDirFormat, ImmutableSet<Attribute> dependencyAttributes) { - this.bundleDirFormat = bundleDirFormat; - this.dependencyAttributes = dependencyAttributes; - } - - @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."); - - validateAttributes(ruleContext); - ObjcCommon common = common(ruleContext); - - NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder(); - - AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); - ReleaseBundlingSupport releaseBundlingSupport = new ReleaseBundlingSupport( - ruleContext, common.getObjcProvider(), LinkedBinary.DEPENDENCIES_ONLY, bundleDirFormat, - bundleName(ruleContext), bundleMinimumOsVersion(ruleContext), - appleConfiguration.getMultiArchPlatform(PlatformType.IOS)); - releaseBundlingSupport - .registerActions(DsymOutputType.APP) - .addFilesToBuild(filesToBuild, Optional.of(DsymOutputType.APP)) - .validateResources() - .validateAttributes(); - - RuleConfiguredTargetBuilder targetBuilder = - ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build()) - .addNativeDeclaredProvider(releaseBundlingSupport.xcTestAppProvider()) - .addProvider( - InstrumentedFilesProvider.class, - InstrumentedFilesCollector.forward(ruleContext, "binary")); - - ObjcProvider exposedObjcProvider = exposedObjcProvider(ruleContext, releaseBundlingSupport); - if (exposedObjcProvider != null) { - targetBuilder - .addNativeDeclaredProvider(exposedObjcProvider); - } - - configureTarget(targetBuilder, ruleContext, releaseBundlingSupport); - return targetBuilder.build(); - } - - /** - * Validates application-related attributes set on this rule and registers any errors with the - * rule context. Default implemenation does nothing; subclasses may override it. - */ - protected void validateAttributes(RuleContext ruleContext) {} - - /** - * Returns the minimum OS version this bundle's plist and resources should be generated for - * (<b>not</b> the minimum OS version its binary is compiled with, that needs to be set in the - * configuration). - */ - protected DottedVersion bundleMinimumOsVersion(RuleContext ruleContext) { - return XcodeConfig.getMinimumOsForPlatformType(ruleContext, PlatformType.IOS); - } - - /** - * Performs additional configuration of the target. The default implementation does nothing, but - * subclasses may override it to add logic. - * @throws InterruptedException - */ - protected void configureTarget(RuleConfiguredTargetBuilder target, RuleContext ruleContext, - ReleaseBundlingSupport releaseBundlingSupport) throws InterruptedException {} - - /** - * Returns the name of this target's bundle. - */ - protected String bundleName(RuleContext ruleContext) { - return ruleContext.getLabel().getName(); - } - - /** - * Returns an exposed {@code ObjcProvider} object. - * @throws InterruptedException - */ - @Nullable - protected ObjcProvider exposedObjcProvider( - RuleContext ruleContext, ReleaseBundlingSupport releaseBundlingSupport) - throws InterruptedException { - return null; - } - - private ObjcCommon common(RuleContext ruleContext) { - ObjcCommon.Builder builder = new ObjcCommon.Builder(ruleContext) - .setIntermediateArtifacts(ObjcRuleClasses.intermediateArtifacts(ruleContext)); - for (Attribute attribute : dependencyAttributes) { - builder.addDepObjcProviders( - ruleContext.getPrerequisites( - attribute.getName(), attribute.getAccessMode(), ObjcProvider.SKYLARK_CONSTRUCTOR)); - } - return builder.build(); - } -} diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MockObjcSupport.java b/src/test/java/com/google/devtools/build/lib/packages/util/MockObjcSupport.java index d42f6f720a..bc99b16aa2 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/util/MockObjcSupport.java +++ b/src/test/java/com/google/devtools/build/lib/packages/util/MockObjcSupport.java @@ -64,6 +64,7 @@ public final class MockObjcSupport { "bundlemerge", "objc_dummy.mm", "environment_plist.sh", + "device_debug_entitlements.plist", "gcov", "ibtoolwrapper", "momcwrapper", @@ -76,8 +77,34 @@ public final class MockObjcSupport { "libtool")) { config.create(TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/objc/" + tool); } + // Since we deleted ios_application, we have to create a custom rule that mocks out a + // close-enough test host app for ios_test to use until those rules are also deleted. + config.create( + TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/objc/fake_test_app.bzl", + "def _fake_test_app_impl(ctx):", + " return struct(", + " instrumented_files=struct(dependency_attributes=['bundle_loader', 'ipa']),", + " providers=[", + " DefaultInfo(files=depset([ctx.file.ipa])),", + " apple_common.new_xctest_app_provider(", + " bundle_loader=ctx.file.bundle_loader,", + " ipa=ctx.file.ipa,", + " objc_provider=apple_common.new_objc_provider(),", + " ),", + " ],", + " )", + "fake_test_app = rule(", + " implementation=_fake_test_app_impl,", + " attrs={", + " 'bundle_loader': attr.label(", + " single_file=True, default='//tools/objc:xctest_appbin'),", + " 'ipa': attr.label(", + " allow_files=True, single_file=True, default='//tools/objc:xctest_app.ipa'),", + " },", + ")"); config.create( TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/objc/BUILD", + "load(':fake_test_app.bzl', 'fake_test_app')", "package(default_visibility=['//visibility:public'])", "exports_files(glob(['**']))", "filegroup(name = 'default_provisioning_profile', srcs = ['foo.mobileprovision'])", @@ -88,10 +115,11 @@ public final class MockObjcSupport { " name = 'protobuf_compiler_support',", " srcs = ['proto_support', 'protobuf_compiler_helper.py'],", ")", + "sh_binary(name = 'environment_plist', srcs = ['environment_plist.sh'])", + "fake_test_app(name = 'xctest_app')", + "apple_binary(name = 'xctest_appbin', platform_type = 'ios', deps = [':dummy_lib'])", "filegroup(name = 'xctest_infoplist', srcs = ['xctest.plist'])", "filegroup(name = 'j2objc_dead_code_pruner', srcs = ['j2objc_dead_code_pruner.py'])", - "ios_application(name = 'xctest_app', binary = ':xctest_appbin')", - "objc_binary(name = 'xctest_appbin', srcs = ['objc_dummy.mm'])", "filegroup(", " name = 'protobuf_well_known_types',", String.format( @@ -124,13 +152,17 @@ public final class MockObjcSupport { if (TestConstants.TOOLS_REPOSITORY_SCRATCH.length() > 0) { config.create( "tools/objc/BUILD", + "load('@" + + TestConstants.TOOLS_REPOSITORY_SCRATCH + + "//tools/objc:fake_test_app.bzl', 'fake_test_app')", "package(default_visibility=['//visibility:public'])", "exports_files(glob(['**']))", - "ios_application(name = 'xctest_app', binary = ':xctest_appbin')", - "objc_binary(name = 'xctest_appbin', srcs = ['objc_dummy.mm'])", + "fake_test_app(name = 'xctest_app')", + "apple_binary(name = 'xctest_appbin', platform_type = 'ios', deps = [':dummy_lib'])", "filegroup(name = 'default_provisioning_profile', srcs = ['foo.mobileprovision'])", "filegroup(name = 'xctest_infoplist', srcs = ['xctest.plist'])"); } + config.create(TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/objc/xctest_app.ipa"); config.create( TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/objc/foo.mobileprovision", "No such luck"); config.create(TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/objc/compile_protos.py"); diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/AppleToolchainSelectionTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/AppleToolchainSelectionTest.java index 8b7fba8160..2dad393ac0 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/AppleToolchainSelectionTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/AppleToolchainSelectionTest.java @@ -21,10 +21,7 @@ import com.google.common.base.Joiner; import com.google.devtools.build.lib.actions.Action; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.CommandAction; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.util.ScratchAttributeWriter; -import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher; import com.google.devtools.build.lib.rules.cpp.CppConfiguration; import com.google.devtools.build.lib.rules.cpp.CppLinkAction; @@ -42,31 +39,6 @@ public class AppleToolchainSelectionTest extends ObjcRuleTestCase { useConfiguration(ObjcCrosstoolMode.LIBRARY, args); } - /** - * Returns the given target in the configuration that it would be given by this - * {@code BuildViewTestCase}'s {@code Transitions}, were the target a top-level target. - */ - private ConfiguredTarget getTopLevelConfiguredTarget(ConfiguredTarget target) - throws InterruptedException { - BuildConfiguration topLevelConfig = getAppleCrosstoolConfiguration(); - return getConfiguredTarget(target.getLabel(), topLevelConfig); - } - - /** - * Returns the action that produces the artifact with the given label and suffix, in a output - * directory consistent with that action being registered by a top-level target. - */ - private CommandAction actionProducingArtifactForTopLevelTarget(String targetLabel, - String artifactSuffix) throws Exception { - ConfiguredTarget libraryTarget = getConfiguredTarget(targetLabel); - ConfiguredTarget topLevelLibraryTarget = getTopLevelConfiguredTarget(libraryTarget); - Label parsedLabel = Label.parseAbsolute(targetLabel); - Artifact linkedLibrary = getBinArtifact( - parsedLabel.getName() + artifactSuffix, - topLevelLibraryTarget); - return (CommandAction) getGeneratingAction(linkedLibrary); - } - @Test public void testToolchainSelectionDefault() throws Exception { createLibraryTargetWriter("//a:lib").write(); @@ -104,9 +76,15 @@ public class AppleToolchainSelectionTest extends ObjcRuleTestCase { .setList("deps", "//b:lib") .write(); - CommandAction linkAction = actionProducingArtifactForTopLevelTarget("//a:bin", "_bin"); - Artifact ccArchive = getFirstArtifactEndingWith(linkAction.getInputs(), "liblib.a"); - CommandAction ccArchiveAction = (CommandAction) getGeneratingAction(ccArchive); + Action lipoAction = actionProducingArtifact("//a:bin", "_lipobin"); + String x8664Bin = + configurationBin("x86_64", ConfigurationDistinguisher.APPLEBIN_IOS, DEFAULT_IOS_SDK_VERSION) + + "a/bin_bin"; + Artifact binArtifact = getFirstArtifactEndingWith(lipoAction.getInputs(), x8664Bin); + CommandAction linkAction = getGeneratingSpawnAction(binArtifact); + CppLinkAction ccArchiveAction = + (CppLinkAction) + getGeneratingAction(getFirstArtifactEndingWith(linkAction.getInputs(), "liblib.a")); Artifact ccObjectFile = getFirstArtifactEndingWith(ccArchiveAction.getInputs(), ".o"); CommandAction ccCompileAction = (CommandAction) getGeneratingAction(ccObjectFile); assertThat(ccCompileAction.getArguments()).contains("tools/osx/crosstool/iossim/wrapped_clang"); @@ -123,9 +101,15 @@ public class AppleToolchainSelectionTest extends ObjcRuleTestCase { .setList("srcs", "a.m") .setList("deps", "//b:lib") .write(); - CommandAction linkAction = actionProducingArtifactForTopLevelTarget("//a:bin", "_bin"); - Artifact ccArchive = getFirstArtifactEndingWith(linkAction.getInputs(), "liblib.a"); - CommandAction ccArchiveAction = (CommandAction) getGeneratingAction(ccArchive); + Action lipoAction = actionProducingArtifact("//a:bin", "_lipobin"); + String armv7Bin = + configurationBin("armv7", ConfigurationDistinguisher.APPLEBIN_IOS, DEFAULT_IOS_SDK_VERSION) + + "a/bin_bin"; + Artifact binArtifact = getFirstArtifactEndingWith(lipoAction.getInputs(), armv7Bin); + CommandAction linkAction = getGeneratingSpawnAction(binArtifact); + CppLinkAction ccArchiveAction = + (CppLinkAction) + getGeneratingAction(getFirstArtifactEndingWith(linkAction.getInputs(), "liblib.a")); Artifact ccObjectFile = getFirstArtifactEndingWith(ccArchiveAction.getInputs(), ".o"); CommandAction ccCompileAction = (CommandAction) getGeneratingAction(ccObjectFile); assertThat(ccCompileAction.getArguments()).contains("tools/osx/crosstool/ios/wrapped_clang"); diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcLibraryTest.java index 684426ef22..2599ce4bdc 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcLibraryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcLibraryTest.java @@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.getFirstArtifactEndingWith; import com.google.common.base.Joiner; +import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; @@ -34,11 +35,14 @@ import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.actions.ActionTemplate.ActionTemplateExpansionException; import com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction; import com.google.devtools.build.lib.analysis.actions.SpawnAction; +import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.packages.util.MockObjcSupport; 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.AppleToolchain; +import com.google.devtools.build.lib.rules.apple.DottedVersion; import com.google.devtools.build.lib.rules.cpp.CppCompileActionTemplate; import com.google.devtools.build.lib.rules.cpp.CppModuleMapAction; import com.google.devtools.build.lib.rules.cpp.UmbrellaHeaderAction; @@ -57,6 +61,21 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class BazelJ2ObjcLibraryTest extends J2ObjcLibraryTest { + /** + * Gets the target with the given label, using the apple_binary multi-arch split transition with + * the default version of iOS as the platform. + */ + private ConfiguredTarget getConfiguredTargetInAppleBinaryTransition(String label) + throws Exception { + BuildConfiguration childConfig = + Iterables.getOnlyElement( + getSplitConfigurations( + targetConfig, + new MultiArchSplitTransitionProvider.AppleBinaryTransition( + PlatformType.IOS, Optional.<DottedVersion>absent()))); + return getConfiguredTarget(label, childConfig); + } + @Test public void testJ2ObjCInformationExportedFromJ2ObjcLibrary() throws Exception { ConfiguredTarget j2objcLibraryTarget = getConfiguredTarget( @@ -265,7 +284,8 @@ public class BazelJ2ObjcLibraryTest extends J2ObjcLibraryTest { (CommandAction) getGeneratingAction( getBinArtifact( - String.format("%s_bin", labelName), getConfiguredTarget(targetLabel))); + String.format("%s_bin", labelName), + getConfiguredTargetInAppleBinaryTransition(targetLabel))); checkObjcCompileActions( getFirstArtifactEndingWith(linkAction.getInputs(), archiveFileName), @@ -458,18 +478,19 @@ public class BazelJ2ObjcLibraryTest extends J2ObjcLibraryTest { protected void addSimpleBinaryTarget(String j2objcLibraryTargetDep) throws Exception { scratch.file("app/app.m"); scratch.file("app/Info.plist"); - scratch.file("app/BUILD", + scratch.file( + "app/BUILD", "package(default_visibility=['//visibility:public'])", "objc_library(", " name = 'lib',", " deps = ['" + j2objcLibraryTargetDep + "'])", "", - "objc_binary(", + "apple_binary(", " name = 'app',", " srcs = ['app.m'],", + " platform_type = 'ios',", " deps = [':lib'],", ")"); - } protected void addSimpleJ2ObjcLibraryWithEntryClasses() throws Exception { @@ -598,27 +619,16 @@ public class BazelJ2ObjcLibraryTest extends J2ObjcLibraryTest { " name = 'j2',", " deps = [ '//java/c/y:ylib' ],", " jre_deps = [ '//third_party/java/j2objc:jre_io_lib' ])", - "ios_application(", - " name = 'app',", - " binary = ':bin',", - " infoplist = 'info.plist',", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " deps = [':j2'],", - ")", - "ios_test(", + "apple_binary(", " name = 'test',", " srcs = ['test.m'],", + " platform_type = 'ios',", " deps = [':j2'],", - " xctest = 1,", - " xctest_app = ':app',", ")"); CommandAction linkAction = linkAction("//x:test"); List<String> linkArgs = normalizeBashArgs(linkAction.getArguments()); - ConfiguredTarget target = getConfiguredTarget("//x:test"); + ConfiguredTarget target = getConfiguredTargetInAppleBinaryTransition("//x:test"); String binDir = target.getConfiguration().getBinDirectory(RepositoryName.MAIN).getExecPathString(); Artifact fileList = getFirstArtifactEndingWith(linkAction.getInputs(), "test-linker.objlist"); @@ -844,7 +854,7 @@ public class BazelJ2ObjcLibraryTest extends J2ObjcLibraryTest { addSimpleJ2ObjcLibraryWithEntryClasses(); addSimpleBinaryTarget("//java/com/google/app/test:transpile"); - ConfiguredTarget appTarget = getConfiguredTarget("//app:app", getAppleCrosstoolConfiguration()); + ConfiguredTarget appTarget = getConfiguredTargetInAppleBinaryTransition("//app:app"); Artifact prunedArchive = getBinArtifact( "_j2objc_pruned/app/java/com/google/app/test/libtest_j2objc_pruned.a", appTarget); @@ -852,7 +862,7 @@ public class BazelJ2ObjcLibraryTest extends J2ObjcLibraryTest { getBinArtifact("_j2objc_pruned/app/java/com/google/app/test/test.param.j2objc", appTarget); ConfiguredTarget javaTarget = - getConfiguredTarget("//java/com/google/app/test:test", getAppleCrosstoolConfiguration()); + getConfiguredTargetInAppleBinaryTransition("//java/com/google/app/test:test"); Artifact inputArchive = getBinArtifact("libtest_j2objc.a", javaTarget); Artifact headerMappingFile = getBinArtifact("test.mapping.j2objc", javaTarget); Artifact dependencyMappingFile = getBinArtifact("test.dependency_mapping.j2objc", javaTarget); diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ExperimentalObjcBinaryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ExperimentalObjcBinaryTest.java deleted file mode 100644 index 0f8f03ccff..0000000000 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/ExperimentalObjcBinaryTest.java +++ /dev/null @@ -1,302 +0,0 @@ -// Copyright 2017 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import static com.google.common.truth.Truth.assertThat; -import static com.google.devtools.build.lib.rules.objc.LegacyCompilationSupport.AUTOMATIC_SDK_FRAMEWORKS; - -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.actions.Action; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.actions.CommandAction; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.util.ScratchAttributeWriter; -import com.google.devtools.build.lib.packages.util.MockObjcSupport; -import com.google.devtools.build.lib.rules.apple.ApplePlatform; -import com.google.devtools.build.lib.rules.apple.AppleToolchain; -import com.google.devtools.build.lib.rules.cpp.CppCompileAction; -import com.google.devtools.build.lib.rules.cpp.CppLinkAction; -import com.google.devtools.build.lib.rules.objc.ObjcCommandLineOptions.ObjcCrosstoolMode; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Test case for linking targets with the OSX crosstool. */ -@RunWith(JUnit4.class) -@LegacyTest -public class ExperimentalObjcBinaryTest extends ObjcRuleTestCase { - static final RuleType RULE_TYPE = new BinaryRuleType("objc_binary"); - - private static final String WRAPPED_CLANG = "wrapped_clang"; - private static final String WRAPPED_CLANGPLUSPLUS = "wrapped_clang++"; - - private ConfiguredTarget addMockBinAndLibs(List<String> srcs) throws Exception { - createLibraryTargetWriter("//lib1:lib1") - .setAndCreateFiles("srcs", "a.m", "b.m", "private.h") - .setAndCreateFiles("hdrs", "hdr.h") - .write(); - createLibraryTargetWriter("//lib2:lib2") - .setAndCreateFiles("srcs", "a.m", "b.m", "private.h") - .setAndCreateFiles("hdrs", "hdr.h") - .write(); - - return createBinaryTargetWriter("//bin:bin") - .setAndCreateFiles("srcs", srcs) - .setList("deps", "//lib1:lib1", "//lib2:lib2") - .write(); - } - - private ImmutableList<String> automaticSdkFrameworks() { - ImmutableList.Builder<String> result = ImmutableList.<String>builder(); - for (SdkFramework framework : AUTOMATIC_SDK_FRAMEWORKS) { - result.add("-framework " + framework.getName()); - } - return result.build(); - } - - @Test - public void testDeviceBuild() throws Exception { - useConfiguration( - "--crosstool_top=" + MockObjcSupport.DEFAULT_OSX_CROSSTOOL, - "--experimental_objc_crosstool=all", - "--experimental_disable_go", - "--cpu=ios_armv7", - "--ios_cpu=armv7"); - ApplePlatform platform = ApplePlatform.IOS_DEVICE; - - addMockBinAndLibs(ImmutableList.of("a.m")); - CommandAction action = linkAction("//bin:bin"); - assertRequiresDarwin(action); - assertThat(Artifact.toRootRelativePaths(action.getInputs())) - .containsExactly( - "bin/libbin.a", - "lib1/liblib1.a", - "lib2/liblib2.a", - "bin/bin-linker.objlist"); - assertThat(Artifact.toRootRelativePaths(action.getOutputs())).containsExactly("bin/bin_bin"); - verifyObjlist( - action, - "bin-linker.objlist", - execPathEndingWith(action.getInputs(), "libbin.a"), - execPathEndingWith(action.getInputs(), "liblib1.a"), - execPathEndingWith(action.getInputs(), "liblib2.a")); - assertThat(action.getArguments()) - .containsExactlyElementsIn( - new ImmutableList.Builder<String>() - .add("tools/osx/crosstool/ios/" + WRAPPED_CLANG) - .add("-arch armv7") - .add("-Xlinker", "-objc_abi_version", "-Xlinker", "2") - .add("-Xlinker", "-rpath", "-Xlinker", "@executable_path/Frameworks") - .add("-fobjc-link-runtime") - .add("-ObjC") - .add("-filelist " + execPathEndingWith(action.getInputs(), "bin-linker.objlist")) - .add("-o " + Iterables.getOnlyElement(Artifact.toExecPaths(action.getOutputs()))) - .add("-F" + AppleToolchain.sdkDir() + AppleToolchain.DEVELOPER_FRAMEWORK_PATH) - .add("-F" + frameworkDir(platform)) - .add("-isysroot") - .add(AppleToolchain.sdkDir()) - // TODO(b/35853671): Factor out "-lc++" - .add("-lc++") - .add("-target", "armv7-apple-ios") - .add("-miphoneos-version-min=" + DEFAULT_IOS_SDK_VERSION) - .addAll(automaticSdkFrameworks()) - .build()) - .inOrder(); - } - - @Test - public void testSimulatorBuild() throws Exception { - useConfiguration( - "--crosstool_top=" + MockObjcSupport.DEFAULT_OSX_CROSSTOOL, - "--experimental_objc_crosstool=all", - "--experimental_disable_go", - "--cpu=ios_x86_64", - "--ios_cpu=x86_64"); - ApplePlatform platform = ApplePlatform.IOS_SIMULATOR; - - addMockBinAndLibs(ImmutableList.of("a.m")); - CommandAction action = linkAction("//bin:bin"); - assertThat(action.getArguments()) - .containsAllOf( - "tools/osx/crosstool/iossim/" + WRAPPED_CLANG, - "-arch x86_64", - "-mios-simulator-version-min=" + DEFAULT_IOS_SDK_VERSION, - "-F" + frameworkDir(platform)); - } - - @Test - public void testAlwaysLinkCcDependenciesAreForceLoaded() throws Exception { - useConfiguration( - "--crosstool_top=" + MockObjcSupport.DEFAULT_OSX_CROSSTOOL, - "--experimental_objc_crosstool=all", - "--experimental_disable_go", - "--cpu=ios_armv7", - "--ios_cpu=armv7"); - - scratch.file( - "bin/BUILD", - "cc_library(", - " name = 'cclib1',", - " srcs = ['dep1.c'],", - " alwayslink = 1,", - ")", - "cc_library(", - " name = 'cclib2',", - " srcs = ['dep2.c'],", - " deps = [':cclib1'],", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " deps = [':cclib2'],", - ")"); - - // cclib1 is force loaded. - assertThat(Joiner.on(" ").join(linkAction("//bin").getArguments())) - .containsMatch(Pattern.compile(" -force_load [^\\s]+/libcclib1.lo\\b")); - } - - @Test - public void testObjcPlusPlusLinkAction() throws Exception { - useConfiguration( - "--crosstool_top=" + MockObjcSupport.DEFAULT_OSX_CROSSTOOL, - "--experimental_objc_crosstool=all", - "--experimental_disable_go", - "--cpu=ios_armv7", - "--ios_cpu=armv7"); - - addMockBinAndLibs(ImmutableList.of("a.mm")); - - CommandAction action = linkAction("//bin:bin"); - assertThat(action.getArguments()) - .containsAllOf( - "tools/osx/crosstool/ios/" + WRAPPED_CLANGPLUSPLUS, - "-stdlib=libc++", - "-std=gnu++11"); - } - - @Test - public void testUnstrippedArtifactGeneratedForBinaryStripping() throws Exception { - useConfiguration( - "--crosstool_top=" + MockObjcSupport.DEFAULT_OSX_CROSSTOOL, - "--experimental_objc_crosstool=all", - "--experimental_disable_go", - "--objc_enable_binary_stripping", - "--compilation_mode=opt"); - addMockBinAndLibs(ImmutableList.of("a.m")); - Action linkAction = actionProducingArtifact("//bin:bin", "_bin_unstripped"); - Action stripAction = actionProducingArtifact("//bin:bin", "_bin"); - assertThat(linkAction).isNotNull(); - assertThat(stripAction).isNotNull(); - } - - - @Test - public void testDeadStripLinkArguments() throws Exception { - useConfiguration( - "--crosstool_top=" + MockObjcSupport.DEFAULT_OSX_CROSSTOOL, - "--experimental_objc_crosstool=all", - "--experimental_disable_go", - "--cpu=ios_armv7", - "--ios_cpu=armv7", - "--objc_enable_binary_stripping", - "--compilation_mode=opt"); - addMockBinAndLibs(ImmutableList.of("a.mm")); - CommandAction linkAction = - (CommandAction) actionProducingArtifact("//bin:bin", "_bin_unstripped"); - assertThat(linkAction.getArguments()) - .containsAllOf("-dead_strip", "-no_dead_strip_inits_and_terms"); - } - - @Test - public void testDeadStripLinkArgumentsNotPresentIfStrippingNotEnabled() throws Exception { - useConfiguration( - "--crosstool_top=" + MockObjcSupport.DEFAULT_OSX_CROSSTOOL, - "--experimental_objc_crosstool=all", - "--experimental_disable_go", - "--cpu=ios_armv7", - "--ios_cpu=armv7", - "--compilation_mode=opt"); - addMockBinAndLibs(ImmutableList.of("a.mm")); - CommandAction linkAction = - (CommandAction) actionProducingArtifact("//bin:bin", "_bin"); - assertThat(linkAction.getArguments()) - .containsNoneOf("--dead_strip", "--no_dead_strip_inits_and_terms"); - } - - @Test - public void testDeadStripLinkArgumentsNotPresentIfCompilationModeFastbuild() throws Exception { - useConfiguration( - "--crosstool_top=" + MockObjcSupport.DEFAULT_OSX_CROSSTOOL, - "--experimental_objc_crosstool=all", - "--experimental_disable_go", - "--cpu=ios_armv7", - "--ios_cpu=armv7", - "--objc_enable_binary_stripping", - "--compilation_mode=fastbuild"); - addMockBinAndLibs(ImmutableList.of("a.mm")); - CommandAction linkAction = - (CommandAction) actionProducingArtifact("//bin:bin", "_bin"); - assertThat(linkAction.getArguments()) - .containsNoneOf("--dead_strip", "--no_dead_strip_inits_and_terms"); - } - - @Test - public void testCompileEnv() throws Exception { - MockObjcSupport.createCrosstoolPackage(mockToolsConfig); - useConfiguration( - ObjcCrosstoolMode.LIBRARY, - "--experimental_disable_go", - "--experimental_disable_jvm", - "--ios_sdk_version=2.9", - "--xcode_version=5.0", - "--cpu=ios_x86_64"); - ScratchAttributeWriter.fromLabelString(this, "objc_library", "//main:lib") - .setList("srcs", "a.m") - .write(); - - CppCompileAction compileAction = (CppCompileAction) compileAction("//main:lib", "a.o"); - - Map<String, String> environment = compileAction.getEnvironment(); - assertThat(environment).containsEntry("XCODE_VERSION_OVERRIDE", "5.0"); - assertThat(environment).containsEntry("APPLE_SDK_VERSION_OVERRIDE", "2.9"); - } - - @Test - public void testArchiveEnv() throws Exception { - MockObjcSupport.createCrosstoolPackage(mockToolsConfig); - useConfiguration( - ObjcCrosstoolMode.LIBRARY, - "--experimental_disable_go", - "--experimental_disable_jvm", - "--ios_sdk_version=2.9", - "--xcode_version=5.0", - "--cpu=ios_x86_64"); - ScratchAttributeWriter.fromLabelString(this, "objc_library", "//main:lib") - .setList("srcs", "a.m") - .write(); - - CppLinkAction archiveAction = (CppLinkAction) archiveAction("//main:lib"); - - Map<String, String> environment = archiveAction.getEnvironment(); - assertThat(environment).containsEntry("XCODE_VERSION_OVERRIDE", "5.0"); - assertThat(environment).containsEntry("APPLE_SDK_VERSION_OVERRIDE", "2.9"); - } -} diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/IosApplicationTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/IosApplicationTest.java deleted file mode 100644 index 5183cfa09d..0000000000 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/IosApplicationTest.java +++ /dev/null @@ -1,1115 +0,0 @@ -// Copyright 2017 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import static com.google.common.truth.Truth.assertThat; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.ReleaseBundlingRule.APP_ICON_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.ReleaseBundlingRule.LAUNCH_IMAGE_ATTR; - -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableListMultimap; -import com.google.common.collect.ImmutableMultiset; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSetMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.collect.Multiset; -import com.google.devtools.build.lib.actions.Action; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.actions.CommandAction; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.analysis.RunfilesProvider; -import com.google.devtools.build.lib.analysis.actions.SpawnAction; -import com.google.devtools.build.lib.analysis.config.BuildConfiguration; -import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher; -import com.google.devtools.build.lib.rules.apple.DottedVersion; -import com.google.devtools.build.lib.testutil.Scratch; -import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos; -import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos.BundleFile; -import com.google.devtools.build.xcode.plmerge.proto.PlMergeProtos; -import java.io.IOException; -import java.util.List; -import java.util.Set; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Test case for ios_application. */ -@RunWith(JUnit4.class) -@LegacyTest -public class IosApplicationTest extends ObjcRuleTestCase { - protected static final RuleType RULE_TYPE = - new RuleType("ios_application") { - @Override - Iterable<String> requiredAttributes( - Scratch scratch, String packageDir, Set<String> alreadyAdded) throws IOException { - ImmutableList.Builder<String> attributes = new ImmutableList.Builder<>(); - if (!alreadyAdded.contains("binary")) { - scratch.file(packageDir + "/bin/a.m"); - scratch.file(packageDir + "/bin/BUILD", "objc_binary(name = 'bin', srcs = ['a.m'])"); - attributes.add("binary = '//" + packageDir + "/bin:bin'"); - } - return attributes.build(); - } - }; - - protected static final BinaryRuleTypePair RULE_TYPE_PAIR = - new BinaryRuleTypePair( - ObjcBinaryTest.RULE_TYPE, RULE_TYPE, ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT); - - private ConfiguredTarget addMockAppAndLibs(String... extraAppAttributes) - throws Exception { - createLibraryTargetWriter("//lib1:lib1") - .setAndCreateFiles("srcs", "a.m", "b.m", "private.h") - .setAndCreateFiles("hdrs", "hdr.h") - .write(); - createLibraryTargetWriter("//lib2:lib2") - .setAndCreateFiles("srcs", "a.m", "b.m", "private.h") - .setAndCreateFiles("hdrs", "hdr.h") - .write(); - scratch.file("x/a.m"); - scratch.file("x/x-Info.plist"); - scratch.file("x/BUILD", - "objc_binary(", - " name = 'bin',", - " srcs = ['a.m'],", - " deps = ['//lib1:lib1', '//lib2:lib2'],", - ")", - "", - "ios_application(", - " name = 'x',", - " binary = ':bin',", - Joiner.on(',').join(extraAppAttributes), - ")"); - return getConfiguredTarget("//x:x"); - } - - @Test - public void testSplitConfigurationProviders() throws Exception { - useConfiguration("--ios_multi_cpus=i386,x86_64"); - scratch.file("x/BUILD", - "objc_binary(", - " name = 'bin',", - " srcs = ['a.m'],", - ")", - "", - "ios_application(", - " name = 'x',", - " infoplist = 'Info.plist',", - " binary = ':bin',", - ")"); - RuleContext ruleContext = getRuleContext(getConfiguredTarget("//x:x")); - ImmutableListMultimap<BuildConfiguration, ObjcProvider> prereqByConfig = - ruleContext.getPrerequisitesByConfiguration( - "binary", Mode.SPLIT, ObjcProvider.SKYLARK_CONSTRUCTOR); - List<String> childCpus = Lists.transform(prereqByConfig.keySet().asList(), - new Function<BuildConfiguration, String>() { - @Override - public String apply(BuildConfiguration config) { - return config.getFragment(AppleConfiguration.class).getIosCpu(); - } - }); - assertThat(childCpus).containsExactly("i386", "x86_64"); - } - - @Test - public void testRunfiles() throws Exception { - ConfiguredTarget application = addMockAppAndLibs(); - RunfilesProvider runfiles = application.getProvider(RunfilesProvider.class); - assertThat(runfiles.getDefaultRunfiles().getArtifacts()).isEmpty(); - assertThat(Artifact.toRootRelativePaths(runfiles.getDataRunfiles().getArtifacts())) - .containsExactly("x/x.ipa"); - } - - @Test - public void testFilesToRun() throws Exception { - checkFilesToRun(RULE_TYPE); - } - - @Test - public void testNoRunfilesSupportForDevice() throws Exception { - checkNoRunfilesSupportForDevice(RULE_TYPE); - } - - @Test - public void testGenerateRunnerScriptAction() throws Exception { - checkGenerateRunnerScriptAction(RULE_TYPE); - } - - @Test - public void testGenerateRunnerScriptAction_escaped() throws Exception { - checkGenerateRunnerScriptAction_escaped(RULE_TYPE); - } - - @Test - public void testSigningAction() throws Exception { - checkDeviceSigningAction(RULE_TYPE); - } - - @Test - public void testSigningWithCertName() throws Exception { - checkSigningWithCertName(RULE_TYPE); - } - - @Test - public void testPostProcessingAction() throws Exception { - checkPostProcessingAction(RULE_TYPE); - } - - @Test - public void testSigningAndPostProcessing() throws Exception { - checkSigningAndPostProcessing(RULE_TYPE); - } - - @Test - public void testSigning_simulatorBuild() throws Exception { - checkSigningSimulatorBuild(RULE_TYPE_PAIR, false); - } - - @Test - public void testSigning_simulatorBuild_multiCpu() throws Exception { - checkSigningSimulatorBuild(RULE_TYPE_PAIR, true); - } - - @Test - public void testProvisioningProfile_deviceBuild() throws Exception { - checkProvisioningProfileDeviceBuild(RULE_TYPE_PAIR, false); - } - - @Test - public void testProvisioningProfile_deviceBuild_multiCpu() throws Exception { - checkProvisioningProfileDeviceBuild(RULE_TYPE_PAIR, true); - } - - @Test - public void testUserSpecifiedProvisioningProfile_deviceBuild() throws Exception { - checkProvisioningProfileUserSpecified(RULE_TYPE_PAIR, false); - } - - @Test - public void testUserSpecifiedProvisioningProfile_deviceBuild_multiCpu() throws Exception { - checkProvisioningProfileUserSpecified(RULE_TYPE_PAIR, true); - } - - @Test - public void testMergeControlAction() throws Exception { - addMockAppAndLibs("infoplist = 'Info.plist'"); - Action mergeAction = bundleMergeAction("//x:x"); - Action action = bundleMergeControlAction("//x:x"); - assertThat(action.getInputs()).isEmpty(); - assertThat(Artifact.toRootRelativePaths(action.getOutputs())) - .containsExactly("x/x.ipa-control"); - assertThat(bundleMergeControl("//x:x")) - .isEqualTo( - BundleMergeProtos.Control.newBuilder() - .addBundleFile( - BundleFile.newBuilder() - .setSourceFile(execPathEndingWith(mergeAction.getInputs(), "x_lipobin")) - .setBundlePath("x") - .setExternalFileAttribute(BundleableFile.EXECUTABLE_EXTERNAL_FILE_ATTRIBUTE) - .build()) - .setBundleRoot(String.format(ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT, "x")) - .setBundleInfoPlistFile(execPathEndingWith(mergeAction.getInputs(), "Info.plist")) - .setOutFile(execPathEndingWith(mergeAction.getOutputs(), "x.unprocessed.ipa")) - .setMinimumOsVersion(DEFAULT_IOS_SDK_VERSION.toString()) - .setSdkVersion(DEFAULT_IOS_SDK_VERSION.toString()) - .setPlatform("IOS_SIMULATOR") - .setFallbackBundleIdentifier("example.x") - .build()); - } - - @Test - public void testMergeBundleAction() throws Exception { - checkMergeBundleAction(RULE_TYPE_PAIR); - } - - @Test - public void testCheckPrimaryBundleIdInMergedPlist() throws Exception { - checkPrimaryBundleIdInMergedPlist(RULE_TYPE_PAIR); - } - - @Test - public void testCheckFallbackBundleIdInMergedPlist() throws Exception { - checkFallbackBundleIdInMergedPlist(RULE_TYPE_PAIR); - } - - @Test - public void testErrorForLaunchImageGivenWithNoAssetCatalog() throws Exception { - checkAssetCatalogAttributeError(RULE_TYPE, LAUNCH_IMAGE_ATTR); - } - - @Test - public void testErrorForAppIconGivenWithNoAssetCatalog() throws Exception { - checkAssetCatalogAttributeError(RULE_TYPE, APP_ICON_ATTR); - } - - @Test - public void testCollectsAssetCatalogsTransitively() throws Exception { - checkCollectsAssetCatalogsTransitively(RULE_TYPE_PAIR); - } - - @Test - public void testSpecifyAppIconAndLaunchImageUsingXcassetsOfDependency() throws Exception { - checkSpecifyAppIconAndLaunchImageUsingXcassetsOfDependency( - RULE_TYPE_PAIR, DEFAULT_IOS_SDK_VERSION); - } - - private void addTargetWithAssetCatalogs() throws IOException { - scratch.file("x/foo.xcassets/foo"); - scratch.file("x/foo.xcassets/bar"); - scratch.file("x/a.m"); - scratch.file("x/BUILD", - "objc_binary(", - " name = 'bin',", - " asset_catalogs = ['foo.xcassets/foo', 'bar.xcassets/bar'],", - " srcs = ['a.m'],", - ")", - "", - "ios_application(", - " name = 'x',", - " binary = ':bin',", - ")"); - } - - @Test - public void testActoolAction() throws Exception { - addTargetWithAssetCatalogs(); - checkActoolActionCorrectness(DEFAULT_IOS_SDK_VERSION); - } - - @Test - public void testPassesFamiliesToActool() throws Exception { - checkPassesFamiliesToActool(RULE_TYPE_PAIR); - } - - @Test - public void testPassesFamiliesToIbtool() throws Exception { - checkPassesFamiliesToIbtool(RULE_TYPE_PAIR); - } - - @Test - public void testReportsErrorsForInvalidFamiliesAttribute() throws Exception { - checkReportsErrorsForInvalidFamiliesAttribute(RULE_TYPE); - } - - @Test - public void testMergeActionsWithAssetCatalog() throws Exception { - // TODO(matvore): add this test to IosTestTest.java. - addTargetWithAssetCatalogs(); - checkMergeActionsWithAssetCatalog(RULE_TYPE_PAIR); - } - - private void addBinAndLibWithRawResources() throws Exception { - addBinAndLibWithResources( - "resources", "resource1.txt", "ja.lproj/resource2.txt", "objc_binary"); - scratch.file("x/BUILD", - "ios_application(", - " name = 'x',", - " binary = '//bin:bin',", - ")"); - } - - private void addBinAndLibWithStrings() throws Exception { - addBinAndLibWithResources( - "strings", "foo.strings", "ja.lproj/bar.strings", "objc_binary"); - scratch.file("x/BUILD", - "ios_application(", - " name = 'x',", - " binary = '//bin:bin',", - ")"); - } - - @Test - public void testCollectsRawResourceFilesTransitively() throws Exception { - addBinAndLibWithRawResources(); - checkCollectsResourceFilesTransitively( - "//x:x", - ImmutableList.of("lib/resource1.txt", "bin/ja.lproj/resource2.txt"), - ImmutableList.of("lib/resource1.txt"), - ImmutableSetMultimap.<String, Multiset<String>>of( - "bin_bin", - ImmutableMultiset.of("bin/ja.lproj/resource2.txt", "lib/resource1.txt"), - "bin_static_lib_bin", - ImmutableMultiset.of("bin/ja.lproj/resource2.txt", "lib/resource1.txt"), - "x_x", - ImmutableMultiset.of("bin/ja.lproj/resource2.txt", "lib/resource1.txt"), - "lib_lib", - ImmutableMultiset.of("lib/resource1.txt"))); - } - - @Test - public void testCollectsStringsFilesTransitively() throws Exception { - addBinAndLibWithStrings(); - checkCollectsResourceFilesTransitively( - "//x:x", - ImmutableList.of("x/lib/foo.strings.binary", "x/bin/ja.lproj/bar.strings.binary"), - ImmutableList.of("x/lib/foo.strings.binary"), - ImmutableSetMultimap.<String, Multiset<String>>of( - "bin_bin", - ImmutableMultiset.of("bin/ja.lproj/bar.strings", "lib/foo.strings"), - "bin_static_lib_bin", - ImmutableMultiset.of("bin/ja.lproj/bar.strings", "lib/foo.strings"), - "x_x", - ImmutableMultiset.of("bin/ja.lproj/bar.strings", "lib/foo.strings"), - "lib_lib", - ImmutableMultiset.of("lib/foo.strings"))); - } - - @Test - public void testResourceFilesMergedInBundle() throws Exception { - addBinAndLibWithRawResources(); - checkBundleablesAreMerged("//x:x", - ImmutableListMultimap.of( - "resource1.txt", "resource1.txt", - "ja.lproj/resource2.txt", "ja.lproj/resource2.txt")); - } - - @Test - public void testResourceFlattenedInBundle() throws Exception { - addBinAndLibWithResources( - "resources", "libres/resource1.txt", "binres/resource2.txt", "objc_binary"); - scratch.file("x/BUILD", - "ios_application(", - " name = 'x',", - " binary = '//bin:bin',", - ")"); - checkBundleablesAreMerged("//x:x", - ImmutableListMultimap.of( - "libres/resource1.txt", "resource1.txt", - "binres/resource2.txt", "resource2.txt")); - } - - @Test - public void testStructuredResourceFilesMergedInBundle() throws Exception { - addBinAndLibWithResources( - "structured_resources", "libres/resource1.txt", "binres/resource2.txt", "objc_binary"); - scratch.file("x/BUILD", - "ios_application(", - " name = 'x',", - " binary = '//bin:bin',", - ")"); - checkBundleablesAreMerged("//x:x", - ImmutableListMultimap.of( - "libres/resource1.txt", "libres/resource1.txt", - "binres/resource2.txt", "binres/resource2.txt")); - } - - @Test - public void testStringsFilesMergedInBundle() throws Exception { - addBinAndLibWithStrings(); - checkBundleablesAreMerged("//x:x", - ImmutableListMultimap.of( - "foo.strings.binary", "foo.strings", - "ja.lproj/bar.strings.binary", "ja.lproj/bar.strings")); - } - - @Test - public void testMergesXcdatamodelZips() throws Exception { - checkMergesXcdatamodelZips(RULE_TYPE_PAIR); - } - - @Test - public void testPlistRequiresDotInName() throws Exception { - checkError("x", "x", - "'//x:Infoplist' does not produce any ios_application infoplist files (expected .plist)", - "objc_binary(", - " name = 'bin',", - " srcs = ['a.m'],", - ")", - "", - "ios_application(", - " name = 'x',", - " infoplist = 'Infoplist',", - " binary = ':bin',", - ")"); - } - - @Test - public void testPopulatesBundling() throws Exception { - scratch.file("x/x-Info.plist"); - scratch.file("x/a.m"); - scratch.file("x/assets.xcassets/1"); - scratch.file("x/BUILD", - "objc_binary(", - " name = 'bin',", - " srcs = ['a.m'],", - " asset_catalogs = ['assets.xcassets/1']", - ")", - "ios_application(", - " name = 'x',", - " binary = ':bin',", - " infoplist = 'x-Info.plist',", - ")"); - - PlMergeProtos.Control control = plMergeControl("//x:x"); - assertThat(control.getSourceFileList()) - .contains(getSourceArtifact("x/x-Info.plist").getExecPathString()); - - Artifact actoolzipOutput = getBinArtifact("x.actool.zip", "//x:x"); - assertThat(getGeneratingAction(actoolzipOutput).getInputs()) - .contains(getSourceArtifact("x/assets.xcassets/1")); - } - - @Test - public void testMergesPartialInfoplists() throws Exception { - checkMergesPartialInfoplists(RULE_TYPE_PAIR); - } - - @Test - public void testNibZipsMergedIntoBundle() throws Exception { - checkNibZipsMergedIntoBundle(RULE_TYPE_PAIR); - } - - @Test - public void testNoEntitlementsDefined() throws Exception { - checkNoEntitlementsDefined(RULE_TYPE); - } - - @Test - public void testEntitlementsDefined() throws Exception { - checkEntitlementsDefined(RULE_TYPE); - } - - @Test - public void testExtraEntitlements() throws Exception { - checkExtraEntitlements(RULE_TYPE); - } - - @Test - public void testDebugEntitlements() throws Exception { - checkDebugEntitlements(RULE_TYPE); - } - - @Test - public void testFastbuildDebugEntitlements() throws Exception { - checkFastbuildDebugEntitlements(RULE_TYPE); - } - - @Test - public void testOptNoDebugEntitlements() throws Exception { - checkOptNoDebugEntitlements(RULE_TYPE); - } - - @Test - public void testExplicitNoDebugEntitlements() throws Exception { - checkExplicitNoDebugEntitlements(RULE_TYPE); - } - - @Test - public void testMultiPlatformBuild_fails() throws Exception { - checkBinaryActionMultiPlatform_fails(RULE_TYPE_PAIR); - } - - @Test - public void testMultiArchitectureResources() throws Exception { - checkMultiCpuResourceInheritance(RULE_TYPE_PAIR); - } - - /** - * Regression test for b/27946171. Verifies that nodistinct_host_configuration functions in - * builds with more than one split transition. (In this case, both ios_application and - * ios_extension split into two child configurations.) - */ - @Test - public void testNoDistinctHostConfiguration() throws Exception { - useConfiguration("--ios_multi_cpus=i386,x86_64", "--nodistinct_host_configuration"); - scratch.file("x/BUILD", - "ios_extension_binary(", - " name = 'ext_bin',", - " srcs = ['ebin.m'],", - ")", - "", - "ios_extension(", - " name = 'ext',", - " binary = ':ext_bin',", - ")", - "", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - ")", - "", - "ios_application(", - " name = 'app',", - " binary = ':bin',", - " extensions = [':ext'],", - ")"); - - getConfiguredTarget("//x:app"); - - // Assert that only the deprecation warnings are emitted, but no other events. - assertContainsEventWithFrequency( - "This rule is deprecated. Please use the new Apple build rules " - + "(https://github.com/bazelbuild/rules_apple) to build Apple targets.", - 4); - } - - @Test - public void testApplicationExtensionSharedDependencyResourceActions() throws Exception { - useConfiguration("--ios_multi_cpus=i386,x86_64"); - scratch.file("x/BUILD", - "objc_library(", - " name = 'res',", - " xibs = ['interface.xib'],", - " storyboards = ['story.storyboard'],", - " datamodels = ['data.xcdatamodel/1'],", - " asset_catalogs = ['assets.xcassets/foo'],", - ")", - "", - "ios_extension_binary(", - " name = 'ext_bin',", - " srcs = ['ebin.m'],", - " deps = [':res'],", - ")", - "", - "ios_extension(", - " name = 'ext',", - " binary = ':ext_bin',", - ")", - "", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " deps = [':res'],", - ")", - "", - "ios_application(", - " name = 'app',", - " binary = ':bin',", - " extensions = [':ext'],", - ")"); - - Action appIpaAction = bundleMergeAction("//x:app"); - - Action extIpaAction = bundleMergeAction("//x:ext"); - - Artifact appNibZip = Iterables.getOnlyElement(inputsEndingWith(appIpaAction, "nib.zip")); - Artifact extNibZip = Iterables.getOnlyElement(inputsEndingWith(extIpaAction, "nib.zip")); - assertThat(appNibZip.getExecPath()).isNotEqualTo(extNibZip.getExecPath()); - - Artifact appStoryboardZip = - Iterables.getOnlyElement(inputsEndingWith(appIpaAction, "story.storyboard.zip")); - Artifact extStoryboardZip = - Iterables.getOnlyElement(inputsEndingWith(extIpaAction, "story.storyboard.zip")); - assertThat(appStoryboardZip.getExecPath()).isNotEqualTo(extStoryboardZip.getExecPath()); - - Artifact appDatamodelZip = Iterables.getOnlyElement(inputsEndingWith(appIpaAction, "data.zip")); - Artifact extDatamodelZip = Iterables.getOnlyElement(inputsEndingWith(extIpaAction, "data.zip")); - assertThat(appDatamodelZip.getExecPath()).isNotEqualTo(extDatamodelZip.getExecPath()); - - Artifact appAssetZip = Iterables.getOnlyElement(inputsEndingWith(appIpaAction, "actool.zip")); - Artifact extAssetZip = Iterables.getOnlyElement(inputsEndingWith(extIpaAction, "actool.zip")); - assertThat(appAssetZip.getExecPath()).isNotEqualTo(extAssetZip.getExecPath()); - } - - @Test - public void testMultiCpuCompiledResources() throws Exception { - checkMultiCpuCompiledResources(RULE_TYPE_PAIR); - } - - @Test - public void testMomczipActions() throws Exception { - checkMomczipActions(RULE_TYPE_PAIR, DEFAULT_IOS_SDK_VERSION); - } - - @Test - public void testConvertStringsActions() throws Exception { - checkConvertStringsAction(RULE_TYPE_PAIR); - } - - @Test - public void testCompileXibActions() throws Exception { - checkCompileXibActions(RULE_TYPE_PAIR, DEFAULT_IOS_SDK_VERSION, "iphone"); - } - - @Test - public void testRegistersStoryboardCompileActions() throws Exception { - checkRegistersStoryboardCompileActions(RULE_TYPE_PAIR, DEFAULT_IOS_SDK_VERSION, "iphone"); - } - - @Test - public void testMultiCpuCompiledResourcesFromGenrule() throws Exception { - checkMultiCpuCompiledResourcesFromGenrule(RULE_TYPE_PAIR); - } - - @Test - public void testMultiCpuGeneratedResourcesFromGenrule() throws Exception { - checkMultiCpuGeneratedResourcesFromGenrule(RULE_TYPE_PAIR); - } - - @Test - public void testTwoStringsOneBundlePath() throws Exception { - //TODO(bazel-team): This error should be on //x:x but shows up on :bin right now until that - // doesn't support bundling anymore. - checkTwoStringsOneBundlePath(RULE_TYPE_PAIR, "bin"); - } - - @Test - public void testTwoResourcesOneBundlePath() throws Exception { - //TODO(bazel-team): This error should be on //x:x but shows up on :bin right now until that - // doesn't support bundling anymore. - checkTwoResourcesOneBundlePath(RULE_TYPE_PAIR, "bin"); - } - - @Test - public void testSameStringsTwice() throws Exception { - //TODO(bazel-team): This error should be on //x:x but shows up on :bin right now until that - // doesn't support bundling anymore. - checkSameStringsTwice(RULE_TYPE_PAIR, "bin"); - } - - @Test - public void testGenruleWithoutJavaCcDeps() throws Exception { - checkGenruleWithoutJavaCcDependency(RULE_TYPE_PAIR); - } - - @Test - public void testCcDependencyWithProtoDependencyMultiArch() throws Exception { - checkCcDependencyWithProtoDependencyMultiArch( - RULE_TYPE_PAIR, ConfigurationDistinguisher.IOS_APPLICATION); - } - - @Test - public void testAppleSdkVersionEnv() throws Exception { - RULE_TYPE_PAIR.scratchTargets(scratch); - - useConfiguration("--ios_multi_cpus=x86_64,i386"); - SpawnAction action = (SpawnAction) getGeneratingAction( - getBinArtifact("x_lipobin", getConfiguredTarget("//x:x"))); - - assertAppleSdkVersionEnv(action); - } - - @Test - public void testNonDefaultAppleSdkVersionEnv() throws Exception { - RULE_TYPE_PAIR.scratchTargets(scratch); - - useConfiguration("--ios_sdk_version=8.1", "--ios_multi_cpus=x86_64,i386"); - SpawnAction action = (SpawnAction) getGeneratingAction( - getBinArtifact("x_lipobin", getConfiguredTarget("//x:x"))); - - assertAppleSdkVersionEnv(action, "8.1"); - } - - @Test - public void testAppleSdkDefaultPlatformEnv() throws Exception { - RULE_TYPE_PAIR.scratchTargets(scratch); - - useConfiguration("--ios_multi_cpus=x86_64,i386"); - SpawnAction action = (SpawnAction) getGeneratingAction( - getBinArtifact("x_lipobin", getConfiguredTarget("//x:x"))); - - assertAppleSdkPlatformEnv(action, "iPhoneSimulator"); - } - - @Test - public void testAppleSdkDevicePlatformEnv() throws Exception { - RULE_TYPE_PAIR.scratchTargets(scratch); - - useConfiguration("--ios_multi_cpus=arm64,armv7"); - SpawnAction action = (SpawnAction) getGeneratingAction( - getBinArtifact("x_lipobin", getConfiguredTarget("//x:x"))); - - assertAppleSdkPlatformEnv(action, "iPhoneOS"); - } - - @Test - public void testXcodeVersionEnv() throws Exception { - RULE_TYPE_PAIR.scratchTargets(scratch); - - useConfiguration("--xcode_version=5.8", "--ios_multi_cpus=x86_64,i386"); - SpawnAction action = (SpawnAction) getGeneratingAction( - getBinArtifact("x_lipobin", getConfiguredTarget("//x:x"))); - - assertXcodeVersionEnv(action, "5.8"); - } - - @Test - public void testLaunchStoryboardIncluded() throws Exception { - checkLaunchStoryboardIncluded(RULE_TYPE_PAIR); - } - - @Test - public void testLaunchStoryboardXibIncluded() throws Exception { - checkLaunchStoryboardXib(RULE_TYPE_PAIR); - } - - @Test - public void testLaunchStoryboardLproj() throws Exception { - checkLaunchStoryboardLproj(RULE_TYPE_PAIR); - } - - @Test - public void testAutomaticPlistEntries() throws Exception { - checkAutomaticPlistEntries(RULE_TYPE); - } - - @Test - public void testBundleMergeInputContainsPlMergeOutput() throws Exception { - checkBundleMergeInputContainsPlMergeOutput(RULE_TYPE); - } - - @Test - public void testMultipleInfoPlists() throws Exception { - checkMultipleInfoPlists(RULE_TYPE); - } - - @Test - public void testInfoplistAndInfoplistsTogether() throws Exception { - checkInfoplistAndInfoplistsTogether(RULE_TYPE); - } - - @Test - public void testLateLoadedObjcFrameworkInFinalBundle() throws Exception { - scratch.file("x/Foo.framework/Foo"); - scratch.file("x/Foo.framework/Info.plist"); - scratch.file("x/Foo.framework/Headers/Foo.h"); - scratch.file("x/Foo.framework/Resources/bar.png"); - scratch.file( - "x/BUILD", - "objc_framework(", - " name = 'foo_framework',", - " framework_imports = glob(['Foo.framework/**']),", - " is_dynamic = 1,", - ")", - "", - "objc_binary(", - " name = 'bin',", - " srcs = [ 'a.m' ],", - " runtime_deps = [ ':foo_framework' ],", - ")", - "", - "ios_application(", - " name = 'x',", - " binary = ':bin',", - ")"); - - BundleMergeProtos.Control mergeControl = bundleMergeControl("//x:x"); - - assertThat(mergeControl.getBundleFileList()) - .containsAllOf( - BundleFile.newBuilder() - .setBundlePath("Frameworks/Foo.framework/Foo") - .setSourceFile(getSourceArtifact("x/Foo.framework/Foo").getExecPathString()) - .setExternalFileAttribute(BundleableFile.EXECUTABLE_EXTERNAL_FILE_ATTRIBUTE) - .build(), - BundleFile.newBuilder() - .setBundlePath("Frameworks/Foo.framework/Info.plist") - .setSourceFile(getSourceArtifact("x/Foo.framework/Info.plist").getExecPathString()) - .setExternalFileAttribute(BundleableFile.EXECUTABLE_EXTERNAL_FILE_ATTRIBUTE) - .build(), - BundleFile.newBuilder() - .setBundlePath("Frameworks/Foo.framework/Resources/bar.png") - .setSourceFile( - getSourceArtifact("x/Foo.framework/Resources/bar.png").getExecPathString()) - .setExternalFileAttribute(BundleableFile.DEFAULT_EXTERNAL_FILE_ATTRIBUTE) - .build()); - - assertThat(mergeControl.getBundleFileList()) - .doesNotContain( - BundleFile.newBuilder() - .setBundlePath("Frameworks/Foo.framework/Headers/Foo.h") - .setSourceFile( - getSourceArtifact("x/Foo.framework/Headers/Foo.h").getExecPathString()) - .setExternalFileAttribute(BundleableFile.DEFAULT_EXTERNAL_FILE_ATTRIBUTE) - .build()); - } - - @Test - public void testLateloadedObjcFrameworkSigned() throws Exception { - useConfiguration("--cpu=ios_arm64"); - - scratch.file("x/Foo.framework/Foo"); - scratch.file("x/Foo.framework/Info.plist"); - scratch.file("x/Foo.framework/Headers/Foo.h"); - scratch.file("x/Foo.framework/Resources/bar.png"); - scratch.file( - "x/BUILD", - "objc_framework(", - " name = 'foo_framework',", - " framework_imports = glob(['Foo.framework/**']),", - " is_dynamic = 1,", - ")", - "", - "objc_binary(", - " name = 'bin',", - " srcs = [ 'a.m' ],", - " runtime_deps = [ ':foo_framework' ],", - ")", - "", - "ios_application(", - " name = 'x',", - " binary = ':bin',", - ")"); - - SpawnAction signingAction = (SpawnAction) ipaGeneratingAction(); - - assertThat(normalizeBashArgs(signingAction.getArguments())) - .containsAllOf("--sign", "${t}/Payload/x.app/Frameworks/*", "--sign", "${t}/Payload/x.app") - .inOrder(); - } - - @Test - public void aspectOnSplitAttributeRegressionTest() throws Exception { - useConfiguration("--ios_multi_cpus=armv7,arm64"); - scratch.file("x/a.m"); - scratch.file("x/x-Info.plist"); - scratch.file( - "x/extension.bzl", - "def _my_aspect_impl(target, ctx):", - " if type(ctx.rule.attr.binary) != 'list':", - " fail('Expected a list for split')", - " if len(ctx.rule.attr.binary) != 2:", - " fail('Expected 2 items in split')", - " return struct()", - "my_aspect = aspect(_my_aspect_impl)", - "def _my_rule_impl(ctx):", - " pass", - "my_rule = rule(_my_rule_impl, attrs = { 'deps' : attr.label_list(aspects = [my_aspect]) })" - ); - scratch.file("x/BUILD", - "load(':extension.bzl', 'my_rule')", - "objc_binary(name = 'bin', srcs = ['a.m'], )", - "ios_application(name = 'x', binary = ':bin',)", - "my_rule(name = 'y', deps = [ ':x' ])" - ); - getConfiguredTarget("//x:y"); - } - - @Test - public void aspectOnSplitAttributeNoSplitRegressionTest() throws Exception { - useConfiguration("--ios_multi_cpus=arm64"); - scratch.file("x/a.m"); - scratch.file("x/x-Info.plist"); - scratch.file( - "x/extension.bzl", - "def _my_aspect_impl(target, ctx):", - " if type(ctx.rule.attr.binary) != 'list':", - " fail('Expected a list for split')", - " if len(ctx.rule.attr.binary) != 1:", - " fail('Expected 1 items in split')", - " return struct()", - "my_aspect = aspect(_my_aspect_impl)", - "def _my_rule_impl(ctx):", - " pass", - "my_rule = rule(_my_rule_impl, attrs = { 'deps' : attr.label_list(aspects = [my_aspect]) })" - ); - scratch.file("x/BUILD", - "load(':extension.bzl', 'my_rule')", - "objc_binary(name = 'bin', srcs = ['a.m'], )", - "ios_application(name = 'x', binary = ':bin',)", - "my_rule(name = 'y', deps = [ ':x' ])" - ); - getConfiguredTarget("//x:y"); - } - - @Test - public void testMergeBundleActionsWithNestedBundle() throws Exception { - checkMergeBundleActionsWithNestedBundle(RULE_TYPE_PAIR, targetConfig); - } - - @Test - public void testIncludesStoryboardOutputZipsAsMergeZips() throws Exception { - checkIncludesStoryboardOutputZipsAsMergeZips(RULE_TYPE_PAIR, targetConfig); - } - - @Test - public void testCcDependency() throws Exception { - checkCcDependency(RULE_TYPE_PAIR, ConfigurationDistinguisher.IOS_APPLICATION); - } - - @Test - public void testCcDependencyMultiArch() throws Exception { - checkCcDependencyMultiArch(RULE_TYPE_PAIR, ConfigurationDistinguisher.IOS_APPLICATION); - } - - @Test - public void testCCDependencyWithProtoDependency() throws Exception { - checkCcDependencyWithProtoDependency( - RULE_TYPE_PAIR, ConfigurationDistinguisher.IOS_APPLICATION); - } - - @Test - public void testCcDependencyAndJ2objcDependency() throws Exception { - checkCcDependencyAndJ2objcDependency( - RULE_TYPE_PAIR, ConfigurationDistinguisher.IOS_APPLICATION); - } - - @Test - public void testApplicationExtension() throws Exception { - // Including minimum OS version to trigger a special code path in extension split transitions - // which have a higher chance of conflicting with application transitions. See flag - // --DO_NOT_USE_configuration_distinguisher for details. - useConfiguration("--ios_multi_cpus=i386,x86_64", "--ios_minimum_os=8.1"); - DottedVersion minOsString = DottedVersion.fromString("8.1"); - scratch.file( - "x/BUILD", - "ios_extension_binary(", - " name = 'ext_bin',", - " srcs = ['ebin.m'],", - ")", - "", - "ios_extension(", - " name = 'ext',", - " binary = ':ext_bin',", - ")", - "", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - ")", - "", - "ios_application(", - " name = 'app',", - " binary = ':bin',", - " extensions = [':ext'],", - ")"); - - SpawnAction appLipoAction = - (SpawnAction) - getGeneratingAction( - getBinArtifact( - "app_lipobin", getConfiguredTarget("//x:app", getTargetConfiguration()))); - - assertThat(Artifact.toExecPaths(appLipoAction.getInputs())) - .containsExactly( - configurationBin("i386", ConfigurationDistinguisher.IOS_APPLICATION, minOsString) - + "x/bin_bin", - configurationBin("x86_64", ConfigurationDistinguisher.IOS_APPLICATION, minOsString) - + "x/bin_bin", - MOCK_XCRUNWRAPPER_PATH); - - SpawnAction extLipoAction = - (SpawnAction) - getGeneratingAction( - getBinArtifact( - "ext_lipobin", getConfiguredTarget("//x:ext", getTargetConfiguration()))); - - assertThat(Artifact.toExecPaths(extLipoAction.getInputs())) - .containsExactly( - configurationBin("i386", ConfigurationDistinguisher.IOS_EXTENSION, minOsString) - + "x/ext_bin_bin", - configurationBin("x86_64", ConfigurationDistinguisher.IOS_EXTENSION, minOsString) - + "x/ext_bin_bin", MOCK_XCRUNWRAPPER_PATH); - } - - @Test - public void testGenruleDependency() throws Exception { - checkGenruleDependency(RULE_TYPE_PAIR); - } - - @Test - public void testGenruleDependencyMultiArch() throws Exception { - checkGenruleDependencyMultiArch(RULE_TYPE_PAIR, ConfigurationDistinguisher.IOS_APPLICATION); - } - - @Test - public void testTargetHasCpuSpecificDsymFiles() throws Exception { - checkTargetHasCpuSpecificDsymFiles(RULE_TYPE); - } - - @Test - public void testTargetHasDsymPlist() throws Exception { - checkTargetHasDsymPlist(RULE_TYPE); - } - - @Test - public void testMultiArchitectureFanOut() throws Exception { - checkBinaryLipoActionMultiCpu(RULE_TYPE_PAIR, ConfigurationDistinguisher.IOS_APPLICATION); - } - - @Test - public void testMultiArchitectureWithConfigurableAttribute() throws Exception { - useConfiguration("--ios_multi_cpus=armv7,arm64", "--cpu=ios_i386"); - scratch.file( - "x/BUILD", - "config_setting(", - " name = 'i386',", - " values = {'cpu': 'ios_i386'},", - ")", - "", - "config_setting(", - " name = 'armv7',", - " values = {'cpu': 'ios_armv7'},", - ")", - "", - "objc_library(", - " name = 'libi386',", - " srcs = ['i386.m'],", - ")", - "", - "objc_library(", - " name = 'libarmv7',", - " srcs = ['armv7.m'],", - ")", - "", - "objc_library(", - " name = 'libdefault',", - " srcs = ['default.m'],", - ")", - "", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " deps = select({", - " ':i386': [':libi386'],", - " ':armv7': [':libarmv7'],", - " '//conditions:default': [':libdefault'],", - " }),", - ")", - "", - "ios_application(", - " name = 'app',", - " binary = ':bin',", - ")"); - - CommandAction appLipoAction = - (CommandAction) - getGeneratingAction( - getBinArtifact( - "app_lipobin", getConfiguredTarget("//x:app", getTargetConfiguration()))); - - assertThat(Artifact.toExecPaths(appLipoAction.getInputs())) - .containsExactly( - configurationBin("armv7", ConfigurationDistinguisher.IOS_APPLICATION) + "x/bin_bin", - configurationBin("arm64", ConfigurationDistinguisher.IOS_APPLICATION) + "x/bin_bin", - MOCK_XCRUNWRAPPER_PATH); - - ImmutableSet.Builder<Artifact> binInputs = ImmutableSet.builder(); - for (Artifact bin : appLipoAction.getInputs()) { - CommandAction binAction = (CommandAction) getGeneratingAction(bin); - if (binAction != null) { - binInputs.addAll(binAction.getInputs()); - } - } - - assertThat(Artifact.toExecPaths(binInputs.build())) - .containsAllOf( - configurationBin("armv7", ConfigurationDistinguisher.IOS_APPLICATION) - + "x/liblibarmv7.a", - configurationBin("arm64", ConfigurationDistinguisher.IOS_APPLICATION) - + "x/liblibdefault.a"); - - assertThat(Artifact.toExecPaths(binInputs.build())) - .doesNotContain( - configurationBin("i386", ConfigurationDistinguisher.IOS_APPLICATION) - + "x/liblibi386.a"); - } -} diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinaryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinaryTest.java deleted file mode 100644 index 44744a7092..0000000000 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinaryTest.java +++ /dev/null @@ -1,252 +0,0 @@ -// Copyright 2017 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import static com.google.common.truth.Truth.assertThat; -import static com.google.devtools.build.lib.rules.objc.BinaryLinkingTargetFactory.REQUIRES_AT_LEAST_ONE_LIBRARY_OR_SOURCE_FILE; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.ASSET_CATALOG; - -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.RunfilesProvider; -import com.google.devtools.build.lib.analysis.config.CompilationMode; -import com.google.devtools.build.lib.packages.util.MockObjcSupport; -import com.google.devtools.build.lib.packages.util.MockProtoSupport; -import com.google.devtools.build.lib.rules.objc.CompilationSupport.ExtraLinkArgs; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Test case for ios_extension_binary. */ -@RunWith(JUnit4.class) -@LegacyTest -public class IosExtensionBinaryTest extends ObjcRuleTestCase { - static final RuleType RULE_TYPE = new OnlyNeedsSourcesRuleType("ios_extension_binary"); - protected static final ExtraLinkArgs EXTRA_LINK_ARGS = - new ExtraLinkArgs("-e", "_NSExtensionMain", "-fapplication-extension"); - - @Before - public final void initializeToolsConfigMock() throws Exception { - MockProtoSupport.setup(mockToolsConfig); - MockObjcSupport.setup(mockToolsConfig); - } - - @Test - public void testCreate_runfiles() throws Exception { - scratch.file("x/a.m"); - RULE_TYPE.scratchTarget(scratch, "srcs", "['a.m']"); - ConfiguredTarget binary = getConfiguredTarget("//x:x"); - RunfilesProvider runfiles = binary.getProvider(RunfilesProvider.class); - assertThat(runfiles.getDefaultRunfiles().getArtifacts()).isEmpty(); - assertThat(Artifact.toRootRelativePaths(runfiles.getDataRunfiles().getArtifacts())) - .containsExactly("x/x_bin"); - } - - @Test - public void testCreate_errorForNoSourceOrDep() throws Exception { - checkError("x", "x", REQUIRES_AT_LEAST_ONE_LIBRARY_OR_SOURCE_FILE, - "ios_extension_binary(name='x')"); - } - - @Test - public void testCompileWithDotMFileInHeaders() throws Exception { - checkCompileWithDotMFileInHeaders(RULE_TYPE); - } - - @Test - public void testObjcProviderExportsAssetCatalogs() throws Exception { - scratch.file("x/BUILD", - "ios_extension_binary(", - " name = 'x',", - " srcs = ['a.m'],", - " asset_catalogs = ['foo.xcassets/bar', 'foo.xcassets/baz'],", - ")"); - ObjcProvider provider = providerForTarget("//x:x"); - assertThat(provider.get(ASSET_CATALOG)) - .containsExactly( - getSourceArtifact("x/foo.xcassets/bar"), - getSourceArtifact("x/foo.xcassets/baz")); - } - - @Test - public void testLinksFrameworksOfSelfAndTransitiveDependencies() throws Exception { - checkLinksFrameworksOfSelfAndTransitiveDependencies(RULE_TYPE); - } - - @Test - public void testLinksWeakFrameworksOfSelfAndTransitiveDependencies() throws Exception { - checkLinksWeakFrameworksOfSelfAndTransitiveDependencies(RULE_TYPE); - } - - @Test - public void testLinksDylibsTransitively() throws Exception { - checkLinksDylibsTransitively(RULE_TYPE); - } - - @Test - public void testPopulatesCompilationArtifacts() throws Exception { - checkPopulatesCompilationArtifacts(RULE_TYPE); - } - - @Test - public void testArchivesPrecompiledObjectFiles() throws Exception { - checkArchivesPrecompiledObjectFiles(RULE_TYPE); - } - - @Test - public void testErrorsWrongFileTypeForSrcsWhenCompiling() throws Exception { - checkErrorsWrongFileTypeForSrcsWhenCompiling(RULE_TYPE); - } - - @Test - public void testObjcCopts() throws Exception { - checkObjcCopts(RULE_TYPE); - } - - @Test - public void testObjcCopts_argumentOrdering() throws Exception { - checkObjcCopts_argumentOrdering(RULE_TYPE); - } - - @Test - public void testAllowVariousNonBlacklistedTypesInHeaders() throws Exception { - checkAllowVariousNonBlacklistedTypesInHeaders(RULE_TYPE); - } - - @Test - public void testWarningForBlacklistedTypesInHeaders() throws Exception { - checkWarningForBlacklistedTypesInHeaders(RULE_TYPE); - } - - @Test - public void testCppSourceCompilesWithCppFlags() throws Exception { - checkCppSourceCompilesWithCppFlags(RULE_TYPE); - } - - @Test - public void testLinkOpts() throws Exception { - checkLinkopts(RULE_TYPE); - } - - @Test - public void testProtoBundlingAndLinking() throws Exception { - checkProtoBundlingAndLinking(RULE_TYPE); - } - - @Test - public void testProtoBundlingWithTargetsWithNoDeps() throws Exception { - checkProtoBundlingWithTargetsWithNoDeps(RULE_TYPE); - } - - @Test - public void testLinkingRuleCanUseCrosstool() throws Exception { - checkLinkingRuleCanUseCrosstool(RULE_TYPE); - } - - @Test - public void testBinaryStrippings() throws Exception { - checkBinaryStripAction(RULE_TYPE); - } - - @Test - public void testCompilationActionsForDebug() throws Exception { - checkClangCoptsForCompilationMode(RULE_TYPE, CompilationMode.DBG, CodeCoverageMode.NONE); - } - - @Test - public void testCompilationActionsForOptimized() throws Exception { - checkClangCoptsForCompilationMode(RULE_TYPE, CompilationMode.OPT, CodeCoverageMode.NONE); - } - - @Test - public void testClangCoptsForDebugModeWithoutGlib() throws Exception { - checkClangCoptsForDebugModeWithoutGlib(RULE_TYPE); - } - - @Test - public void testLinkActionCorrect() throws Exception { - checkLinkActionCorrect(RULE_TYPE, EXTRA_LINK_ARGS); - } - - @Test - public void testFrameworkDepLinkFlags() throws Exception { - checkFrameworkDepLinkFlags(RULE_TYPE, EXTRA_LINK_ARGS); - } - - @Test - public void testCompilationActionsForDebugInGcovCoverage() throws Exception { - checkClangCoptsForCompilationMode(RULE_TYPE, CompilationMode.DBG, - CodeCoverageMode.GCOV); - } - - @Test - public void testCompilationActionsForDebugInLlvmCovCoverage() throws Exception { - checkClangCoptsForCompilationMode(RULE_TYPE, CompilationMode.DBG, - CodeCoverageMode.LLVMCOV); - } - - @Test - public void testCompilationActionsForOptimizedInGcovCoverage() throws Exception { - checkClangCoptsForCompilationMode(RULE_TYPE, CompilationMode.OPT, - CodeCoverageMode.GCOV); - } - - @Test - public void testCompilationActionsForOptimizedInLlvmCovCoverage() throws Exception { - checkClangCoptsForCompilationMode(RULE_TYPE, CompilationMode.OPT, - CodeCoverageMode.LLVMCOV); - } - - @Test - public void testCompileWithTextualHeaders() throws Exception { - checkCompileWithTextualHeaders(RULE_TYPE); - } - - @Test - public void testCompilesWithHdrs() throws Exception { - checkCompilesWithHdrs(RULE_TYPE); - } - - @Test - public void testCompilesSources() throws Exception { - checkCompilesSources(RULE_TYPE); - } - - @Test - public void testLinkActionWithTransitiveCppDependency() throws Exception { - checkLinkActionWithTransitiveCppDependency(RULE_TYPE, EXTRA_LINK_ARGS); - } - - @Test - public void testLinkWithFrameworkImportsIncludesFlagsAndInputArtifacts() throws Exception { - checkLinkWithFrameworkImportsIncludesFlagsAndInputArtifacts(RULE_TYPE); - } - - @Test - public void testForceLoadsAlwayslinkTargets() throws Exception { - checkForceLoadsAlwayslinkTargets(RULE_TYPE, EXTRA_LINK_ARGS); - } - - @Test - public void testReceivesTransitivelyPropagatedDefines() throws Exception { - checkReceivesTransitivelyPropagatedDefines(RULE_TYPE); - } - - @Test - public void testSdkIncludesUsedInCompileAction() throws Exception { - checkSdkIncludesUsedInCompileAction(RULE_TYPE); - } -} diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/IosExtensionTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/IosExtensionTest.java deleted file mode 100644 index 5045ccd1a8..0000000000 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/IosExtensionTest.java +++ /dev/null @@ -1,641 +0,0 @@ -// Copyright 2017 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import static com.google.common.truth.Truth.assertThat; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.ReleaseBundlingRule.APP_ICON_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.ReleaseBundlingRule.LAUNCH_IMAGE_ATTR; - -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableListMultimap; -import com.google.common.collect.ImmutableMultiset; -import com.google.common.collect.ImmutableSetMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Multiset; -import com.google.devtools.build.lib.actions.Action; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.actions.CommandAction; -import com.google.devtools.build.lib.actions.CommandLineExpansionException; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.config.BuildConfiguration; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher; -import com.google.devtools.build.lib.rules.apple.DottedVersion; -import com.google.devtools.build.lib.testutil.Scratch; -import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos; -import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos.BundleFile; -import java.io.IOException; -import java.util.List; -import java.util.Set; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Test case for ios_extension. */ -@RunWith(JUnit4.class) -@LegacyTest -public class IosExtensionTest extends ObjcRuleTestCase { - protected static final RuleType RULE_TYPE = - new RuleType("ios_extension") { - @Override - Iterable<String> requiredAttributes( - Scratch scratch, String packageDir, Set<String> alreadyAdded) throws IOException { - ImmutableList.Builder<String> attributes = new ImmutableList.Builder<>(); - if (!alreadyAdded.contains("binary")) { - scratch.file(packageDir + "/extension_binary/a.m"); - scratch.file( - packageDir + "/extension_binary/BUILD", - "ios_extension_binary(", - " name = 'extension_binary',", - " srcs = ['a.m'],", - ")"); - attributes.add(String.format("binary = '//%s/extension_binary'", packageDir)); - } - return attributes.build(); - } - }; - - protected static final BinaryRuleTypePair RULE_TYPE_PAIR = - new BinaryRuleTypePair( - IosExtensionBinaryTest.RULE_TYPE, - RULE_TYPE, - ReleaseBundlingSupport.EXTENSION_BUNDLE_DIR_FORMAT); - - private ConfiguredTarget addMockExtensionAndLibs(String... extraExtAttributes) - throws Exception { - createLibraryTargetWriter("//lib1:lib1") - .setAndCreateFiles("srcs", "a.m", "b.m", "private.h") - .setAndCreateFiles("hdrs", "hdr.h") - .write(); - createLibraryTargetWriter("//lib2:lib2") - .setAndCreateFiles("srcs", "a.m", "b.m", "private.h") - .setAndCreateFiles("hdrs", "hdr.h") - .write(); - scratch.file("x/a.m"); - scratch.file("x/BUILD", - "ios_extension_binary(", - " name = 'bin',", - " srcs = ['a.m'],", - " deps = ['//lib1:lib1', '//lib2:lib2'],", - ")", - "", - "ios_extension(", - " name = 'x',", - " binary = ':bin',", - Joiner.on(',').join(extraExtAttributes), - ")"); - return getConfiguredTarget("//x:x"); - } - - @Test - public void testSigningAction() throws Exception { - checkDeviceSigningAction(RULE_TYPE); - } - - @Test - public void testSigningWithCertName() throws Exception { - checkSigningWithCertName(RULE_TYPE); - } - - @Test - public void testPostProcessingAction() throws Exception { - checkPostProcessingAction(RULE_TYPE); - } - - @Test - public void testSigningAndPostProcessing() throws Exception { - checkSigningAndPostProcessing(RULE_TYPE); - } - - @Test - public void testSigning_simulatorBuild() throws Exception { - checkSigningSimulatorBuild(RULE_TYPE_PAIR, false); - } - - @Test - public void testSigning_simulatorBuild_multiCpu() throws Exception { - checkSigningSimulatorBuild(RULE_TYPE_PAIR, true); - } - - @Test - public void testProvisioningProfile_deviceBuild() throws Exception { - checkProvisioningProfileDeviceBuild(RULE_TYPE_PAIR, false); - } - - @Test - public void testProvisioningProfile_deviceBuild_multiCpu() throws Exception { - checkProvisioningProfileDeviceBuild(RULE_TYPE_PAIR, true); - } - - @Test - public void testUserSpecifiedProvisioningProfile_deviceBuild() throws Exception { - checkProvisioningProfileUserSpecified(RULE_TYPE_PAIR, false); - } - - @Test - public void testUserSpecifiedProvisioningProfile_deviceBuild_multiCpu() throws Exception { - checkProvisioningProfileUserSpecified(RULE_TYPE_PAIR, true); - } - - @Test - public void testMergeControlAction() throws Exception { - addMockExtensionAndLibs("infoplist = 'Info.plist'"); - Action mergeAction = bundleMergeAction("//x:x"); - Action action = bundleMergeControlAction("//x:x"); - assertThat(action.getInputs()).isEmpty(); - assertThat(Artifact.toRootRelativePaths(action.getOutputs())).containsExactly( - "x/x.ipa-control"); - assertThat(bundleMergeControl("//x:x")) - .isEqualTo( - BundleMergeProtos.Control.newBuilder() - .addBundleFile( - BundleFile.newBuilder() - .setSourceFile(execPathEndingWith(mergeAction.getInputs(), "x_lipobin")) - .setBundlePath("x") - .setExternalFileAttribute(BundleableFile.EXECUTABLE_EXTERNAL_FILE_ATTRIBUTE) - .build()) - .setBundleRoot("PlugIns/x.appex") - .setBundleInfoPlistFile( - getMergedInfoPlist(getConfiguredTarget("//x:x")).getExecPathString()) - .setOutFile(execPathEndingWith(mergeAction.getOutputs(), "x.unprocessed.ipa")) - .setMinimumOsVersion(DEFAULT_IOS_SDK_VERSION.toString()) - .setSdkVersion(DEFAULT_IOS_SDK_VERSION.toString()) - .setPlatform("IOS_SIMULATOR") - .setFallbackBundleIdentifier("example.x") - .build()); - } - - @Test - public void testMergeBundleAction() throws Exception { - checkMergeBundleAction(RULE_TYPE_PAIR); - } - - protected List<BuildConfiguration> getExtensionConfigurations() throws InterruptedException { - return getSplitConfigurations(getTargetConfiguration(), - IosExtension.MINIMUM_OS_AND_SPLIT_ARCH_TRANSITION); - } - - @Test - public void testErrorForLaunchImageGivenWithNoAssetCatalog() throws Exception { - checkAssetCatalogAttributeError(RULE_TYPE, LAUNCH_IMAGE_ATTR); - } - - @Test - public void testErrorForAppIconGivenWithNoAssetCatalog() throws Exception { - checkAssetCatalogAttributeError(RULE_TYPE, APP_ICON_ATTR); - } - - @Test - public void testCollectsAssetCatalogsTransitively() throws Exception { - checkCollectsAssetCatalogsTransitively(RULE_TYPE_PAIR); - } - - @Test - public void testSpecifyAppIconAndLaunchImageUsingXcassetsOfDependency() throws Exception { - checkSpecifyAppIconAndLaunchImageUsingXcassetsOfDependency( - RULE_TYPE_PAIR, DEFAULT_IOS_SDK_VERSION); - } - - private void addTargetWithAssetCatalogs() throws IOException { - scratch.file("x/foo.xcassets/foo"); - scratch.file("x/foo.xcassets/bar"); - scratch.file("x/a.m"); - scratch.file("x/BUILD", - "ios_extension_binary(", - " name = 'bin',", - " asset_catalogs = ['foo.xcassets/foo', 'bar.xcassets/bar'],", - " srcs = ['a.m'],", - ")", - "", - "ios_extension(", - " name = 'x',", - " binary = ':bin',", - ")"); - } - - @Test - public void testActoolActionCorrectness() throws Exception { - addTargetWithAssetCatalogs(); - checkActoolActionCorrectness(DEFAULT_IOS_SDK_VERSION); - } - - @Test - public void testPassesFamiliesToActool() throws Exception { - checkPassesFamiliesToActool(RULE_TYPE_PAIR); - } - - @Test - public void testPassesFamiliesToIbtool() throws Exception { - checkPassesFamiliesToIbtool(RULE_TYPE_PAIR); - } - - @Test - public void testReportsErrorsForInvalidFamiliesAttribute() throws Exception { - checkReportsErrorsForInvalidFamiliesAttribute(RULE_TYPE); - } - - @Test - public void testMergeActionsWithAssetCatalog() throws Exception { - addTargetWithAssetCatalogs(); - checkMergeActionsWithAssetCatalog(RULE_TYPE_PAIR); - } - - private void addBinAndLibWithRawResources() throws Exception { - addBinAndLibWithResources( - "resources", "resource1.txt", "ja.lproj/resource2.txt", "ios_extension_binary"); - scratch.file("x/BUILD", - "ios_extension(", - " name = 'x',", - " binary = '//bin:bin',", - ")"); - } - - private void addBinAndLibWithStrings() throws Exception { - addBinAndLibWithResources( - "strings", "foo.strings", "ja.lproj/bar.strings", "ios_extension_binary"); - scratch.file("x/BUILD", - "ios_extension(", - " name = 'x',", - " binary = '//bin:bin',", - ")"); - } - - @Test - public void testCollectsRawResourceFilesTransitively() throws Exception { - addBinAndLibWithRawResources(); - checkCollectsResourceFilesTransitively( - "//x:x", - ImmutableList.of("lib/resource1.txt", "bin/ja.lproj/resource2.txt"), - ImmutableList.of("lib/resource1.txt"), - ImmutableSetMultimap.<String, Multiset<String>>of( - "bin_bin", ImmutableMultiset.of("bin/ja.lproj/resource2.txt", "lib/resource1.txt"), - "x_x", ImmutableMultiset.of("bin/ja.lproj/resource2.txt", "lib/resource1.txt"), - "lib_lib", ImmutableMultiset.of("lib/resource1.txt"))); - } - - @Test - public void testCollectsStringsFilesTransitively() throws Exception { - addBinAndLibWithStrings(); - checkCollectsResourceFilesTransitively( - "//x:x", - ImmutableList.of("x/lib/foo.strings.binary", "x/bin/ja.lproj/bar.strings.binary"), - ImmutableList.of("lib/foo.strings.binary"), - ImmutableSetMultimap.<String, Multiset<String>>of( - "bin_bin", ImmutableMultiset.of("bin/ja.lproj/bar.strings", "lib/foo.strings"), - "x_x", ImmutableMultiset.of("bin/ja.lproj/bar.strings", "lib/foo.strings"), - "lib_lib", ImmutableMultiset.of("lib/foo.strings"))); - } - - @Test - public void testResourceFilesMergedInBundle() throws Exception { - addBinAndLibWithRawResources(); - checkBundleablesAreMerged("//x:x", - ImmutableListMultimap.of( - "resource1.txt", "resource1.txt", - "ja.lproj/resource2.txt", "ja.lproj/resource2.txt")); - } - - @Test - public void testStringsFilesMergedInBundle() throws Exception { - addBinAndLibWithStrings(); - checkBundleablesAreMerged("//x:x", - ImmutableListMultimap.of( - "foo.strings.binary", "foo.strings", - "ja.lproj/bar.strings.binary", "ja.lproj/bar.strings")); - } - - @Test - public void testMergesXcdatamodelZips() throws Exception { - checkMergesXcdatamodelZips(RULE_TYPE_PAIR); - } - - @Test - public void testPlistRequiresDotInName() throws Exception { - checkError("x", "x", - "'//x:Infoplist' does not produce any ios_extension infoplist files (expected .plist)", - "ios_extension_binary(", - " name = 'bin',", - " srcs = ['a.m'],", - ")", - "", - "ios_extension(", - " name = 'x',", - " infoplist = 'Infoplist',", - " binary = ':bin',", - ")"); - } - - @Test - public void testMergesPartialInfoplists() throws Exception { - checkMergesPartialInfoplists(RULE_TYPE_PAIR); - } - - @Test - public void testNibZipsMergedIntoBundle() throws Exception { - checkNibZipsMergedIntoBundle(RULE_TYPE_PAIR); - } - - @Test - public void testNoEntitlementsDefined() throws Exception { - checkNoEntitlementsDefined(RULE_TYPE); - } - - @Test - public void testEntitlementsDefined() throws Exception { - checkEntitlementsDefined(RULE_TYPE); - } - - @Test - public void testExtraEntitlements() throws Exception { - checkExtraEntitlements(RULE_TYPE); - } - - @Test - public void testDebugEntitlements() throws Exception { - checkDebugEntitlements(RULE_TYPE); - } - - @Test - public void testFastbuildDebugEntitlements() throws Exception { - checkFastbuildDebugEntitlements(RULE_TYPE); - } - - @Test - public void testOptNoDebugEntitlements() throws Exception { - checkOptNoDebugEntitlements(RULE_TYPE); - } - - @Test - public void testExplicitNoDebugEntitlements() throws Exception { - checkExplicitNoDebugEntitlements(RULE_TYPE); - } - - @Test - public void testPassesFallbackBundleIdToBundleMerging() throws Exception { - checkBundleIdPassedAsFallbackId(RULE_TYPE); - } - - @Test - public void testPassesPrimaryBundleIdToBundleMerging() throws Exception { - checkBundleIdPassedAsPrimaryId(RULE_TYPE); - } - - @Test - public void testMultiPlatformBuild_fails() throws Exception { - checkBinaryActionMultiPlatform_fails(RULE_TYPE_PAIR); - } - - @Test - public void testMultiArchitectureResources() throws Exception { - checkMultiCpuResourceInheritance(RULE_TYPE_PAIR); - } - - @Test - public void testMultiCpuCompiledResources() throws Exception { - checkMultiCpuCompiledResources(RULE_TYPE_PAIR); - } - - @Test - public void testMomczipActions() throws Exception { - checkMomczipActions(RULE_TYPE_PAIR, DEFAULT_IOS_SDK_VERSION); - } - - @Test - public void testConvertStringsActions() throws Exception { - checkConvertStringsAction(RULE_TYPE_PAIR); - } - - @Test - public void testCompileXibActions() throws Exception { - checkCompileXibActions(RULE_TYPE_PAIR, DEFAULT_IOS_SDK_VERSION, "iphone"); - } - - @Test - public void testRegistersStoryboardCompileActions() throws Exception { - checkRegistersStoryboardCompileActions( - RULE_TYPE_PAIR, DEFAULT_IOS_SDK_VERSION, "iphone"); - } - - @Test - public void testMultiCpuCompiledResourcesFromGenrule() throws Exception { - checkMultiCpuCompiledResourcesFromGenrule(RULE_TYPE_PAIR); - } - - @Test - public void testMultiCpuGeneratedResourcesFromGenrule() throws Exception { - checkMultiCpuGeneratedResourcesFromGenrule(RULE_TYPE_PAIR); - } - - @Test - public void testTwoStringsOneBundlePath() throws Exception { - checkTwoStringsOneBundlePath(RULE_TYPE_PAIR, "x"); - } - - @Test - public void testTwoResourcesOneBundlePath() throws Exception { - checkTwoResourcesOneBundlePath(RULE_TYPE_PAIR, "x"); - } - - @Test - public void testSameStringsTwice() throws Exception { - checkSameStringsTwice(RULE_TYPE_PAIR, "x"); - } - - @Test - public void testExtensionReplacesMinimumOsInBundleMerge() throws Exception { - useConfiguration("--ios_minimum_os=7.1"); - addMockExtensionAndLibs("infoplist = 'Info.plist'"); - - assertThat(bundleMergeControl("//x:x").getMinimumOsVersion()) - .isEqualTo(IosExtension.EXTENSION_MINIMUM_OS_VERSION.toString()); - } - - @Test - public void testExtensionReplacesMinimumOsVersionInBundleMergeAtMost80() throws Exception { - useConfiguration("--ios_minimum_os=8.1"); - addMockExtensionAndLibs("infoplist = 'Info.plist'"); - - assertThat(bundleMergeControl("//x:x").getMinimumOsVersion()) - .isEqualTo("8.1"); - } - - @Test - public void testCheckPrimaryBundleIdInMergedPlist() throws Exception { - checkPrimaryBundleIdInMergedPlist(RULE_TYPE_PAIR); - } - - @Test - public void testCheckFallbackBundleIdInMergedPlist() throws Exception { - checkFallbackBundleIdInMergedPlist(RULE_TYPE_PAIR); - } - - protected void checkExtensionReplacesMinimumOsInCompilation() throws Exception { - addMockExtensionAndLibs("infoplist = 'Info.plist'"); - - Action lipoAction = lipoBinAction("//x:x"); - - for (Artifact bin : lipoAction.getInputs()) { - CommandAction action = (CommandAction) getGeneratingAction(bin); - if (action == null) { - continue; - } - assertThat(generatingArgumentsToString(action)) - .contains("-mios-simulator-version-min=" + IosExtension.EXTENSION_MINIMUM_OS_VERSION); - assertThat(generatingArgumentsToString(action)) - .doesNotContain("-mios-simulator-version-min=7.1"); - } - } - - private String generatingArgumentsToString(CommandAction generatingAction) - throws CommandLineExpansionException { - return Joiner.on(' ').join(generatingAction.getArguments()); - } - - protected void checkExtensionDoesNotReplaceMinimumOsInCompilation() throws Exception { - addMockExtensionAndLibs("infoplist = 'Info.plist'"); - - Action lipoAction = lipoBinAction("//x:x"); - - for (Artifact bin : lipoAction.getInputs()) { - CommandAction action = (CommandAction) getGeneratingAction(bin); - if (action == null) { - continue; - } - assertThat(generatingArgumentsToString(action)).contains("-mios-simulator-version-min=8.1"); - assertThat(generatingArgumentsToString(action)) - .doesNotContain("-mios-simulator-version-min=" + DEFAULT_IOS_SDK_VERSION); - } - } - - @Test - public void testExtensionReplacesMinimumOsVersionInMomcZipAtMost80() throws Exception { - useConfiguration("--ios_minimum_os=8.1"); - checkMomczipActions(RULE_TYPE_PAIR, DottedVersion.fromString("8.1")); - } - - @Test - public void testGenruleWithoutJavaCcDeps() throws Exception { - checkGenruleWithoutJavaCcDependency(RULE_TYPE_PAIR); - } - - @Test - public void testCcDependencyWithProtoDependencyMultiArch() throws Exception { - checkCcDependencyWithProtoDependencyMultiArch( - RULE_TYPE_PAIR, ConfigurationDistinguisher.IOS_EXTENSION); - } - - @Test - public void testLaunchStoryboardIncluded() throws Exception { - checkLaunchStoryboardIncluded(RULE_TYPE_PAIR); - } - - @Test - public void testLaunchStoryboardXibIncluded() throws Exception { - checkLaunchStoryboardXib(RULE_TYPE_PAIR); - } - - @Test - public void testLaunchStoryboardLproj() throws Exception { - checkLaunchStoryboardLproj(RULE_TYPE_PAIR); - } - - @Test - public void testAutomaticPlistEntries() throws Exception { - checkAutomaticPlistEntries(RULE_TYPE); - } - - @Test - public void testBundleMergeInputContainsPlMergeOutput() throws Exception { - checkBundleMergeInputContainsPlMergeOutput(RULE_TYPE); - } - - @Test - public void testMergeBundleActionsWithNestedBundle() throws Exception { - BuildConfiguration extensionConfiguration = - Iterables.getOnlyElement(getExtensionConfigurations()); - checkMergeBundleActionsWithNestedBundle(RULE_TYPE_PAIR, extensionConfiguration); - } - - @Test - public void testIncludesStoryboardOutputZipsAsMergeZips() throws Exception { - BuildConfiguration extensionConfiguration = - Iterables.getOnlyElement(getExtensionConfigurations()); - checkIncludesStoryboardOutputZipsAsMergeZips(RULE_TYPE_PAIR, extensionConfiguration); - } - - @Test - public void testCcDependency() throws Exception { - checkCcDependency(RULE_TYPE_PAIR, ConfigurationDistinguisher.IOS_EXTENSION); - } - - @Test - public void testCcDependencyMultiArch() throws Exception { - checkCcDependencyMultiArch(RULE_TYPE_PAIR, ConfigurationDistinguisher.IOS_EXTENSION); - } - - @Test - public void testCcDependencyWithProtoDependency() throws Exception { - checkCcDependencyWithProtoDependency(RULE_TYPE_PAIR, ConfigurationDistinguisher.IOS_EXTENSION); - } - - @Test - public void testCcDependencyAndJ2objcDependency() throws Exception { - checkCcDependencyAndJ2objcDependency(RULE_TYPE_PAIR, ConfigurationDistinguisher.IOS_EXTENSION); - } - - @Test - public void testMultiArchitectureFanOut() throws Exception { - checkBinaryLipoActionMultiCpu(RULE_TYPE_PAIR, ConfigurationDistinguisher.IOS_EXTENSION); - } - - @Test - public void testTargetHasCpuSpecificDsymFiles() throws Exception { - checkTargetHasCpuSpecificDsymFiles(RULE_TYPE); - } - - @Test - public void testTargetHasDsymPlist() throws Exception { - checkTargetHasDsymPlist(RULE_TYPE); - } - - @Test - public void testGenruleDependencyMultiArch() throws Exception { - checkGenruleDependencyMultiArch(RULE_TYPE_PAIR, ConfigurationDistinguisher.IOS_EXTENSION); - } - - @Test - public void testExtensionReplacesMinimumOsInCompilation() throws Exception { - useConfiguration("--ios_minimum_os=7.1"); - checkExtensionReplacesMinimumOsInCompilation(); - } - - @Test - public void testExtensionReplacesMinimumOsInCompilationAtMost80() throws Exception { - useConfiguration("--ios_minimum_os=8.1"); - checkExtensionDoesNotReplaceMinimumOsInCompilation(); - } - - @Test - public void testExtensionReplacesMinimumOsInCompilationMultiArch() throws Exception { - useConfiguration("--ios_minimum_os=7.1", "--ios_multi_cpus=i386,x86_64"); - checkExtensionReplacesMinimumOsInCompilation(); - } - - @Test - public void testExtensionReplacesMinimumOsInCompilationAtMost80MultiArch() throws Exception { - useConfiguration("--ios_minimum_os=8.1", "--ios_multi_cpus=i386,x86_64"); - checkExtensionDoesNotReplaceMinimumOsInCompilation(); - } -} diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/IosTestTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/IosTestTest.java index f789de4ef1..05130bd7f6 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/IosTestTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/IosTestTest.java @@ -20,7 +20,6 @@ import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.actions.Action; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.CommandAction; import com.google.devtools.build.lib.analysis.ConfiguredTarget; @@ -34,11 +33,8 @@ import com.google.devtools.build.lib.analysis.test.TestProvider; import com.google.devtools.build.lib.analysis.test.TestRunnerAction; import com.google.devtools.build.lib.packages.util.MockObjcSupport; import com.google.devtools.build.lib.packages.util.MockProtoSupport; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher; -import com.google.devtools.build.lib.rules.apple.AppleToolchain; import com.google.devtools.build.lib.rules.apple.XcodeVersionProperties; import com.google.devtools.build.lib.rules.objc.ObjcCommandLineOptions.ObjcCrosstoolMode; -import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.xcode.plmerge.proto.PlMergeProtos; import java.util.List; import java.util.Map; @@ -172,7 +168,7 @@ public class IosTestTest extends ObjcRuleTestCase { "lib1/_objs/lib1/lib1/b.gcno", "lib2/_objs/lib2/lib2/a.gcno", "lib2/_objs/lib2/lib2/b.gcno", - "tools/objc/_objs/xctest_appbin/tools/objc/objc_dummy.gcno"); + "tools/objc/_objs/dummy_lib/tools/objc/objc_dummy.gcno"); } @Test @@ -205,26 +201,14 @@ public class IosTestTest extends ObjcRuleTestCase { @Test public void testXcTestAppIpaIsInFilesToBuild() throws Exception { scratch.file("x/BUILD", - "ios_application(", - " name = 'xctest_app',", - " binary = ':xctest_app_bin',", - " infoplist = 'Info.plist',", - ")", - "", - "objc_binary(", - " name = 'xctest_app_bin',", - " srcs = ['a.m'],", - ")", - "", "ios_test(", " name = 'x',", " xctest = 1,", - " xctest_app = ':xctest_app',", " srcs = ['test.m'],", ")"); ConfiguredTarget target = getConfiguredTarget("//x:x"); Iterable<Artifact> filesToBuild = target.getProvider(FileProvider.class).getFilesToBuild(); - assertThat(filesToBuild).contains(getBinArtifact("xctest_app.ipa", target)); + assertThat(Artifact.toRootRelativePaths(filesToBuild)).contains("tools/objc/xctest_app.ipa"); } @Test @@ -241,10 +225,10 @@ public class IosTestTest extends ObjcRuleTestCase { ImmutableList<String> expectedRunfiles = ImmutableList.of( "test/XcTest.ipa", - "test/testApp.ipa", "test/XcTest_test_script", "tools/objc/StdRedirect.dylib", - "tools/objc/testrunner"); + "tools/objc/testrunner", + "tools/objc/xctest_app.ipa"); RunfilesProvider runfiles = target.getProvider(RunfilesProvider.class); assertThat(Artifact.toRootRelativePaths(runfiles.getDefaultRunfiles().getArtifacts())) .containsExactlyElementsIn(expectedRunfiles); @@ -261,12 +245,13 @@ public class IosTestTest extends ObjcRuleTestCase { InstrumentedFilesProvider instrumentedFilesProvider = target.getProvider(InstrumentedFilesProvider.class); assertThat(Artifact.toRootRelativePaths(instrumentedFilesProvider.getInstrumentedFiles())) - .containsExactly("test/src.m", "test/test-src.m"); + .containsExactly("tools/objc/objc_dummy.mm", "test/test-src.m"); assertThat( Artifact.toRootRelativePaths( instrumentedFilesProvider.getInstrumentationMetadataFiles())) .containsExactly( - "test/_objs/XcTest/test/test-src.gcno", "test/_objs/testAppBin/test/src.gcno"); + "test/_objs/XcTest/test/test-src.gcno", + "tools/objc/_objs/dummy_lib/tools/objc/objc_dummy.gcno"); } @Test @@ -281,7 +266,7 @@ public class IosTestTest extends ObjcRuleTestCase { // Missing "test/test-src.m" since the target including it has been excluded. assertThat(Artifact.toRootRelativePaths(instrumentedFilesProvider.getInstrumentedFiles())) - .containsExactly("test/src.m"); + .containsExactly("tools/objc/objc_dummy.mm"); } @Test @@ -325,41 +310,24 @@ public class IosTestTest extends ObjcRuleTestCase { } protected void setUpXCTestClient() throws Exception { - scratch.file("/test/XcTest-Info.plist"); - scratch.file("/test/App-Info.plist"); scratch.file("/test/src.m"); scratch.file("/test/test-src.m"); scratch.file("test/BUILD", - "objc_binary(", - " name = 'testAppBin',", - " srcs = ['src.m'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':testAppBin',", - ")", "ios_test(", " name = 'XcTest',", " srcs = ['test-src.m'],", " xctest = True,", - " xctest_app = ':testApp',", ")"); } @Test public void testCreate_recognizesDylibsAttribute() throws Exception { - createBinaryTargetWriter("//bin:bin").setAndCreateFiles("srcs", "a.m").write(); scratch.file("test/BUILD", - "ios_application(", - " name = 'testApp',", - " binary = '//bin:bin',", - ")", "ios_test(", " name = 'test',", " srcs = ['test-src.m'],", " xctest = 1,", - " xctest_app = ':testApp',", " sdk_dylibs = ['libdy'],", ")"); CommandAction action = linkAction("//test:test"); @@ -433,15 +401,10 @@ public class IosTestTest extends ObjcRuleTestCase { public void testHasDefaultInfoplistForXcTest() throws Exception { createBinaryTargetWriter("//bin:bin").setAndCreateFiles("srcs", "a.m").write(); scratch.file("x/BUILD", - "ios_application(", - " name = 'testApp',", - " binary = '//bin:bin',", - ")", "ios_test(", " name = 'x',", " srcs = ['x-src.m'],", " xctest = 1,", - " xctest_app = ':testApp',", ")"); PlMergeProtos.Control control = plMergeControl("//x:x"); assertThat(control.getSourceFileList()) @@ -472,14 +435,9 @@ public class IosTestTest extends ObjcRuleTestCase { .write(); checkError("x", "x", IosTest.REQUIRES_SOURCE_ERROR, - "ios_application(", - " name = 'testApp',", - " binary = '//bin:bin',", - ")", "ios_test(", " name = 'x',", " xctest = 1,", - " xctest_app = ':testApp',", " deps = ['//lib:lib'],", ")"); } @@ -488,15 +446,10 @@ public class IosTestTest extends ObjcRuleTestCase { throws Exception { createBinaryTargetWriter("//bin:bin").setAndCreateFiles("srcs", "a.m").write(); scratch.file("x/BUILD", - "ios_application(", - " name = 'testApp',", - " binary = '//bin:bin',", - ")", "ios_test(", " name = 'x',", " srcs = ['a.m'],", " xctest = 1,", - " xctest_app = ':testApp',", Joiner.on(",").join(extraAttrs), ")"); TemplateExpansionAction action = @@ -544,105 +497,6 @@ public class IosTestTest extends ObjcRuleTestCase { } @Test - public void testGetsDefinesFromTestRig() throws Exception { - scratch.file("x/BUILD", - "objc_library(", - " name = 'lib',", - " srcs = ['lib.m'],", - " defines = ['LIB_DEFINE=1'],", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " defines = ['BIN_DEFINE=1'],", - " deps = [':lib'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "ios_test(", - " name = 'test',", - " srcs = ['test.m'],", - " defines = ['TEST_DEFINE=1'],", - " xctest = 1,", - " xctest_app = ':testApp',", - ")"); - assertContainsSublist(compileAction("//x:test", "test.o").getArguments(), - ImmutableList.of("-DLIB_DEFINE=1", "-DBIN_DEFINE=1", "-DTEST_DEFINE=1")); - } - - @Test - public void testGetsSdkDylibsFromTestRig() throws Exception { - scratch.file("x/BUILD", - "objc_library(", - " name = 'lib',", - " srcs = ['lib.m'],", - " sdk_dylibs = ['lib_dylib'],", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " sdk_dylibs = ['bin_dylib'],", - " deps = [':lib'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "ios_test(", - " name = 'test',", - " srcs = ['test.m'],", - " sdk_dylibs = ['test_dylib'],", - " xctest = 1,", - " xctest_app = ':testApp',", - ")"); - - String linkArgs = Joiner.on(' ').join(linkAction("//x:test").getArguments()); - assertThat(linkArgs).contains("-l_dylib"); - assertThat(linkArgs).contains("-lbin_dylib"); - assertThat(linkArgs).contains("-ltest_dylib"); - } - - @Test - public void testGetsSdkFrameworksFromTestRig() throws Exception { - scratch.file("x/BUILD", - "objc_library(", - " name = 'lib',", - " srcs = ['lib.m'],", - " sdk_frameworks = ['lib_fx'],", - " weak_sdk_frameworks = ['lib_wfx'],", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " sdk_frameworks = ['bin_fx'],", - " weak_sdk_frameworks = ['bin_wfx'],", - " deps = [':lib'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "ios_test(", - " name = 'test',", - " srcs = ['test.m'],", - " sdk_frameworks = ['test_fx'],", - " weak_sdk_frameworks = ['test_wfx'],", - " xctest = 1,", - " xctest_app = ':testApp',", - ")"); - - String linkArgs = Joiner.on(' ').join(linkAction("//x:test").getArguments()); - assertThat(linkArgs).contains("-framework lib_fx"); - assertThat(linkArgs).contains("-weak_framework lib_wfx"); - assertThat(linkArgs).contains("-framework bin_fx"); - assertThat(linkArgs).contains("-weak_framework bin_wfx"); - assertThat(linkArgs).contains("-framework test_fx"); - assertThat(linkArgs).contains("-weak_framework test_wfx"); - } - - @Test public void testLinkIncludeOrder_staticLibsFirst() throws Exception { checkLinkIncludeOrderStaticLibsFirst(RULE_TYPE); } @@ -884,7 +738,6 @@ public class IosTestTest extends ObjcRuleTestCase { " name = 'some_test_with_device',", " srcs = ['SomeOtherTest.m'],", " xctest = 1,", - " xctest_app = ':testApp',", " target_device = ':device',", ")", "ios_device(", @@ -892,13 +745,6 @@ public class IosTestTest extends ObjcRuleTestCase { " ios_version = '1.2',", " type = 'iMarmoset',", " locale = 'en-gb'", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "objc_binary(name = 'bin',", - " srcs = ['app.m'],", ")"); scratch.file("test/SomeOtherTest.m"); @@ -906,26 +752,23 @@ public class IosTestTest extends ObjcRuleTestCase { TemplateExpansionAction action = getTestScriptGenerationAction(getConfiguredTarget("//test:some_test_with_device")); - assertThat(action.getSubstitutions()).containsExactly( - Substitution.of("%(memleaks)s", "false"), - - Substitution.of("%(test_app_ipa)s", "test/some_test_with_device.ipa"), - Substitution.of("%(test_app_name)s", "some_test_with_device"), - Substitution.of("%(test_bundle_path)s", "test/some_test_with_device.ipa"), - - Substitution.of("%(xctest_app_ipa)s", "test/testApp.ipa"), - Substitution.of("%(xctest_app_name)s", "testApp"), - Substitution.of("%(test_host_path)s", "test/testApp.ipa"), - - Substitution.of("%(plugin_jars)s", ""), - Substitution.of("%(device_type)s", "iMarmoset"), - Substitution.of("%(locale)s", "en-gb"), - Substitution.of("%(simulator_sdk)s", "1.2"), - Substitution.of("%(testrunner_binary)s", "tools/objc/testrunner"), - Substitution.of("%(std_redirect_dylib_path)s", "tools/objc/StdRedirect.dylib"), - Substitution.of("%(test_env)s", ""), - Substitution.of("%(test_type)s", "XCTEST") - ); + assertThat(action.getSubstitutions()) + .containsExactly( + Substitution.of("%(memleaks)s", "false"), + Substitution.of("%(test_app_ipa)s", "test/some_test_with_device.ipa"), + Substitution.of("%(test_app_name)s", "some_test_with_device"), + Substitution.of("%(test_bundle_path)s", "test/some_test_with_device.ipa"), + Substitution.of("%(xctest_app_ipa)s", "tools/objc/xctest_app.ipa"), + Substitution.of("%(xctest_app_name)s", "xctest_app"), + Substitution.of("%(test_host_path)s", "tools/objc/xctest_app.ipa"), + Substitution.of("%(plugin_jars)s", ""), + Substitution.of("%(device_type)s", "iMarmoset"), + Substitution.of("%(locale)s", "en-gb"), + Substitution.of("%(simulator_sdk)s", "1.2"), + Substitution.of("%(testrunner_binary)s", "tools/objc/testrunner"), + Substitution.of("%(std_redirect_dylib_path)s", "tools/objc/StdRedirect.dylib"), + Substitution.of("%(test_env)s", ""), + Substitution.of("%(test_type)s", "XCTEST")); } @Test @@ -935,14 +778,12 @@ public class IosTestTest extends ObjcRuleTestCase { " name = 'one_plugin',", " srcs = ['SomeTest.m'],", " xctest = 1,", - " xctest_app = ':testApp',", " plugins = [':a_plugin_deploy.jar'],", ")", "ios_test(", " name = 'two_plugins',", " srcs = ['SomeOtherTest.m'],", " xctest = 1,", - " xctest_app = ':testApp',", " plugins = [':a_plugin_deploy.jar', ':b_plugin_deploy.jar'],", ")", "java_binary(", @@ -954,13 +795,6 @@ public class IosTestTest extends ObjcRuleTestCase { " name = 'b_plugin',", " srcs = ['B.java'],", " main_class = 'B',", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "objc_binary(name = 'bin',", - " srcs = ['app.m'],", ")"); scratch.file("test/SomeTest.m"); @@ -1064,83 +898,11 @@ public class IosTestTest extends ObjcRuleTestCase { } @Test - public void testProtobufPropagatedHeaderSearchPaths() throws Exception { - scratch.file( - "test/BUILD", - "ios_test(", - " name = 'protos_test',", - " srcs = ['SomeTest.m'],", - " xctest = 1,", - " xctest_app = ':protos_app',", - ")", - "ios_application(", - " name = 'protos_app',", - " binary = ':protos_bin',", - ")", - "objc_binary(", - " name = 'protos_bin',", - " srcs = ['app.m'],", - " deps = [':protos_objc'],", - ")", - "objc_proto_library(", - " name = 'protos_objc',", - " deps = [':protos_lib'],", - " portable_proto_filters = ['filter.pbascii'],", - ")", - "proto_library(", - " name = 'protos_lib',", - " srcs = ['a.proto'],", - ")"); - - ObjcProvider appProvider = - getConfiguredTarget("//test:protos_app") - .get(XcTestAppProvider.SKYLARK_CONSTRUCTOR) - .getObjcProvider(); - ConfiguredTarget binTarget = getConfiguredTarget("//test:protos_bin"); - Artifact protoHeader = - getBinArtifact("_generated_protos/protos_bin/test/A.pbobjc.h", binTarget); - - assertThat(PathFragment.safePathStrings(appProvider.get(ObjcProvider.INCLUDE))) - .containsAllOf( - "objcproto/include", - protoHeader.getExecPath().getParentDirectory().getParentDirectory().toString()); - } - - @Test public void testCcDependency() throws Exception { checkCcDependency(RULE_TYPE, "xctest", "0"); } @Test - public void testPassesTestRigAppAsBundleLoaderFlagToLinker() throws Exception { - useConfiguration("--cpu=ios_x86_64", - "--crosstool_top=" + MockObjcSupport.DEFAULT_OSX_CROSSTOOL, - "--experimental_disable_go"); - scratch.file("x/BUILD", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "ios_test(", - " name = 'test',", - " srcs = ['test.m'],", - " xctest = 1,", - " xctest_app = ':testApp',", - ")"); - CommandAction testLinkAction = linkAction("//x:test"); - Action appLipoAction = lipoBinAction("//x:testApp"); - Artifact rigBinary = Iterables.getOnlyElement(appLipoAction.getOutputs()); - - String linkArgs = Joiner.on(' ').join(testLinkAction.getArguments()); - assertThat(linkArgs).contains("-bundle_loader " + rigBinary.getExecPath()); - assertThat(testLinkAction.getInputs()).contains(rigBinary); - } - - @Test public void testCompilationActionsForDebugInGcovCoverage() throws Exception { checkClangCoptsForCompilationMode(RULE_TYPE, CompilationMode.DBG, CodeCoverageMode.GCOV); @@ -1165,46 +927,6 @@ public class IosTestTest extends ObjcRuleTestCase { } @Test - public void testMultiArchUserHeaderSearchPathsUsed() throws Exception { - // Usually, an ios_test would depend on apple_binary through a skylark_ios_application in its - // 'binary' attribute. Since we don't have skylark_ios_application here, we use the 'deps' - // attribute instead. - scratch.file("x/BUILD", - "genrule(", - " name = 'gen_hdrs',", - " outs = ['generated.h'],", - " cmd = 'echo hello > \\$@',", - ")", - "apple_binary(", - " name = 'apple_bin',", - " srcs = ['apple_bin.m'],", - " platform_type = 'ios',", - " hdrs = ['generated.h'],", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "ios_test(", - " name = 'test',", - " srcs = ['test.m'],", - " xctest = 1,", - " xctest_app = ':testApp',", - " deps = [':apple_bin']", - ")"); - CommandAction compileAction = compileAction("//x:test", "test.o"); - // The genfiles root for child configurations must be present in the compile action so that - // generated headers can be resolved. - assertThat(Joiner.on(" ").join(compileAction.getArguments())).contains("-iquote " - + configurationGenfiles("x86_64", ConfigurationDistinguisher.APPLEBIN_IOS, - defaultMinimumOs(ConfigurationDistinguisher.APPLEBIN_IOS))); - } - - @Test public void testXcTest_linkAction_inCoverageMode() throws Exception { useConfiguration("--collect_code_coverage"); setUpXCTestClient(); @@ -1232,37 +954,6 @@ public class IosTestTest extends ObjcRuleTestCase { } @Test - public void testGetsHeadersFromTestRig() throws Exception { - scratch.file( - "x/BUILD", - "objc_library(", - " name = 'lib',", - " srcs = ['lib.m'],", - " hdrs = ['lib.h'],", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " hdrs = ['bin.h'],", - " deps = [':lib'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "ios_test(", - " name = 'test',", - " srcs = ['test.m'],", - " hdrs = ['test.h'],", - " xctest = 1,", - " xctest_app = ':testApp',", - ")"); - Iterable<Artifact> compileInputs = - compileAction("//x:test", "test.o").getPossibleInputsForTesting(); - assertThat(Artifact.toExecPaths(compileInputs)).containsAllOf("x/lib.h", "x/bin.h", "x/test.h"); - } - - @Test public void testReceivesTransitivelyPropagatedDefines() throws Exception { checkReceivesTransitivelyPropagatedDefines(RULE_TYPE); } @@ -1271,88 +962,4 @@ public class IosTestTest extends ObjcRuleTestCase { public void testSdkIncludesUsedInCompileAction() throws Exception { checkSdkIncludesUsedInCompileAction(RULE_TYPE); } - - @Test - public void testGetsIncludesFromTestRig() throws Exception { - scratch.file("x/BUILD", - "objc_library(", - " name = 'lib',", - " srcs = ['lib.m'],", - " includes = ['libinc'],", - " sdk_includes = ['libinc_sdk'],", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " includes = ['bininc'],", - " sdk_includes = ['bininc_sdk'],", - " deps = [':lib'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "ios_test(", - " name = 'test',", - " srcs = ['test.m'],", - " includes = ['testinc'],", - " sdk_includes = ['testinc_sdk'],", - " xctest = 1,", - " xctest_app = ':testApp',", - ")"); - // We remove spaces because the crosstool case does not use spaces for include paths. - String compileArgs = Joiner.on("") - .join(compileAction("//x:test", "test.o").getArguments()) - .replace(" ", ""); - assertThat(compileArgs).contains("-Ix/libinc"); - assertThat(compileArgs).contains("-Ix/bininc"); - assertThat(compileArgs).contains("-Ix/testinc"); - - String sdkIncludeDir = AppleToolchain.sdkDir() + "/usr/include/"; - assertThat(compileArgs).contains("-I" + sdkIncludeDir + "libinc_sdk"); - assertThat(compileArgs).contains("-I" + sdkIncludeDir + "bininc_sdk"); - assertThat(compileArgs).contains("-I" + sdkIncludeDir + "testinc_sdk"); - } - - @Test - public void testGetsFrameworksFromTestRig() throws Exception { - scratch.file("x/BUILD", - "objc_framework(", - " name = 'fx',", - " framework_imports = ['fx.framework/1'],", - ")", - "objc_library(", - " name = 'lib',", - " srcs = ['lib.m'],", - " deps = [':fx'],", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " deps = [':lib'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "ios_test(", - " name = 'test',", - " srcs = ['test.m'],", - " xctest = 1,", - " xctest_app = ':testApp',", - ")"); - CommandAction compileAction = compileAction("//x:test", "test.o"); - - assertThat(Artifact.toExecPaths(compileAction.getInputs())) - .contains("x/fx.framework/1"); - // We remove spaces since the crosstool case does not use spaces for '-F'. - String compileActionArgs = Joiner.on("") - .join(compileAction.getArguments()) - .replace(" ", ""); - - assertThat(compileActionArgs).contains("-Fx"); - - CommandAction linkAction = linkAction("//x:test"); - assertThat(Joiner.on(" ").join(linkAction.getArguments())).doesNotContain("-framework fx"); - } } diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyIosApplicationTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyIosApplicationTest.java deleted file mode 100644 index 122600b445..0000000000 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyIosApplicationTest.java +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2017 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import com.google.devtools.build.lib.rules.objc.ObjcCommandLineOptions.ObjcCrosstoolMode; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** - * Legacy test: These tests test --experimental_objc_crosstool=off. See README. - */ -@RunWith(JUnit4.class) -@LegacyTest -public class LegacyIosApplicationTest extends IosApplicationTest { - @Override - protected ObjcCrosstoolMode getObjcCrosstoolMode() { - return ObjcCrosstoolMode.OFF; - } - -} diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyIosExtensionBinaryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyIosExtensionBinaryTest.java deleted file mode 100644 index d28371a647..0000000000 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyIosExtensionBinaryTest.java +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2017 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import com.google.devtools.build.lib.rules.objc.ObjcCommandLineOptions.ObjcCrosstoolMode; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** - * Legacy test: These tests test --experimental_objc_crosstool=off. See README. - */ -@RunWith(JUnit4.class) -@LegacyTest -public class LegacyIosExtensionBinaryTest extends IosExtensionBinaryTest { - @Override - protected ObjcCrosstoolMode getObjcCrosstoolMode() { - return ObjcCrosstoolMode.OFF; - } - - // Module maps are not made action inputs in the crosstool rules. - @Test - public void testCompilesSourcesWithModuleMapsEnabled() throws Exception { - checkCompilesSourcesWithModuleMapsEnabled(RULE_TYPE); - } - -} diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyIosExtensionTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyIosExtensionTest.java deleted file mode 100644 index 73af61b459..0000000000 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyIosExtensionTest.java +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2017 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import com.google.devtools.build.lib.rules.objc.ObjcCommandLineOptions.ObjcCrosstoolMode; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** - * Legacy test: These tests test --experimental_objc_crosstool=off. See README. - */ -@RunWith(JUnit4.class) -@LegacyTest -public class LegacyIosExtensionTest extends IosExtensionTest { - @Override - public ObjcCrosstoolMode getObjcCrosstoolMode() { - return ObjcCrosstoolMode.OFF; - } -} diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyIosTestTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyIosTestTest.java index 25c7d2d7ed..f955d3e635 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyIosTestTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyIosTestTest.java @@ -28,5 +28,4 @@ public class LegacyIosTestTest extends IosTestTest { protected ObjcCrosstoolMode getObjcCrosstoolMode() { return ObjcCrosstoolMode.OFF; } - } diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyObjcBinaryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyObjcBinaryTest.java deleted file mode 100644 index c8cb67d358..0000000000 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyObjcBinaryTest.java +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2017 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.common.base.Joiner; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.actions.CommandAction; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.actions.SpawnAction; -import com.google.devtools.build.lib.rules.objc.ObjcCommandLineOptions.ObjcCrosstoolMode; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** - * Legacy test: These tests test --experimental_objc_crosstool=off. See README. - */ -@RunWith(JUnit4.class) -@LegacyTest -public class LegacyObjcBinaryTest extends ObjcBinaryTest { - @Override - protected ObjcCrosstoolMode getObjcCrosstoolMode() { - return ObjcCrosstoolMode.OFF; - } - - // Module maps are not made action inputs in the crosstool rules. - @Test - public void testCompilesSourcesWithModuleMapsEnabled() throws Exception { - checkCompilesSourcesWithModuleMapsEnabled(RULE_TYPE); - } - - @Override - @Test - public void testCreate_debugSymbolActionWithAppleFlag() throws Exception { - useConfiguration("--apple_generate_dsym"); - RULE_TYPE.scratchTarget(scratch, "srcs", "['a.m']"); - ConfiguredTarget target = getConfiguredTarget("//x:x"); - - Artifact artifact = getBinArtifact("x.app.dSYM.temp.zip", target); - String execPath = artifact.getExecPath().getParentDirectory().toString(); - CommandAction linkAction = (CommandAction) getGeneratingAction(artifact); - assertThat(Joiner.on(" ").join(linkAction.getArguments())) - .contains( - Joiner.on(" ") - .join( - "&&", - MOCK_XCRUNWRAPPER_PATH, - ObjcRuleClasses.DSYMUTIL, - execPath + "/x_bin", - "-o", - execPath + "/x.app.dSYM.temp", - "&&", - "zipped_bundle=${PWD}/" + artifact.getExecPathString(), - "&&", - "cd " + artifact.getExecPathString().replace(".zip", ""), - "&&", - "/usr/bin/zip -q -r \"${zipped_bundle}\" .")); - - Artifact plistArtifact = getBinArtifact("x.app.dSYM/Contents/Info.plist", target); - Artifact debugSymbolArtifact = - getBinArtifact("x.app.dSYM/Contents/Resources/DWARF/x_bin", target); - SpawnAction plistAction = (SpawnAction) getGeneratingAction(plistArtifact); - SpawnAction debugSymbolAction = (SpawnAction) getGeneratingAction(debugSymbolArtifact); - assertThat(debugSymbolAction).isEqualTo(plistAction); - - String dsymUnzipActionArg = - "unzip -p " - + execPath - + "/x.app.dSYM.temp.zip" - + " Contents/Info.plist > " - + plistArtifact.getExecPathString() - + " && unzip -p " - + execPath - + "/x.app.dSYM.temp.zip" - + " Contents/Resources/DWARF/x_bin > " - + debugSymbolArtifact.getExecPathString(); - assertThat(plistAction.getArguments()).contains(dsymUnzipActionArg); - } - -} diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryTest.java deleted file mode 100644 index 110180c2c0..0000000000 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryTest.java +++ /dev/null @@ -1,961 +0,0 @@ -// Copyright 2017 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import static com.google.common.truth.Truth.assertThat; -import static com.google.devtools.build.lib.rules.objc.BinaryLinkingTargetFactory.REQUIRES_AT_LEAST_ONE_LIBRARY_OR_SOURCE_FILE; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.ReleaseBundlingRule.APP_ICON_ATTR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.ReleaseBundlingRule.LAUNCH_IMAGE_ATTR; - -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableListMultimap; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultiset; -import com.google.common.collect.ImmutableSetMultimap; -import com.google.common.collect.Multiset; -import com.google.devtools.build.lib.actions.Action; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.actions.CommandAction; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.RunfilesProvider; -import com.google.devtools.build.lib.analysis.actions.SpawnAction; -import com.google.devtools.build.lib.analysis.config.CompilationMode; -import com.google.devtools.build.lib.packages.util.MockObjcSupport; -import com.google.devtools.build.lib.packages.util.MockProtoSupport; -import com.google.devtools.build.lib.rules.objc.CompilationSupport.ExtraLinkArgs; -import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos; -import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos.BundleFile; -import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos.MergeZip; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Test case for objc_binary. */ -@RunWith(JUnit4.class) -@LegacyTest -public class ObjcBinaryTest extends ObjcRuleTestCase { - static final RuleType RULE_TYPE = new BinaryRuleType("objc_binary"); - - protected ConfiguredTarget addMockBinAndLibs(List<String> srcs) throws Exception { - createLibraryTargetWriter("//lib1:lib1") - .setAndCreateFiles("srcs", "a.m", "b.m", "private.h") - .setAndCreateFiles("hdrs", "hdr.h") - .write(); - createLibraryTargetWriter("//lib2:lib2") - .setAndCreateFiles("srcs", "a.m", "b.m", "private.h") - .setAndCreateFiles("hdrs", "hdr.h") - .write(); - - return createBinaryTargetWriter("//bin:bin") - .setAndCreateFiles("srcs", srcs) - .setList("deps", "//lib1:lib1", "//lib2:lib2") - .write(); - } - - @Before - public final void initializeToolsConfigMock() throws Exception { - MockProtoSupport.setup(mockToolsConfig); - MockObjcSupport.setup(mockToolsConfig); - } - - @Test - public void testCreate_runfiles() throws Exception { - ConfiguredTarget binary = addMockBinAndLibs(ImmutableList.of("a.m")); - RunfilesProvider runfiles = binary.getProvider(RunfilesProvider.class); - assertThat(runfiles.getDefaultRunfiles().getArtifacts()).isEmpty(); - assertThat(Artifact.toRootRelativePaths(runfiles.getDataRunfiles().getArtifacts())) - .containsExactly( - "bin/bin.ipa", - "bin/bin_bin"); - } - - @Test - public void testFilesToRun() throws Exception { - checkFilesToRun(RULE_TYPE); - } - - @Test - public void testNoRunfilesSupportForDevice() throws Exception { - checkNoRunfilesSupportForDevice(RULE_TYPE); - } - - @Test - public void testGenerateRunnerScriptAction() throws Exception { - checkGenerateRunnerScriptAction(RULE_TYPE); - } - - @Test - public void testGenerateRunnerScriptAction_escaped() throws Exception { - checkGenerateRunnerScriptAction_escaped(RULE_TYPE); - } - - @Test - public void testLinkActionDuplicateInputs() throws Exception { - checkLinkActionDuplicateInputs(RULE_TYPE, new ExtraLinkArgs()); - } - - @Test - /** - * Tests that bitcode is disabled for simulator builds even if enabled by flag. - */ - public void testLinkActionsWithBitcode_simulator() throws Exception { - useConfiguration("--apple_bitcode=embedded", "--ios_multi_cpus=x86_64"); - createBinaryTargetWriter("//objc:bin").setAndCreateFiles("srcs", "a.m").write(); - - CommandAction linkAction = linkAction("//objc:bin"); - - String commandLine = Joiner.on(" ").join(linkAction.getArguments()); - assertThat(commandLine).doesNotContain("-fembed-bitcode"); - assertThat(commandLine).doesNotContain("-fembed-bitcode-marker"); - } - - @Test - public void testLinkActionsWithNoBitcode() throws Exception { - useConfiguration("--apple_bitcode=none", "--ios_multi_cpus=arm64"); - createBinaryTargetWriter("//objc:bin").setAndCreateFiles("srcs", "a.m").write(); - - CommandAction linkAction = linkAction("//objc:bin"); - - String commandLine = Joiner.on(" ").join(linkAction.getArguments()); - assertThat(commandLine).doesNotContain("-fembed-bitcode"); - assertThat(commandLine).doesNotContain("-fembed-bitcode-marker"); - } - - @Test - public void testSigningAction() throws Exception { - checkDeviceSigningAction(RULE_TYPE); - } - - @Test - public void testSigningWithCertName() throws Exception { - checkSigningWithCertName(RULE_TYPE); - } - - @Test - public void testProvisioningProfile_simulatorBuild() throws Exception { - useConfiguration("--cpu=ios_i386"); - addMockBinAndLibs(ImmutableList.of("a.m")); - - Artifact provisioningProfile = - getFileConfiguredTarget("//tools/objc:foo.mobileprovision").getArtifact(); - SpawnAction spawnAction = bundleMergeAction("//bin:bin"); - assertThat(spawnAction.getInputs()).doesNotContain(provisioningProfile); - - BundleMergeProtos.Control control = bundleMergeControl("//bin:bin"); - assertThat(mobileProvisionProfiles(control)).isEmpty(); - } - - @Test - public void testProvisioningProfile_deviceBuild() throws Exception { - useConfiguration("--cpu=ios_armv7"); - - addMockBinAndLibs(ImmutableList.of("a.m")); - - Artifact provisioningProfile = - getFileConfiguredTarget("//tools/objc:foo.mobileprovision").getArtifact(); - SpawnAction spawnAction = bundleMergeAction("//bin:bin"); - assertThat(spawnAction.getInputs()).contains(provisioningProfile); - - BundleMergeProtos.Control control = bundleMergeControl("//bin:bin"); - Map<String, String> profiles = mobileProvisionProfiles(control); - ImmutableMap<String, String> expectedProfiles = ImmutableMap.of( - provisioningProfile.getExecPathString(), - ReleaseBundlingSupport.PROVISIONING_PROFILE_BUNDLE_FILE); - assertThat(profiles).isEqualTo(expectedProfiles); - } - - @Test - public void testUserSpecifiedProvisioningProfile_deviceBuild() throws Exception { - useConfiguration("--cpu=ios_armv7"); - scratch.file("custom/BUILD", "exports_files(['pp.mobileprovision'])"); - scratch.file("custom/pp.mobileprovision"); - createLibraryTargetWriter("//lib1:lib1") - .setAndCreateFiles("srcs", "a.m", "b.m", "private.h") - .setAndCreateFiles("hdrs", "hdr.h") - .write(); - createLibraryTargetWriter("//lib2:lib2") - .setAndCreateFiles("srcs", "a.m", "b.m", "private.h") - .setAndCreateFiles("hdrs", "hdr.h") - .write(); - createBinaryTargetWriter("//bin:bin") - .setAndCreateFiles("srcs", "a.m") - .setList("deps", "//lib1:lib1", "//lib2:lib2") - .set("provisioning_profile", "'//custom:pp.mobileprovision'") - .write(); - - Artifact defaultProvisioningProfile = - getFileConfiguredTarget("//tools/objc:foo.mobileprovision").getArtifact(); - Artifact customProvisioningProfile = - getFileConfiguredTarget("//custom:pp.mobileprovision").getArtifact(); - SpawnAction spawnAction = bundleMergeAction("//bin:bin"); - assertThat(spawnAction.getInputs()).contains(customProvisioningProfile); - assertThat(spawnAction.getInputs()).doesNotContain(defaultProvisioningProfile); - - BundleMergeProtos.Control control = bundleMergeControl("//bin:bin"); - Map<String, String> profiles = mobileProvisionProfiles(control); - Map<String, String> expectedProfiles = ImmutableMap.of( - customProvisioningProfile.getExecPathString(), - ReleaseBundlingSupport.PROVISIONING_PROFILE_BUNDLE_FILE); - assertThat(profiles).isEqualTo(expectedProfiles); - } - - @Test - public void testCreate_mergeControlAction() throws Exception { - createLibraryTargetWriter("//lib1:lib1") - .setAndCreateFiles("srcs", "a.m", "b.m", "private.h") - .setAndCreateFiles("hdrs", "hdr.h") - .write(); - createLibraryTargetWriter("//lib2:lib2") - .setAndCreateFiles("srcs", "a.m", "b.m", "private.h") - .setAndCreateFiles("hdrs", "hdr.h") - .write(); - createBinaryTargetWriter("//bin:bin") - .setAndCreateFiles("srcs", "a.m") - .setList("deps", "//lib1:lib1", "//lib2:lib2") - .set("infoplist", "'bin-Info.plist'") - .write(); - - Action mergeAction = bundleMergeAction("//bin:bin"); - Action action = bundleMergeControlAction("//bin:bin"); - assertThat(action.getInputs()).isEmpty(); - assertThat(Artifact.toRootRelativePaths(action.getOutputs())).containsExactly( - "bin/bin.ipa-control"); - assertThat(bundleMergeControl("//bin:bin")) - .isEqualTo( - BundleMergeProtos.Control.newBuilder() - .addBundleFile( - BundleFile.newBuilder() - .setSourceFile(execPathEndingWith(mergeAction.getInputs(), "bin")) - .setBundlePath("bin") - .setExternalFileAttribute(BundleableFile.EXECUTABLE_EXTERNAL_FILE_ATTRIBUTE) - .build()) - .setBundleRoot("Payload/bin.app") - .setBundleInfoPlistFile( - execPathEndingWith(mergeAction.getInputs(), "bin-MergedInfo.plist")) - .setOutFile(execPathEndingWith(mergeAction.getOutputs(), "bin.unprocessed.ipa")) - .setMinimumOsVersion(DEFAULT_IOS_SDK_VERSION.toString()) - .setSdkVersion(DEFAULT_IOS_SDK_VERSION.toString()) - .setPlatform("IOS_SIMULATOR") - .setFallbackBundleIdentifier("example.bin") - .build()); - } - - @Test - public void testCreate_mergeBundleAction() throws Exception { - createLibraryTargetWriter("//lib1:lib1") - .setAndCreateFiles("srcs", "a.m", "b.m", "private.h") - .setAndCreateFiles("hdrs", "hdr.h") - .write(); - createLibraryTargetWriter("//lib2:lib2") - .setAndCreateFiles("srcs", "a.m", "b.m", "private.h") - .setAndCreateFiles("hdrs", "hdr.h") - .write(); - createBinaryTargetWriter("//bin:bin") - .setAndCreateFiles("srcs", "a.m") - .setList("deps", "//lib1:lib1", "//lib2:lib2") - .set("infoplist", "'bin-Info.plist'") - .write(); - - SpawnAction action = bundleMergeAction("//bin:bin"); - assertThat(Artifact.toRootRelativePaths(action.getInputs())) - .containsExactly( - MOCK_BUNDLEMERGE_PATH, - "bin/bin_lipobin", - "bin/bin.ipa-control", - "bin/bin-MergedInfo.plist"); - assertThat(Artifact.toRootRelativePaths(action.getOutputs())) - .containsExactly("bin/bin.unprocessed.ipa"); - assertNotRequiresDarwin(action); - assertThat(action.getEnvironment()).isEmpty(); - assertThat(action.getArguments()) - .containsExactly( - MOCK_BUNDLEMERGE_PATH, execPathEndingWith(action.getInputs(), "bin.ipa-control")) - .inOrder(); - } - - @Test - public void testCheckPrimaryBundleIdInMergedPlist() throws Exception { - checkPrimaryBundleIdInMergedPlist(RULE_TYPE); - } - - @Test - public void testCheckFallbackBundleIdInMergedPlist() throws Exception { - checkFallbackBundleIdInMergedPlist(RULE_TYPE); - } - - @Test - public void testCreate_errorForNoSourceOrDep() throws Exception { - scratch.file("x/Foo.plist"); - checkError("x", "x", REQUIRES_AT_LEAST_ONE_LIBRARY_OR_SOURCE_FILE, - "objc_binary(name='x')"); - } - - @Test - public void testCompileWithDotMFileInHeaders() throws Exception { - checkCompileWithDotMFileInHeaders(RULE_TYPE); - } - - @Test - public void testCreate_NoDebugSymbolActionWithoutAppleFlag() throws Exception { - checkNoDebugSymbolFileWithoutAppleFlag(RULE_TYPE); - } - - @Test - public void testErrorForLaunchImageGivenWithNoAssetCatalog() throws Exception { - checkAssetCatalogAttributeError(RULE_TYPE, LAUNCH_IMAGE_ATTR); - } - - @Test - public void testErrorForAppIconGivenWithNoAssetCatalog() throws Exception { - checkAssetCatalogAttributeError(RULE_TYPE, APP_ICON_ATTR); - } - - @Test - public void testCollectsAssetCatalogsTransitively() throws Exception { - scratch.file("lib/ac.xcassets/foo"); - scratch.file("lib/ac.xcassets/bar"); - createLibraryTargetWriter("//lib:lib") - .setAndCreateFiles("srcs", "a.m", "b.m", "private.h") - .set("asset_catalogs", "glob(['ac.xcassets/**'])") - .write(); - scratch.file("bin/ac.xcassets/baz"); - scratch.file("bin/ac.xcassets/42"); - createBinaryTargetWriter("//bin:bin") - .setAndCreateFiles("srcs", "src.m") - .setList("deps", "//lib:lib") - .set("asset_catalogs", "glob(['ac.xcassets/**'])") - .write(); - - // Test that the actoolzip Action has arguments and inputs obtained from dependencies. - SpawnAction actoolZipAction = actoolZipActionForIpa("//bin:bin"); - assertThat(Artifact.toExecPaths(actoolZipAction.getInputs())).containsExactly( - "lib/ac.xcassets/foo", "lib/ac.xcassets/bar", "bin/ac.xcassets/baz", "bin/ac.xcassets/42", - MOCK_ACTOOLWRAPPER_PATH); - assertContainsSublist(actoolZipAction.getArguments(), - ImmutableList.of("lib/ac.xcassets", "bin/ac.xcassets")); - } - - @Test - public void testCcDependencyLinkoptsArePropagatedToLinkAction() throws Exception { - useConfiguration("--experimental_disable_go", "--cpu=ios_i386", - "--crosstool_top=//tools/osx/crosstool:crosstool"); - - scratch.file("bin/BUILD", - "cc_library(", - " name = 'cclib1',", - " srcs = ['dep1.c'],", - " linkopts = ['-framework F1', '-framework F2', '-Wl,--other-opt'],", - ")", - "cc_library(", - " name = 'cclib2',", - " srcs = ['dep2.c'],", - " linkopts = ['-another-opt', '-framework F2'],", - " deps = ['cclib1'],", - ")", - "cc_library(", - " name = 'cclib3',", - " srcs = ['dep2.c'],", - " linkopts = ['-one-more-opt', '-framework UIKit'],", - " deps = ['cclib1'],", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " deps = [':cclib2', ':cclib3'],", - ")"); - - // Frameworks from the CROSSTOOL "apply_implicit_frameworks" feature should be present. - assertThat(Joiner.on(" ").join(linkAction("//bin").getArguments())) - .contains("-framework Foundation -framework UIKit"); - // Frameworks included in linkopts by the user should get placed together with no duplicates. - // (They may duplicate the ones inserted by the CROSSTOOL feature, but we don't test that here.) - assertThat(Joiner.on(" ").join(linkAction("//bin").getArguments())) - .contains("-framework F2 -framework F1"); - // Linkopts should also be grouped together. - assertThat(Joiner.on(" ").join(linkAction("//bin").getArguments())) - .contains("-another-opt -Wl,--other-opt -one-more-opt"); - } - - @Test - public void testAlwaysLinkCcDependenciesAreForceLoaded() throws Exception { - useConfiguration("--experimental_disable_go", "--cpu=ios_i386", - "--crosstool_top=//tools/osx/crosstool:crosstool"); - - scratch.file("bin/BUILD", - "cc_library(", - " name = 'cclib1',", - " srcs = ['dep1.c'],", - " alwayslink = 1,", - ")", - "cc_library(", - " name = 'cclib2',", - " srcs = ['dep2.c'],", - " deps = [':cclib1'],", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " deps = [':cclib2'],", - ")"); - - // cclib1 is force loaded. - assertThat(Joiner.on(" ").join(linkAction("//bin").getArguments())) - .containsMatch(Pattern.compile(" -force_load [^\\s]+/libcclib1.lo\\b")); - } - - @Test - public void testSpecifyAppIconAndLaunchImageUsingXcassetsOfDependency() throws Exception { - checkSpecifyAppIconAndLaunchImageUsingXcassetsOfDependency(RULE_TYPE); - } - - @Test - public void testCreate_actoolAction() throws Exception { - addTargetWithAssetCatalogs(RULE_TYPE); - checkActoolActionCorrectness(DEFAULT_IOS_SDK_VERSION); - } - - @Test - public void testPassesFamiliesToActool() throws Exception { - checkPassesFamiliesToActool(RULE_TYPE); - } - - @Test - public void testPassesFamiliesToIbtool() throws Exception { - checkPassesFamiliesToIbtool(RULE_TYPE); - } - - @Test - public void testReportsErrorsForInvalidFamiliesAttribute() throws Exception { - checkReportsErrorsForInvalidFamiliesAttribute(RULE_TYPE); - } - - @SuppressWarnings("deprecation") // getMergeWithoutNamePrefixZipList is deprecated - @Test - public void testCreate_mergeActionsWithAssetCatalog() throws Exception { - // TODO(matvore): add this test to IosTestTest.java. - addTargetWithAssetCatalogs(RULE_TYPE); - - Artifact actoolZipOut = getBinArtifact("x.actool.zip", "//x:x"); - assertThat(bundleMergeAction("//x:x").getInputs()).contains(actoolZipOut); - - BundleMergeProtos.Control mergeControl = bundleMergeControl("//x:x"); - assertThat(mergeControl.getMergeZipList()).containsExactly(MergeZip.newBuilder() - .setEntryNamePrefix("Payload/x.app/") - .setSourcePath(actoolZipOut.getExecPathString()) - .build()); - } - - private void addBinAndLibWithRawResources() throws Exception { - addBinAndLibWithResources("resources", "resource1.txt", "ja.lproj/resource2.txt", - "objc_binary"); - } - - private void addBinAndLibWithStrings() throws Exception { - addBinAndLibWithResources("strings", "foo.strings", "ja.lproj/bar.strings", - "objc_binary"); - } - - @Test - public void testCollectsRawResourceFilesTransitively() throws Exception { - addBinAndLibWithRawResources(); - checkCollectsResourceFilesTransitively( - "//bin:bin", - ImmutableList.of("lib/resource1.txt", "bin/ja.lproj/resource2.txt"), - ImmutableList.of("lib/resource1.txt"), - ImmutableSetMultimap.<String, Multiset<String>>of( - "bin_bin", - ImmutableMultiset.of("bin/ja.lproj/resource2.txt", "lib/resource1.txt"), - "bin_static_lib_bin", - ImmutableMultiset.of("bin/ja.lproj/resource2.txt", "lib/resource1.txt"), - "lib_lib", - ImmutableMultiset.of("lib/resource1.txt"))); - } - - @Test - public void testCollectsStringsFilesTransitively() throws Exception { - addBinAndLibWithStrings(); - checkCollectsResourceFilesTransitively( - "//bin:bin", - ImmutableList.of("bin/lib/foo.strings.binary", "bin/bin/ja.lproj/bar.strings.binary"), - ImmutableList.of("lib/foo.strings.binary"), - ImmutableSetMultimap.<String, Multiset<String>>of( - "bin_bin", - ImmutableMultiset.of("bin/ja.lproj/bar.strings", "lib/foo.strings"), - "bin_static_lib_bin", - ImmutableMultiset.of("bin/ja.lproj/bar.strings", "lib/foo.strings"), - "lib_lib", - ImmutableMultiset.of("lib/foo.strings"))); - } - - @Test - public void testResourceFilesMergedInBundle() throws Exception { - addBinAndLibWithRawResources(); - checkBundleablesAreMerged("//bin:bin", - ImmutableListMultimap.of( - "resource1.txt", "resource1.txt", - "ja.lproj/resource2.txt", "ja.lproj/resource2.txt")); - } - - @Test - public void testStringsFilesMergedInBundle() throws Exception { - addBinAndLibWithStrings(); - checkBundleablesAreMerged("//bin:bin", - ImmutableListMultimap.of( - "foo.strings.binary", "foo.strings", - "ja.lproj/bar.strings.binary", "ja.lproj/bar.strings")); - } - - @Test - public void testLinksFrameworksOfSelfAndTransitiveDependencies() throws Exception { - checkLinksFrameworksOfSelfAndTransitiveDependencies(RULE_TYPE); - } - - @Test - public void testLinksWeakFrameworksOfSelfAndTransitiveDependencies() throws Exception { - checkLinksWeakFrameworksOfSelfAndTransitiveDependencies(RULE_TYPE); - } - - @Test - public void testMergesXcdatamodelZips() throws Exception { - checkMergesXcdatamodelZips(RULE_TYPE); - } - - @Test - public void testPlistRequiresDotInName() throws Exception { - checkError("x", "x", - "'//x:Infoplist' does not produce any objc_binary infoplist files (expected .plist)", - "objc_binary(", - " name = 'x',", - " srcs = ['a.m'],", - " infoplist = 'Infoplist'", - ")"); - } - - @Test - public void testLinkIncludeOrder_staticLibsFirst() throws Exception { - checkLinkIncludeOrderStaticLibsFirst(RULE_TYPE); - } - - @Test - public void testLinksDylibsTransitively() throws Exception { - checkLinksDylibsTransitively(RULE_TYPE); - } - - @Test - public void testPopulatesCompilationArtifacts() throws Exception { - checkPopulatesCompilationArtifacts(RULE_TYPE); - } - - @Test - public void testArchivesPrecompiledObjectFiles() throws Exception { - checkArchivesPrecompiledObjectFiles(RULE_TYPE); - } - - @Test - public void testPopulatesBundling() throws Exception { - checkPopulatesBundling(RULE_TYPE); - } - - @Test - public void testRegistersStoryboardCompilationActions() throws Exception { - checkRegistersStoryboardCompileActions(RULE_TYPE, "iphone"); - } - - @Test - public void testSwiftStdlibActions() throws Exception { - checkRegisterSwiftStdlibActions(RULE_TYPE, "iphonesimulator"); - } - - @Test - public void testSwiftStdlibActionsWithToolchain() throws Exception { - useConfiguration("--xcode_toolchain=test_toolchain"); - checkRegisterSwiftStdlibActions(RULE_TYPE, "iphonesimulator", "test_toolchain"); - } - - @Test - public void testRegistersSwiftSupportActions() throws Exception { - checkRegisterSwiftSupportActions(RULE_TYPE, "iphonesimulator"); - } - - @Test - public void testRegistersSwiftSupportActionsWithToolchain() throws Exception { - useConfiguration("--xcode_toolchain=test_toolchain"); - checkRegisterSwiftSupportActions(RULE_TYPE, "iphonesimulator", "test_toolchain"); - } - - @Test - public void testErrorsWrongFileTypeForSrcsWhenCompiling() throws Exception { - checkErrorsWrongFileTypeForSrcsWhenCompiling(RULE_TYPE); - } - - @Test - public void testObjcCopts() throws Exception { - checkObjcCopts(RULE_TYPE); - } - - @Test - public void testObjcCopts_argumentOrdering() throws Exception { - checkObjcCopts_argumentOrdering(RULE_TYPE); - } - - @Test - public void testMergesActoolPartialInfoplist() throws Exception { - checkMergesPartialInfoplists(RULE_TYPE); - } - - @Test - public void checkDefinesFromCcLibraryDep() throws Exception { - checkDefinesFromCcLibraryDep(RULE_TYPE); - } - - @Test - public void testCompileXibActions() throws Exception { - checkCompileXibActions(RULE_TYPE); - } - - @Test - public void testNibZipsMergedIntoBundle() throws Exception { - checkNibZipsMergedIntoBundle(RULE_TYPE); - } - - @Test - public void testAllowVariousNonBlacklistedTypesInHeaders() throws Exception { - checkAllowVariousNonBlacklistedTypesInHeaders(RULE_TYPE); - } - - @Test - public void testWarningForBlacklistedTypesInHeaders() throws Exception { - checkWarningForBlacklistedTypesInHeaders(RULE_TYPE); - } - - @Test - public void testCppSourceCompilesWithCppFlags() throws Exception { - checkCppSourceCompilesWithCppFlags(RULE_TYPE); - } - - @Test - public void testPassesFallbackBundleIdToBundleMerging() throws Exception { - checkBundleIdPassedAsFallbackId(RULE_TYPE); - } - - @Test - public void testPassesPrimaryBundleIdToBundleMerging() throws Exception { - checkBundleIdPassedAsPrimaryId(RULE_TYPE); - } - - @Test - public void testNestedBundleIdIsNotAffectedByParent() throws Exception { - scratch.file("bndl/BUILD", - "objc_bundle_library(", - " name = 'bndl',", - ")"); - - createLibraryTargetWriter("//lib:lib") - .setAndCreateFiles("hdrs", "lib.h") - .setList("bundles", "//bndl:bndl") - .write(); - - createBinaryTargetWriter("//bin:bin") - .setAndCreateFiles("srcs", "a.m") - .setList("deps", "//lib:lib") - .set("bundle_id", "'com.main.bundle'") - .write(); - - BundleMergeProtos.Control control = bundleMergeControl("//bin:bin"); - - assertThat(control.getPrimaryBundleIdentifier()).isEqualTo("com.main.bundle"); - // The nested bndl should not get its parent's bundle_id - assertThat(control.getNestedBundleList().get(0).getPrimaryBundleIdentifier()) - .isNotEqualTo("com.main.bundle"); - } - - @Test - public void testAutomaticPlistEntries() throws Exception { - checkAutomaticPlistEntries(RULE_TYPE); - } - - @Test - public void testBundleMergeInputContainsPlMergeOutput() throws Exception { - checkBundleMergeInputContainsPlMergeOutput(RULE_TYPE); - } - - @Test - public void testMultipleInfoPlists() throws Exception { - checkMultipleInfoPlists(RULE_TYPE); - } - - @Test - public void testInfoplistAndInfoplistsTogether() throws Exception { - checkInfoplistAndInfoplistsTogether(RULE_TYPE); - } - - @Test - public void testLinkOpts() throws Exception { - checkLinkopts(RULE_TYPE); - } - - @Test - public void testProtoBundlingAndLinking() throws Exception { - checkProtoBundlingAndLinking(RULE_TYPE); - } - - @Test - public void testProtoBundlingWithTargetsWithNoDeps() throws Exception { - checkProtoBundlingWithTargetsWithNoDeps(RULE_TYPE); - } - - @Test - public void testCanUseCrosstool() throws Exception { - checkLinkingRuleCanUseCrosstool(RULE_TYPE); - } - - @Test - public void testBinaryStrippings() throws Exception { - checkBinaryStripAction(RULE_TYPE); - } - - @Test - public void testAppleSdkVersionEnv() throws Exception { - addMockBinAndLibs(ImmutableList.of("a.m")); - CommandAction action = linkAction("//bin:bin"); - - assertAppleSdkVersionEnv(action); - } - - @Test - public void testNonDefaultAppleSdkVersionEnv() throws Exception { - useConfiguration("--ios_sdk_version=8.1"); - - addMockBinAndLibs(ImmutableList.of("a.m")); - CommandAction action = linkAction("//bin:bin"); - - assertAppleSdkVersionEnv(action, "8.1"); - } - - @Test - public void testAppleSdkDefaultPlatformEnv() throws Exception { - addMockBinAndLibs(ImmutableList.of("a.m")); - CommandAction action = linkAction("//bin:bin"); - - assertAppleSdkPlatformEnv(action, "iPhoneSimulator"); - } - - @Test - public void testAppleSdkDevicePlatformEnv() throws Exception { - useConfiguration("--cpu=ios_arm64"); - - addMockBinAndLibs(ImmutableList.of("a.m")); - CommandAction action = linkAction("//bin:bin"); - - assertAppleSdkPlatformEnv(action, "iPhoneOS"); - } - - @Test - public void testMergeBundleActionsWithNestedBundle() throws Exception { - checkMergeBundleActionsWithNestedBundle(RULE_TYPE); - } - - @Test - public void testIncludesStoryboardOutputZipsAsMergeZips() throws Exception { - checkIncludesStoryboardOutputZipsAsMergeZips(RULE_TYPE); - } - - @Test - public void testCompilationActionsForDebug() throws Exception { - checkClangCoptsForCompilationMode(RULE_TYPE, CompilationMode.DBG, CodeCoverageMode.NONE); - } - - @Test - public void testClangCoptsForDebugModeWithoutGlib() throws Exception { - checkClangCoptsForDebugModeWithoutGlib(RULE_TYPE); - } - - @Test - public void testCompilationActionsForOptimized() throws Exception { - checkClangCoptsForCompilationMode(RULE_TYPE, CompilationMode.OPT, CodeCoverageMode.NONE); - } - - @Test - public void testCcDependency() throws Exception { - checkCcDependency(RULE_TYPE); - } - - @Test - public void testLinkActionCorrect() throws Exception { - checkLinkActionCorrect(RULE_TYPE, new ExtraLinkArgs()); - } - - @Test - public void testFrameworkDepLinkFlags() throws Exception { - checkFrameworkDepLinkFlags(RULE_TYPE, new ExtraLinkArgs()); - } - - @Test - public void testLinkActionsWithEmbeddedBitcode() throws Exception { - useConfiguration("--apple_bitcode=embedded", "--ios_multi_cpus=arm64"); - createBinaryTargetWriter("//objc:bin").setAndCreateFiles("srcs", "a.m").write(); - - CommandAction linkAction = linkAction("//objc:bin"); - String commandLine = Joiner.on(" ").join(linkAction.getArguments()); - - assertThat(commandLine).contains("-fembed-bitcode"); - assertThat(commandLine).contains("-Xlinker -bitcode_verify"); - assertThat(commandLine).contains("-Xlinker -bitcode_hide_symbols"); - } - - @Test - public void testLinkActionsWithEmbeddedBitcodeMarkers() throws Exception { - useConfiguration("--apple_bitcode=embedded_markers", "--ios_multi_cpus=arm64"); - createBinaryTargetWriter("//objc:bin").setAndCreateFiles("srcs", "a.m").write(); - - CommandAction linkAction = linkAction("//objc:bin"); - - assertThat(Joiner.on(" ").join(linkAction.getArguments())).contains("-fembed-bitcode-marker"); - } - - @Test - public void testCompilationActionsForDebugInGcovCoverage() throws Exception { - checkClangCoptsForCompilationMode(RULE_TYPE, CompilationMode.DBG, - CodeCoverageMode.GCOV); - } - - @Test - public void testCompilationActionsForDebugInLlvmCovCoverage() throws Exception { - checkClangCoptsForCompilationMode(RULE_TYPE, CompilationMode.DBG, - CodeCoverageMode.LLVMCOV); - } - - @Test - public void testCompilationActionsForOptimizedInGcovCoverage() throws Exception { - checkClangCoptsForCompilationMode(RULE_TYPE, CompilationMode.OPT, - CodeCoverageMode.GCOV); - } - - @Test - public void testCompilationActionsForOptimizedInLlvmCovCoverage() throws Exception { - checkClangCoptsForCompilationMode(RULE_TYPE, CompilationMode.OPT, - CodeCoverageMode.LLVMCOV); - } - - @Test - public void testXcodeVersionEnv() throws Exception { - useConfiguration("--xcode_version=5.8"); - - addMockBinAndLibs(ImmutableList.of("a.m")); - CommandAction action = linkAction("//bin:bin"); - - assertXcodeVersionEnv(action, "5.8"); - } - - @Test - public void testCompileWithTextualHeaders() throws Exception { - checkCompileWithTextualHeaders(RULE_TYPE); - } - - @Test - public void testCompilesWithHdrs() throws Exception { - checkCompilesWithHdrs(RULE_TYPE); - } - - @Test - public void testCompilesSources() throws Exception { - checkCompilesSources(RULE_TYPE); - } - - @Test - public void testLinkActionWithTransitiveCppDependency() throws Exception { - checkLinkActionWithTransitiveCppDependency(RULE_TYPE, new ExtraLinkArgs()); - } - - @Test - public void testLinkWithFrameworkImportsIncludesFlagsAndInputArtifacts() throws Exception { - checkLinkWithFrameworkImportsIncludesFlagsAndInputArtifacts(RULE_TYPE); - } - - @Test - public void testForceLoadsAlwayslinkTargets() throws Exception { - checkForceLoadsAlwayslinkTargets(RULE_TYPE, new ExtraLinkArgs()); - } - - @Test - public void testReceivesTransitivelyPropagatedDefines() throws Exception { - checkReceivesTransitivelyPropagatedDefines(RULE_TYPE); - } - - @Test - public void testSdkIncludesUsedInCompileAction() throws Exception { - checkSdkIncludesUsedInCompileAction(RULE_TYPE); - } - - @Test - public void testCreate_debugSymbolActionWithAppleFlag() throws Exception { - useConfiguration("--apple_generate_dsym"); - RULE_TYPE.scratchTarget(scratch, "srcs", "['a.m']"); - ConfiguredTarget target = getConfiguredTarget("//x:x"); - - Artifact artifact = getBinArtifact("x.app.dSYM.temp.zip", target); - String execPath = artifact.getExecPath().getParentDirectory().toString(); - CommandAction linkAction = (CommandAction) getGeneratingAction(artifact); - assertThat(linkAction.getArguments()).containsAllOf( - "DSYM_HINT_LINKED_BINARY=" + execPath + "/x_bin", - "DSYM_HINT_DSYM_PATH=" + execPath + "/x.app.dSYM.temp", - "DSYM_HINT_DSYM_BUNDLE_ZIP=" + artifact.getExecPathString()); - - Artifact plistArtifact = getBinArtifact("x.app.dSYM/Contents/Info.plist", target); - Artifact debugSymbolArtifact = - getBinArtifact("x.app.dSYM/Contents/Resources/DWARF/x_bin", target); - SpawnAction plistAction = (SpawnAction) getGeneratingAction(plistArtifact); - SpawnAction debugSymbolAction = (SpawnAction) getGeneratingAction(debugSymbolArtifact); - assertThat(debugSymbolAction).isEqualTo(plistAction); - - String dsymUnzipActionArg = - "unzip -p " - + execPath - + "/x.app.dSYM.temp.zip" - + " Contents/Info.plist > " - + plistArtifact.getExecPathString() - + " && unzip -p " - + execPath - + "/x.app.dSYM.temp.zip" - + " Contents/Resources/DWARF/x_bin > " - + debugSymbolArtifact.getExecPathString(); - assertThat(plistAction.getArguments()).contains(dsymUnzipActionArg); - } - - @Test - public void testTargetHasDebugSymbols() throws Exception { - checkTargetHasDebugSymbols(RULE_TYPE); - } - - @Test - public void testFilesToCompileOutputGroup() throws Exception { - checkFilesToCompileOutputGroup(RULE_TYPE); - } - - @Test - public void testCustomModuleMap() throws Exception { - checkCustomModuleMap(RULE_TYPE); - } - - @Test - public void testGenruleDependency() throws Exception { - checkGenruleDependency(RULE_TYPE); - } -} diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcBundleLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcBundleLibraryTest.java index 8f7e2862db..a076ba852f 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcBundleLibraryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcBundleLibraryTest.java @@ -19,10 +19,7 @@ import static com.google.devtools.build.lib.rules.objc.ObjcProvider.NESTED_BUNDL import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.testutil.Scratch; -import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos; -import com.google.devtools.build.xcode.plmerge.proto.PlMergeProtos; import java.io.IOException; import java.util.Set; import org.junit.Test; @@ -67,85 +64,6 @@ public class ObjcBundleLibraryTest extends ObjcRuleTestCase { } @Test - public void testProvidesBundling() throws Exception { - addBundleWithResource(); - scratch.file( - "bin/BUILD", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " bundles = ['//bndl:bndl'],", - ")"); - BundleMergeProtos.Control mergeControl = bundleMergeControl("//bin:bin"); - BundleMergeProtos.Control nestedControl = - Iterables.getOnlyElement(mergeControl.getNestedBundleList()); - BundleMergeProtos.BundleFile bundleFile = - BundleMergeProtos.BundleFile.newBuilder() - .setBundlePath("foo.data") - .setSourceFile(getSourceArtifact("bndl/foo.data").getExecPathString()) - .setExternalFileAttribute(BundleableFile.DEFAULT_EXTERNAL_FILE_ATTRIBUTE) - .build(); - - // Should put resource in .bundle directory, not bundle root (.app dir) - assertThat(nestedControl.getBundleFileList()).containsExactly(bundleFile); - assertThat(mergeControl.getBundleFileList()).doesNotContain(bundleFile); - } - - @Test - public void testDoesNotMergeInfoplistOfNestedBundle() throws Exception { - scratch.file("bndl1/bndl1-Info.plist"); - scratch.file("bndl1/BUILD", - "objc_bundle_library(", - " name = 'bndl1',", - " infoplist = 'bndl1-Info.plist',", - ")"); - scratch.file("bndl2/bndl2-Info.plist"); - scratch.file("bndl2/BUILD", - "objc_bundle_library(", - " name = 'bndl2',", - " bundles = ['//bndl1:bndl1'],", - " infoplist = 'bndl2-Info.plist',", - ")"); - scratch.file("bin/bin-Info.plist"); - scratch.file("bin/bin.m"); - scratch.file("bin/BUILD", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " bundles = ['//bndl2:bndl2'],", - " infoplist = 'bin-Info.plist'", - ")"); - Artifact bundle1Infoplist = getSourceArtifact("bndl1/bndl1-Info.plist"); - Artifact bundle2Infoplist = getSourceArtifact("bndl2/bndl2-Info.plist"); - Artifact binaryInfoplist = getSourceArtifact("bin/bin-Info.plist"); - Artifact binaryMergedInfoplist = getMergedInfoPlist(getConfiguredTarget("//bin:bin")); - - PlMergeProtos.Control binaryPlMergeControl = plMergeControl("//bin:bin"); - - assertThat(binaryPlMergeControl.getSourceFileList()) - .contains(binaryInfoplist.getExecPathString()); - assertThat(binaryPlMergeControl.getSourceFileList()) - .containsNoneOf(bundle1Infoplist.getExecPathString(), bundle2Infoplist.getExecPathString()); - - assertThat(bundleMergeAction("//bin:bin").getInputs()) - .containsAllOf(bundle1Infoplist, bundle2Infoplist, binaryMergedInfoplist); - - BundleMergeProtos.Control binControl = bundleMergeControl("//bin:bin"); - assertThat(binControl.getBundleInfoPlistFile()) - .isEqualTo(binaryMergedInfoplist.getExecPathString()); - - BundleMergeProtos.Control bundle2Control = - Iterables.getOnlyElement(binControl.getNestedBundleList()); - assertThat(bundle2Control.getBundleInfoPlistFile()) - .isEqualTo(bundle2Infoplist.getExecPathString()); - - BundleMergeProtos.Control bundle1Control = - Iterables.getOnlyElement(bundle2Control.getNestedBundleList()); - assertThat(bundle1Control.getBundleInfoPlistFile()) - .isEqualTo(bundle1Infoplist.getExecPathString()); - } - - @Test public void testRegistersStoryboardCompilationActions() throws Exception { checkRegistersStoryboardCompileActions(RULE_TYPE, "iphone"); } diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcFrameworkTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcFrameworkTest.java index e4a9dded52..6e90760563 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcFrameworkTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcFrameworkTest.java @@ -25,10 +25,7 @@ import static com.google.devtools.build.lib.rules.objc.ObjcProvider.WEAK_SDK_FRA import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.actions.SpawnAction; import com.google.devtools.build.lib.vfs.PathFragment; -import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos; -import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos.BundleFile; import java.util.Set; import org.junit.Test; import org.junit.runner.RunWith; @@ -226,94 +223,4 @@ public class ObjcFrameworkTest extends ObjcRuleTestCase { " })", ")"); } - - @Test - public void testDynamicFrameworkInFinalBundle() throws Exception { - scratch.file("x/Foo.framework/Foo"); - scratch.file("x/Foo.framework/Info.plist"); - scratch.file("x/Foo.framework/Headers/Foo.h"); - scratch.file("x/Foo.framework/Resources/bar.png"); - scratch.file( - "x/BUILD", - "objc_framework(", - " name = 'foo_framework',", - " framework_imports = glob(['Foo.framework/**']),", - " is_dynamic = 1,", - ")", - "", - "objc_binary(", - " name = 'bin',", - " srcs = [ 'a.m' ],", - " deps = [ ':foo_framework' ],", - ")", - "", - "ios_application(", - " name = 'x',", - " binary = ':bin',", - ")"); - - BundleMergeProtos.Control mergeControl = bundleMergeControl("//x:x"); - - assertThat(mergeControl.getBundleFileList()) - .containsAllOf( - BundleFile.newBuilder() - .setBundlePath("Frameworks/Foo.framework/Foo") - .setSourceFile(getSourceArtifact("x/Foo.framework/Foo").getExecPathString()) - .setExternalFileAttribute(BundleableFile.EXECUTABLE_EXTERNAL_FILE_ATTRIBUTE) - .build(), - BundleFile.newBuilder() - .setBundlePath("Frameworks/Foo.framework/Info.plist") - .setSourceFile(getSourceArtifact("x/Foo.framework/Info.plist").getExecPathString()) - .setExternalFileAttribute(BundleableFile.EXECUTABLE_EXTERNAL_FILE_ATTRIBUTE) - .build(), - BundleFile.newBuilder() - .setBundlePath("Frameworks/Foo.framework/Resources/bar.png") - .setSourceFile( - getSourceArtifact("x/Foo.framework/Resources/bar.png").getExecPathString()) - .setExternalFileAttribute(BundleableFile.DEFAULT_EXTERNAL_FILE_ATTRIBUTE) - .build()); - - assertThat(mergeControl.getBundleFileList()) - .doesNotContain( - BundleFile.newBuilder() - .setBundlePath("Frameworks/Foo.framework/Headers/Foo.h") - .setSourceFile( - getSourceArtifact("x/Foo.framework/Headers/Foo.h").getExecPathString()) - .setExternalFileAttribute(BundleableFile.DEFAULT_EXTERNAL_FILE_ATTRIBUTE) - .build()); - } - - @Test - public void testDynamicFrameworkSigned() throws Exception { - useConfiguration("--ios_cpu=arm64"); - - scratch.file("x/Foo.framework/Foo"); - scratch.file("x/Foo.framework/Info.plist"); - scratch.file("x/Foo.framework/Headers/Foo.h"); - scratch.file("x/Foo.framework/Resources/bar.png"); - scratch.file( - "x/BUILD", - "objc_framework(", - " name = 'foo_framework',", - " framework_imports = glob(['Foo.framework/**']),", - " is_dynamic = 1,", - ")", - "", - "objc_binary(", - " name = 'bin',", - " srcs = [ 'a.m' ],", - " deps = [ ':foo_framework' ],", - ")", - "", - "ios_application(", - " name = 'x',", - " binary = ':bin',", - ")"); - - SpawnAction signingAction = (SpawnAction) ipaGeneratingAction(); - - assertThat(normalizeBashArgs(signingAction.getArguments())) - .containsAllOf("--sign", "${t}/Payload/x.app/Frameworks/*", "--sign", "${t}/Payload/x.app") - .inOrder(); - } } diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcImportTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcImportTest.java index fd3e065a6b..d312405810 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcImportTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcImportTest.java @@ -122,12 +122,6 @@ public class ObjcImportTest extends ObjcRuleTestCase { public void testProvidesStoryboardObjects() throws Exception { checkProvidesStoryboardObjects(RULE_TYPE); } - - @Test - public void testNestedBundleInformationPropagatedToDependers() throws Exception { - checkNestedBundleInformationPropagatedToDependers(RULE_TYPE); - } - @Test public void testSdkIncludesUsedInCompileActionsOfDependers() throws Exception { checkSdkIncludesUsedInCompileActionsOfDependers(RULE_TYPE); diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java index 4e426c3d5e..0803dd0756 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java @@ -1229,11 +1229,6 @@ public class ObjcLibraryTest extends ObjcRuleTestCase { } @Test - public void testBundleInformationPropagatedThroughLibraries() throws Exception { - checkNestedBundleInformationPropagatedToDependers(RULE_TYPE); - } - - @Test public void testAppleSdkVersionEnv() throws Exception { createLibraryTargetWriter("//objc:lib") .setAndCreateFiles("srcs", "a.m", "b.m", "private.h") @@ -1639,15 +1634,17 @@ public class ObjcLibraryTest extends ObjcRuleTestCase { public void testApplePlatformEnvForCcLibraryDep() throws Exception { useConfiguration("--cpu=ios_i386"); - scratch.file("package/BUILD", + scratch.file( + "package/BUILD", "cc_library(", " name = 'cc_lib',", " srcs = ['a.cc'],", ")", "", - "objc_binary(", + "apple_binary(", " name = 'objc_bin',", " srcs = ['b.m'],", + " platform_type = 'ios',", " deps = [':cc_lib'],", ")"); diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcProtoAspectTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcProtoAspectTest.java index 35adffbd07..ae80e06379 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcProtoAspectTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcProtoAspectTest.java @@ -19,10 +19,10 @@ import static com.google.common.truth.Truth.assertThat; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.packages.util.MockObjcSupport; import com.google.devtools.build.lib.packages.util.MockProtoSupport; +import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher; import com.google.devtools.build.lib.vfs.PathFragment; import org.junit.Before; import org.junit.Test; @@ -31,7 +31,7 @@ import org.junit.runners.JUnit4; /** Test case for the objc_proto_library aspect. */ @RunWith(JUnit4.class) -public final class ObjcProtoAspectTest extends BuildViewTestCase { +public final class ObjcProtoAspectTest extends ObjcRuleTestCase { @Before public final void initializeToolsConfigMock() throws Exception { @@ -80,8 +80,8 @@ public final class ObjcProtoAspectTest extends BuildViewTestCase { PathFragment includePath = header.getExecPath().getParentDirectory(); PathFragment genIncludePath = PathFragment.create( - getConfiguration(targetConfig, AppleCrosstoolTransition.APPLE_CROSSTOOL_TRANSITION) - .getGenfilesFragment() + configurationGenfiles( + "x86_64", ConfigurationDistinguisher.APPLEBIN_IOS, DEFAULT_IOS_SDK_VERSION) + "/" + includePath); @@ -163,8 +163,8 @@ public final class ObjcProtoAspectTest extends BuildViewTestCase { assertThat(Artifact.toExecPaths(objcProtoProvider.getPortableProtoFilters())) .containsExactly( - getConfiguration(targetConfig, AppleCrosstoolTransition.APPLE_CROSSTOOL_TRANSITION) - .getGenfilesFragment() + configurationGenfiles( + "x86_64", ConfigurationDistinguisher.APPLEBIN_IOS, DEFAULT_IOS_SDK_VERSION) + "/x/_proto_filters/objc_proto/generated_filter_file.pbascii"); } @@ -206,15 +206,17 @@ public final class ObjcProtoAspectTest extends BuildViewTestCase { assertThat(Artifact.toExecPaths(objcProtoProvider.getPortableProtoFilters())) .containsAllOf( "x/filter.pbascii", - getConfiguration(targetConfig, AppleCrosstoolTransition.APPLE_CROSSTOOL_TRANSITION) - .getGenfilesFragment() + configurationGenfiles( + "x86_64", ConfigurationDistinguisher.APPLEBIN_IOS, DEFAULT_IOS_SDK_VERSION) + "/x/_proto_filters/objc_proto_2/generated_filter_file.pbascii"); } private ConfiguredTarget getObjcProtoAspectConfiguredTarget(String label) throws Exception { - scratch.file("bin/BUILD", - "objc_binary(", + scratch.file( + "bin/BUILD", + "apple_binary(", " name = 'link_target',", + " platform_type = 'ios',", " deps = ['" + label + "'],", ")"); diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java index b28980800f..631eaf77c3 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java @@ -205,8 +205,6 @@ public abstract class ObjcRuleTestCase extends BuildViewTestCase { switch (configurationDistinguisher) { case UNKNOWN: return String.format("%s-out/ios_%s-fastbuild/", TestConstants.PRODUCT_NAME, arch); - case IOS_EXTENSION: // Intentional fall-through. - case IOS_APPLICATION: case APPLEBIN_IOS: return String.format( "%1$s-out/ios-%2$s-min%4$s-%3$s-ios_%2$s-fastbuild/", @@ -249,15 +247,13 @@ public abstract class ObjcRuleTestCase extends BuildViewTestCase { protected static String iosConfigurationCcDepsBin( String arch, ConfigurationDistinguisher configurationDistinguisher) { switch (configurationDistinguisher) { - case IOS_EXTENSION: case APPLEBIN_IOS: return String.format( "%s-out/%s-ios_%s-fastbuild/bin/", TestConstants.PRODUCT_NAME, configurationDistinguisher.toString().toLowerCase(Locale.US), arch); - case UNKNOWN: // Intentional fall-through. - case IOS_APPLICATION: + case UNKNOWN: return String.format("%s-out/ios_%s-fastbuild/bin/", TestConstants.PRODUCT_NAME, arch); default: throw new AssertionError(); @@ -272,9 +268,6 @@ public abstract class ObjcRuleTestCase extends BuildViewTestCase { ConfigurationDistinguisher configurationDistinguisher) { switch (configurationDistinguisher) { case UNKNOWN: - case IOS_EXTENSION: - return IosExtension.EXTENSION_MINIMUM_OS_VERSION; - case IOS_APPLICATION: case APPLEBIN_IOS: return DEFAULT_IOS_SDK_VERSION; case APPLEBIN_WATCHOS: @@ -322,11 +315,10 @@ public abstract class ObjcRuleTestCase extends BuildViewTestCase { return ScratchAttributeWriter.fromLabelString(this, "objc_library", labelString); } - /** - * Creates an {@code objc_binary} target writer for the label indicated by the given String. - */ + /** Creates an {@code apple_binary} target writer for the label indicated by the given String. */ protected ScratchAttributeWriter createBinaryTargetWriter(String labelString) { - return ScratchAttributeWriter.fromLabelString(this, "objc_binary", labelString); + return ScratchAttributeWriter.fromLabelString(this, "apple_binary", labelString) + .set("platform_type", "'ios'"); } private static String compilationModeFlag(CompilationMode mode) { @@ -2767,17 +2759,23 @@ public abstract class ObjcRuleTestCase extends BuildViewTestCase { .write(); String sdkIncludeDir = AppleToolchain.sdkDir() + "/usr/include"; + CommandAction archiveAction = archiveAction("//lib:lib"); + Artifact aObj = getFirstArtifactEndingWith(archiveAction.getInputs(), "a.o"); + CommandAction aCompileAction = (CommandAction) getGeneratingAction(aObj); + // We remove spaces because the crosstool case does not use spaces for include paths. - String compileAArgs = Joiner.on("") - .join(compileAction("//lib:lib", "a.o").getArguments()) - .replace(" ", ""); + String compileAArgs = Joiner.on("").join(aCompileAction.getArguments()).replace(" ", ""); assertThat(compileAArgs).contains("-I" + sdkIncludeDir + "/from_lib"); assertThat(compileAArgs).contains("-I" + sdkIncludeDir + "/foo"); assertThat(compileAArgs).contains("-I" + sdkIncludeDir + "/bar/baz"); - String compileBArgs = Joiner.on("") - .join(compileAction("//bin:bin", "b.o").getArguments()) - .replace(" ", ""); + CommandAction linkAction = linkAction("//bin:bin"); + Artifact binLib = getFirstArtifactEndingWith(linkAction.getInputs(), "libbin.a"); + CommandAction binArchiveAction = (CommandAction) getGeneratingAction(binLib); + Artifact bObj = getFirstArtifactEndingWith(binArchiveAction.getInputs(), "b.o"); + CommandAction bCompileAction = (CommandAction) getGeneratingAction(bObj); + + String compileBArgs = Joiner.on("").join(bCompileAction.getArguments()).replace(" ", ""); assertThat(compileBArgs).contains("-I" + sdkIncludeDir + "/from_bin"); assertThat(compileBArgs).contains("-I" + sdkIncludeDir + "/from_lib"); assertThat(compileBArgs).contains("-I" + sdkIncludeDir + "/foo"); @@ -3257,45 +3255,6 @@ public abstract class ObjcRuleTestCase extends BuildViewTestCase { assertThat(control.getBundleFileList()).containsAllIn(expectedBundleFiles); } - protected void checkNestedBundleInformationPropagatedToDependers(RuleType ruleType) - throws Exception { - scratch.file("bndl/bndl-Info.plist"); - scratch.file("bndl/bndl.png"); - scratch.file("bndl/BUILD", - "objc_bundle_library(", - " name = 'bndl',", - " infoplist = 'bndl-Info.plist',", - " resources = ['bndl.png'],", - ")"); - - ruleType.scratchTarget(scratch, "bundles", "['//bndl:bndl']"); - - scratch.file("bin/bin.m"); - scratch.file("bin/BUILD", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " deps = ['//x:x'],", - ")"); - - assertThat(bundleMergeAction("//bin:bin").getInputs()) - .containsAllOf( - getSourceArtifact("bndl/bndl-Info.plist"), getSourceArtifact("bndl/bndl.png")); - - BundleMergeProtos.Control binControl = bundleMergeControl("//bin:bin"); - BundleMergeProtos.Control bundleControl = - Iterables.getOnlyElement(binControl.getNestedBundleList()); - - assertThat(bundleControl.getBundleInfoPlistFile()).isEqualTo("bndl/bndl-Info.plist"); - - assertThat(bundleControl.getBundleFileList()) - .containsExactly(BundleMergeProtos.BundleFile.newBuilder() - .setBundlePath("bndl.png") - .setSourceFile("bndl/bndl.png") - .setExternalFileAttribute(BundleableFile.DEFAULT_EXTERNAL_FILE_ATTRIBUTE) - .build()); - } - protected void checkConvertStringsAction(BinaryRuleTypePair ruleTypePair) throws Exception { scratch.file("lib/foo.strings"); scratch.file("lib/es.lproj/bar.strings"); diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcSkylarkTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcSkylarkTest.java index a5453e5b51..e45e623ceb 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcSkylarkTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcSkylarkTest.java @@ -203,8 +203,9 @@ public class ObjcSkylarkTest extends ObjcRuleTestCase { " srcs = ['a.m'],", " defines = ['mock_define']", ")", - "objc_binary(", + "apple_binary(", " name = 'bin',", + " platform_type = 'ios',", " deps = [':my_target']", ")"); @@ -240,8 +241,9 @@ public class ObjcSkylarkTest extends ObjcRuleTestCase { " srcs = ['a.m'],", " deps = [':my_target']", ")", - "objc_binary(", + "apple_binary(", " name = 'bin',", + " platform_type = 'ios',", " deps = [':lib']", ")"); diff --git a/src/test/shell/bazel/apple/bazel_objc_test.sh b/src/test/shell/bazel/apple/bazel_objc_test.sh index 955562a492..4bd61c235e 100755 --- a/src/test/shell/bazel/apple/bazel_objc_test.sh +++ b/src/test/shell/bazel/apple/bazel_objc_test.sh @@ -24,11 +24,11 @@ if [ "${PLATFORM}" != "darwin" ]; then exit 0 fi -function make_app() { +function make_lib() { rm -rf ios mkdir -p ios - cat >ios/app.m <<EOF + cat >ios/main.m <<EOF #import <UIKit/UIKit.h> int main(int argc, char *argv[]) { @@ -39,110 +39,36 @@ int main(int argc, char *argv[]) { } EOF - cat >ios/App-Info.plist <<EOF -<plist version="1.0"> -<dict> - <key>CFBundleExecutable</key> - <string>app</string> - <key>CFBundleName</key> - <string>app</string> - <key>CFBundleDisplayName</key> - <string>app</string> - <key>CFBundlePackageType</key> - <string>APPL</string> - <key>CFBundleIdentifier</key> - <string>com.google.app</string> - <key>CFBundleSignature</key> - <string>????</string> - <key>CFBundleVersion</key> - <string>1.0</string> - <key>LSRequiresIPhoneOS</key> - <true/> -</dict> -</plist> -EOF - - cat >ios/PassTest-Info.plist <<EOF -<plist version="1.0"> -<dict> - <key>CFBundleExecutable</key> - <string>PassingXcTest</string> -</dict> -</plist> -EOF - - cat >ios/passtest.m <<EOF -#import <XCTest/XCTest.h> - -@interface PassingXcTest : XCTestCase - -@end - -@implementation PassingXcTest - -- (void)testPass { - XCTAssertEqual(1, 1, @"should pass"); -} - -@end -EOF - cat >ios/BUILD <<EOF -objc_binary(name = "bin", - non_arc_srcs = ['app.m']) -ios_application(name = "app", - binary = ':bin', - infoplist = 'App-Info.plist') -ios_test(name = 'PassingXcTest', - srcs = ['passtest.m'], - infoplist = "PassTest-Info.plist", - xctest = True, - xctest_app = ':app') +objc_library(name = "lib", + non_arc_srcs = ['main.m']) EOF } function test_build_app() { setup_objc_test_support - make_app - - bazel build --verbose_failures --ios_sdk_version=$IOS_SDK_VERSION \ - //ios:app >$TEST_log 2>&1 || fail "should pass" - ls bazel-bin/ios/app.ipa || fail "should generate app.ipa" -} - -function test_ios_test() { - setup_objc_test_support - make_app - - bazel build --test_output=all --ios_sdk_version=$IOS_SDK_VERSION \ - --ios_minimum_os=8.0 \ - //ios:PassingXcTest >$TEST_log 2>&1 || fail "should pass" - ls bazel-out/ios_x86_64-fastbuild/bin/ios/PassingXcTest.ipa \ - || fail "should generate PassingXcTest.ipa" -} - -function test_valid_ios_sdk_version() { - setup_objc_test_support - make_app + make_lib bazel build --verbose_failures --ios_sdk_version=$IOS_SDK_VERSION \ - //ios:app >$TEST_log 2>&1 || fail "should pass" - ls bazel-bin/ios/app.ipa || fail "should generate app.ipa" + //ios:lib >$TEST_log 2>&1 || fail "should pass" + ls bazel-out/ios_x86_64-fastbuild/bin/ios/liblib.a \ + || fail "should generate lib.a" } # Bazel caches mappings for ios sdk locations for local host execution. # Verify that multiple invocations (with primed cache) work. function test_xcrun_cache() { setup_objc_test_support - make_app + make_lib ! ls bazel-out/__xcruncache || fail "clean build should not have cache file" bazel build --verbose_failures --ios_sdk_version=$IOS_SDK_VERSION \ - //ios:bin >$TEST_log 2>&1 || fail "should pass" + //ios:lib >$TEST_log 2>&1 || fail "should pass" ls bazel-out/__xcruncache || fail "xcrun cache should be present" bazel build --verbose_failures --ios_sdk_version=$IOS_SDK_VERSION \ - //ios:app >$TEST_log 2>&1 || fail "should pass" - ls bazel-bin/ios/app.ipa || fail "should generate app.ipa" + //ios:lib >$TEST_log 2>&1 || fail "should pass" + ls bazel-out/ios_x86_64-fastbuild/bin/ios/liblib.a \ + || fail "should generate lib.a" ls bazel-out/__xcruncache || fail "xcrun cache should be present" bazel clean @@ -151,10 +77,10 @@ function test_xcrun_cache() { function test_invalid_ios_sdk_version() { setup_objc_test_support - make_app + make_lib ! bazel build --verbose_failures --ios_sdk_version=2.34 \ - //ios:app >$TEST_log 2>&1 || fail "should fail" + //ios:lib >$TEST_log 2>&1 || fail "should fail" expect_log "SDK \"iphonesimulator2.34\" cannot be located." } |