diff options
Diffstat (limited to 'src/main/java/com')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java | 5 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/objc/AbstractIosTestRule.java (renamed from src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelIosTestRule.java) | 119 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/objc/ExperimentalIosTest.java | 73 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/objc/ExperimentalIosTestRule.java | 105 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java | 132 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/objc/IosTestRule.java | 38 |
6 files changed, 198 insertions, 274 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 3b0b0988bf..3ce6ee04f6 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 @@ -47,7 +47,6 @@ import com.google.devtools.build.lib.bazel.rules.java.BazelJavaLibraryRule; import com.google.devtools.build.lib.bazel.rules.java.BazelJavaPluginRule; import com.google.devtools.build.lib.bazel.rules.java.BazelJavaRuleClasses; import com.google.devtools.build.lib.bazel.rules.java.BazelJavaTestRule; -import com.google.devtools.build.lib.bazel.rules.objc.BazelIosTestRule; import com.google.devtools.build.lib.bazel.rules.objc.BazelJ2ObjcLibraryRule; import com.google.devtools.build.lib.bazel.rules.python.BazelPyBinaryRule; import com.google.devtools.build.lib.bazel.rules.python.BazelPyLibraryRule; @@ -100,6 +99,7 @@ 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.IosFrameworkBinaryRule; import com.google.devtools.build.lib.rules.objc.IosFrameworkRule; +import com.google.devtools.build.lib.rules.objc.IosTestRule; import com.google.devtools.build.lib.rules.objc.J2ObjcLibraryBaseRule; import com.google.devtools.build.lib.rules.objc.ObjcBinaryRule; import com.google.devtools.build.lib.rules.objc.ObjcBuildInfoFactory; @@ -316,7 +316,8 @@ public class BazelRuleClassProvider { builder.addRuleDefinition(new BazelAndroidLibraryRule()); builder.addRuleDefinition(new BazelAndroidBinaryRule()); - builder.addRuleDefinition(new BazelIosTestRule()); + builder.addRuleDefinition(new IosTestRule()); + // TODO(bazel-team): Remove this line after experimental_ios_test is completely removed. builder.addRuleDefinition(new ExperimentalIosTestRule()); builder.addRuleDefinition(new IosDeviceRule()); builder.addRuleDefinition(new ObjcBinaryRule()); diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelIosTestRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractIosTestRule.java index 01c5b07d7e..f0ae9abce9 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelIosTestRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractIosTestRule.java @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -package com.google.devtools.build.lib.bazel.rules.objc; + +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; @@ -22,7 +23,6 @@ import static com.google.devtools.build.lib.syntax.Type.STRING_LIST; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.Constants; -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.analysis.config.BuildConfiguration; @@ -31,96 +31,89 @@ import com.google.devtools.build.lib.packages.Attribute.LateBoundLabelList; import com.google.devtools.build.lib.packages.ImplicitOutputsFunction; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.RuleClass; -import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.java.J2ObjcConfiguration; -import com.google.devtools.build.lib.rules.objc.ExperimentalIosTest; -import com.google.devtools.build.lib.rules.objc.IosTest; -import com.google.devtools.build.lib.rules.objc.ObjcConfiguration; -import com.google.devtools.build.lib.rules.objc.ObjcRuleClasses; -import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport; -import com.google.devtools.build.lib.rules.objc.XcodeSupport; import com.google.devtools.build.lib.util.FileType; import java.util.List; /** - * Rule definition for the ios_test rule. + * Rule definition for {@code ios_test} rule. Abstract so that extensions can support + * the equivalent ios_test and experimental_ios_test rules until experimental_ios_test is + * fully deprecated. */ -public final class BazelIosTestRule implements RuleDefinition { +public abstract class AbstractIosTestRule implements RuleDefinition { @Override public RuleClass build(RuleClass.Builder builder, final RuleDefinitionEnvironment env) { return builder .requiresConfigurationFragments(ObjcConfiguration.class, J2ObjcConfiguration.class, AppleConfiguration.class) /*<!-- #BLAZE_RULE(ios_test).IMPLICIT_OUTPUTS --> - <ul> - <li><code><var>name</var>.ipa</code>: the test bundle as an - <code>.ipa</code> file - <li><code><var>name</var>.xcodeproj/project.pbxproj: An Xcode project file which can be - used to develop or build on a Mac.</li> - </ul> - <!-- #END_BLAZE_RULE.IMPLICIT_OUTPUTS -->*/ + <ul> + <li><code><var>name</var>.ipa</code>: the test bundle as an + <code>.ipa</code> file + <li><code><var>name</var>.xcodeproj/project.pbxproj: An Xcode project file which can be + used to develop or build on a Mac.</li> + </ul> + <!-- #END_BLAZE_RULE.IMPLICIT_OUTPUTS -->*/ .setImplicitOutputsFunction( ImplicitOutputsFunction.fromFunctions(ReleaseBundlingSupport.IPA, XcodeSupport.PBXPROJ)) .override( attr(IosTest.TARGET_DEVICE, LABEL) .allowedFileTypes() .allowedRuleClasses("ios_device") - .value(env.getLabel( - Constants.TOOLS_REPOSITORY + "//tools/objc/sim_devices:default"))) + .value( + env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc/sim_devices:default"))) /* <!-- #BLAZE_RULE(ios_test).ATTRIBUTE(ios_test_target_device) --> - The device against how to run the test. If this attribute is defined, the test will run on - the lab device. Otherwise, the test will run on simulator. - ${SYNOPSIS} - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ + The device against how to run the test. If this attribute is defined, the test will run on + the lab device. Otherwise, the test will run on simulator. + ${SYNOPSIS} + <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ .add( attr("ios_test_target_device", LABEL) .allowedFileTypes() .allowedRuleClasses("ios_lab_device")) /* <!-- #BLAZE_RULE(ios_test).ATTRIBUTE(ios_device_arg) --> - Extra arguments to pass to the <code>ios_test_target_device</code>'s binary. They should be - in the form KEY=VALUE or simply KEY (check your device's documentation for allowed - parameters). - ${SYNOPSIS} - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ + Extra arguments to pass to the <code>ios_test_target_device</code>'s binary. They should be + in the form KEY=VALUE or simply KEY (check your device's documentation for allowed + parameters). + ${SYNOPSIS} + <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ .add(attr("ios_device_arg", STRING_LIST)) /* <!-- #BLAZE_RULE(ios_test).ATTRIBUTE(plugins) --> - Plugins to pass to the test runner. - ${SYNOPSIS} - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ + Plugins to pass to the test runner. + ${SYNOPSIS} + <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ .add(attr("plugins", LABEL_LIST).allowedFileTypes(FileType.of("_deploy.jar"))) - .add(attr("$test_template", LABEL) - .value(env.getLabel( - Constants.TOOLS_REPOSITORY + "//tools/objc:ios_test.sh.bazel_template"))) - .add(attr("$test_runner", LABEL) - .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:testrunner"))) - .add(attr(IosTest.MEMLEAKS_DEP, LABEL) - .value(env.getLabel("//tools/objc/memleaks:memleaks"))) - .add(attr(IosTest.MEMLEAKS_PLUGIN, LABEL) - .value(env.getLabel("//tools/objc:memleaks_plugin"))) - .override(attr(":gcov", LABEL_LIST).cfg(HOST) - .value(new LateBoundLabelList<BuildConfiguration>() { - @Override - public List<Label> getDefault(Rule rule, BuildConfiguration configuration) { - if (!configuration.isCodeCoverageEnabled()) { - return ImmutableList.of(); - } - return ImmutableList.of( - configuration.getFragment(ObjcConfiguration.class).getExperimentalGcovLabel()); - } - })) - .build(); - } - - @Override - public Metadata getMetadata() { - return RuleDefinition.Metadata.builder() - .name("ios_test") - .type(RuleClassType.TEST) - .ancestors(BaseRuleClasses.BaseRule.class, BaseRuleClasses.TestBaseRule.class, - ObjcRuleClasses.IosTestBaseRule.class, ObjcRuleClasses.SimulatorRule.class) - .factoryClass(ExperimentalIosTest.class) + .add( + attr("$test_template", LABEL) + .value( + env.getLabel( + Constants.TOOLS_REPOSITORY + "//tools/objc:ios_test.sh.bazel_template"))) + .add( + attr("$test_runner", LABEL) + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:testrunner"))) + .add( + attr(IosTest.MEMLEAKS_DEP, LABEL).value(env.getLabel("//tools/objc/memleaks:memleaks"))) + .add( + attr(IosTest.MEMLEAKS_PLUGIN, LABEL) + .value(env.getLabel("//tools/objc:memleaks_plugin"))) + .override( + attr(":gcov", LABEL_LIST) + .cfg(HOST) + .value( + new LateBoundLabelList<BuildConfiguration>() { + @Override + public List<Label> getDefault(Rule rule, BuildConfiguration configuration) { + if (!configuration.isCodeCoverageEnabled()) { + return ImmutableList.of(); + } + return ImmutableList.of( + configuration + .getFragment(ObjcConfiguration.class) + .getExperimentalGcovLabel()); + } + })) .build(); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ExperimentalIosTest.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ExperimentalIosTest.java deleted file mode 100644 index 2218dac01f..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ExperimentalIosTest.java +++ /dev/null @@ -1,73 +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.collect.ImmutableMap; -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.RuleContext; -import com.google.devtools.build.lib.analysis.Runfiles; -import com.google.devtools.build.lib.analysis.RunfilesProvider; -import com.google.devtools.build.lib.analysis.RunfilesSupport; -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.test.ExecutionInfoProvider; -import com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider; - -/** - * Implementation for {@code experimental_ios_test} rule in Bazel. - * - * <p>Note that this will be renamed to {@code ios_test}, and {@link - * com.google.devtools.build.lib.bazel.rules.objc.BazelIosTest} will be removed when it is slightly - * more feature complete. - */ -public final class ExperimentalIosTest extends IosTest { - @Override - public ConfiguredTarget create(RuleContext ruleContext, ObjcCommon common, - XcodeProvider xcodeProvider, NestedSet<Artifact> filesToBuild) throws InterruptedException { - - Runfiles.Builder runfilesBuilder = new Runfiles.Builder(ruleContext.getWorkspaceName()) - .addRunfiles(ruleContext, RunfilesProvider.DEFAULT_RUNFILES); - NestedSetBuilder<Artifact> filesToBuildBuilder = NestedSetBuilder.<Artifact>stableOrder() - .addTransitive(filesToBuild); - - TestSupport testSupport = - new TestSupport(ruleContext) - .registerTestRunnerActions() - .addRunfiles(runfilesBuilder) - .addFilesToBuild(filesToBuildBuilder); - - Artifact executable = testSupport.generatedTestScript(); - - Runfiles runfiles = runfilesBuilder.build(); - RunfilesSupport runfilesSupport = - RunfilesSupport.withExecutable(ruleContext, runfiles, executable); - - return new RuleConfiguredTargetBuilder(ruleContext) - .setFilesToBuild(filesToBuildBuilder.build()) - .add(XcodeProvider.class, xcodeProvider) - .add(RunfilesProvider.class, RunfilesProvider.simple(runfiles)) - .add( - ExecutionInfoProvider.class, - new ExecutionInfoProvider(ImmutableMap.of(ExecutionRequirements.REQUIRES_DARWIN, ""))) - .addProvider( - InstrumentedFilesProvider.class, - new CompilationSupport(ruleContext).getInstrumentedFilesProvider(common)) - .addProviders(testSupport.getExtraProviders()) - .setRunfilesSupport(runfilesSupport, executable) - .build(); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ExperimentalIosTestRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ExperimentalIosTestRule.java index cde6d5e4d2..1629a0ac8c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ExperimentalIosTestRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ExperimentalIosTestRule.java @@ -14,120 +14,37 @@ 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.STRING_LIST; - -import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.Constants; 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.analysis.config.BuildConfiguration; -import com.google.devtools.build.lib.cmdline.Label; -import com.google.devtools.build.lib.packages.Attribute.LateBoundLabelList; -import com.google.devtools.build.lib.packages.ImplicitOutputsFunction; -import com.google.devtools.build.lib.packages.Rule; -import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration; -import com.google.devtools.build.lib.rules.java.J2ObjcConfiguration; -import com.google.devtools.build.lib.util.FileType; - -import java.util.List; /** * Rule definition for {@code experimental_ios_test} rule in Bazel. * - * <p>Note that this will be renamed to {@code ios_test}, and {@link - * com.google.devtools.build.lib.bazel.rules.objc.BazelIosTestRule} will be removed when it is - * slightly more feature complete. + * <p>experimental_ios_test is equivalent to ios_test. */ -public final class ExperimentalIosTestRule implements RuleDefinition { - @Override - public RuleClass build(RuleClass.Builder builder, final RuleDefinitionEnvironment env) { - return builder - .requiresConfigurationFragments(ObjcConfiguration.class, J2ObjcConfiguration.class, - AppleConfiguration.class) - /*<!-- #BLAZE_RULE(experimental_ios_test).IMPLICIT_OUTPUTS --> - <ul> - <li><code><var>name</var>.ipa</code>: the test bundle as an - <code>.ipa</code> file - <li><code><var>name</var>.xcodeproj/project.pbxproj: An Xcode project file which can be - used to develop or build on a Mac.</li> - </ul> - <!-- #END_BLAZE_RULE.IMPLICIT_OUTPUTS -->*/ - .setImplicitOutputsFunction( - ImplicitOutputsFunction.fromFunctions(ReleaseBundlingSupport.IPA, XcodeSupport.PBXPROJ)) - .override( - attr(IosTest.TARGET_DEVICE, LABEL) - .allowedFileTypes() - .allowedRuleClasses("ios_device") - .value(env.getLabel( - Constants.TOOLS_REPOSITORY + "//tools/objc/sim_devices:default"))) - /* <!-- #BLAZE_RULE(experimental_ios_test).ATTRIBUTE(ios_test_target_device) --> - The device against how to run the test. If this attribute is defined, the test will run on - the lab device. Otherwise, the test will run on simulator. - ${SYNOPSIS} - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add( - attr("ios_test_target_device", LABEL) - .allowedFileTypes() - .allowedRuleClasses("ios_lab_device")) - /* <!-- #BLAZE_RULE(experimental_ios_test).ATTRIBUTE(ios_device_arg) --> - Extra arguments to pass to the <code>ios_test_target_device</code>'s binary. They should be - in the form KEY=VALUE or simply KEY (check your device's documentation for allowed - parameters). - ${SYNOPSIS} - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add(attr("ios_device_arg", STRING_LIST)) - /* <!-- #BLAZE_RULE(experimental_ios_test).ATTRIBUTE(plugins) --> - Plugins to pass to the test runner. - ${SYNOPSIS} - <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add(attr("plugins", LABEL_LIST).allowedFileTypes(FileType.of("_deploy.jar"))) - .add(attr("$test_template", LABEL) - .value(env.getLabel( - Constants.TOOLS_REPOSITORY + "//tools/objc:ios_test.sh.bazel_template"))) - .add(attr("$test_runner", LABEL).value(env.getLabel( - Constants.TOOLS_REPOSITORY + "//tools/objc:testrunner"))) - .add(attr(IosTest.MEMLEAKS_DEP, LABEL) - .value(env.getLabel("//tools/objc/memleaks:memleaks"))) - .add(attr(IosTest.MEMLEAKS_PLUGIN, LABEL) - .value(env.getLabel("//tools/objc:memleaks_plugin"))) - .override(attr(":gcov", LABEL_LIST).cfg(HOST) - .value(new LateBoundLabelList<BuildConfiguration>() { - @Override - public List<Label> getDefault(Rule rule, BuildConfiguration configuration) { - if (!configuration.isCodeCoverageEnabled()) { - return ImmutableList.of(); - } - return ImmutableList.of( - configuration.getFragment(ObjcConfiguration.class).getExperimentalGcovLabel()); - } - })) - .build(); - } - +public final class ExperimentalIosTestRule extends AbstractIosTestRule { @Override public Metadata getMetadata() { return RuleDefinition.Metadata.builder() .name("experimental_ios_test") .type(RuleClassType.TEST) - .ancestors(BaseRuleClasses.BaseRule.class, BaseRuleClasses.TestBaseRule.class, - ObjcRuleClasses.IosTestBaseRule.class, ObjcRuleClasses.SimulatorRule.class) - .factoryClass(ExperimentalIosTest.class) + .ancestors( + BaseRuleClasses.BaseRule.class, + BaseRuleClasses.TestBaseRule.class, + ObjcRuleClasses.IosTestBaseRule.class, + ObjcRuleClasses.SimulatorRule.class) + .factoryClass(IosTest.class) .build(); } } /*<!-- #BLAZE_RULE (NAME = experimental_ios_test, TYPE = TEST, FAMILY = Objective-C) --> - ${ATTRIBUTE_SIGNATURE} -<p>This rule provides a way to build iOS unit tests written in KIF, GTM and XCTest test frameworks +<p>Deprecated. Use ios_test instead.</p> + +<p>This rule provides a way to build iOS unit tests written in GTM and XCTest test frameworks on both iOS simulator and real devices. </p> diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java index 95102bdf9c..ec3219e5ac 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java @@ -19,28 +19,37 @@ import static com.google.devtools.build.lib.rules.objc.ObjcProvider.XCDATAMODEL; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.RuleConfiguredTarget; import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; +import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; import com.google.devtools.build.lib.analysis.RuleContext; +import com.google.devtools.build.lib.analysis.Runfiles; +import com.google.devtools.build.lib.analysis.RunfilesProvider; +import com.google.devtools.build.lib.analysis.RunfilesSupport; 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.RuleConfiguredTargetFactory; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.objc.CompilationSupport.ExtraLinkArgs; import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.LinkedBinary; +import com.google.devtools.build.lib.rules.test.ExecutionInfoProvider; +import com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider; import com.google.devtools.build.lib.syntax.Type; import java.util.ArrayList; import java.util.List; /** - * Contains information needed to create a {@link RuleConfiguredTarget} and invoke test runners - * for some instantiation of this rule. + * Implementation for {@code experimental_ios_test} rule in Bazel. + * + * <p>Note that this will be renamed to {@code ios_test}, and {@link + * com.google.devtools.build.lib.bazel.rules.objc.BazelIosTest} will be removed when it is slightly + * more feature complete. */ -// TODO(bazel-team): Extract a TestSupport class that takes on most of the logic in this class. -public abstract class IosTest implements RuleConfiguredTargetFactory { +public final class IosTest implements RuleConfiguredTargetFactory { + private static final ImmutableList<SdkFramework> AUTOMATIC_SDK_FRAMEWORKS_FOR_XCTEST = ImmutableList.of(new SdkFramework("XCTest")); @@ -58,49 +67,46 @@ public abstract class IosTest implements RuleConfiguredTargetFactory { "ios_test cannot be built for multiple CPUs at the same time"; /** + * {@inheritDoc} + * * Creates a target, including registering actions, just as {@link #create(RuleContext)} does. * The difference between {@link #create(RuleContext)} and this method is that this method does * only what is needed to support tests on the environment besides generate the Xcodeproj file * and build the app and test {@code .ipa}s. The {@link #create(RuleContext)} method delegates * to this method. - */ - protected abstract ConfiguredTarget create(RuleContext ruleContext, ObjcCommon common, - XcodeProvider xcodeProvider, NestedSet<Artifact> filesToBuild) throws InterruptedException; - + */ @Override public final ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException { ObjcCommon common = common(ruleContext); - + if (!common.getCompilationArtifacts().get().getArchive().isPresent()) { ruleContext.ruleError(REQUIRES_SOURCE_ERROR); } - + if (!ruleContext.getFragment(AppleConfiguration.class).getIosMultiCpus().isEmpty()) { ruleContext.ruleError(NO_MULTI_CPUS_ERROR); } - + XcodeProvider.Builder xcodeProviderBuilder = new XcodeProvider.Builder(); NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder(); addResourceFilesToBuild(ruleContext, common.getObjcProvider(), filesToBuild); - - XcodeProductType productType; + + XcodeProductType productType = getProductType(ruleContext); ExtraLinkArgs extraLinkArgs; Iterable<Artifact> extraLinkInputs; if (!isXcTest(ruleContext)) { - productType = XcodeProductType.APPLICATION; extraLinkArgs = new ExtraLinkArgs(); extraLinkInputs = ImmutableList.of(); } else { - productType = XcodeProductType.UNIT_TEST; XcodeProvider appIpaXcodeProvider = ruleContext.getPrerequisite(XCTEST_APP, Mode.TARGET, XcodeProvider.class); xcodeProviderBuilder .setTestHost(appIpaXcodeProvider) .setProductType(productType); - + XcTestAppProvider testApp = xcTestAppProvider(ruleContext); Artifact bundleLoader = testApp.getBundleLoader(); - + // -bundle causes this binary to be linked as a bundle and not require an entry point // (i.e. main()) // -bundle_loader causes the code in this test to have access to the symbols in the test rig, @@ -109,33 +115,33 @@ public abstract class IosTest implements RuleConfiguredTargetFactory { extraLinkArgs = new ExtraLinkArgs( "-bundle", "-bundle_loader", bundleLoader.getExecPathString()); - + extraLinkInputs = ImmutableList.of(bundleLoader); - + filesToBuild.add(testApp.getIpa()); } - + new CompilationSupport(ruleContext) .registerLinkActions(common.getObjcProvider(), extraLinkArgs, extraLinkInputs) .registerJ2ObjcCompileAndArchiveActions(common.getObjcProvider()) .registerCompileAndArchiveActions(common) .addXcodeSettings(xcodeProviderBuilder, common) .validateAttributes(); - + ObjcConfiguration objcConfiguration = ObjcRuleClasses.objcConfiguration(ruleContext); - ReleaseBundlingSupport releaseBundlingSupport = new ReleaseBundlingSupport( - ruleContext, common.getObjcProvider(), LinkedBinary.LOCAL_AND_DEPENDENCIES, - ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT, objcConfiguration.getMinimumOs()); - releaseBundlingSupport + new ReleaseBundlingSupport( + ruleContext, + common.getObjcProvider(), + LinkedBinary.LOCAL_AND_DEPENDENCIES, + ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT, + objcConfiguration.getMinimumOs()) .registerActions() .addXcodeSettings(xcodeProviderBuilder) .addFilesToBuild(filesToBuild) .validateResources() .validateAttributes(); - new ResourceSupport(ruleContext) - .validateAttributes() - .addXcodeSettings(xcodeProviderBuilder); + new ResourceSupport(ruleContext).validateAttributes().addXcodeSettings(xcodeProviderBuilder); new XcodeSupport(ruleContext) .addXcodeSettings(xcodeProviderBuilder, common.getObjcProvider(), productType) @@ -146,32 +152,64 @@ public abstract class IosTest implements RuleConfiguredTargetFactory { .addFilesToBuild(filesToBuild) .registerActions(xcodeProviderBuilder.build()); - return create(ruleContext, common, xcodeProviderBuilder.build(), filesToBuild.build()); + XcodeProvider xcodeProvider = xcodeProviderBuilder.build(); + NestedSet<Artifact> filesToBuildSet = filesToBuild.build(); + + Runfiles.Builder runfilesBuilder = + new Runfiles.Builder(ruleContext.getWorkspaceName()) + .addRunfiles(ruleContext, RunfilesProvider.DEFAULT_RUNFILES); + NestedSetBuilder<Artifact> filesToBuildBuilder = + NestedSetBuilder.<Artifact>stableOrder().addTransitive(filesToBuildSet); + + TestSupport testSupport = + new TestSupport(ruleContext) + .registerTestRunnerActions() + .addRunfiles(runfilesBuilder) + .addFilesToBuild(filesToBuildBuilder); + + Artifact executable = testSupport.generatedTestScript(); + + Runfiles runfiles = runfilesBuilder.build(); + RunfilesSupport runfilesSupport = + RunfilesSupport.withExecutable(ruleContext, runfiles, executable); + + return new RuleConfiguredTargetBuilder(ruleContext) + .setFilesToBuild(filesToBuildBuilder.build()) + .add(XcodeProvider.class, xcodeProvider) + .add(RunfilesProvider.class, RunfilesProvider.simple(runfiles)) + .add( + ExecutionInfoProvider.class, + new ExecutionInfoProvider(ImmutableMap.of(ExecutionRequirements.REQUIRES_DARWIN, ""))) + .addProvider( + InstrumentedFilesProvider.class, + new CompilationSupport(ruleContext).getInstrumentedFilesProvider(common)) + .addProviders(testSupport.getExtraProviders()) + .setRunfilesSupport(runfilesSupport, executable) + .build(); } + private XcodeProductType getProductType(RuleContext ruleContext) { + if (isXcTest(ruleContext)) { + return XcodeProductType.UNIT_TEST; + } else { + return XcodeProductType.APPLICATION; + } + } + private void addResourceFilesToBuild( RuleContext ruleContext, ObjcProvider objcProvider, NestedSetBuilder<Artifact> filesToBuild) { IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext); - + Iterable<Xcdatamodel> xcdatamodels = Xcdatamodels.xcdatamodels(intermediateArtifacts, objcProvider.get(XCDATAMODEL)); filesToBuild.addAll(Xcdatamodel.outputZips(xcdatamodels)); - + for (Artifact storyboard : objcProvider.get(STORYBOARD)) { filesToBuild.add(intermediateArtifacts.compiledStoryboardZip(storyboard)); } } - protected static boolean isXcTest(RuleContext ruleContext) { - return ruleContext.attributes().get(IS_XCTEST, Type.BOOLEAN); - } - - /** Returns the {@link XcTestAppProvider} of the {@code xctest_app} attribute. */ - protected static XcTestAppProvider xcTestAppProvider(RuleContext ruleContext) { - return ruleContext.getPrerequisite(XCTEST_APP, Mode.TARGET, XcTestAppProvider.class); - } - private ObjcCommon common(RuleContext ruleContext) { ImmutableList<SdkFramework> extraSdkFrameworks = isXcTest(ruleContext) ? AUTOMATIC_SDK_FRAMEWORKS_FOR_XCTEST : ImmutableList.<SdkFramework>of(); @@ -179,7 +217,7 @@ public abstract class IosTest implements RuleConfiguredTargetFactory { if (isXcTest(ruleContext)) { extraDepObjcProviders.add(xcTestAppProvider(ruleContext).getObjcProvider()); } - + // Add the memleaks library if the --ios_memleaks flag is true. The library pauses the test // after all tests have been executed so that leaks can be run. ObjcConfiguration config = ruleContext.getFragment(ObjcConfiguration.class); @@ -191,4 +229,14 @@ public abstract class IosTest implements RuleConfiguredTargetFactory { new ObjcLibrary.ExtraImportLibraries(ObjcRuleClasses.j2ObjcLibraries(ruleContext)), extraDepObjcProviders); } + + protected static boolean isXcTest(RuleContext ruleContext) { + return ruleContext.attributes().get(IS_XCTEST, Type.BOOLEAN); + } + + /** Returns the {@link XcTestAppProvider} of the {@code xctest_app} attribute. */ + protected static XcTestAppProvider xcTestAppProvider(RuleContext ruleContext) { + return ruleContext.getPrerequisite(XCTEST_APP, Mode.TARGET, XcTestAppProvider.class); + } + } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosTestRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTestRule.java new file mode 100644 index 0000000000..d2c2e7457e --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTestRule.java @@ -0,0 +1,38 @@ +// 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.devtools.build.lib.analysis.BaseRuleClasses; +import com.google.devtools.build.lib.analysis.RuleDefinition; +import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType; + +/** + * Rule definition for {@code ios_test} rule in Bazel. + */ +public class IosTestRule extends AbstractIosTestRule { + @Override + public Metadata getMetadata() { + return RuleDefinition.Metadata.builder() + .name("ios_test") + .type(RuleClassType.TEST) + .ancestors( + BaseRuleClasses.BaseRule.class, + BaseRuleClasses.TestBaseRule.class, + ObjcRuleClasses.IosTestBaseRule.class, + ObjcRuleClasses.SimulatorRule.class) + .factoryClass(IosTest.class) + .build(); + } +} |