Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 # Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import getopt | 6 import getopt |
| 7 import sys | 7 import sys |
| 8 import subprocess | 8 import subprocess |
| 9 import re | 9 import re |
| 10 import os | 10 import os |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 # endif | 50 # endif |
| 51 | 51 |
| 52 for filename in args: | 52 for filename in args: |
| 53 # normalize the filename to avoid any DOS-type funkiness | 53 # normalize the filename to avoid any DOS-type funkiness |
| 54 filename = os.path.abspath(filename) | 54 filename = os.path.abspath(filename) |
| 55 filename = filename.replace('\\', '/') | 55 filename = filename.replace('\\', '/') |
| 56 | 56 |
| 57 # | 57 # |
| 58 # Run the C compiler as a preprocessor and pipe the output into a string | 58 # Run the C compiler as a preprocessor and pipe the output into a string |
| 59 # | 59 # |
| 60 p = subprocess.Popen(['cl.exe', | 60 cl_command = ['cl.exe', |
| 61 '/nologo', | 61 '/nologo', |
| 62 '/D__ASSEMBLER__', | 62 '/D__ASSEMBLER__', |
| 63 '/DNACL_BUILD_ARCH=' + nacl_build_arch, | 63 '/DNACL_BUILD_ARCH=' + nacl_build_arch, |
| 64 '/DNACL_BUILD_SUBARCH=' + str(nacl_build_subarch), | 64 '/DNACL_BUILD_SUBARCH=' + str(nacl_build_subarch), |
| 65 '/DNACL_WINDOWS=1', | 65 '/DNACL_WINDOWS=1', |
| 66 '/TP', | 66 '/TP', |
| 67 '/E', | 67 '/E', |
| 68 '/I' + nacl_path, | 68 '/I' + nacl_path, |
| 69 filename], | 69 filename] |
| 70 p = subprocess.Popen(cl_command, | |
| 70 shell=True, | 71 shell=True, |
| 71 stdout=subprocess.PIPE, | 72 stdout=subprocess.PIPE, |
| 72 stderr=open(os.devnull, 'w')) | 73 stderr=subprocess.PIPE) |
| 73 cl_output = p.communicate()[0] | 74 cl_results = p.communicate() |
| 75 cl_status = p.wait() | |
|
scottmg
2015/11/04 23:08:40
It's weird to communicate() and then wait() as the
Roland McGrath
2015/11/04 23:15:33
Done.
| |
| 76 cl_output = cl_results[0] | |
| 77 cl_errors = cl_results[1] | |
| 78 | |
| 79 if cl_status != 0: | |
| 80 print >>sys.stderr, 'FAILED: %s\n%s\n' % (' '.join(cl_command), | |
| 81 cl_errors) | |
| 82 return cl_status | |
| 74 | 83 |
| 75 # | 84 # |
| 76 # Uncomment this if you need to see exactly what the MSVC preprocessor | 85 # Uncomment this if you need to see exactly what the MSVC preprocessor |
| 77 # has done to your input file. | 86 # has done to your input file. |
| 78 #print >>sys.stderr, '-------------------------------------' | 87 #print >>sys.stderr, '-------------------------------------' |
| 79 #print >>sys.stderr, '# PREPROCESSOR OUTPUT BEGINS #' | 88 #print >>sys.stderr, '# PREPROCESSOR OUTPUT BEGINS #' |
| 80 #print >>sys.stderr, '-------------------------------------' | 89 #print >>sys.stderr, '-------------------------------------' |
| 81 #print >>sys.stderr, cl_output | 90 #print >>sys.stderr, cl_output |
| 82 #print >>sys.stderr, '-------------------------------------' | 91 #print >>sys.stderr, '-------------------------------------' |
| 83 #print >>sys.stderr, '# PREPROCESSOR OUTPUT ENDS #' | 92 #print >>sys.stderr, '# PREPROCESSOR OUTPUT ENDS #' |
| 84 #print >>sys.stderr, '-------------------------------------' | 93 #print >>sys.stderr, '-------------------------------------' |
| 85 | 94 |
| 86 # GNU uses '#<linenum> for line number directives; MSVC uses | 95 # GNU uses '#<linenum> for line number directives; MSVC uses |
| 87 # '#line <linenum>.' | 96 # '#line <linenum>.' |
| 88 foo = re.compile(r'^#line ', re.MULTILINE) | 97 foo = re.compile(r'^#line ', re.MULTILINE) |
| 89 cl_output = foo.sub(r'#', cl_output) | 98 cl_output = foo.sub(r'#', cl_output) |
| 90 | 99 |
| 91 if p.wait() == 0: # success | 100 # |
|
scottmg
2015/11/04 23:08:40
Although I see it was already like this. Well.
| |
| 92 # | 101 # Pipe the preprocessor output into the assembler |
| 93 # Pipe the preprocessor output into the assembler | 102 # |
| 94 # | 103 as_command = [nacl_path + as_exe, |
| 95 p = subprocess.Popen([nacl_path + as_exe, | 104 '-defsym','@feat.00=1', |
| 96 '-defsym','@feat.00=1', | 105 '--' + str(nacl_build_subarch), |
| 97 '--' + str(nacl_build_subarch), | 106 '-o', output_filename] |
| 98 '-o', output_filename ], | 107 p = subprocess.Popen(as_command, |
| 99 stdin=subprocess.PIPE, | 108 stdin=subprocess.PIPE, |
| 100 stderr=subprocess.PIPE) | 109 stderr=subprocess.PIPE) |
| 101 as_output, as_error = p.communicate(cl_output) | 110 as_output, as_error = p.communicate(cl_output) |
| 111 as_status = p.wait() | |
|
scottmg
2015/11/04 23:08:40
Same.
Roland McGrath
2015/11/04 23:15:33
Done.
| |
| 102 | 112 |
| 103 # | 113 # |
| 104 # massage the assembler stderr into a format that Visual Studio likes | 114 # massage the assembler stderr into a format that Visual Studio likes |
| 105 # | 115 # |
| 106 as_error = re.sub(r'\{standard input\}', filename, as_error) | 116 as_error = re.sub(r'\{standard input\}', filename, as_error) |
| 107 as_error = re.sub(r':([0-9]+):', r'(\1) :', as_error) | 117 as_error = re.sub(r':([0-9]+):', r'(\1) :', as_error) |
| 108 as_error = re.sub(r'Error', 'error', as_error) | 118 as_error = re.sub(r'Error', 'error', as_error) |
| 109 as_error = re.sub(r'Warning', 'warning', as_error) | 119 as_error = re.sub(r'Warning', 'warning', as_error) |
| 110 | 120 |
| 111 if as_error: | 121 if as_error: |
| 112 print >>sys.stderr, as_error | 122 print >>sys.stderr, as_error |
| 113 | 123 |
| 114 # endif | 124 if as_status != 0: |
| 125 print >>sys.stderr, 'FAILED: %s\n' % ' '.join(as_command) | |
| 126 return as_status | |
| 127 | |
| 115 # endfor | 128 # endfor |
| 116 | 129 |
| 117 except getopt.error, e: | 130 except getopt.error, e: |
| 118 print >>sys.stderr, str(e) | 131 print >>sys.stderr, str(e) |
| 119 print >>sys.stderr, ['Usage: ', | 132 print >>sys.stderr, ['Usage: ', |
| 120 argv[0], | 133 argv[0], |
| 121 '-a {Win32|x64} -o output_file [-p native_client_path] input_file'] | 134 '-a {Win32|x64} -o output_file [-p native_client_path] input_file'] |
| 122 # endtry | 135 # endtry |
| 123 | 136 |
| 124 # enddef | 137 # enddef |
| 125 | 138 |
| 126 if __name__ == '__main__': | 139 if __name__ == '__main__': |
| 127 sys.exit(main(sys.argv)) | 140 sys.exit(main(sys.argv)) |
| 128 # endif | 141 # endif |
| OLD | NEW |