OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 3 # Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
6 | 6 |
7 import os | 7 import os |
8 import sys | 8 import sys |
9 import utils | 9 import utils |
10 import subprocess | 10 import subprocess |
11 | 11 |
12 def is_executable(path): | 12 def is_executable(path): |
13 return os.path.isfile(path) and os.access(path, os.X_OK) | 13 return os.path.isfile(path) and os.access(path, os.X_OK) |
14 | 14 |
15 def which(program): | 15 def which(program): |
16 for path in os.environ["PATH"].split(os.pathsep): | 16 for path in os.environ["PATH"].split(os.pathsep): |
17 path = path.strip('"') | 17 path = path.strip('"') |
18 program_path = os.path.join(path, program) | 18 program_path = os.path.join(path, program) |
19 if is_executable(program_path): | 19 if is_executable(program_path): |
20 return program_path | 20 return program_path |
21 | 21 |
22 return None | 22 return None |
23 | 23 |
24 def relative_to_fletch_root(*target): | 24 def relative_to_dartino_root(*target): |
25 fletch_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 25 dartino_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
26 return os.path.join(fletch_path, *target) | 26 return os.path.join(dartino_path, *target) |
27 | 27 |
28 def invoke_clang(args): | 28 def invoke_clang(args): |
29 os_name = utils.GuessOS() | 29 os_name = utils.GuessOS() |
30 if os_name == "macos": | 30 if os_name == "macos": |
31 os_name = "mac" | 31 os_name = "mac" |
32 args.extend([ | 32 args.extend([ |
33 '-isysroot', | 33 '-isysroot', |
34 subprocess.check_output(['xcrun', '--show-sdk-path']).strip()]) | 34 subprocess.check_output(['xcrun', '--show-sdk-path']).strip()]) |
35 clang_bin = relative_to_fletch_root( | 35 clang_bin = relative_to_dartino_root( |
36 "third_party", "clang", os_name, "bin", "clang") | 36 "third_party", "clang", os_name, "bin", "clang") |
37 print clang_bin | 37 print clang_bin |
38 args.insert(0, clang_bin) | 38 args.insert(0, clang_bin) |
39 print "'%s'" % "' '".join(args) | 39 print "'%s'" % "' '".join(args) |
40 os.execv(clang_bin, args) | 40 os.execv(clang_bin, args) |
41 | 41 |
42 def invoke_gcc(args): | 42 def invoke_gcc(args): |
43 args.insert(0, "gcc") | 43 args.insert(0, "gcc") |
44 os.execv("/usr/bin/gcc", args) | 44 os.execv("/usr/bin/gcc", args) |
45 | 45 |
46 def invoke_gcc_arm(args): | 46 def invoke_gcc_arm(args): |
47 args.insert(0, "arm-linux-gnueabihf-gcc-4.8") | 47 args.insert(0, "arm-linux-gnueabihf-gcc-4.8") |
48 os.execv("/usr/bin/arm-linux-gnueabihf-gcc-4.8", args) | 48 os.execv("/usr/bin/arm-linux-gnueabihf-gcc-4.8", args) |
49 | 49 |
50 def invoke_gcc_arm64(args): | 50 def invoke_gcc_arm64(args): |
51 args.insert(0, "aarch64-linux-gnu-gcc-4.8") | 51 args.insert(0, "aarch64-linux-gnu-gcc-4.8") |
52 os.execv("/usr/bin/aarch64-linux-gnu-gcc-4.8", args) | 52 os.execv("/usr/bin/aarch64-linux-gnu-gcc-4.8", args) |
53 | 53 |
54 def invoke_gcc_arm_embedded(args): | 54 def invoke_gcc_arm_embedded(args): |
55 os_name = utils.GuessOS() | 55 os_name = utils.GuessOS() |
56 if os_name == "macos": | 56 if os_name == "macos": |
57 os_name = "mac" | 57 os_name = "mac" |
58 # There is no way of disabling the passing of '-arch x86_64' from the | 58 # There is no way of disabling the passing of '-arch x86_64' from the |
59 # files generated by gyp on Mac. | 59 # files generated by gyp on Mac. |
60 args.remove("-arch") | 60 args.remove("-arch") |
61 args.remove("x86_64") | 61 args.remove("x86_64") |
62 gcc_arm_embedded_bin = relative_to_fletch_root( | 62 gcc_arm_embedded_bin = relative_to_dartino_root( |
63 "third_party", "gcc-arm-embedded", os_name, "gcc-arm-embedded", "bin", | 63 "third_party", "gcc-arm-embedded", os_name, "gcc-arm-embedded", "bin", |
64 "arm-none-eabi-gcc") | 64 "arm-none-eabi-gcc") |
65 if not os.path.exists(gcc_arm_embedded_bin): | 65 if not os.path.exists(gcc_arm_embedded_bin): |
66 gcc_arm_embedded_download = relative_to_fletch_root( | 66 gcc_arm_embedded_download = relative_to_dartino_root( |
67 "third_party", "gcc-arm-embedded", "download") | 67 "third_party", "gcc-arm-embedded", "download") |
68 print "\n*************** TOOLCHAIN ERROR ********************" | 68 print "\n*************** TOOLCHAIN ERROR ********************" |
69 print "%s not found" % gcc_arm_embedded_bin | 69 print "%s not found" % gcc_arm_embedded_bin |
70 print "Run %s to download\n" % gcc_arm_embedded_download | 70 print "Run %s to download\n" % gcc_arm_embedded_download |
71 exit(1) | 71 exit(1) |
72 args.insert(0, gcc_arm_embedded_bin) | 72 args.insert(0, gcc_arm_embedded_bin) |
73 os.execv(gcc_arm_embedded_bin, args) | 73 os.execv(gcc_arm_embedded_bin, args) |
74 | 74 |
75 def invoke_gcc_local(args): | 75 def invoke_gcc_local(args): |
76 if which("arm-eabi-gcc") is not None: | 76 if which("arm-eabi-gcc") is not None: |
77 args.insert(0, "arm-eabi-gcc") | 77 args.insert(0, "arm-eabi-gcc") |
78 os.execvp("arm-eabi-gcc", args) | 78 os.execvp("arm-eabi-gcc", args) |
79 else: | 79 else: |
80 args.insert(0, "arm-none-eabi-gcc") | 80 args.insert(0, "arm-none-eabi-gcc") |
81 os.execvp("arm-none-eabi-gcc", args) | 81 os.execvp("arm-none-eabi-gcc", args) |
82 | 82 |
83 def main(): | 83 def main(): |
84 args = sys.argv[1:] | 84 args = sys.argv[1:] |
85 if "-L/FLETCH_ASAN" in args: | 85 if "-L/DARTINO_ASAN" in args: |
86 args.remove("-L/FLETCH_ASAN") | 86 args.remove("-L/DARTINO_ASAN") |
87 args.insert(0, '-fsanitize-undefined-trap-on-error') | 87 args.insert(0, '-fsanitize-undefined-trap-on-error') |
88 args.insert(0, '-fsanitize=address') | 88 args.insert(0, '-fsanitize=address') |
89 if "-DFLETCH_CLANG" in args: | 89 if "-DDARTINO_CLANG" in args: |
90 args.remove("-DFLETCH_CLANG") | 90 args.remove("-DDARTINO_CLANG") |
91 invoke_clang(args) | 91 invoke_clang(args) |
92 elif "-L/FLETCH_CLANG" in args: | 92 elif "-L/DARTINO_CLANG" in args: |
93 args.remove("-L/FLETCH_CLANG") | 93 args.remove("-L/DARTINO_CLANG") |
94 invoke_clang(args) | 94 invoke_clang(args) |
95 elif "-DFLETCH_ARM" in args: | 95 elif "-DDARTINO_ARM" in args: |
96 invoke_gcc_arm(args) | 96 invoke_gcc_arm(args) |
97 elif "-L/FLETCH_ARM" in args: | 97 elif "-L/DARTINO_ARM" in args: |
98 args.remove("-L/FLETCH_ARM") | 98 args.remove("-L/DARTINO_ARM") |
99 invoke_gcc_arm(args) | 99 invoke_gcc_arm(args) |
100 elif "-DFLETCH_ARM64" in args: | 100 elif "-DDARTINO_ARM64" in args: |
101 invoke_gcc_arm64(args) | 101 invoke_gcc_arm64(args) |
102 elif "-L/FLETCH_ARM64" in args: | 102 elif "-L/DARTINO_ARM64" in args: |
103 args.remove("-L/FLETCH_ARM64") | 103 args.remove("-L/DARTINO_ARM64") |
104 invoke_gcc_arm64(args) | 104 invoke_gcc_arm64(args) |
105 elif "-DGCC_XARM_EMBEDDED" in args: | 105 elif "-DGCC_XARM_EMBEDDED" in args: |
106 invoke_gcc_arm_embedded(args) | 106 invoke_gcc_arm_embedded(args) |
107 elif "-L/GCC_XARM_EMBEDDED" in args: | 107 elif "-L/GCC_XARM_EMBEDDED" in args: |
108 args.remove("-L/GCC_XARM_EMBEDDED") | 108 args.remove("-L/GCC_XARM_EMBEDDED") |
109 invoke_gcc_arm_embedded(args) | 109 invoke_gcc_arm_embedded(args) |
110 elif "-DGCC_XARM_LOCAL" in args: | 110 elif "-DGCC_XARM_LOCAL" in args: |
111 invoke_gcc_local(args) | 111 invoke_gcc_local(args) |
112 elif "-L/GCC_XARM_LOCAL" in args: | 112 elif "-L/GCC_XARM_LOCAL" in args: |
113 args.remove("-L/GCC_XARM_LOCAL") | 113 args.remove("-L/GCC_XARM_LOCAL") |
114 invoke_gcc_local(args) | 114 invoke_gcc_local(args) |
115 else: | 115 else: |
116 invoke_gcc(args) | 116 invoke_gcc(args) |
117 | 117 |
118 if __name__ == '__main__': | 118 if __name__ == '__main__': |
119 main() | 119 main() |
OLD | NEW |