aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSamuel Freilich <sfreilich@google.com>2019-10-08 12:39:11 -0400
committerc-parsons <cparsons@google.com>2019-10-08 12:39:11 -0400
commit376680d27667c09f4ff1021fa3fc442e02819031 (patch)
tree15a03a0b41d79650642595ed6a6004306f97c415 /lib
parent0e9da0dd08b763a5e3eece10a5abba5df6b8e46f (diff)
downloadbazel-skylib-376680d27667c09f4ff1021fa3fc442e02819031.tar.gz
Expose target_under_test's bin and genfiles path (#202)
The output directories for the target under test may differ when the target is under a config transition (config_settings is passed to analysistest.make). Since analysis tests may assert about the command-line of generated actions, and those command-lines may contain paths to output files, this is useful information to expose.
Diffstat (limited to 'lib')
-rw-r--r--lib/unittest.bzl38
1 files changed, 33 insertions, 5 deletions
diff --git a/lib/unittest.bzl b/lib/unittest.bzl
index 873d8f0..718eca4 100644
--- a/lib/unittest.bzl
+++ b/lib/unittest.bzl
@@ -126,11 +126,16 @@ def _make(impl, attrs = {}):
toolchains = [TOOLCHAIN_TYPE],
)
-_ActionInfo = provider(fields = ["actions"])
+_ActionInfo = provider(fields = ["actions", "bin_path", "genfiles_path"])
def _action_retrieving_aspect_impl(target, ctx):
- _ignore = [ctx]
- return [_ActionInfo(actions = target.actions)]
+ return [
+ _ActionInfo(
+ actions = target.actions,
+ bin_path = ctx.bin_dir.path,
+ genfiles_path = ctx.genfiles_dir.path,
+ ),
+ ]
_action_retrieving_aspect = aspect(
attr_aspects = [],
@@ -463,8 +468,29 @@ def _target_actions(env):
"""
# Validate?
- dep = _target_under_test(env)
- return dep[_ActionInfo].actions
+ return _target_under_test(env)[_ActionInfo].actions
+
+def _target_bin_dir_path(env):
+ """Returns ctx.bin_dir.path for the target under test.
+
+ Args:
+ env: The test environment returned by `analysistest.begin`.
+
+ Returns:
+ Output bin dir path string.
+ """
+ return _target_under_test(env)[_ActionInfo].bin_path
+
+def _target_genfiles_dir_path(env):
+ """Returns ctx.genfiles_dir.path for the target under test.
+
+ Args:
+ env: The test environment returned by `analysistest.begin`.
+
+ Returns:
+ Output genfiles dir path string.
+ """
+ return _target_under_test(env)[_ActionInfo].genfiles_path
def _target_under_test(env):
"""Returns the target under test.
@@ -506,5 +532,7 @@ analysistest = struct(
end = _end_analysis_test,
fail = _fail,
target_actions = _target_actions,
+ target_bin_dir_path = _target_bin_dir_path,
+ target_genfiles_dir_path = _target_genfiles_dir_path,
target_under_test = _target_under_test,
)