Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(964)

Side by Side Diff: tools/build.py

Issue 10823209: Add support for building the Dart VM for Android OS. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Removed unused script tools/android/envsetup.sh Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 3 # Copyright (c) 2011, 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 shutil 10 import shutil
11 import subprocess 11 import subprocess
12 import sys 12 import sys
13 import utils 13 import utils
14 14
15 HOST_OS = utils.GuessOS() 15 HOST_OS = utils.GuessOS()
16 HOST_CPUS = utils.GuessCpus() 16 HOST_CPUS = utils.GuessCpus()
17 armcompilerlocation = '/opt/codesourcery/arm-2009q1' 17 armcompilerlocation = '/opt/codesourcery/arm-2009q1'
18 SCRIPT_DIR = os.path.dirname(sys.argv[0])
19 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..'))
20 THIRD_PARTY_ROOT = os.path.join(DART_ROOT, 'third_party')
18 21
19 def BuildOptions(): 22 def BuildOptions():
20 result = optparse.OptionParser() 23 result = optparse.OptionParser()
21 result.add_option("-m", "--mode", 24 result.add_option("-m", "--mode",
22 help='Build variants (comma-separated).', 25 help='Build variants (comma-separated).',
23 metavar='[all,debug,release]', 26 metavar='[all,debug,release]',
24 default='debug') 27 default='debug')
25 result.add_option("-v", "--verbose", 28 result.add_option("-v", "--verbose",
26 help='Verbose output.', 29 help='Verbose output.',
27 default=False, action="store_true") 30 default=False, action="store_true")
28 result.add_option("--arch", 31 result.add_option("--arch",
29 help='Target architectures (comma-separated).', 32 help='Target architectures (comma-separated).',
30 metavar='[all,ia32,x64,simarm,arm]', 33 metavar='[all,ia32,x64,simarm,arm]',
31 default=utils.GuessArchitecture()) 34 default=utils.GuessArchitecture())
35 result.add_option("--os",
36 help='Target OS',
37 default=utils.GuessOS()),
32 result.add_option("-j", 38 result.add_option("-j",
33 help='The number of parallel jobs to run.', 39 help='The number of parallel jobs to run.',
34 metavar=HOST_CPUS, 40 metavar=HOST_CPUS,
35 default=str(HOST_CPUS)) 41 default=str(HOST_CPUS))
36 result.add_option("--devenv", 42 result.add_option("--devenv",
37 help='Path containing devenv.com on Windows', 43 help='Path containing devenv.com on Windows',
38 default='C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\Common7\\ID E') 44 default='C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\Common7\\ID E')
39 return result 45 return result
40 46
41 47
42 def ProcessOptions(options): 48 def ProcessOptions(options, args):
43 if options.arch == 'all': 49 if options.arch == 'all':
44 options.arch = 'ia32,x64' 50 options.arch = 'ia32,x64'
45 if options.mode == 'all': 51 if options.mode == 'all':
46 options.mode = 'release,debug' 52 options.mode = 'release,debug'
47 options.mode = options.mode.split(',') 53 options.mode = options.mode.split(',')
48 options.arch = options.arch.split(',') 54 options.arch = options.arch.split(',')
49 for mode in options.mode: 55 for mode in options.mode:
50 if not mode in ['debug', 'release']: 56 if not mode in ['debug', 'release']:
51 print "Unknown mode %s" % mode 57 print "Unknown mode %s" % mode
52 return False 58 return False
53 for arch in options.arch: 59 for arch in options.arch:
54 if not arch in ['ia32', 'x64', 'simarm', 'arm']: 60 if not arch in ['ia32', 'x64', 'simarm', 'arm']:
55 print "Unknown arch %s" % arch 61 print "Unknown arch %s" % arch
56 return False 62 return False
63 if options.os != HOST_OS:
64 if options.os != 'android':
65 print "Unsupported target os %s" % options.os
66 return False
67 if not HOST_OS in ['linux']:
68 print ("Cross-compilation to %s is not supported on host os %s."
69 % (options.os, HOST_OS))
70 return False
71 if not arch in ['ia32']:
72 print ("Cross-compilation to %s is not supported for architecture %s."
73 % (options.os, arch))
74 return False
75 # We have not yet tweaked the v8 dart build to work with the Android
76 # NDK/SDK, so don't try to build it.
77 if args == []:
78 print "For android builds you must specify a target, such as 'dart'."
79 return False
80 if 'v8' in args:
81 print "The v8 target is not supported for android builds."
82 return False
57 return True 83 return True
58 84
59 85
60 def setTools(arch): 86 def SetTools(arch, toolchainprefix):
61 if arch == 'arm': 87 toolsOverride = None
88 if arch == 'arm' and toolchainprefix == None:
89 toolchainprefix = armcompilerlocation + "/bin/arm-none-linux-gnueabi"
90 if toolchainprefix:
62 toolsOverride = { 91 toolsOverride = {
63 "CC" : armcompilerlocation + "/bin/arm-none-linux-gnueabi-gcc", 92 "CC" : toolchainprefix + "-gcc",
64 "CXX" : armcompilerlocation + "/bin/arm-none-linux-gnueabi-g++", 93 "CXX" : toolchainprefix + "-g++",
65 "AR" : armcompilerlocation + "/bin/arm-none-linux-gnueabi-ar", 94 "AR" : toolchainprefix + "-ar",
66 "LINK": armcompilerlocation + "/bin/arm-none-linux-gnueabi-g++", 95 "LINK": toolchainprefix + "-g++",
67 "NM" : armcompilerlocation + "/bin/arm-none-linux-gnueabi-nm", 96 "NM" : toolchainprefix + "-nm",
68 } 97 }
69 return toolsOverride 98 return toolsOverride
99
100
101 def CheckDirExists(path, docstring):
102 if not os.path.isdir(path):
103 raise Exception('Could not find %s directory %s'
104 % (docstring, path))
105
106
107 def SetCrossCompilationEnvironment(host_os, target_os, target_arch, old_path):
108 global THIRD_PARTY_ROOT
109 if host_os not in ['linux']:
110 raise Exception('Unsupported host os %s' % host_os)
111 if target_os not in ['android']:
112 raise Exception('Unsupported target os %s' % target_os)
113 if target_arch not in ['ia32']:
114 raise Exception('Unsupported target architecture %s' % target_arch)
115
116 CheckDirExists(THIRD_PARTY_ROOT, 'third party tools');
117 android_tools = os.path.join(THIRD_PARTY_ROOT, 'android_tools')
118 CheckDirExists(android_tools, 'Android tools')
119 android_ndk_root = os.path.join(android_tools, 'ndk')
120 CheckDirExists(android_ndk_root, 'Android NDK')
121 android_sdk_root = os.path.join(android_tools, 'sdk')
122 CheckDirExists(android_sdk_root, 'Android SDK')
123
124 os.environ['ANDROID_NDK_ROOT'] = android_ndk_root
125 os.environ['ANDROID_SDK_ROOT'] = android_sdk_root
126
127 toolchain_arch = 'x86-4.4.3'
128 toolchain_dir = 'linux-x86'
129 android_toolchain = os.path.join(android_ndk_root,
130 'toolchains', toolchain_arch,
131 'prebuilt', toolchain_dir, 'bin')
132 CheckDirExists(android_toolchain, 'Android toolchain')
133
134 os.environ['ANDROID_TOOLCHAIN'] = android_toolchain
135
136 android_sdk_version = 9
137
138 android_sdk_tools = os.path.join(android_sdk_root, 'tools')
139 CheckDirExists(android_sdk_tools, 'Android SDK tools')
140
141 android_sdk_platform_tools = os.path.join(android_sdk_root, 'platform-tools')
142 CheckDirExists(android_sdk_platform_tools, 'Android SDK platform tools')
143
144 pathList = [old_path,
145 android_ndk_root,
146 android_sdk_tools,
147 android_sdk_platform_tools,
148 # for Ninja - maybe don't need?
149 android_toolchain
150 ]
151 os.environ['PATH'] = ':'.join(pathList)
152
153 gypDefinesList = [
154 'target_arch=ia32',
155 'OS=%s' % target_os,
156 'android_build_type=0',
157 'host_os=%s' % host_os,
158 'linux_fpic=1',
159 'release_optimize=s',
160 'linux_use_tcmalloc=0',
161 'android_sdk=%s', os.path.join(android_sdk_root, 'platforms',
162 'android-%d' % android_sdk_version),
163 'android_sdk_tools=%s' % android_sdk_platform_tools
164 ]
165
166 os.environ['GYP_DEFINES'] = ' '.join(gypDefinesList)
70 167
71 168
72 def Execute(args): 169 def Execute(args):
73 print "#" + ' '.join(args) 170 print "#" + ' '.join(args)
74 process = subprocess.Popen(args) 171 process = subprocess.Popen(args)
75 process.wait() 172 process.wait()
76 if process.returncode != 0: 173 if process.returncode != 0:
77 raise Error(args[0] + " failed") 174 raise Error(args[0] + " failed")
78 175
79 176
177 def GClientRunHooks():
178 Execute(['gclient', 'runhooks'])
179
180
181 def RunhooksIfNeeded(host_os, mode, arch, target_os):
182 build_root = utils.GetBuildRoot(host_os)
183 build_cookie_path = os.path.join(build_root, 'lastHooksTargetOS.txt')
184
185 old_target_os = None
186 try:
187 with open(build_cookie_path) as f:
188 old_target_os = f.read(1024)
189 except IOError as e:
190 pass
191 if target_os != old_target_os:
192 try:
193 os.mkdir(build_root)
194 except OSError as e:
195 pass
196 with open(build_cookie_path, 'w') as f:
197 f.write(target_os)
198 GClientRunHooks()
199
200
80 def CurrentDirectoryBaseName(): 201 def CurrentDirectoryBaseName():
81 """Returns the name of the current directory""" 202 """Returns the name of the current directory"""
82 return os.path.relpath(os.curdir, start=os.pardir) 203 return os.path.relpath(os.curdir, start=os.pardir)
83 204
205
84 def Main(): 206 def Main():
85 utils.ConfigureJava() 207 utils.ConfigureJava()
86 # Parse the options. 208 # Parse the options.
87 parser = BuildOptions() 209 parser = BuildOptions()
88 (options, args) = parser.parse_args() 210 (options, args) = parser.parse_args()
89 if not ProcessOptions(options): 211 if not ProcessOptions(options, args):
90 parser.print_help() 212 parser.print_help()
91 return 1 213 return 1
92 # Determine which targets to build. By default we build the "all" target. 214 # Determine which targets to build. By default we build the "all" target.
93 if len(args) == 0: 215 if len(args) == 0:
94 if HOST_OS == 'macos': 216 if HOST_OS == 'macos':
95 target = 'All' 217 target = 'All'
96 else: 218 else:
97 target = 'all' 219 target = 'all'
98 else: 220 else:
99 target = args[0] 221 target = args[0]
222
223 target_os = options.os
224
225 # Remember path
226 old_path = os.environ['PATH']
100 # Build the targets for each requested configuration. 227 # Build the targets for each requested configuration.
101 for mode in options.mode: 228 for mode in options.mode:
102 for arch in options.arch: 229 for arch in options.arch:
103 build_config = utils.GetBuildConf(mode, arch) 230 build_config = utils.GetBuildConf(mode, arch)
104 if HOST_OS == 'macos': 231 if HOST_OS == 'macos':
105 project_file = 'dart.xcodeproj' 232 project_file = 'dart.xcodeproj'
106 if os.path.exists('dart-%s.gyp' % CurrentDirectoryBaseName()): 233 if os.path.exists('dart-%s.gyp' % CurrentDirectoryBaseName()):
107 project_file = 'dart-%s.xcodeproj' % CurrentDirectoryBaseName() 234 project_file = 'dart-%s.xcodeproj' % CurrentDirectoryBaseName()
108 args = ['xcodebuild', 235 args = ['xcodebuild',
109 '-project', 236 '-project',
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 args = [make, 269 args = [make,
143 '-j', 270 '-j',
144 options.j, 271 options.j,
145 'BUILDTYPE=' + build_config, 272 'BUILDTYPE=' + build_config,
146 ] 273 ]
147 if options.verbose: 274 if options.verbose:
148 args += ['V=1'] 275 args += ['V=1']
149 276
150 args += [target] 277 args += [target]
151 278
152 toolsOverride = setTools(arch) 279 if target_os != HOST_OS:
280 SetCrossCompilationEnvironment(
281 HOST_OS, target_os, arch, old_path)
282
283 RunhooksIfNeeded(HOST_OS, mode, arch, target_os)
284
285 toolchainprefix = None
286 if target_os == 'android':
287 toolchainprefix = ('%s/i686-linux-android'
288 % os.environ['ANDROID_TOOLCHAIN'])
289 toolsOverride = SetTools(arch, toolchainprefix)
153 if toolsOverride: 290 if toolsOverride:
291 printToolOverrides = target_os != 'android'
154 for k, v in toolsOverride.iteritems(): 292 for k, v in toolsOverride.iteritems():
155 args.append( k + "=" + v) 293 args.append( k + "=" + v)
156 print k + " = " + v 294 if printToolOverrides:
295 print k + " = " + v
157 296
158 print ' '.join(args) 297 print ' '.join(args)
159 process = subprocess.Popen(args) 298 process = subprocess.Popen(args)
160 process.wait() 299 process.wait()
161 if process.returncode != 0: 300 if process.returncode != 0:
162 print "BUILD FAILED" 301 print "BUILD FAILED"
163 return 1 302 return 1
164 303
165 return 0 304 return 0
166 305
167 306
168 if __name__ == '__main__': 307 if __name__ == '__main__':
169 sys.exit(Main()) 308 sys.exit(Main())
OLDNEW
« runtime/tools/utils.py ('K') | « runtime/vm/vm.gypi ('k') | tools/gyp/configurations.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698