| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 print "Unknown os %s" % os | 94 print "Unknown os %s" % os |
| 95 return False | 95 return False |
| 96 if os != HOST_OS: | 96 if os != HOST_OS: |
| 97 if os != 'android': | 97 if os != 'android': |
| 98 print "Unsupported target os %s" % os | 98 print "Unsupported target os %s" % os |
| 99 return False | 99 return False |
| 100 if not HOST_OS in ['linux']: | 100 if not HOST_OS in ['linux']: |
| 101 print ("Cross-compilation to %s is not supported on host os %s." | 101 print ("Cross-compilation to %s is not supported on host os %s." |
| 102 % (os, HOST_OS)) | 102 % (os, HOST_OS)) |
| 103 return False | 103 return False |
| 104 if not arch in ['ia32', 'arm']: | 104 if not arch in ['ia32']: |
| 105 print ("Cross-compilation to %s is not supported for architecture %s." | 105 print ("Cross-compilation to %s is not supported for architecture %s." |
| 106 % (os, arch)) | 106 % (os, arch)) |
| 107 return False | 107 return False |
| 108 # We have not yet tweaked the v8 dart build to work with the Android | 108 # We have not yet tweaked the v8 dart build to work with the Android |
| 109 # NDK/SDK, so don't try to build it. | 109 # NDK/SDK, so don't try to build it. |
| 110 if args == []: | 110 if args == []: |
| 111 print "For android builds you must specify a target, such as 'samples'." | 111 print "For android builds you must specify a target, such as 'samples'." |
| 112 return False | 112 return False |
| 113 if 'v8' in args: | 113 if 'v8' in args: |
| 114 print "The v8 target is not supported for android builds." | 114 print "The v8 target is not supported for android builds." |
| (...skipping 22 matching lines...) Expand all Loading... |
| 137 raise Exception('Could not find %s directory %s' | 137 raise Exception('Could not find %s directory %s' |
| 138 % (docstring, path)) | 138 % (docstring, path)) |
| 139 | 139 |
| 140 | 140 |
| 141 def SetCrossCompilationEnvironment(host_os, target_os, target_arch, old_path): | 141 def SetCrossCompilationEnvironment(host_os, target_os, target_arch, old_path): |
| 142 global THIRD_PARTY_ROOT | 142 global THIRD_PARTY_ROOT |
| 143 if host_os not in ['linux']: | 143 if host_os not in ['linux']: |
| 144 raise Exception('Unsupported host os %s' % host_os) | 144 raise Exception('Unsupported host os %s' % host_os) |
| 145 if target_os not in ['android']: | 145 if target_os not in ['android']: |
| 146 raise Exception('Unsupported target os %s' % target_os) | 146 raise Exception('Unsupported target os %s' % target_os) |
| 147 if target_arch not in ['ia32', 'arm']: | 147 if target_arch not in ['ia32']: |
| 148 raise Exception('Unsupported target architecture %s' % target_arch) | 148 raise Exception('Unsupported target architecture %s' % target_arch) |
| 149 | 149 |
| 150 CheckDirExists(THIRD_PARTY_ROOT, 'third party tools'); | 150 CheckDirExists(THIRD_PARTY_ROOT, 'third party tools'); |
| 151 android_tools = os.path.join(THIRD_PARTY_ROOT, 'android_tools') | 151 android_tools = os.path.join(THIRD_PARTY_ROOT, 'android_tools') |
| 152 CheckDirExists(android_tools, 'Android tools') | 152 CheckDirExists(android_tools, 'Android tools') |
| 153 android_ndk_root = os.path.join(android_tools, 'ndk') | 153 android_ndk_root = os.path.join(android_tools, 'ndk') |
| 154 CheckDirExists(android_ndk_root, 'Android NDK') | 154 CheckDirExists(android_ndk_root, 'Android NDK') |
| 155 android_sdk_root = os.path.join(android_tools, 'sdk') | 155 android_sdk_root = os.path.join(android_tools, 'sdk') |
| 156 CheckDirExists(android_sdk_root, 'Android SDK') | 156 CheckDirExists(android_sdk_root, 'Android SDK') |
| 157 | 157 |
| 158 os.environ['ANDROID_NDK_ROOT'] = android_ndk_root | 158 os.environ['ANDROID_NDK_ROOT'] = android_ndk_root |
| 159 os.environ['ANDROID_SDK_ROOT'] = android_sdk_root | 159 os.environ['ANDROID_SDK_ROOT'] = android_sdk_root |
| 160 | 160 |
| 161 if target_arch == 'arm': | 161 toolchain_arch = 'x86-4.4.3' |
| 162 toolchain_arch = 'arm-linux-androideabi-4.6' | |
| 163 else: | |
| 164 toolchain_arch = 'x86-4.4.3' | |
| 165 toolchain_dir = 'linux-x86' | 162 toolchain_dir = 'linux-x86' |
| 166 android_toolchain = os.path.join(android_ndk_root, | 163 android_toolchain = os.path.join(android_ndk_root, |
| 167 'toolchains', toolchain_arch, | 164 'toolchains', toolchain_arch, |
| 168 'prebuilt', toolchain_dir, 'bin') | 165 'prebuilt', toolchain_dir, 'bin') |
| 169 CheckDirExists(android_toolchain, 'Android toolchain') | 166 CheckDirExists(android_toolchain, 'Android toolchain') |
| 170 | 167 |
| 171 os.environ['ANDROID_TOOLCHAIN'] = android_toolchain | 168 os.environ['ANDROID_TOOLCHAIN'] = android_toolchain |
| 172 | 169 |
| 173 android_sdk_version = 15 | 170 android_sdk_version = 15 |
| 174 | 171 |
| 175 android_sdk_tools = os.path.join(android_sdk_root, 'tools') | 172 android_sdk_tools = os.path.join(android_sdk_root, 'tools') |
| 176 CheckDirExists(android_sdk_tools, 'Android SDK tools') | 173 CheckDirExists(android_sdk_tools, 'Android SDK tools') |
| 177 | 174 |
| 178 android_sdk_platform_tools = os.path.join(android_sdk_root, 'platform-tools') | 175 android_sdk_platform_tools = os.path.join(android_sdk_root, 'platform-tools') |
| 179 CheckDirExists(android_sdk_platform_tools, 'Android SDK platform tools') | 176 CheckDirExists(android_sdk_platform_tools, 'Android SDK platform tools') |
| 180 | 177 |
| 181 pathList = [old_path, | 178 pathList = [old_path, |
| 182 android_ndk_root, | 179 android_ndk_root, |
| 183 android_sdk_tools, | 180 android_sdk_tools, |
| 184 android_sdk_platform_tools, | 181 android_sdk_platform_tools, |
| 185 # for Ninja - maybe don't need? | 182 # for Ninja - maybe don't need? |
| 186 android_toolchain | 183 android_toolchain |
| 187 ] | 184 ] |
| 188 os.environ['PATH'] = ':'.join(pathList) | 185 os.environ['PATH'] = ':'.join(pathList) |
| 189 | 186 |
| 190 android_target_arch = target_arch | |
| 191 if target_arch == 'ia32': | |
| 192 android_target_arch = 'x86' | |
| 193 | |
| 194 gypDefinesList = [ | 187 gypDefinesList = [ |
| 195 'target_arch=%s' % target_arch, | 188 'target_arch=ia32', |
| 196 'android_target_arch=%s' % android_target_arch, | |
| 197 'OS=%s' % target_os, | 189 'OS=%s' % target_os, |
| 198 'android_build_type=0', | 190 'android_build_type=0', |
| 199 'host_os=%s' % host_os, | 191 'host_os=%s' % host_os, |
| 200 'linux_fpic=1', | 192 'linux_fpic=1', |
| 201 'release_optimize=s', | 193 'release_optimize=s', |
| 202 'linux_use_tcmalloc=0', | 194 'linux_use_tcmalloc=0', |
| 203 'android_sdk=%s', os.path.join(android_sdk_root, 'platforms', | 195 'android_sdk=%s', os.path.join(android_sdk_root, 'platforms', |
| 204 'android-%d' % android_sdk_version), | 196 'android-%d' % android_sdk_version), |
| 205 'android_sdk_tools=%s' % android_sdk_platform_tools | 197 'android_sdk_tools=%s' % android_sdk_platform_tools |
| 206 ] | 198 ] |
| 207 | 199 |
| 208 os.environ['GYP_DEFINES'] = ' '.join(gypDefinesList) | 200 os.environ['GYP_DEFINES'] = ' '.join(gypDefinesList) |
| 209 | 201 |
| 210 | 202 |
| 211 def Execute(args): | 203 def Execute(args): |
| 212 process = subprocess.Popen(args) | 204 process = subprocess.Popen(args) |
| 213 process.wait() | 205 process.wait() |
| 214 if process.returncode != 0: | 206 if process.returncode != 0: |
| 215 raise Exception(args[0] + " failed") | 207 raise Exception(args[0] + " failed") |
| 216 | 208 |
| 217 | 209 |
| 218 def GClientRunHooks(): | 210 def GClientRunHooks(): |
| 219 Execute(['gclient', 'runhooks']) | 211 Execute(['gclient', 'runhooks']) |
| 220 | 212 |
| 221 | 213 |
| 222 def RunhooksIfNeeded(host_os, mode, target_arch, target_os): | 214 def RunhooksIfNeeded(host_os, mode, arch, target_os): |
| 223 if host_os != 'linux': | 215 if host_os != 'linux': |
| 224 return | 216 return |
| 225 build_root = utils.GetBuildRoot(host_os) | 217 build_root = utils.GetBuildRoot(host_os) |
| 226 build_cookie_path = os.path.join(build_root, 'lastHooksTargetOS.txt') | 218 build_cookie_path = os.path.join(build_root, 'lastHooksTargetOS.txt') |
| 227 | 219 |
| 228 old_target_os = None | 220 old_target_os = None |
| 229 old_target_arch = None | |
| 230 try: | 221 try: |
| 231 with open(build_cookie_path) as f: | 222 with open(build_cookie_path) as f: |
| 232 lines = f.readlines() | 223 old_target_os = f.read(1024) |
| 233 old_target_os = lines[0] | |
| 234 old_target_arch = lines[1] | |
| 235 except IOError as e: | 224 except IOError as e: |
| 236 pass | 225 pass |
| 237 if (target_os != old_target_os) or (target_arch != old_target_arch): | 226 if target_os != old_target_os: |
| 238 try: | 227 try: |
| 239 os.mkdir(build_root) | 228 os.mkdir(build_root) |
| 240 except OSError as e: | 229 except OSError as e: |
| 241 pass | 230 pass |
| 242 with open(build_cookie_path, 'w') as f: | 231 with open(build_cookie_path, 'w') as f: |
| 243 f.write(target_os + '\n') | 232 f.write(target_os) |
| 244 f.write(target_arch + '\n') | |
| 245 GClientRunHooks() | 233 GClientRunHooks() |
| 246 | 234 |
| 247 | 235 |
| 248 def CurrentDirectoryBaseName(): | 236 def CurrentDirectoryBaseName(): |
| 249 """Returns the name of the current directory""" | 237 """Returns the name of the current directory""" |
| 250 return os.path.relpath(os.curdir, start=os.pardir) | 238 return os.path.relpath(os.curdir, start=os.pardir) |
| 251 | 239 |
| 252 | 240 |
| 253 def FilterEmptyXcodebuildSections(process): | 241 def FilterEmptyXcodebuildSections(process): |
| 254 """ | 242 """ |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 args += [target] | 411 args += [target] |
| 424 | 412 |
| 425 if target_os != HOST_OS: | 413 if target_os != HOST_OS: |
| 426 SetCrossCompilationEnvironment( | 414 SetCrossCompilationEnvironment( |
| 427 HOST_OS, target_os, arch, old_path) | 415 HOST_OS, target_os, arch, old_path) |
| 428 | 416 |
| 429 RunhooksIfNeeded(HOST_OS, mode, arch, target_os) | 417 RunhooksIfNeeded(HOST_OS, mode, arch, target_os) |
| 430 | 418 |
| 431 toolchainprefix = None | 419 toolchainprefix = None |
| 432 if target_os == 'android': | 420 if target_os == 'android': |
| 433 if arch == 'ia32': | 421 toolchainprefix = ('%s/i686-linux-android' |
| 434 toolchainprefix = ('%s/i686-linux-android' | 422 % os.environ['ANDROID_TOOLCHAIN']) |
| 435 % os.environ['ANDROID_TOOLCHAIN']) | |
| 436 if arch == 'arm': | |
| 437 toolchainprefix = ('%s/arm-linux-androideabi' | |
| 438 % os.environ['ANDROID_TOOLCHAIN']) | |
| 439 toolsOverride = SetTools(arch, toolchainprefix) | 423 toolsOverride = SetTools(arch, toolchainprefix) |
| 440 if toolsOverride: | 424 if toolsOverride: |
| 441 printToolOverrides = target_os != 'android' | 425 printToolOverrides = target_os != 'android' |
| 442 for k, v in toolsOverride.iteritems(): | 426 for k, v in toolsOverride.iteritems(): |
| 443 args.append( k + "=" + v) | 427 args.append( k + "=" + v) |
| 444 if printToolOverrides: | 428 if printToolOverrides: |
| 445 print k + " = " + v | 429 print k + " = " + v |
| 446 if not os.path.isfile(toolsOverride['CC.target']): | 430 if not os.path.isfile(toolsOverride['CC.target']): |
| 447 if arch == 'arm': | 431 if arch == 'arm': |
| 448 print arm_cc_error | 432 print arm_cc_error |
| (...skipping 16 matching lines...) Expand all Loading... |
| 465 process.wait() | 449 process.wait() |
| 466 if process.returncode != 0: | 450 if process.returncode != 0: |
| 467 print "BUILD FAILED" | 451 print "BUILD FAILED" |
| 468 return 1 | 452 return 1 |
| 469 | 453 |
| 470 return 0 | 454 return 0 |
| 471 | 455 |
| 472 | 456 |
| 473 if __name__ == '__main__': | 457 if __name__ == '__main__': |
| 474 sys.exit(Main()) | 458 sys.exit(Main()) |
| OLD | NEW |