OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2012, the Dart 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 | 7 |
8 import optparse | 8 import optparse |
9 import os | 9 import os |
10 import re | 10 import re |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 result.add_option("-v", "--verbose", | 53 result.add_option("-v", "--verbose", |
54 help='Verbose output.', | 54 help='Verbose output.', |
55 default=False, action="store_true") | 55 default=False, action="store_true") |
56 result.add_option("-a", "--arch", | 56 result.add_option("-a", "--arch", |
57 help='Target architectures (comma-separated).', | 57 help='Target architectures (comma-separated).', |
58 metavar='[all,ia32,x64,simarm,arm,simarmv6,armv6,simarmv5te,armv5te,' | 58 metavar='[all,ia32,x64,simarm,arm,simarmv6,armv6,simarmv5te,armv5te,' |
59 'simmips,mips,simarm64,arm64,simdbc,armsimdbc]', | 59 'simmips,mips,simarm64,arm64,simdbc,armsimdbc]', |
60 default=utils.GuessArchitecture()) | 60 default=utils.GuessArchitecture()) |
61 result.add_option("--os", | 61 result.add_option("--os", |
62 help='Target OSs (comma-separated).', | 62 help='Target OSs (comma-separated).', |
63 metavar='[all,host,android,fuchsia]', | 63 metavar='[all,host,android]', |
64 default='host') | 64 default='host') |
65 result.add_option("-t", "--toolchain", | 65 result.add_option("-t", "--toolchain", |
66 help='Cross-compiler toolchain path', | 66 help='Cross-compiler toolchain path', |
67 default=None) | 67 default=None) |
68 result.add_option("-j", | 68 result.add_option("-j", |
69 help='The number of parallel jobs to run.', | 69 help='The number of parallel jobs to run.', |
70 metavar=HOST_CPUS, | 70 metavar=HOST_CPUS, |
71 default=str(HOST_CPUS)) | 71 default=str(HOST_CPUS)) |
72 (vs_directory, vs_executable) = utils.GuessVisualStudioPath() | 72 (vs_directory, vs_executable) = utils.GuessVisualStudioPath() |
73 result.add_option("--devenv", | 73 result.add_option("--devenv", |
(...skipping 28 matching lines...) Expand all Loading... |
102 return False | 102 return False |
103 for arch in options.arch: | 103 for arch in options.arch: |
104 archs = ['ia32', 'x64', 'simarm', 'arm', 'simarmv6', 'armv6', | 104 archs = ['ia32', 'x64', 'simarm', 'arm', 'simarmv6', 'armv6', |
105 'simarmv5te', 'armv5te', 'simmips', 'mips', 'simarm64', 'arm64', | 105 'simarmv5te', 'armv5te', 'simmips', 'mips', 'simarm64', 'arm64', |
106 'simdbc', 'simdbc64', 'armsimdbc'] | 106 'simdbc', 'simdbc64', 'armsimdbc'] |
107 if not arch in archs: | 107 if not arch in archs: |
108 print "Unknown arch %s" % arch | 108 print "Unknown arch %s" % arch |
109 return False | 109 return False |
110 options.os = [ProcessOsOption(os_name) for os_name in options.os] | 110 options.os = [ProcessOsOption(os_name) for os_name in options.os] |
111 for os_name in options.os: | 111 for os_name in options.os: |
112 if not os_name in ['android', 'freebsd', 'fuchsia', 'linux', 'macos', 'win32
']: | 112 if not os_name in ['android', 'freebsd', 'linux', 'macos', 'win32']: |
113 print "Unknown os %s" % os_name | 113 print "Unknown os %s" % os_name |
114 return False | 114 return False |
115 if os_name != HOST_OS: | 115 if os_name != HOST_OS: |
116 if os_name != 'android' and os_name != 'fuchsia': | 116 if os_name != 'android': |
117 print "Unsupported target os %s" % os_name | 117 print "Unsupported target os %s" % os_name |
118 return False | 118 return False |
119 if not HOST_OS in ['linux']: | 119 if not HOST_OS in ['linux']: |
120 print ("Cross-compilation to %s is not supported on host os %s." | 120 print ("Cross-compilation to %s is not supported on host os %s." |
121 % (os_name, HOST_OS)) | 121 % (os_name, HOST_OS)) |
122 return False | 122 return False |
123 if not arch in ['ia32', 'x64', 'arm', 'armv6', 'armv5te', 'arm64', 'mips', | 123 if not arch in ['ia32', 'x64', 'arm', 'armv6', 'armv5te', 'arm64', 'mips', |
124 'simdbc', 'simdbc64']: | 124 'simdbc', 'simdbc64']: |
125 print ("Cross-compilation to %s is not supported for architecture %s." | 125 print ("Cross-compilation to %s is not supported for architecture %s." |
126 % (os_name, arch)) | 126 % (os_name, arch)) |
(...skipping 14 matching lines...) Expand all Loading... |
141 android_toolchain = GetAndroidToolchainDir(HOST_OS, arch) | 141 android_toolchain = GetAndroidToolchainDir(HOST_OS, arch) |
142 if arch == 'arm' or arch == 'simdbc': | 142 if arch == 'arm' or arch == 'simdbc': |
143 return os.path.join(android_toolchain, 'arm-linux-androideabi') | 143 return os.path.join(android_toolchain, 'arm-linux-androideabi') |
144 if arch == 'arm64' or arch == 'simdbc64': | 144 if arch == 'arm64' or arch == 'simdbc64': |
145 return os.path.join(android_toolchain, 'aarch64-linux-android') | 145 return os.path.join(android_toolchain, 'aarch64-linux-android') |
146 if arch == 'ia32': | 146 if arch == 'ia32': |
147 return os.path.join(android_toolchain, 'i686-linux-android') | 147 return os.path.join(android_toolchain, 'i686-linux-android') |
148 if arch == 'x64': | 148 if arch == 'x64': |
149 return os.path.join(android_toolchain, 'x86_64-linux-android') | 149 return os.path.join(android_toolchain, 'x86_64-linux-android') |
150 | 150 |
151 if target_os == 'fuchsia': | |
152 fuchsia_toolchain = GetFuchsiaToolchainDir(HOST_OS, arch) | |
153 if arch == 'arm64': | |
154 return os.path.join(fuchsia_toolchain, 'aarch64-elf') | |
155 if arch == 'x64': | |
156 return os.path.join(fuchsia_toolchain, 'x86_64-elf') | |
157 | |
158 # If no cross compiler is specified, only try to figure one out on Linux. | 151 # If no cross compiler is specified, only try to figure one out on Linux. |
159 if not HOST_OS in ['linux']: | 152 if not HOST_OS in ['linux']: |
160 raise Exception('Unless --toolchain is used cross-building is only ' | 153 raise Exception('Unless --toolchain is used cross-building is only ' |
161 'supported on Linux.') | 154 'supported on Linux.') |
162 | 155 |
163 # For ARM Linux, by default use the Linux distribution's cross-compiler. | 156 # For ARM Linux, by default use the Linux distribution's cross-compiler. |
164 if arch == 'arm' or arch == 'armsimdbc': | 157 if arch == 'arm' or arch == 'armsimdbc': |
165 # To use a non-hf compiler, specify on the command line with --toolchain. | 158 # To use a non-hf compiler, specify on the command line with --toolchain. |
166 return (DEFAULT_ARM_CROSS_COMPILER_PATH + "/arm-linux-gnueabihf") | 159 return (DEFAULT_ARM_CROSS_COMPILER_PATH + "/arm-linux-gnueabihf") |
167 if arch == 'arm64': | 160 if arch == 'arm64': |
168 return (DEFAULT_ARM_CROSS_COMPILER_PATH + "/aarch64-linux-gnu") | 161 return (DEFAULT_ARM_CROSS_COMPILER_PATH + "/aarch64-linux-gnu") |
169 | 162 |
170 # TODO(zra): Find default MIPS Linux cross-compiler. | 163 # TODO(zra): Find default MIPS Linux cross-compiler. |
171 | 164 |
172 return None | 165 return None |
173 | 166 |
174 | 167 |
175 def SetTools(arch, target_os, options): | 168 def SetTools(arch, target_os, options): |
176 toolsOverride = None | 169 toolsOverride = None |
177 | 170 |
178 toolchainprefix = GetToolchainPrefix(target_os, arch, options) | 171 toolchainprefix = GetToolchainPrefix(target_os, arch, options) |
179 | 172 |
180 # Override the Android toolchain's linker to handle some complexity in the | 173 # Override the Android toolchain's linker to handle some complexity in the |
181 # linker arguments that gyp has trouble with. | 174 # linker arguments that gyp has trouble with. |
182 linker = "" | 175 linker = "" |
183 if target_os == 'android': | 176 if target_os == 'android': |
184 linker = os.path.join(DART_ROOT, 'tools', 'android_link.py') | 177 linker = os.path.join(DART_ROOT, 'tools', 'android_link.py') |
185 elif target_os == 'fuchsia': | |
186 linker = os.path.join(DART_ROOT, 'tools', 'fuchsia_link.py') | |
187 elif toolchainprefix: | 178 elif toolchainprefix: |
188 linker = toolchainprefix + "-g++" | 179 linker = toolchainprefix + "-g++" |
189 | 180 |
190 if toolchainprefix: | 181 if toolchainprefix: |
191 toolsOverride = { | 182 toolsOverride = { |
192 "CC.target" : toolchainprefix + "-gcc", | 183 "CC.target" : toolchainprefix + "-gcc", |
193 "CXX.target" : toolchainprefix + "-g++", | 184 "CXX.target" : toolchainprefix + "-g++", |
194 "AR.target" : toolchainprefix + "-ar", | 185 "AR.target" : toolchainprefix + "-ar", |
195 "LINK.target": linker, | 186 "LINK.target": linker, |
196 "NM.target" : toolchainprefix + "-nm", | 187 "NM.target" : toolchainprefix + "-nm", |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 toolchain_arch = 'x86_64-4.9' | 219 toolchain_arch = 'x86_64-4.9' |
229 toolchain_dir = 'linux-x86_64' | 220 toolchain_dir = 'linux-x86_64' |
230 android_toolchain = os.path.join(android_ndk_root, | 221 android_toolchain = os.path.join(android_ndk_root, |
231 'toolchains', toolchain_arch, | 222 'toolchains', toolchain_arch, |
232 'prebuilt', toolchain_dir, 'bin') | 223 'prebuilt', toolchain_dir, 'bin') |
233 CheckDirExists(android_toolchain, 'Android toolchain') | 224 CheckDirExists(android_toolchain, 'Android toolchain') |
234 | 225 |
235 return android_toolchain | 226 return android_toolchain |
236 | 227 |
237 | 228 |
238 def GetFuchsiaToolchainDir(host_os, target_arch): | |
239 global THIRD_PARTY_ROOT | |
240 if host_os not in ['linux']: | |
241 raise Exception('Unsupported host os %s' % host_os) | |
242 if target_arch not in ['x64', 'arm64',]: | |
243 raise Exception('Unsupported target architecture %s' % target_arch) | |
244 | |
245 # Set up path to the Android NDK. | |
246 CheckDirExists(THIRD_PARTY_ROOT, 'third party tools') | |
247 fuchsia_tools = os.path.join(THIRD_PARTY_ROOT, 'fuchsia_tools') | |
248 CheckDirExists(fuchsia_tools, 'Fuchsia tools') | |
249 | |
250 toolchain_arch = 'x86_64-elf-5.3.0-Linux-x86_64' | |
251 if target_arch == 'arm64': | |
252 toolchain_arch = 'aarch64-elf-5.3.0-Linux-x86_64' | |
253 fuchsia_toolchain = os.path.join( | |
254 fuchsia_tools, 'toolchains', toolchain_arch, 'bin') | |
255 CheckDirExists(fuchsia_toolchain, 'Fuchsia toolchain') | |
256 | |
257 return fuchsia_toolchain | |
258 | |
259 | |
260 def Execute(args): | 229 def Execute(args): |
261 process = subprocess.Popen(args) | 230 process = subprocess.Popen(args) |
262 process.wait() | 231 process.wait() |
263 if process.returncode != 0: | 232 if process.returncode != 0: |
264 raise Exception(args[0] + " failed") | 233 raise Exception(args[0] + " failed") |
265 | 234 |
266 | 235 |
267 def CurrentDirectoryBaseName(): | 236 def CurrentDirectoryBaseName(): |
268 """Returns the name of the current directory""" | 237 """Returns the name of the current directory""" |
269 return os.path.relpath(os.curdir, start=os.pardir) | 238 return os.path.relpath(os.curdir, start=os.pardir) |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 else: | 558 else: |
590 if BuildOneConfig(options, target, target_os, | 559 if BuildOneConfig(options, target, target_os, |
591 mode, arch, cross_build) != 0: | 560 mode, arch, cross_build) != 0: |
592 return 1 | 561 return 1 |
593 | 562 |
594 return 0 | 563 return 0 |
595 | 564 |
596 | 565 |
597 if __name__ == '__main__': | 566 if __name__ == '__main__': |
598 sys.exit(Main()) | 567 sys.exit(Main()) |
OLD | NEW |