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

Side by Side Diff: dart/tools/build.py

Issue 119673004: Version 1.1.0-dev.5.2 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 11 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
« no previous file with comments | « dart/tools/android_link.py ('k') | dart/tools/dom/scripts/systemnative.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
23 Couldn't find the arm cross compiler. 23 Couldn't find the arm cross compiler.
24 To make sure that you have the arm cross compilation tools installed, run: 24 To make sure that you have the arm cross compilation tools installed, run:
25 25
26 $ wget http://src.chromium.org/chrome/trunk/src/build/install-build-deps.sh 26 $ wget http://src.chromium.org/chrome/trunk/src/build/install-build-deps.sh
27 OR 27 OR
28 $ svn co http://src.chromium.org/chrome/trunk/src/build; cd build 28 $ svn co http://src.chromium.org/chrome/trunk/src/build; cd build
29 Then, 29 Then,
30 $ chmod u+x install-build-deps.sh 30 $ chmod u+x install-build-deps.sh
31 $ ./install-build-deps.sh --arm --no-chromeos-fonts 31 $ ./install-build-deps.sh --arm --no-chromeos-fonts
32 """ 32 """
33 DEFAULT_ARM_CROSS_COMPILER_PATH = '/usr' 33 DEFAULT_ARM_CROSS_COMPILER_PATH = '/usr/bin'
34
34 35
35 def BuildOptions(): 36 def BuildOptions():
36 result = optparse.OptionParser() 37 result = optparse.OptionParser()
37 result.add_option("-m", "--mode", 38 result.add_option("-m", "--mode",
38 help='Build variants (comma-separated).', 39 help='Build variants (comma-separated).',
39 metavar='[all,debug,release]', 40 metavar='[all,debug,release]',
40 default='debug') 41 default='debug')
41 result.add_option("-v", "--verbose", 42 result.add_option("-v", "--verbose",
42 help='Verbose output.', 43 help='Verbose output.',
43 default=False, action="store_true") 44 default=False, action="store_true")
44 result.add_option("-a", "--arch", 45 result.add_option("-a", "--arch",
45 help='Target architectures (comma-separated).', 46 help='Target architectures (comma-separated).',
46 metavar='[all,ia32,x64,simarm,arm,simmips,mips]', 47 metavar='[all,ia32,x64,simarm,arm,simmips,mips]',
47 default=utils.GuessArchitecture()) 48 default=utils.GuessArchitecture())
48 result.add_option("--os", 49 result.add_option("--os",
49 help='Target OSs (comma-separated).', 50 help='Target OSs (comma-separated).',
50 metavar='[all,host,android]', 51 metavar='[all,host,android]',
51 default='host') 52 default='host')
53 result.add_option("-t", "--toolchain",
54 help='Cross-compiler toolchain path',
55 default=None)
52 result.add_option("-j", 56 result.add_option("-j",
53 help='The number of parallel jobs to run.', 57 help='The number of parallel jobs to run.',
54 metavar=HOST_CPUS, 58 metavar=HOST_CPUS,
55 default=str(HOST_CPUS)) 59 default=str(HOST_CPUS))
56 (vs_directory, vs_executable) = utils.GuessVisualStudioPath() 60 (vs_directory, vs_executable) = utils.GuessVisualStudioPath()
57 result.add_option("--devenv", 61 result.add_option("--devenv",
58 help='Path containing devenv.com on Windows', 62 help='Path containing devenv.com on Windows',
59 default=vs_directory) 63 default=vs_directory)
60 result.add_option("--executable", 64 result.add_option("--executable",
61 help='Name of the devenv.com/msbuild executable on Windows (varies for ' 65 help='Name of the devenv.com/msbuild executable on Windows (varies for '
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 print "Unknown os %s" % os 98 print "Unknown os %s" % os
95 return False 99 return False
96 if os != HOST_OS: 100 if os != HOST_OS:
97 if os != 'android': 101 if os != 'android':
98 print "Unsupported target os %s" % os 102 print "Unsupported target os %s" % os
99 return False 103 return False
100 if not HOST_OS in ['linux']: 104 if not HOST_OS in ['linux']:
101 print ("Cross-compilation to %s is not supported on host os %s." 105 print ("Cross-compilation to %s is not supported on host os %s."
102 % (os, HOST_OS)) 106 % (os, HOST_OS))
103 return False 107 return False
104 if not arch in ['ia32']: 108 if not arch in ['ia32', 'arm']:
105 print ("Cross-compilation to %s is not supported for architecture %s." 109 print ("Cross-compilation to %s is not supported for architecture %s."
106 % (os, arch)) 110 % (os, arch))
107 return False 111 return False
108 # We have not yet tweaked the v8 dart build to work with the Android 112 # We have not yet tweaked the v8 dart build to work with the Android
109 # NDK/SDK, so don't try to build it. 113 # NDK/SDK, so don't try to build it.
110 if args == []: 114 if args == []:
111 print "For android builds you must specify a target, such as 'samples'." 115 print "For android builds you must specify a target, such as 'runtime'."
112 return False 116 return False
113 if 'v8' in args: 117 if 'v8' in args:
114 print "The v8 target is not supported for android builds." 118 print "The v8 target is not supported for android builds."
115 return False 119 return False
116 return True 120 return True
117 121
118 122
119 def SetTools(arch, toolchainprefix): 123 def SetTools(arch, target_os, toolchainprefix):
120 toolsOverride = None 124 toolsOverride = None
125
126 # For Android, by default use the toolchain from third_party/android_tools.
127 if target_os == 'android' and toolchainprefix == None:
128 android_toolchain = GetAndroidToolchainDir(HOST_OS, arch)
129 if arch == 'arm':
130 toolchainprefix = os.path.join(
131 android_toolchain, 'arm-linux-androideabi')
132 if arch == 'ia32':
133 toolchainprefix = os.path.join(
134 android_toolchain, 'i686-linux-android')
135
136 # For ARM Linux, by default use the Linux distribution's cross-compiler.
121 if arch == 'arm' and toolchainprefix == None: 137 if arch == 'arm' and toolchainprefix == None:
122 # Here, we specify the hf compiler. If this changes, we must also remove 138 # We specify the hf compiler. If this changes, we must also remove
123 # the ARM_FLOAT_ABI_HARD define in configurations_make.gypi. 139 # the ARM_FLOAT_ABI_HARD define in configurations_make.gypi.
124 toolchainprefix = (DEFAULT_ARM_CROSS_COMPILER_PATH + 140 toolchainprefix = (DEFAULT_ARM_CROSS_COMPILER_PATH +
125 "/bin/arm-linux-gnueabihf") 141 "/arm-linux-gnueabihf")
142
143 # TODO(zra): Find a default MIPS Linux cross-compiler?
144
145 # Override the Android toolchain's linker to handle some complexity in the
146 # linker arguments that gyp has trouble with.
147 linker = ""
148 if target_os == 'android':
149 linker = os.path.join(DART_ROOT, 'tools', 'android_link.py')
150 elif toolchainprefix:
151 linker = toolchainprefix + "-g++"
152
126 if toolchainprefix: 153 if toolchainprefix:
127 toolsOverride = { 154 toolsOverride = {
128 "CC.target" : toolchainprefix + "-gcc", 155 "CC.target" : toolchainprefix + "-gcc",
129 "CXX.target" : toolchainprefix + "-g++", 156 "CXX.target" : toolchainprefix + "-g++",
130 "AR.target" : toolchainprefix + "-ar", 157 "AR.target" : toolchainprefix + "-ar",
131 "LINK.target": toolchainprefix + "-g++", 158 "LINK.target": linker,
132 "NM.target" : toolchainprefix + "-nm", 159 "NM.target" : toolchainprefix + "-nm",
133 } 160 }
134 return toolsOverride 161 return toolsOverride
135 162
136 163
137 def CheckDirExists(path, docstring): 164 def CheckDirExists(path, docstring):
138 if not os.path.isdir(path): 165 if not os.path.isdir(path):
139 raise Exception('Could not find %s directory %s' 166 raise Exception('Could not find %s directory %s'
140 % (docstring, path)) 167 % (docstring, path))
141 168
142 169
143 def SetCrossCompilationEnvironment(host_os, target_os, target_arch, old_path): 170 def GetAndroidToolchainDir(host_os, target_arch):
144 global THIRD_PARTY_ROOT 171 global THIRD_PARTY_ROOT
145 if host_os not in ['linux']: 172 if host_os not in ['linux']:
146 raise Exception('Unsupported host os %s' % host_os) 173 raise Exception('Unsupported host os %s' % host_os)
147 if target_os not in ['android']: 174 if target_arch not in ['ia32', 'arm']:
148 raise Exception('Unsupported target os %s' % target_os)
149 if target_arch not in ['ia32']:
150 raise Exception('Unsupported target architecture %s' % target_arch) 175 raise Exception('Unsupported target architecture %s' % target_arch)
151 176
177 # Set up path to the Android NDK.
152 CheckDirExists(THIRD_PARTY_ROOT, 'third party tools'); 178 CheckDirExists(THIRD_PARTY_ROOT, 'third party tools');
153 android_tools = os.path.join(THIRD_PARTY_ROOT, 'android_tools') 179 android_tools = os.path.join(THIRD_PARTY_ROOT, 'android_tools')
154 CheckDirExists(android_tools, 'Android tools') 180 CheckDirExists(android_tools, 'Android tools')
155 android_ndk_root = os.path.join(android_tools, 'ndk') 181 android_ndk_root = os.path.join(android_tools, 'ndk')
156 CheckDirExists(android_ndk_root, 'Android NDK') 182 CheckDirExists(android_ndk_root, 'Android NDK')
157 android_sdk_root = os.path.join(android_tools, 'sdk')
158 CheckDirExists(android_sdk_root, 'Android SDK')
159 183
160 os.environ['ANDROID_NDK_ROOT'] = android_ndk_root 184 # Set up the directory of the Android NDK cross-compiler toolchain.
161 os.environ['ANDROID_SDK_ROOT'] = android_sdk_root 185 toolchain_arch = 'arm-linux-androideabi-4.6'
162 186 if target_arch == 'ia32':
163 toolchain_arch = 'x86-4.4.3' 187 toolchain_arch = 'x86-4.6'
164 toolchain_dir = 'linux-x86' 188 toolchain_dir = 'linux-x86_64'
165 android_toolchain = os.path.join(android_ndk_root, 189 android_toolchain = os.path.join(android_ndk_root,
166 'toolchains', toolchain_arch, 190 'toolchains', toolchain_arch,
167 'prebuilt', toolchain_dir, 'bin') 191 'prebuilt', toolchain_dir, 'bin')
168 CheckDirExists(android_toolchain, 'Android toolchain') 192 CheckDirExists(android_toolchain, 'Android toolchain')
169 193
170 os.environ['ANDROID_TOOLCHAIN'] = android_toolchain 194 return android_toolchain
171
172 android_sdk_version = 15
173
174 android_sdk_tools = os.path.join(android_sdk_root, 'tools')
175 CheckDirExists(android_sdk_tools, 'Android SDK tools')
176
177 android_sdk_platform_tools = os.path.join(android_sdk_root, 'platform-tools')
178 CheckDirExists(android_sdk_platform_tools, 'Android SDK platform tools')
179
180 pathList = [old_path,
181 android_ndk_root,
182 android_sdk_tools,
183 android_sdk_platform_tools,
184 # for Ninja - maybe don't need?
185 android_toolchain
186 ]
187 os.environ['PATH'] = ':'.join(pathList)
188
189 gypDefinesList = [
190 'target_arch=ia32',
191 'OS=%s' % target_os,
192 'android_build_type=0',
193 'host_os=%s' % host_os,
194 'linux_fpic=1',
195 'release_optimize=s',
196 'linux_use_tcmalloc=0',
197 'android_sdk=%s', os.path.join(android_sdk_root, 'platforms',
198 'android-%d' % android_sdk_version),
199 'android_sdk_tools=%s' % android_sdk_platform_tools
200 ]
201
202 os.environ['GYP_DEFINES'] = ' '.join(gypDefinesList)
203 195
204 196
205 def Execute(args): 197 def Execute(args):
206 process = subprocess.Popen(args) 198 process = subprocess.Popen(args)
207 process.wait() 199 process.wait()
208 if process.returncode != 0: 200 if process.returncode != 0:
209 raise Exception(args[0] + " failed") 201 raise Exception(args[0] + " failed")
210
211
212 def GClientRunHooks():
213 Execute(['gclient', 'runhooks'])
214
215
216 def RunhooksIfNeeded(host_os, mode, arch, target_os):
217 if host_os != 'linux':
218 return
219 build_root = utils.GetBuildRoot(host_os)
220 build_cookie_path = os.path.join(build_root, 'lastHooksTargetOS.txt')
221
222 old_target_os = None
223 try:
224 with open(build_cookie_path) as f:
225 old_target_os = f.read(1024)
226 except IOError as e:
227 pass
228 if target_os != old_target_os:
229 try:
230 os.mkdir(build_root)
231 except OSError as e:
232 pass
233 with open(build_cookie_path, 'w') as f:
234 f.write(target_os)
235 GClientRunHooks()
236 202
237 203
238 def CurrentDirectoryBaseName(): 204 def CurrentDirectoryBaseName():
239 """Returns the name of the current directory""" 205 """Returns the name of the current directory"""
240 return os.path.relpath(os.curdir, start=os.pardir) 206 return os.path.relpath(os.curdir, start=os.pardir)
241 207
242 208
243 def FilterEmptyXcodebuildSections(process): 209 def FilterEmptyXcodebuildSections(process):
244 """ 210 """
245 Filter output from xcodebuild so empty sections are less verbose. 211 Filter output from xcodebuild so empty sections are less verbose.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 # Determine which targets to build. By default we build the "all" target. 312 # Determine which targets to build. By default we build the "all" target.
347 if len(args) == 0: 313 if len(args) == 0:
348 if HOST_OS == 'macos': 314 if HOST_OS == 'macos':
349 targets = ['All'] 315 targets = ['All']
350 else: 316 else:
351 targets = ['all'] 317 targets = ['all']
352 else: 318 else:
353 targets = args 319 targets = args
354 320
355 filter_xcodebuild_output = False 321 filter_xcodebuild_output = False
356 # Remember path
357 old_path = os.environ['PATH']
358 # Build all targets for each requested configuration. 322 # Build all targets for each requested configuration.
359 for target in targets: 323 for target in targets:
360 for target_os in options.os: 324 for target_os in options.os:
361 for mode in options.mode: 325 for mode in options.mode:
362 for arch in options.arch: 326 for arch in options.arch:
363 os.environ['DART_BUILD_MODE'] = mode 327 os.environ['DART_BUILD_MODE'] = mode
364 build_config = utils.GetBuildConf(mode, arch) 328 build_config = utils.GetBuildConf(mode, arch, target_os)
365 if HOST_OS == 'macos': 329 if HOST_OS == 'macos':
366 filter_xcodebuild_output = True 330 filter_xcodebuild_output = True
367 project_file = 'dart.xcodeproj' 331 project_file = 'dart.xcodeproj'
368 if os.path.exists('dart-%s.gyp' % CurrentDirectoryBaseName()): 332 if os.path.exists('dart-%s.gyp' % CurrentDirectoryBaseName()):
369 project_file = 'dart-%s.xcodeproj' % CurrentDirectoryBaseName() 333 project_file = 'dart-%s.xcodeproj' % CurrentDirectoryBaseName()
370 args = ['xcodebuild', 334 args = ['xcodebuild',
371 '-project', 335 '-project',
372 project_file, 336 project_file,
373 '-target', 337 '-target',
374 target, 338 target,
(...skipping 30 matching lines...) Expand all
405 options.j, 369 options.j,
406 'BUILDTYPE=' + build_config, 370 'BUILDTYPE=' + build_config,
407 ] 371 ]
408 if target_os != HOST_OS: 372 if target_os != HOST_OS:
409 args += ['builddir_name=' + utils.GetBuildDir(HOST_OS, target_os)] 373 args += ['builddir_name=' + utils.GetBuildDir(HOST_OS, target_os)]
410 if options.verbose: 374 if options.verbose:
411 args += ['V=1'] 375 args += ['V=1']
412 376
413 args += [target] 377 args += [target]
414 378
415 if target_os != HOST_OS: 379 toolchainprefix = options.toolchain
416 SetCrossCompilationEnvironment( 380 toolsOverride = SetTools(arch, target_os, toolchainprefix)
417 HOST_OS, target_os, arch, old_path)
418
419 RunhooksIfNeeded(HOST_OS, mode, arch, target_os)
420
421 toolchainprefix = None
422 if target_os == 'android':
423 toolchainprefix = ('%s/i686-linux-android'
424 % os.environ['ANDROID_TOOLCHAIN'])
425 toolsOverride = SetTools(arch, toolchainprefix)
426 if toolsOverride: 381 if toolsOverride:
427 printToolOverrides = target_os != 'android'
428 for k, v in toolsOverride.iteritems(): 382 for k, v in toolsOverride.iteritems():
429 args.append( k + "=" + v) 383 args.append( k + "=" + v)
430 if printToolOverrides: 384 if options.verbose:
431 print k + " = " + v 385 print k + " = " + v
432 if not os.path.isfile(toolsOverride['CC.target']): 386 if not os.path.isfile(toolsOverride['CC.target']):
433 if arch == 'arm': 387 if arch == 'arm':
434 print arm_cc_error 388 print arm_cc_error
435 else: 389 else:
436 print "Couldn't find compiler: %s" % toolsOverride['CC.target'] 390 print "Couldn't find compiler: %s" % toolsOverride['CC.target']
437 return 1 391 return 1
438 392
439 393
440 print ' '.join(args) 394 print ' '.join(args)
(...skipping 10 matching lines...) Expand all
451 process.wait() 405 process.wait()
452 if process.returncode != 0: 406 if process.returncode != 0:
453 print "BUILD FAILED" 407 print "BUILD FAILED"
454 return 1 408 return 1
455 409
456 return 0 410 return 0
457 411
458 412
459 if __name__ == '__main__': 413 if __name__ == '__main__':
460 sys.exit(Main()) 414 sys.exit(Main())
OLDNEW
« no previous file with comments | « dart/tools/android_link.py ('k') | dart/tools/dom/scripts/systemnative.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698