1+ load (
2+ "@bazel_skylib//rules:common_settings.bzl" ,
3+ "BuildSettingInfo" ,
4+ )
15load ("//:erlang_app_info.bzl" , "ErlangAppInfo" )
26load (":util.bzl" , "erl_libs_contents" )
37load (
@@ -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}
111119fi
112120
121+ mkdir -p "{log_dir}"
122+
113123set -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
142155SETLOCAL EnableDelayedExpansion
@@ -147,7 +160,7 @@ REM TEST_SRCDIR is provided by bazel but with unix directory separators
147160set dir=%TEST_SRCDIR%/%TEST_WORKSPACE%/{dir}
148161set dir=%dir:/=\\ %
149162
150- set logdir=%TEST_UNDECLARED_OUTPUTS_DIR%
163+ set logdir={log_dir}
151164set logdir=%logdir:/=\\ %
152165subst b: %logdir%
153166
@@ -184,6 +197,8 @@ set FILTER=-suite {suite_name}
184197
185198if NOT [{package}] == [] cd {package}
186199
200+ if not exist "b:" mkdir b:
201+
187202echo 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%
234250ct_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" ,
0 commit comments