fix_msvc_output.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import subprocess
  2. import sys
  3. import process_command_files as pcf
  4. import process_whole_archive_option as pwa
  5. def out2err(cmd):
  6. return subprocess.Popen(cmd, stdout=sys.stderr).wait()
  7. def decoding_needed(strval):
  8. if sys.version_info >= (3, 0, 0):
  9. return isinstance(strval, bytes)
  10. else:
  11. return False
  12. def out2err_cut_first_line(cmd):
  13. p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
  14. first_line = True
  15. while True:
  16. line = p.stdout.readline()
  17. line = line.decode('utf-8') if decoding_needed(line) else line
  18. if not line:
  19. break
  20. if first_line:
  21. sys.stdout.write(line)
  22. first_line = False
  23. else:
  24. sys.stderr.write(line)
  25. return p.wait()
  26. if __name__ == '__main__':
  27. mode = sys.argv[1]
  28. args, wa_peers, wa_libs = pwa.get_whole_archive_peers_and_libs(pcf.skip_markers(sys.argv[2:]))
  29. cmd = pwa.ProcessWholeArchiveOption('WINDOWS', wa_peers, wa_libs).construct_cmd(args)
  30. run = out2err
  31. if mode in ('cl', 'ml'):
  32. # First line of cl.exe and ml64.exe stdout is useless: it prints input file
  33. run = out2err_cut_first_line
  34. sys.exit(run(cmd))