Add --[no]instrument_test_targets option to Blaze
When true (the default), test rules included by --instrumentation_filter are instrumented. When false, test rules are excluded from instrumentation (whether or not their names would be matched by --instrumentation_filter).
This option provides a superior way to exclude test rules from instrumentation, compared to setting --instrumentation_filter exclusions based on test rule naming conventions. Naming conventions vary from language to language and are not always followed. Blaze already has enforced semantics for test targets (test rule build function names _must_ end in "_test", see TargetUtils.isTestRule). In general, when either option is available, it's better to rely on enforced semantics than unenforced conventions.
Note that this default preserves present behavior. In the future, I think it would make sense to:
* Change the default value of --instrument_test_targets to false.
* Change the default value of --instrumentation_filter to an empty string (match everything).
RELNOTES: Add --instrument_test_targets option.
--
MOS_MIGRATED_REVID=124732226
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
index f7671a2..3977caf 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
@@ -1284,6 +1284,13 @@
}
/**
+ * Returns true if the target for this context is a test target.
+ */
+ public boolean isTestTarget() {
+ return TargetUtils.isTestRule(getTarget());
+ }
+
+ /**
* Returns true if runfiles support should create the runfiles tree, or
* false if it should just create the manifest.
*/
@@ -1298,7 +1305,7 @@
// b. host tools could potentially use data files, but currently don't
// (they're run from the execution root, not a runfiles tree).
// Currently hostConfiguration.buildRunfiles() returns true.
- if (TargetUtils.isTestRule(getTarget())) {
+ if (isTestTarget()) {
// Tests are only executed during testing (duh),
// and their runfiles are generated lazily on local
// execution (see LocalTestStrategy). Therefore, it