fix_msvc_output.py 1.3 KB

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