|
5 | 5 | import subprocess
|
6 | 6 | import sys
|
7 | 7 |
|
8 |
| -args = [os.environ['RUST_ANDROID_GRADLE_CC'], os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG']] + sys.argv[1:] |
| 8 | +args = [ |
| 9 | + os.environ["RUST_ANDROID_GRADLE_CC"], |
| 10 | + os.environ["RUST_ANDROID_GRADLE_CC_LINK_ARG"], |
| 11 | +] + sys.argv[1:] |
| 12 | + |
| 13 | + |
| 14 | +def update_in_place(arglist): |
| 15 | + # The `gcc` library is not included starting from NDK version 23. |
| 16 | + # Work around by using `unwind` replacement. |
| 17 | + ndk_major_version = os.environ["CARGO_NDK_MAJOR_VERSION"] |
| 18 | + if ndk_major_version.isdigit(): |
| 19 | + if 23 <= int(ndk_major_version): |
| 20 | + for i, arg in enumerate(arglist): |
| 21 | + if arg.startswith("-lgcc"): |
| 22 | + # This is one way to preserve line endings. |
| 23 | + arglist[i] = "-lunwind" + arg[len("-lgcc") :] |
| 24 | + |
| 25 | + |
| 26 | +update_in_place(args) |
| 27 | + |
| 28 | +for arg in args: |
| 29 | + if arg.startswith("@"): |
| 30 | + fileargs = open(arg[1:], "r").read().splitlines(keepends=True) |
| 31 | + update_in_place(fileargs) |
| 32 | + open(arg[1:], "w").write("".join(fileargs)) |
9 | 33 |
|
10 |
| -# The `gcc` library is not included starting from NDK version 23. |
11 |
| -# Work around by using `unwind` replacement. |
12 |
| -ndk_major_version = os.environ['CARGO_NDK_MAJOR_VERSION'] |
13 |
| -if ndk_major_version.isdigit(): |
14 |
| - if 23 <= int(ndk_major_version): |
15 |
| - for i, arg in enumerate(args): |
16 |
| - if arg == "-lgcc": |
17 |
| - args[i] = "-lunwind" |
18 | 34 |
|
19 | 35 | # This only appears when the subprocess call fails, but it's helpful then.
|
20 |
| -printable_cmd = ' '.join(pipes.quote(arg) for arg in args) |
| 36 | +printable_cmd = " ".join(pipes.quote(arg) for arg in args) |
21 | 37 | print(printable_cmd)
|
22 | 38 |
|
23 | 39 | sys.exit(subprocess.call(args))
|
0 commit comments