Skip to content

Commit

Permalink
Make redex.py Windows-compatible
Browse files Browse the repository at this point in the history
Summary: Mask some features that are unavailable on Windows. Core functionality remains.

Reviewed By: minjang

Differential Revision: D22892446

fbshipit-source-id: db2933b8a7b22796676a8decf8f5cac5d5e00031
  • Loading branch information
agampe authored and facebook-github-bot committed Aug 3, 2020
1 parent 073444f commit e19a38b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions redex.py
Expand Up @@ -50,6 +50,9 @@
)


IS_WINDOWS = os.name == "nt"


def patch_zip_file():
# See http://bugs.python.org/issue14315
old_decode_extra = zipfile.ZipInfo._decodeExtra
Expand Down Expand Up @@ -102,6 +105,7 @@ def write_debugger_command(dbg, src_root, args):
The choice of debugger is governed by `dbg` which can be either "gdb" or "lldb".
"""
assert not IS_WINDOWS # It's a Linux/Mac script...
fd, script_name = tempfile.mkstemp(suffix=".sh", prefix="redex-{}-".format(dbg))

# Parametrise redex binary.
Expand All @@ -116,7 +120,8 @@ def write_debugger_command(dbg, src_root, args):
f.write(" ".join(dbg_prefix(dbg, src_root)))
f.write(" ")
f.write(" ".join(args))
os.fchmod(fd, 0o775)
if not IS_WINDOWS:
os.fchmod(fd, 0o775) # This is unsupported on windows.

return script_name

Expand Down Expand Up @@ -257,7 +262,13 @@ def maybe_reprint_error(lines, term_handler):


def run_and_stream_stderr(args, env, pass_fds):
proc = subprocess.Popen(args, env=env, pass_fds=pass_fds, stderr=subprocess.PIPE)
if IS_WINDOWS:
# Windows does not support `pass_fds` parameter.
proc = subprocess.Popen(args, env=env, stderr=subprocess.PIPE)
else:
proc = subprocess.Popen(
args, env=env, pass_fds=pass_fds, stderr=subprocess.PIPE
)

def stream_and_return():
err_out = []
Expand Down Expand Up @@ -468,6 +479,11 @@ def run():
if returncode == -6: # SIGABRT
maybe_reprint_error(err_out, term_handler)

if IS_WINDOWS:
raise RuntimeError(
"redex-all crashed with exit code {}!".format(returncode)
)

gdb_script_name = write_debugger_command(
"gdb", state.args.debug_source_root, args
)
Expand Down

0 comments on commit e19a38b

Please sign in to comment.