Skip to content

Commit d69a5ac

Browse files
committed
make compatible with windows and MinGW
1 parent 9500cbf commit d69a5ac

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

pygdbmi/example.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
#!/usr/bin/env python
2-
from pygdbmi.gdbcontroller import GdbController
32
import subprocess
43
import os
4+
import sys
5+
from pygdbmi.gdbcontroller import GdbController
6+
from distutils.spawn import find_executable
57

6-
SAMPLE_C_CODE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'tests/sample_c_app')
8+
SAMPLE_C_CODE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'tests', 'sample_c_app')
79
SAMPLE_C_BINARY = os.path.join(SAMPLE_C_CODE_DIR, 'pygdbmiapp.a')
10+
PYTHON3 = sys.version_info.major == 3
11+
USING_WINDOWS = os.name == 'nt'
12+
13+
if USING_WINDOWS:
14+
SAMPLE_C_BINARY = SAMPLE_C_BINARY.replace('\\', '/')
15+
MAKE_CMD = 'mingw32-make.exe'
16+
else:
17+
MAKE_CMD = 'make'
818

919

1020
def main(verbose=True):
@@ -14,7 +24,11 @@ def main(verbose=True):
1424
"""
1525

1626
# Build C program
17-
subprocess.check_output(["make", "-C", SAMPLE_C_CODE_DIR, '--quiet'])
27+
find_executable(MAKE_CMD)
28+
if not find_executable(MAKE_CMD):
29+
print('Could not find executable "%s". Ensure it is installed and on your $PATH.' % MAKE_CMD)
30+
exit(1)
31+
subprocess.check_output([MAKE_CMD, "-C", SAMPLE_C_CODE_DIR, '--quiet'])
1832

1933
# Initialize object that manages gdb subprocess
2034
gdbmi = GdbController(verbose=verbose)

pygdbmi/gdbcontroller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,14 @@ def _get_responses_windows(self, timeout_sec, verbose):
228228
while(True):
229229
try:
230230
self.gdb_process.stdout.flush()
231-
raw_output = self.gdb_process.stdout.read()
231+
raw_output = self.gdb_process.stdout.readline()
232232
responses += self._get_responses_list(raw_output, 'stdout', verbose)
233233
except IOError:
234234
pass
235235

236236
try:
237237
self.gdb_process.stderr.flush()
238-
raw_output = self.gdb_process.stderr.read()
238+
raw_output = self.gdb_process.stderr.readline()
239239
responses += self._get_responses_list(raw_output, 'stderr', verbose)
240240
except IOError:
241241
pass

0 commit comments

Comments
 (0)