Skip to content

Commit

Permalink
Fixed Windows installation
Browse files Browse the repository at this point in the history
  • Loading branch information
spietras committed Aug 29, 2020
1 parent c05cca9 commit 37c497d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion conda.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
16 changes: 14 additions & 2 deletions utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 37c497d

Please sign in to comment.