Skip to content

Commit c4e2ed1

Browse files
committed
cleans up build and fixes some errors.
1 parent 054d5e0 commit c4e2ed1

File tree

2 files changed

+236
-208
lines changed

2 files changed

+236
-208
lines changed

builder/__init__.py

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,9 @@ def _convert_line(lne):
290290
def process_output(myproc, out_to_screen, spinner, cmpl, out_queue):
291291
line = b''
292292
err_line = b''
293-
294293
last_line_len = -1
294+
line_updated = False
295+
err_updated = False
295296

296297
event = threading.Event()
297298

@@ -303,23 +304,29 @@ def process_output(myproc, out_to_screen, spinner, cmpl, out_queue):
303304
t = None
304305

305306
while True:
306-
if myproc.poll() is not None:
307-
break
308-
309307
# --- extract line using read(1)
310308
out = myproc.stdout.read(1)
311309
while out:
310+
line_updated = True
312311
line += out
313312
if out == b'\n':
314313
line = _convert_line(line.strip())
315314
if not line:
316315
line = b''
317-
continue
316+
break
318317

319318
out_queue.put(line)
320319

321320
if not spinner and out_to_screen:
322-
if cmpl and (line.startswith('[') or line.startswith('--')):
321+
if (
322+
cmpl and (
323+
line.startswith('[') or
324+
(
325+
line.startswith('--') and
326+
len(line) <= 80
327+
)
328+
)
329+
):
323330
if last_line_len != -1:
324331
sys.stdout.write('\r')
325332

@@ -346,6 +353,7 @@ def process_output(myproc, out_to_screen, spinner, cmpl, out_queue):
346353
out = myproc.stderr.read(1)
347354

348355
while out:
356+
err_updated = True
349357
if not spinner and out_to_screen and cmpl and last_line_len != -1:
350358
sys.stdout.write('\n')
351359
sys.stdout.flush()
@@ -356,7 +364,7 @@ def process_output(myproc, out_to_screen, spinner, cmpl, out_queue):
356364
err_line = _convert_line(err_line.strip())
357365
if not err_line:
358366
err_line = b''
359-
continue
367+
break
360368

361369
out_queue.put(err_line)
362370
if out_to_screen and not spinner:
@@ -367,6 +375,13 @@ def process_output(myproc, out_to_screen, spinner, cmpl, out_queue):
367375

368376
out = myproc.stderr.read(1)
369377

378+
if not err_updated and not line_updated:
379+
if myproc.poll() is not None:
380+
break
381+
382+
err_updated = False
383+
line_updated = False
384+
370385
if t is not None:
371386
event.set()
372387
t.join()
@@ -387,46 +402,54 @@ def spawn(cmd_, out_to_screen=True, spinner=False, env=None, cmpl=False):
387402
if isinstance(cmd_[0], str):
388403
cmd_ = [cmd_[:]]
389404

390-
cmd_ = ' && '.join(' '.join(c) for c in cmd_)
391-
392-
if sys.platform.startswith('darwin'):
393-
if cmd_.startswith('make '):
394-
cmd_ = 'g' + cmd_
395-
396-
if ' make ' in cmd_:
397-
cmd_ = cmd_.replace(' make ', ' gmake ')
398-
399-
if 'GITHUB_RUN_ID' in os.environ:
400-
print(cmd_)
405+
cmd_ = list(' '.join(c) for c in cmd_)
401406

402407
que = queue.Queue()
403408

404409
p = subprocess.Popen(
405-
cmd_,
410+
'bash',
406411
stdout=subprocess.PIPE,
407412
stderr=subprocess.PIPE,
413+
stdin=subprocess.PIPE,
408414
shell=True,
409415
env=env
410416
)
411417

418+
os.set_blocking(p.stdout.fileno(), False)
419+
os.set_blocking(p.stderr.fileno(), False)
420+
412421
proc_thread = threading.Thread(
413422
target=process_output,
414423
args=(p, out_to_screen, spinner, cmpl, que)
415424
)
416425

417426
proc_thread.start()
418-
419427
output_buffer = []
420428

429+
while cmd_:
430+
item = cmd_.pop(0)
431+
if sys.platform.startswith('darwin'):
432+
if item.startswith('make '):
433+
item = 'g' + item
434+
435+
if ' make ' in item:
436+
item = item.replace(' make ', ' gmake ')
437+
438+
if 'GITHUB_RUN_ID' in os.environ:
439+
print(item)
440+
441+
p.stdin.write(item.encode('utf-8') + b'\n')
442+
443+
p.stdin.close()
444+
421445
while proc_thread and proc_thread.is_alive(): # wait for thread to finish
422446
try:
423447
line = que.get_nowait() # or q.get(timeout=.1)
424448
output_buffer.append(line)
425449
except queue.Empty:
426450
pass
427-
428451
try:
429-
proc_thread.join(1)
452+
proc_thread.join(0.025)
430453
except: # NOQA
431454
break
432455

0 commit comments

Comments
 (0)