Skip to content

Commit 677e299

Browse files
committed
Add ct_logdir build setting for ct_test rules
If set, will cause common test logs to be sent to the indicated path, instead of $TEST_UNDECLARED_OUTPUTS_DIR While not useful with remote exection, it is convenient when executing locally
1 parent c5917c4 commit 677e299

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ string_flag(
2121
build_setting_default = "",
2222
visibility = ["//visibility:public"],
2323
)
24+
25+
string_flag(
26+
name = "ct_logdir",
27+
build_setting_default = "",
28+
visibility = ["//visibility:public"],
29+
)

MODULE.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
module(
22
name = "rules_erlang",
3-
version = "3.8.4",
43
compatibility_level = 3,
4+
version = "3.8.4",
55
)
66

77
bazel_dep(
88
name = "rules_pkg",
99
version = "0.5.1",
1010
)
11-
1211
bazel_dep(
1312
name = "bazel_skylib",
1413
version = "1.2.0",

private/ct.bzl

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
load(
2+
"@bazel_skylib//rules:common_settings.bzl",
3+
"BuildSettingInfo",
4+
)
15
load("//:erlang_app_info.bzl", "ErlangAppInfo")
26
load(":util.bzl", "erl_libs_contents")
37
load(
@@ -49,6 +53,8 @@ def _impl(ctx):
4953

5054
erl_libs_path = path_join(package, erl_libs_dir)
5155

56+
ct_logdir = ctx.attr._ct_logdir[BuildSettingInfo].value
57+
5258
ct_hooks_args = ""
5359
if len(ctx.attr.ct_hooks) > 0:
5460
ct_hooks_args = "-ct_hooks " + " ".join(ctx.attr.ct_hooks)
@@ -63,6 +69,8 @@ def _impl(ctx):
6369
for k, v in ctx.attr.test_env.items():
6470
test_env_commands.append("export {}=\"{}\"".format(k, v))
6571

72+
log_dir = ct_logdir if ct_logdir != "" else "${TEST_UNDECLARED_OUTPUTS_DIR}"
73+
6674
output = ctx.actions.declare_file(ctx.label.name)
6775
script = """set -eo pipefail
6876
@@ -110,13 +118,15 @@ if [ -n "{package}" ]; then
110118
cd {package}
111119
fi
112120
121+
mkdir -p "{log_dir}"
122+
113123
set -x
114124
"{erlang_home}"/bin/ct_run \\
115125
-no_auto_compile \\
116126
-noinput \\
117127
${{FILTER}} \\
118128
-dir $TEST_SRCDIR/$TEST_WORKSPACE/{dir} \\
119-
-logdir ${{TEST_UNDECLARED_OUTPUTS_DIR}} \\
129+
-logdir "{log_dir}" \\
120130
{ct_hooks_args} \\
121131
-sname {sname}
122132
""".format(
@@ -128,6 +138,7 @@ set -x
128138
sharding_method = ctx.attr.sharding_method,
129139
suite_name = ctx.attr.suite_name,
130140
dir = short_dirname(ctx.files.compiled_suites[0]),
141+
log_dir = log_dir,
131142
ct_hooks_args = ct_hooks_args,
132143
sname = sname(ctx),
133144
test_env = "\n".join(test_env_commands),
@@ -137,6 +148,8 @@ set -x
137148
for k, v in ctx.attr.test_env.items():
138149
test_env_commands.append("set {}={}".format(k, v))
139150

151+
log_dir = ct_logdir if ct_logdir != "" else "%TEST_UNDECLARED_OUTPUTS_DIR%"
152+
140153
output = ctx.actions.declare_file(ctx.label.name + ".bat")
141154
script = """@echo off
142155
SETLOCAL EnableDelayedExpansion
@@ -147,7 +160,7 @@ REM TEST_SRCDIR is provided by bazel but with unix directory separators
147160
set dir=%TEST_SRCDIR%/%TEST_WORKSPACE%/{dir}
148161
set dir=%dir:/=\\%
149162
150-
set logdir=%TEST_UNDECLARED_OUTPUTS_DIR%
163+
set logdir={log_dir}
151164
set logdir=%logdir:/=\\%
152165
subst b: %logdir%
153166
@@ -184,6 +197,8 @@ set FILTER=-suite {suite_name}
184197
185198
if NOT [{package}] == [] cd {package}
186199
200+
if not exist "b:" mkdir b:
201+
187202
echo on
188203
"{erlang_home}\\bin\\ct_run" ^
189204
-no_auto_compile ^
@@ -205,6 +220,7 @@ exit /b %CT_RUN_ERRORLEVEL%
205220
sharding_method = ctx.attr.sharding_method,
206221
suite_name = ctx.attr.suite_name,
207222
dir = short_dirname(ctx.files.compiled_suites[0]),
223+
log_dir = log_dir,
208224
ct_hooks_args = ct_hooks_args,
209225
sname = sname(ctx),
210226
test_env = "\n".join(test_env_commands),
@@ -234,6 +250,9 @@ exit /b %CT_RUN_ERRORLEVEL%
234250
ct_test = rule(
235251
implementation = _impl,
236252
attrs = {
253+
"_ct_logdir": attr.label(
254+
default = Label("//:ct_logdir"),
255+
),
237256
"shard_suite": attr.label(
238257
executable = True,
239258
cfg = "target",

test/MODULE.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ bazel_dep(
77
name = "platforms",
88
version = "0.0.5",
99
)
10-
1110
bazel_dep(
1211
name = "rules_erlang",
1312
version = "3.0.0",

0 commit comments

Comments
 (0)