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

Side by Side Diff: tools/build.py

Issue 397593006: Fixes create_sdk target for cross-builds. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 5 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 | « no previous file | tools/utils.py » ('j') | tools/utils.py » ('J')
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
11 import shutil 11 import shutil
12 import subprocess 12 import subprocess
13 import sys 13 import sys
14 import time 14 import time
15 import utils 15 import utils
16 16
17 HOST_OS = utils.GuessOS() 17 HOST_OS = utils.GuessOS()
18 HOST_ARCH = utils.GuessArchitecture()
18 HOST_CPUS = utils.GuessCpus() 19 HOST_CPUS = utils.GuessCpus()
19 SCRIPT_DIR = os.path.dirname(sys.argv[0]) 20 SCRIPT_DIR = os.path.dirname(sys.argv[0])
20 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..')) 21 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..'))
21 THIRD_PARTY_ROOT = os.path.join(DART_ROOT, 'third_party') 22 THIRD_PARTY_ROOT = os.path.join(DART_ROOT, 'third_party')
22 23
23 arm_cc_error = """ 24 arm_cc_error = """
24 Couldn't find the arm cross compiler. 25 Couldn't find the arm cross compiler.
25 To make sure that you have the arm cross compilation tools installed, run: 26 To make sure that you have the arm cross compilation tools installed, run:
26 27
27 $ wget http://src.chromium.org/chrome/trunk/src/build/install-build-deps.sh 28 $ wget http://src.chromium.org/chrome/trunk/src/build/install-build-deps.sh
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 % (os, arch)) 114 % (os, arch))
114 return False 115 return False
115 # We have not yet tweaked the v8 dart build to work with the Android 116 # We have not yet tweaked the v8 dart build to work with the Android
116 # NDK/SDK, so don't try to build it. 117 # NDK/SDK, so don't try to build it.
117 if args == []: 118 if args == []:
118 print "For android builds you must specify a target, such as 'runtime'." 119 print "For android builds you must specify a target, such as 'runtime'."
119 return False 120 return False
120 return True 121 return True
121 122
122 123
123 def SetTools(arch, target_os, toolchainprefix): 124 def GetToolchainPrefix(target_os, arch, options):
125 if options.toolchain != None:
126 return options.toolchain
127
128 if target_os == 'android':
129 android_toolchain = GetAndroidToolchainDir(HOST_OS, arch)
130 if arch == 'arm':
131 return os.path.join(android_toolchain, 'arm-linux-androideabi')
132 if arch == 'ia32':
133 return os.path.join(android_toolchain, 'i686-linux-android')
134
135 # If no cross compiler is specified, only try to figure one out on Linux.
136 if not HOST_OS in ['linux']:
137 print "Unless --toolchain is used cross-building is only supported on Linux"
138 return None
139
140 # For ARM Linux, by default use the Linux distribution's cross-compiler.
141 if arch == 'arm':
142 # To use a non-hf compiler, specify on the command line with --toolchain.
143 return (DEFAULT_ARM_CROSS_COMPILER_PATH + "/arm-linux-gnueabihf")
144
145 # TODO(zra): Find default MIPS and ARM64 Linux cross-compilers.
146
147 return None
148
149
150 def SetTools(arch, target_os, options):
124 toolsOverride = None 151 toolsOverride = None
125 152
126 # For Android, by default use the toolchain from third_party/android_tools. 153 toolchainprefix = GetToolchainPrefix(target_os, arch, options)
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.
137 if arch == 'arm' and toolchainprefix == None:
138 # We specify the hf compiler. If this changes, we must also remove
139 # the ARM_FLOAT_ABI_HARD define in configurations_make.gypi.
140 toolchainprefix = (DEFAULT_ARM_CROSS_COMPILER_PATH +
141 "/arm-linux-gnueabihf")
142
143 # TODO(zra): Find a default MIPS Linux cross-compiler?
144 154
145 # Override the Android toolchain's linker to handle some complexity in the 155 # Override the Android toolchain's linker to handle some complexity in the
146 # linker arguments that gyp has trouble with. 156 # linker arguments that gyp has trouble with.
147 linker = "" 157 linker = ""
148 if target_os == 'android': 158 if target_os == 'android':
149 linker = os.path.join(DART_ROOT, 'tools', 'android_link.py') 159 linker = os.path.join(DART_ROOT, 'tools', 'android_link.py')
150 elif toolchainprefix: 160 elif toolchainprefix:
151 linker = toolchainprefix + "-g++" 161 linker = toolchainprefix + "-g++"
152 162
153 if toolchainprefix: 163 if toolchainprefix:
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 "$n.showballoontip(%d, '%s', '%s', " 360 "$n.showballoontip(%d, '%s', '%s', "
351 "[system.windows.forms.tooltipicon]::%s);\"") % ( 361 "[system.windows.forms.tooltipicon]::%s);\"") % (
352 5000, # Notification stays on for this many milliseconds 362 5000, # Notification stays on for this many milliseconds
353 message, title, icon) 363 message, title, icon)
354 364
355 if command: 365 if command:
356 # Ignore return code, if this command fails, it doesn't matter. 366 # Ignore return code, if this command fails, it doesn't matter.
357 os.system(command) 367 os.system(command)
358 368
359 369
370 filter_xcodebuild_output = False
371 def BuildOneConfig(options, target, target_os, mode, arch, override_tools=True):
372 global filter_xcodebuild_output
373 start_time = time.time()
374 os.environ['DART_BUILD_MODE'] = mode
375 build_config = utils.GetBuildConf(mode, arch, target_os)
376 if HOST_OS == 'macos':
377 filter_xcodebuild_output = True
378 project_file = 'dart.xcodeproj'
379 if os.path.exists('dart-%s.gyp' % CurrentDirectoryBaseName()):
380 project_file = 'dart-%s.xcodeproj' % CurrentDirectoryBaseName()
381 args = ['xcodebuild',
382 '-project',
383 project_file,
384 '-target',
385 target,
386 '-configuration',
387 build_config,
388 'SYMROOT=%s' % os.path.abspath('xcodebuild')
389 ]
390 elif HOST_OS == 'win32':
391 project_file = 'dart.sln'
392 if os.path.exists('dart-%s.gyp' % CurrentDirectoryBaseName()):
393 project_file = 'dart-%s.sln' % CurrentDirectoryBaseName()
394 # Select a platform suffix to pass to devenv.
395 if arch == 'ia32':
396 platform_suffix = 'Win32'
397 elif arch == 'x64':
398 platform_suffix = 'x64'
399 else:
400 print 'Unsupported arch for MSVC build: %s' % arch
401 return 1
402 config_name = '%s|%s' % (build_config, platform_suffix)
403 if target == 'all':
404 args = [options.devenv + os.sep + options.executable,
405 '/build',
406 config_name,
407 project_file
408 ]
409 else:
410 args = [options.devenv + os.sep + options.executable,
411 '/build',
412 config_name,
413 '/project',
414 target,
415 project_file
416 ]
417 else:
418 make = 'make'
419 if HOST_OS == 'freebsd':
420 make = 'gmake'
421 # work around lack of flock
422 os.environ['LINK'] = '$(CXX)'
423 args = [make,
424 '-j',
425 options.j,
426 'BUILDTYPE=' + build_config,
427 ]
428 if target_os != HOST_OS:
429 args += ['builddir_name=' + utils.GetBuildDir(HOST_OS, target_os)]
430 if options.verbose:
431 args += ['V=1']
432
433 args += [target]
434
435 toolsOverride = None
436 if override_tools:
437 toolsOverride = SetTools(arch, target_os, options)
438 if toolsOverride:
439 for k, v in toolsOverride.iteritems():
440 args.append( k + "=" + v)
441 if options.verbose:
442 print k + " = " + v
443 if not os.path.isfile(toolsOverride['CC.target']):
444 if arch == 'arm':
445 print arm_cc_error
446 else:
447 print "Couldn't find compiler: %s" % toolsOverride['CC.target']
448 return 1
449
450
451 print ' '.join(args)
452 process = None
453 if filter_xcodebuild_output:
454 process = subprocess.Popen(args,
455 stdin=None,
456 bufsize=1, # Line buffered.
457 stdout=subprocess.PIPE,
458 stderr=subprocess.STDOUT)
459 FilterEmptyXcodebuildSections(process)
460 else:
461 process = subprocess.Popen(args, stdin=None)
462 process.wait()
463 if process.returncode != 0:
464 NotifyBuildDone(build_config, success=False, start=start_time)
465 return 1
466 else:
467 NotifyBuildDone(build_config, success=True, start=start_time)
468
469 return 0
470
471
472 def BuildCrossSdk(options, target_os, mode, arch):
zra 2014/07/15 23:15:52 This is where the new stuff is.
473 # First build 'create_sdk' for the host. Do not override the host toolchain.
474 if BuildOneConfig(options, 'create_sdk', HOST_OS, mode, HOST_ARCH, False) != 0 :
Ivan Posva 2014/07/16 05:46:02 Long Life
zra 2014/07/16 14:48:20 Done.
475 return 1
476
477 # Then, build the runtime for the target arch.
478 if BuildOneConfig(options, 'runtime', target_os, mode, arch) != 0:
479 return 1
480
481 # Copy dart-sdk from the host build products dir to the target build
482 # products dir, and copy the dart binary for target to the sdk bin/ dir.
483 src = os.path.join(
484 utils.GetBuildRoot(HOST_OS, mode, HOST_ARCH, HOST_OS), 'dart-sdk')
485 dst = os.path.join(
486 utils.GetBuildRoot(HOST_OS, mode, arch, target_os), 'dart-sdk')
487 shutil.rmtree(dst, ignore_errors=True)
488 shutil.copytree(src, dst)
489
490 dart = os.path.join(
491 utils.GetBuildRoot(HOST_OS, mode, arch, target_os), 'dart')
492 bin = os.path.join(dst, 'bin')
493 shutil.copy(dart, bin)
494
495 # Strip the dart binary
496 toolchainprefix = GetToolchainPrefix(target_os, arch, options)
497 if toolchainprefix == None:
498 print "Couldn't figure out the cross-toolchain"
499 return 1
500 strip = toolchainprefix + '-strip'
501 subprocess.call([strip, os.path.join(bin, 'dart')])
502
503 return 0
504
505
360 def Main(): 506 def Main():
361 utils.ConfigureJava() 507 utils.ConfigureJava()
362 # Parse the options. 508 # Parse the options.
363 parser = BuildOptions() 509 parser = BuildOptions()
364 (options, args) = parser.parse_args() 510 (options, args) = parser.parse_args()
365 if not ProcessOptions(options, args): 511 if not ProcessOptions(options, args):
366 parser.print_help() 512 parser.print_help()
367 return 1 513 return 1
368 # Determine which targets to build. By default we build the "all" target. 514 # Determine which targets to build. By default we build the "all" target.
369 if len(args) == 0: 515 if len(args) == 0:
370 if HOST_OS == 'macos': 516 if HOST_OS == 'macos':
371 targets = ['All'] 517 targets = ['All']
372 else: 518 else:
373 targets = ['all'] 519 targets = ['all']
374 else: 520 else:
375 targets = args 521 targets = args
376 522
377 filter_xcodebuild_output = False
378 # Build all targets for each requested configuration. 523 # Build all targets for each requested configuration.
379 for target in targets: 524 for target in targets:
380 for target_os in options.os: 525 for target_os in options.os:
381 for mode in options.mode: 526 for mode in options.mode:
382 for arch in options.arch: 527 for arch in options.arch:
383 start_time = time.time() 528 if target in ['create_sdk'] and utils.IsCrossBuild(target_os, arch):
384 os.environ['DART_BUILD_MODE'] = mode 529 if BuildCrossSdk(options, target_os, mode, arch) != 0:
385 build_config = utils.GetBuildConf(mode, arch, target_os)
386 if HOST_OS == 'macos':
387 filter_xcodebuild_output = True
388 project_file = 'dart.xcodeproj'
389 if os.path.exists('dart-%s.gyp' % CurrentDirectoryBaseName()):
390 project_file = 'dart-%s.xcodeproj' % CurrentDirectoryBaseName()
391 args = ['xcodebuild',
392 '-project',
393 project_file,
394 '-target',
395 target,
396 '-configuration',
397 build_config,
398 'SYMROOT=%s' % os.path.abspath('xcodebuild')
399 ]
400 elif HOST_OS == 'win32':
401 project_file = 'dart.sln'
402 if os.path.exists('dart-%s.gyp' % CurrentDirectoryBaseName()):
403 project_file = 'dart-%s.sln' % CurrentDirectoryBaseName()
404 # Select a platform suffix to pass to devenv.
405 if arch == 'ia32':
406 platform_suffix = 'Win32'
407 elif arch == 'x64':
408 platform_suffix = 'x64'
409 else:
410 print 'Unsupported arch for MSVC build: %s' % arch
411 return 1 530 return 1
412 config_name = '%s|%s' % (build_config, platform_suffix)
413 if target == 'all':
414 args = [options.devenv + os.sep + options.executable,
415 '/build',
416 config_name,
417 project_file
418 ]
419 else:
420 args = [options.devenv + os.sep + options.executable,
421 '/build',
422 config_name,
423 '/project',
424 target,
425 project_file
426 ]
427 else: 531 else:
428 make = 'make' 532 if BuildOneConfig(options, target, target_os, mode, arch) != 0:
429 if HOST_OS == 'freebsd':
430 make = 'gmake'
431 # work around lack of flock
432 os.environ['LINK'] = '$(CXX)'
433 args = [make,
434 '-j',
435 options.j,
436 'BUILDTYPE=' + build_config,
437 ]
438 if target_os != HOST_OS:
439 args += ['builddir_name=' + utils.GetBuildDir(HOST_OS, target_os)]
440 if options.verbose:
441 args += ['V=1']
442
443 args += [target]
444
445 toolchainprefix = options.toolchain
446 toolsOverride = SetTools(arch, target_os, toolchainprefix)
447 if toolsOverride:
448 for k, v in toolsOverride.iteritems():
449 args.append( k + "=" + v)
450 if options.verbose:
451 print k + " = " + v
452 if not os.path.isfile(toolsOverride['CC.target']):
453 if arch == 'arm':
454 print arm_cc_error
455 else:
456 print "Couldn't find compiler: %s" % toolsOverride['CC.target']
457 return 1 533 return 1
458 534
459
460 print ' '.join(args)
461 process = None
462 if filter_xcodebuild_output:
463 process = subprocess.Popen(args,
464 stdin=None,
465 bufsize=1, # Line buffered.
466 stdout=subprocess.PIPE,
467 stderr=subprocess.STDOUT)
468 FilterEmptyXcodebuildSections(process)
469 else:
470 process = subprocess.Popen(args, stdin=None)
471 process.wait()
472 if process.returncode != 0:
473 NotifyBuildDone(build_config, success=False, start=start_time)
474 return 1
475 else:
476 NotifyBuildDone(build_config, success=True, start=start_time)
477
478 return 0 535 return 0
479 536
480 537
481 if __name__ == '__main__': 538 if __name__ == '__main__':
482 sys.exit(Main()) 539 sys.exit(Main())
OLDNEW
« no previous file with comments | « no previous file | tools/utils.py » ('j') | tools/utils.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698