diff --git a/conda.bzl b/conda.bzl index 4e556f4..564a6ef 100644 --- a/conda.bzl +++ b/conda.bzl @@ -68,7 +68,10 @@ def _install_conda(rctx, installer): # execute installer with flags adjusted to OS if os == "Windows": - result = execute_waitable_windows(rctx, args, quiet=rctx.attr.quiet) + # TODO: fix always returning 0 + # it seems that either miniconda installer returns 0 even on failure or the wrapper does something wrong + # also stdout and stderr are always empty + result = execute_waitable_windows(rctx, args, quiet=rctx.attr.quiet, environment={"CONDA_DLL_SEARCH_MODIFICATION_ENABLE": ""}) else: result = rctx.execute(args, quiet=rctx.attr.quiet) diff --git a/utils.bzl b/utils.bzl index 885edb3..c9e7ed9 100644 --- a/utils.bzl +++ b/utils.bzl @@ -62,10 +62,22 @@ def get_arch(rctx): return get_arch_linux(rctx) -def execute_waitable_windows(rctx, args, tmp_script="tmp.bat", **kwargs): +TMP_SCRIPT_TEMPLATE = """ +@echo off +if "%OS%"=="Windows_NT" setlocal +{envs} +call {args} +set "EXITCODE=%ERRORLEVEL%" +if "%OS%"=="Windows_NT" ( endlocal & exit /b "%EXITCODE%" ) +exit /b "%EXITCODE%"" +""" + + +def execute_waitable_windows(rctx, args, environment={}, tmp_script="tmp.bat", **kwargs): rctx.file( tmp_script, - content = """start /wait "" {}""".format(" ".join([str(a) for a in args])) + content = TMP_SCRIPT_TEMPLATE.format(envs='\n'.join(["set \"{}={}\"".format(k, v) for k, v in environment.items()]), + args=" ".join([str(a) for a in args])) ) result = rctx.execute([rctx.path(tmp_script)], **kwargs) rctx.delete(tmp_script)