From 1f4ce8034892aa490269aacf2fd4c74122d72920 Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Mon, 4 May 2015 15:07:29 +0000 Subject: Add ios_test.sh.bazel_template -- MOS_MIGRATED_REVID=92725547 --- .../lib/rules/objc/ExperimentalIosTestRule.java | 1 + .../build/lib/rules/objc/IosDeviceProvider.java | 3 ++- .../devtools/build/lib/rules/objc/TestSupport.java | 25 ++++++++++++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) (limited to 'src/main/java/com/google') 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 349b3176f5..09602971cd 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 @@ -52,6 +52,7 @@ public final class ExperimentalIosTestRule implements RuleDefinition { .value(env.getLabel("//tools/objc/sim_devices:default"))) .add(attr("$test_template", LABEL) .value(env.getLabel("//tools/objc:ios_test.sh.bazel_template"))) + .add(attr("$test_runner", LABEL).value(env.getLabel("//tools/objc:testrunner"))) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceProvider.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceProvider.java index 98cf21da51..5475ee9ea8 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceProvider.java @@ -80,7 +80,8 @@ public final class IosDeviceProvider implements TransitiveInfoProvider { public IosTestSubstitutionProvider iosTestSubstitutionProvider() { return new IosTestSubstitutionProvider(ImmutableList.of( Substitution.of("%(device_type)s", getType()), - Substitution.of("%(simulator_sdk)s", getIosVersion()) + Substitution.of("%(simulator_sdk)s", getIosVersion()), + Substitution.of("%(locale)s", getLocale()) )); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/TestSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/TestSupport.java index b46ccf4763..173c781f49 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/TestSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/TestSupport.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.rules.objc; +import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; @@ -29,8 +30,6 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.util.FileType; -import java.util.List; - /** * Support for running XcTests. */ @@ -62,7 +61,7 @@ class TestSupport { // xctestIpa is the app bundle being tested Artifact xctestIpa = xctestIpa(); - List substitutions = new ImmutableList.Builder() + ImmutableList.Builder substitutions = new ImmutableList.Builder() .add(Substitution.of("%(test_app_ipa)s", testIpa.getRootRelativePathString())) .add(Substitution.of("%(test_app_name)s", baseNameWithoutIpa(testIpa))) @@ -71,14 +70,18 @@ class TestSupport { .add(Substitution.of("%(iossim_path)s", iossim().getRootRelativePath().getPathString())) - .addAll(deviceSubstitutions().getSubstitutionsForTestRunnerScript()) + .addAll(deviceSubstitutions().getSubstitutionsForTestRunnerScript()); - .build(); + Optional testRunner = testRunner(); + if (testRunner.isPresent()) { + substitutions.add( + Substitution.of("%(testrunner_binary)s", testRunner.get().getRootRelativePathString())); + } Artifact template = ruleContext.getPrerequisiteArtifact("$test_template", Mode.TARGET); ruleContext.registerAction(new TemplateExpansionAction(ruleContext.getActionOwner(), - template, generatedTestScript(), substitutions, /*executable=*/true)); + template, generatedTestScript(), substitutions.build(), /*executable=*/true)); } private IosTestSubstitutionProvider deviceSubstitutions() { @@ -101,6 +104,13 @@ class TestSupport { return ruleContext.getPrerequisiteArtifact("$iossim", Mode.HOST); } + /** + * Gets the binary of the testrunner attribute, if there is one. + */ + private Optional testRunner() { + return Optional.fromNullable(ruleContext.getPrerequisiteArtifact("$test_runner", Mode.TARGET)); + } + /** * Adds all files needed to run this test to the passed Runfiles builder. */ @@ -110,7 +120,8 @@ class TestSupport { .addArtifact(xctestIpa()) .addArtifact(generatedTestScript()) .addArtifact(iossim()) - .addTransitiveArtifacts(deviceRunfiles()); + .addTransitiveArtifacts(deviceRunfiles()) + .addArtifacts(testRunner().asSet()); return this; } -- cgit v1.2.3