Skip to content

Commit

Permalink
Include memleaks plugin support for experimental_ios_test
Browse files Browse the repository at this point in the history
--
MOS_MIGRATED_REVID=105876178
  • Loading branch information
c-parsons authored and hanwen committed Oct 21, 2015
1 parent 0f1b51e commit e90d67e
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public RuleClass build(RuleClass.Builder builder, final RuleDefinitionEnvironmen
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public RuleClass build(RuleClass.Builder builder, final RuleDefinitionEnvironmen
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public abstract class IosTest implements RuleConfiguredTargetFactory {
public static final String IS_XCTEST = "xctest";
public static final String XCTEST_APP = "xctest_app";
public static final String MEMLEAKS_DEP = "$memleaks_dep";
public static final String MEMLEAKS_PLUGIN = "$memleaks_plugin";

@VisibleForTesting
public static final String REQUIRES_SOURCE_ERROR =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,17 @@ private void registerTestScriptSubstitutionAction() throws InterruptedException
// testIpa is the app actually containing the tests
Artifact testIpa = testIpa();

String runMemleaks =
ruleContext.getFragment(ObjcConfiguration.class).runMemleaks() ? "true" : "false";

// The substitutions below are common for simulator and lab device.
ImmutableList.Builder<Substitution> substitutions = new ImmutableList.Builder<Substitution>()
.add(Substitution.of("%(test_app_ipa)s", testIpa.getRootRelativePathString()))
.add(Substitution.of("%(test_app_name)s", baseNameWithoutIpa(testIpa)))
.add(Substitution.of("%(plugin_jars)s", Artifact.joinRootRelativePaths(":", plugins())));
ImmutableList.Builder<Substitution> substitutions =
new ImmutableList.Builder<Substitution>()
.add(Substitution.of("%(memleaks)s", runMemleaks))
.add(Substitution.of("%(test_app_ipa)s", testIpa.getRootRelativePathString()))
.add(Substitution.of("%(test_app_name)s", baseNameWithoutIpa(testIpa)))
.add(
Substitution.of("%(plugin_jars)s", Artifact.joinRootRelativePaths(":", plugins())));

// xctestIpa is the app bundle being tested
Optional<Artifact> xctestIpa = xctestIpa();
Expand Down Expand Up @@ -240,7 +246,14 @@ private ImmutableMap<String, String> gcovEnv() {
* Jar files for plugins to the test runner. May be empty.
*/
private NestedSet<Artifact> plugins() {
return PrerequisiteArtifacts.nestedSet(ruleContext, "plugins", Mode.TARGET);
NestedSetBuilder<Artifact> pluginArtifacts = NestedSetBuilder.stableOrder();
pluginArtifacts.addTransitive(
PrerequisiteArtifacts.nestedSet(ruleContext, "plugins", Mode.TARGET));
if (ruleContext.getFragment(ObjcConfiguration.class).runMemleaks()) {
pluginArtifacts.addTransitive(
PrerequisiteArtifacts.nestedSet(ruleContext, IosTest.MEMLEAKS_PLUGIN, Mode.TARGET));
}
return pluginArtifacts.build();
}

/**
Expand Down
1 change: 1 addition & 0 deletions tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ filegroup(
"//tools/cpp:srcs",
"//tools/j2objc:srcs",
"//tools/objc:srcs",
"//tools/objc/memleaks:srcs",
"//tools/test:srcs",
"//tools/python:srcs",
],
Expand Down
5 changes: 5 additions & 0 deletions tools/objc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ filegroup(
srcs = [":testrunner_stub"],
)

filegroup(
name = "memleaks_plugin",
srcs = [":memleaks_plugin_stub"],
)

sh_binary(
name = "ibtoolwrapper",
srcs = [":ibtoolwrapper.sh"],
Expand Down
11 changes: 11 additions & 0 deletions tools/objc/memleaks/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package(default_visibility = ["//visibility:public"])

filegroup(
name = "memleaks",
srcs = [":memleaks_stub"],
)

filegroup(
name = "srcs",
srcs = glob(["**"]),
)
7 changes: 7 additions & 0 deletions tools/objc/memleaks/memleaks_stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

(
printf 'Bazel does not yet support memleaks detection for ios_tests.\n'
) >&2

exit 1
7 changes: 7 additions & 0 deletions tools/objc/memleaks_plugin_stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

(
printf 'Bazel does not yet support memleaks detection for ios_tests.\n'
) >&2

exit 1

0 comments on commit e90d67e

Please sign in to comment.