|
6 | 6 | import subprocess |
7 | 7 | import sys |
8 | 8 |
|
9 | | -args = [os.environ['RUST_ANDROID_GRADLE_CC'], os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG']] + sys.argv[1:] |
| 9 | +rustcc = os.environ['RUST_ANDROID_GRADLE_CC'] |
| 10 | + |
| 11 | +if sys.platform == 'msys' or sys.platform == 'cygwin': |
| 12 | + import ctypes |
| 13 | + |
| 14 | + cygdll = 'cygwin1.dll' if sys.platform == 'cygwin' else 'msys-2.0.dll' |
| 15 | + cygwin = ctypes.cdll.LoadLibrary(cygdll) |
| 16 | + |
| 17 | + def win2posix(path): |
| 18 | + CCP_WIN_W_TO_POSIX = 3 |
| 19 | + size = cygwin.cygwin_conv_path(CCP_WIN_W_TO_POSIX, path, 0, 0) |
| 20 | + retval = ctypes.create_string_buffer(size) |
| 21 | + cygwin.cygwin_conv_path(CCP_WIN_W_TO_POSIX, path, retval, size) |
| 22 | + return retval.value.decode() |
| 23 | + |
| 24 | + rustcc = win2posix(rustcc) |
| 25 | + |
| 26 | +args = [rustcc, os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG']] + sys.argv[1:] |
| 27 | + |
| 28 | +linkargfileName = '' |
| 29 | +if (sys.platform == 'msys' or sys.platform == 'cygwin') and len(''.join(args)) > 8191: |
| 30 | + import codecs |
| 31 | + import tempfile |
| 32 | + |
| 33 | + def posix2win(path): |
| 34 | + CCP_POSIX_TO_WIN_W = 1 |
| 35 | + size = cygwin.cygwin_conv_path(CCP_POSIX_TO_WIN_W, str(path).encode(), 0, 0) |
| 36 | + retval = ctypes.create_unicode_buffer(size) |
| 37 | + cygwin.cygwin_conv_path(CCP_POSIX_TO_WIN_W, str(path).encode(), retval, size) |
| 38 | + return retval.value |
| 39 | + |
| 40 | + # response file should be use UTF-16 with BOM |
| 41 | + linkargfile = tempfile.NamedTemporaryFile(delete=False) |
| 42 | + linkargfile.write(codecs.BOM_UTF16_LE) |
| 43 | + linkargfile.write('\n'.join(sys.argv[1:]).encode('utf-16-le')) |
| 44 | + linkargfile.close() |
| 45 | + linkargfileName = linkargfile.name |
| 46 | + linkargfileNameW = posix2win(linkargfileName) |
| 47 | + args = [rustcc, os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG'], '@' + linkargfileNameW] |
| 48 | + |
10 | 49 |
|
11 | 50 | # This only appears when the subprocess call fails, but it's helpful then. |
12 | 51 | printable_cmd = ' '.join(pipes.quote(arg) for arg in args) |
|
21 | 60 | with open(linkargs[0][1:]) as f: |
22 | 61 | sys_argv = f.read().splitlines() |
23 | 62 | shutil.copyfile(sys_argv[sys_argv.index('-o') + 1], os.environ['RUST_ANDROID_GRADLE_TARGET']) |
| 63 | +if linkargfileName != '': |
| 64 | + os.unlink(linkargfileName) |
24 | 65 | sys.exit(code) |
0 commit comments