|
1 | 1 | from __future__ import absolute_import, print_function, unicode_literals |
2 | 2 |
|
| 3 | +import codecs |
3 | 4 | import os |
4 | 5 | import pipes |
5 | 6 | import shutil |
6 | 7 | import subprocess |
7 | 8 | import sys |
| 9 | +import tempfile |
| 10 | + |
| 11 | +rustcc = os.environ['RUST_ANDROID_GRADLE_CC'] |
| 12 | + |
| 13 | +if sys.platform == 'msys' or sys.platform == 'cygwin': |
| 14 | + rustcc = subprocess.check_output(['/usr/bin/cygpath', '-u', rustcc]).decode('ascii').strip() |
| 15 | + |
| 16 | +args = [rustcc, os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG']] + sys.argv[1:] |
| 17 | + |
| 18 | +linkargfileName = '' |
| 19 | +if (sys.platform == 'msys' or sys.platform == 'cygwin') and len(''.join(args)) > 8191: |
| 20 | + # response file should be use UTF-16 with BOM |
| 21 | + linkargfile = tempfile.NamedTemporaryFile(delete=False) |
| 22 | + linkargfile.write(codecs.BOM_UTF16_LE) |
| 23 | + linkargfile.write('\n'.join(sys.argv[1:]).encode('utf-16-le')) |
| 24 | + linkargfile.close() |
| 25 | + linkargfileName = linkargfile.name |
| 26 | + linkargfileNameW = subprocess.check_output(['/usr/bin/cygpath', '-w', linkargfileName]).decode('ascii').strip() |
| 27 | + args = [rustcc, os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG'], '@' + linkargfileNameW] |
8 | 28 |
|
9 | | -args = [os.environ['RUST_ANDROID_GRADLE_CC'], os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG']] + sys.argv[1:] |
10 | 29 |
|
11 | 30 | # This only appears when the subprocess call fails, but it's helpful then. |
12 | 31 | printable_cmd = ' '.join(pipes.quote(arg) for arg in args) |
|
20 | 39 | with open(linkargs[0][1:]) as f: |
21 | 40 | sys_argv = f.read().splitlines() |
22 | 41 | shutil.copyfile(sys_argv[sys_argv.index('-o') + 1], os.environ['RUST_ANDROID_GRADLE_TARGET']) |
| 42 | +if linkargfileName != '': |
| 43 | + os.unlink(linkargfileName) |
23 | 44 | sys.exit(code) |
0 commit comments