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

Side by Side Diff: tools/clang/scripts/update.py

Issue 2793343002: Add --enable-pgo option to build clang with PGO
Patch Set: Add clang build with PGO Created 3 years, 7 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
« no previous file with comments | « tools/clang/scripts/package.py ('k') | tools/clang/stage2.cmake » ('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 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """This script is used to download prebuilt clang binaries. 6 """This script is used to download prebuilt clang binaries.
7 7
8 It is also used by package.py to build the prebuilt clang binaries.""" 8 It is also used by package.py to build the prebuilt clang binaries."""
9 9
10 import argparse 10 import argparse
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 return vs_version 368 return vs_version
369 369
370 370
371 def CopyDiaDllTo(target_dir): 371 def CopyDiaDllTo(target_dir):
372 # This script always wants to use the 64-bit msdia*.dll. 372 # This script always wants to use the 64-bit msdia*.dll.
373 dia_path = os.path.join(GetVSVersion().Path(), 'DIA SDK', 'bin', 'amd64') 373 dia_path = os.path.join(GetVSVersion().Path(), 'DIA SDK', 'bin', 'amd64')
374 dia_dll = os.path.join(dia_path, DIA_DLL[GetVSVersion().ShortName()]) 374 dia_dll = os.path.join(dia_path, DIA_DLL[GetVSVersion().ShortName()])
375 CopyFile(dia_dll, target_dir) 375 CopyFile(dia_dll, target_dir)
376 376
377 377
378 def GetNewCCAndCXX(install_dir):
379 if sys.platform == 'win32':
380 cc = os.path.join(install_dir, 'bin', 'clang-cl.exe')
381 cxx = os.path.join(install_dir, 'bin', 'clang-cl.exe')
382 # CMake has a hard time with backslashes in compiler paths:
383 # https://stackoverflow.com/questions/13050827
384 cc = cc.replace('\\', '/')
385 cxx = cxx.replace('\\', '/')
386 else:
387 cc = os.path.join(install_dir, 'bin', 'clang')
388 cxx = os.path.join(install_dir, 'bin', 'clang++')
389
390 return cc, cxx
391
392
393 def BuildLLVMgold(args, install_dir, base_cmake_args, binutils_incdir, cc, cxx):
394 # Build LLVM gold plugin with LTO. That speeds up the linker by ~10%.
395 # We only use LTO for Linux now.
396 print 'Building LTO LLVM Gold plugin'
397 if os.path.exists(LLVM_LTO_GOLD_PLUGIN_DIR):
398 RmTree(LLVM_LTO_GOLD_PLUGIN_DIR)
399 EnsureDirExists(LLVM_LTO_GOLD_PLUGIN_DIR)
400 os.chdir(LLVM_LTO_GOLD_PLUGIN_DIR)
401
402 # Create a symlink to LLVMgold.so build in the previous step so that ar
403 # and ranlib could find it while linking LLVMgold.so with LTO.
404 EnsureDirExists(BFD_PLUGINS_DIR)
405 RunCommand(['ln', '-sf',
406 os.path.join(install_dir, 'lib', 'LLVMgold.so'),
407 os.path.join(BFD_PLUGINS_DIR, 'LLVMgold.so')])
408
409 # Link against binutils's copy of tcmalloc to speed up the linker by ~10%.
410 # In package.py we copy the .so into our package.
411 tcmalloc_ldflags = ['-L' + BINUTILS_LIB_DIR, '-ltcmalloc_minimal']
412 # Make sure that tblgen and the test suite can find tcmalloc.
413 os.environ['LD_LIBRARY_PATH'] = \
414 BINUTILS_LIB_DIR + os.pathsep + os.environ.get('LD_LIBRARY_PATH', '')
415
416 lto_cflags = ['-flto=thin']
417 lto_ldflags = ['-fuse-ld=lld']
418 if args.gcc_toolchain:
419 # Tell the bootstrap compiler to use a specific gcc prefix to search
420 # for standard library headers and shared object files.
421 lto_cflags += ['--gcc-toolchain=' + args.gcc_toolchain]
422 lto_cmake_args = base_cmake_args + [
423 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir,
424 '-DCMAKE_C_COMPILER=' + cc,
425 '-DCMAKE_CXX_COMPILER=' + cxx,
426 '-DCMAKE_C_FLAGS=' + ' '.join(lto_cflags),
427 '-DCMAKE_CXX_FLAGS=' + ' '.join(lto_cflags),
428 '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(lto_ldflags + tcmalloc_ldflags),
429 '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(lto_ldflags),
430 '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(lto_ldflags)]
431
432 # We need to use the proper binutils which support LLVM Gold plugin.
433 lto_env = os.environ.copy()
434 lto_env['PATH'] = BINUTILS_BIN_DIR + os.pathsep + lto_env.get('PATH', '')
435
436 RmCmakeCache('.')
437 RunCommand(['cmake'] + lto_cmake_args + [LLVM_DIR], env=lto_env)
438 RunCommand(['ninja', 'LLVMgold', 'lld'], env=lto_env)
439
440
378 def VeryifyVersionOfBuiltClangMatchesVERSION(): 441 def VeryifyVersionOfBuiltClangMatchesVERSION():
379 """Checks that `clang --version` outputs VERSION. If this fails, VERSION 442 """Checks that `clang --version` outputs VERSION. If this fails, VERSION
380 in this file is out-of-date and needs to be updated (possibly in an 443 in this file is out-of-date and needs to be updated (possibly in an
381 `if use_head_revision:` block in main() first).""" 444 `if use_head_revision:` block in main() first)."""
382 clang = os.path.join(LLVM_BUILD_DIR, 'bin', 'clang') 445 clang = os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')
383 if sys.platform == 'win32': 446 if sys.platform == 'win32':
384 # TODO: Parse `clang-cl /?` output for built clang's version and check that 447 # TODO: Parse `clang-cl /?` output for built clang's version and check that
385 # to check the binary we're actually shipping? But clang-cl.exe is just 448 # to check the binary we're actually shipping? But clang-cl.exe is just
386 # a copy of clang.exe, so this does check the same thing. 449 # a copy of clang.exe, so this does check the same thing.
387 clang += '.exe' 450 clang += '.exe'
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 DeleteChromeToolsShim() 518 DeleteChromeToolsShim()
456 519
457 Checkout('LLVM', LLVM_REPO_URL + '/llvm/trunk', LLVM_DIR) 520 Checkout('LLVM', LLVM_REPO_URL + '/llvm/trunk', LLVM_DIR)
458 Checkout('Clang', LLVM_REPO_URL + '/cfe/trunk', CLANG_DIR) 521 Checkout('Clang', LLVM_REPO_URL + '/cfe/trunk', CLANG_DIR)
459 if sys.platform != 'darwin': 522 if sys.platform != 'darwin':
460 Checkout('LLD', LLVM_REPO_URL + '/lld/trunk', LLD_DIR) 523 Checkout('LLD', LLVM_REPO_URL + '/lld/trunk', LLD_DIR)
461 elif os.path.exists(LLD_DIR): 524 elif os.path.exists(LLD_DIR):
462 # In case someone sends a tryjob that temporary adds lld to the checkout, 525 # In case someone sends a tryjob that temporary adds lld to the checkout,
463 # make sure it's not around on future builds. 526 # make sure it's not around on future builds.
464 RmTree(LLD_DIR) 527 RmTree(LLD_DIR)
465 Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', COMPILER_RT_DIR) 528 if args.enable_pgo:
529 # PGO requires compiler-rt.
530 Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk',
531 os.path.join(LLVM_DIR, 'projects', 'compiler-rt'))
466 if sys.platform == 'darwin': 532 if sys.platform == 'darwin':
467 # clang needs a libc++ checkout, else -stdlib=libc++ won't find includes 533 # clang needs a libc++ checkout, else -stdlib=libc++ won't find includes
468 # (i.e. this is needed for bootstrap builds). 534 # (i.e. this is needed for bootstrap builds).
469 Checkout('libcxx', LLVM_REPO_URL + '/libcxx/trunk', LIBCXX_DIR) 535 Checkout('libcxx', LLVM_REPO_URL + '/libcxx/trunk', LIBCXX_DIR)
470 # We used to check out libcxxabi on OS X; we no longer need that. 536 # We used to check out libcxxabi on OS X; we no longer need that.
471 if os.path.exists(LIBCXXABI_DIR): 537 if os.path.exists(LIBCXXABI_DIR):
472 RmTree(LIBCXXABI_DIR) 538 RmTree(LIBCXXABI_DIR)
473 539
474 cc, cxx = None, None 540 cc, cxx = None, None
475 libstdcpp = None 541 libstdcpp = None
(...skipping 21 matching lines...) Expand all
497 '-DCMAKE_BUILD_TYPE=Release', 563 '-DCMAKE_BUILD_TYPE=Release',
498 '-DLLVM_ENABLE_ASSERTIONS=ON', 564 '-DLLVM_ENABLE_ASSERTIONS=ON',
499 # Statically link MSVCRT to avoid DLL dependencies. 565 # Statically link MSVCRT to avoid DLL dependencies.
500 '-DLLVM_USE_CRT_RELEASE=MT', 566 '-DLLVM_USE_CRT_RELEASE=MT',
501 ] 567 ]
502 568
503 binutils_incdir = '' 569 binutils_incdir = ''
504 if sys.platform.startswith('linux'): 570 if sys.platform.startswith('linux'):
505 binutils_incdir = os.path.join(BINUTILS_DIR, 'include') 571 binutils_incdir = os.path.join(BINUTILS_DIR, 'include')
506 572
507 if args.bootstrap:
508 print 'Building bootstrap compiler'
509 EnsureDirExists(LLVM_BOOTSTRAP_DIR)
510 os.chdir(LLVM_BOOTSTRAP_DIR)
511 bootstrap_args = base_cmake_args + [
512 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir,
513 '-DLLVM_TARGETS_TO_BUILD=host',
514 '-DCMAKE_INSTALL_PREFIX=' + LLVM_BOOTSTRAP_INSTALL_DIR,
515 '-DCMAKE_C_FLAGS=' + ' '.join(cflags),
516 '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
517 ]
518 if cc is not None: bootstrap_args.append('-DCMAKE_C_COMPILER=' + cc)
519 if cxx is not None: bootstrap_args.append('-DCMAKE_CXX_COMPILER=' + cxx)
520 RmCmakeCache('.')
521 RunCommand(['cmake'] + bootstrap_args + [LLVM_DIR], msvc_arch='x64')
522 RunCommand(['ninja'], msvc_arch='x64')
523 if args.run_tests:
524 if sys.platform == 'win32':
525 CopyDiaDllTo(os.path.join(LLVM_BOOTSTRAP_DIR, 'bin'))
526 RunCommand(['ninja', 'check-all'], msvc_arch='x64')
527 RunCommand(['ninja', 'install'], msvc_arch='x64')
528 if args.gcc_toolchain:
529 # Copy that gcc's stdlibc++.so.6 to the build dir, so the bootstrap
530 # compiler can start.
531 CopyFile(libstdcpp, os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'lib'))
532
533 if sys.platform == 'win32':
534 cc = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang-cl.exe')
535 cxx = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang-cl.exe')
536 # CMake has a hard time with backslashes in compiler paths:
537 # https://stackoverflow.com/questions/13050827
538 cc = cc.replace('\\', '/')
539 cxx = cxx.replace('\\', '/')
540 else:
541 cc = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang')
542 cxx = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang++')
543
544 if args.gcc_toolchain:
545 # Tell the bootstrap compiler to use a specific gcc prefix to search
546 # for standard library headers and shared object files.
547 cflags = ['--gcc-toolchain=' + args.gcc_toolchain]
548 cxxflags = ['--gcc-toolchain=' + args.gcc_toolchain]
549 print 'Building final compiler'
550
551 # Build LLVM gold plugin with LTO. That speeds up the linker by ~10%.
552 # We only use LTO for Linux now.
553 if args.bootstrap and args.lto_gold_plugin:
554 print 'Building LTO LLVM Gold plugin'
555 if os.path.exists(LLVM_LTO_GOLD_PLUGIN_DIR):
556 RmTree(LLVM_LTO_GOLD_PLUGIN_DIR)
557 EnsureDirExists(LLVM_LTO_GOLD_PLUGIN_DIR)
558 os.chdir(LLVM_LTO_GOLD_PLUGIN_DIR)
559
560 # Create a symlink to LLVMgold.so build in the previous step so that ar
561 # and ranlib could find it while linking LLVMgold.so with LTO.
562 EnsureDirExists(BFD_PLUGINS_DIR)
563 RunCommand(['ln', '-sf',
564 os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'lib', 'LLVMgold.so'),
565 os.path.join(BFD_PLUGINS_DIR, 'LLVMgold.so')])
566
567 # Link against binutils's copy of tcmalloc to speed up the linker by ~10%.
568 # In package.py we copy the .so into our package.
569 tcmalloc_ldflags = ['-L' + BINUTILS_LIB_DIR, '-ltcmalloc_minimal']
570 # Make sure that tblgen and the test suite can find tcmalloc.
571 os.environ['LD_LIBRARY_PATH'] = \
572 BINUTILS_LIB_DIR + os.pathsep + os.environ.get('LD_LIBRARY_PATH', '')
573
574 lto_cflags = ['-flto=thin']
575 lto_ldflags = ['-fuse-ld=lld']
576 if args.gcc_toolchain:
577 # Tell the bootstrap compiler to use a specific gcc prefix to search
578 # for standard library headers and shared object files.
579 lto_cflags += ['--gcc-toolchain=' + args.gcc_toolchain]
580 lto_cmake_args = base_cmake_args + [
581 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir,
582 '-DCMAKE_C_COMPILER=' + cc,
583 '-DCMAKE_CXX_COMPILER=' + cxx,
584 '-DCMAKE_C_FLAGS=' + ' '.join(lto_cflags),
585 '-DCMAKE_CXX_FLAGS=' + ' '.join(lto_cflags),
586 '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(lto_ldflags + tcmalloc_ldflags),
587 '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(lto_ldflags),
588 '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(lto_ldflags)]
589
590 # We need to use the proper binutils which support LLVM Gold plugin.
591 lto_env = os.environ.copy()
592 lto_env['PATH'] = BINUTILS_BIN_DIR + os.pathsep + lto_env.get('PATH', '')
593
594 RmCmakeCache('.')
595 RunCommand(['cmake'] + lto_cmake_args + [LLVM_DIR], env=lto_env)
596 RunCommand(['ninja', 'LLVMgold', 'lld'], env=lto_env)
597
598
599 # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is 573 # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is
600 # needed, on OS X it requires libc++. clang only automatically links to libc++ 574 # needed, on OS X it requires libc++. clang only automatically links to libc++
601 # when targeting OS X 10.9+, so add stdlib=libc++ explicitly so clang can run 575 # when targeting OS X 10.9+, so add stdlib=libc++ explicitly so clang can run
602 # on OS X versions as old as 10.7. 576 # on OS X versions as old as 10.7.
603 deployment_target = '' 577 deployment_target = ''
604 578
605 if sys.platform == 'darwin' and args.bootstrap: 579 if sys.platform == 'darwin' and args.enable_pgo:
606 # When building on 10.9, /usr/include usually doesn't exist, and while 580 # When building on 10.9, /usr/include usually doesn't exist, and while
607 # Xcode's clang automatically sets a sysroot, self-built clangs don't. 581 # Xcode's clang automatically sets a sysroot, self-built clangs don't.
608 cflags = ['-isysroot', subprocess.check_output( 582 cflags = ['-isysroot', subprocess.check_output(
609 ['xcrun', '--show-sdk-path']).rstrip()] 583 ['xcrun', '--show-sdk-path']).rstrip()]
610 cxxflags = ['-stdlib=libc++'] + cflags 584 cxxflags = ['-stdlib=libc++'] + cflags
611 ldflags += ['-stdlib=libc++'] 585 ldflags += ['-stdlib=libc++']
612 deployment_target = '10.7' 586 deployment_target = '10.7'
613 # Running libc++ tests takes a long time. Since it was only needed for
614 # the install step above, don't build it as part of the main build.
615 # This makes running package.py over 10% faster (30 min instead of 34 min)
616 RmTree(LIBCXX_DIR)
617 587
618 # Build clang. 588 # Build clang.
619 589
620 # If building at head, define a macro that plugins can use for #ifdefing 590 # If building at head, define a macro that plugins can use for #ifdefing
621 # out code that builds at head, but not at CLANG_REVISION or vice versa. 591 # out code that builds at head, but not at CLANG_REVISION or vice versa.
622 if use_head_revision: 592 if use_head_revision:
623 cflags += ['-DLLVM_FORCE_HEAD_REVISION'] 593 cflags += ['-DLLVM_FORCE_HEAD_REVISION']
624 cxxflags += ['-DLLVM_FORCE_HEAD_REVISION'] 594 cxxflags += ['-DLLVM_FORCE_HEAD_REVISION']
625 595
626 # Build PDBs for archival on Windows. Don't use RelWithDebInfo since it 596 # Build PDBs for archival on Windows. Don't use RelWithDebInfo since it
(...skipping 10 matching lines...) Expand all
637 deployment_env = os.environ.copy() 607 deployment_env = os.environ.copy()
638 deployment_env['MACOSX_DEPLOYMENT_TARGET'] = deployment_target 608 deployment_env['MACOSX_DEPLOYMENT_TARGET'] = deployment_target
639 609
640 cmake_args = [] 610 cmake_args = []
641 # TODO(thakis): Unconditionally append this to base_cmake_args instead once 611 # TODO(thakis): Unconditionally append this to base_cmake_args instead once
642 # compiler-rt can build with clang-cl on Windows (http://llvm.org/PR23698) 612 # compiler-rt can build with clang-cl on Windows (http://llvm.org/PR23698)
643 cc_args = base_cmake_args if sys.platform != 'win32' else cmake_args 613 cc_args = base_cmake_args if sys.platform != 'win32' else cmake_args
644 if cc is not None: cc_args.append('-DCMAKE_C_COMPILER=' + cc) 614 if cc is not None: cc_args.append('-DCMAKE_C_COMPILER=' + cc)
645 if cxx is not None: cc_args.append('-DCMAKE_CXX_COMPILER=' + cxx) 615 if cxx is not None: cc_args.append('-DCMAKE_CXX_COMPILER=' + cxx)
646 chrome_tools = list(set(['plugins', 'blink_gc_plugin'] + args.extra_tools)) 616 chrome_tools = list(set(['plugins', 'blink_gc_plugin'] + args.extra_tools))
647 cmake_args += base_cmake_args + [ 617
648 '-DLLVM_ENABLE_THREADS=OFF', 618
619 stage2_cache = os.path.join(CHROMIUM_DIR, 'tools', 'clang', 'stage2.cmake')
620 if args.bootstrap:
621 additional_cmake_args = [
622 '-DBOOTSTRAP_CHROMIUM_TOOLS=%s' % ','.join(chrome_tools),
623 '-DBOOTSTRAP_CMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags),
624 '-DBOOTSTRAP_CMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags),
625 '-DBOOTSTRAP_CMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags),
626 '-DSTAGE2_CACHE_FILE=%s' % stage2_cache,
627 '-C', os.path.join(LLVM_DIR, 'tools', 'clang', 'cmake', 'caches',
628 'DistributionExample.cmake'),
629 ]
630 elif args.enable_pgo:
631 additional_cmake_args = [
632 '-DBOOTSTRAP_BOOTSTRAP_CHROMIUM_TOOLS=%s' % ','.join(chrome_tools),
633 '-DBOOTSTRAP_BOOTSTRAP_LLVM_BINUTILS_INCDIR=' + binutils_incdir,
634 '-DBOOTSTRAP_BOOTSTRAP_CMAKE_C_FLAGS=' + ' '.join(cflags),
635 '-DBOOTSTRAP_BOOTSTRAP_CMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
636 '-DBOOTSTRAP_BOOTSTRAP_CMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags),
637 '-DBOOTSTRAP_BOOTSTRAP_CMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags),
638 '-DBOOTSTRAP_BOOTSTRAP_CMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags),
639 '-DPGO_BUILD_CONFIGURATION=%s' % stage2_cache,
640 '-C', os.path.join(LLVM_DIR, 'tools', 'clang', 'cmake', 'caches',
641 'PGO.cmake')
642 ]
643
644 cmake_args += base_cmake_args + additional_cmake_args + [
645 # Override lto setting from DistributionExample.cmake cache, if used.
646 '-DPACKAGE_VENDOR=',
647 '-DBOOTSTRAP_LLVM_ENABLE_LTO=OFF',
648 '-DCMAKE_VERBOSE_MAKEFILE=ON',
649 '-DBOOTSTRAP_CMAKE_VERBOSE_MAKEFILE=ON',
650 '-DBOOTSTRAP_BOOTSTRAP_CMAKE_VERBOSE_MAKEFILE=ON',
649 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir, 651 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir,
652 '-DBOOTSTRAP_LLVM_BINUTILS_INCDIR=' + binutils_incdir,
650 '-DCMAKE_C_FLAGS=' + ' '.join(cflags), 653 '-DCMAKE_C_FLAGS=' + ' '.join(cflags),
654 '-DBOOTSTRAP_CMAKE_C_FLAGS=' + ' '.join(cflags),
651 '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags), 655 '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
652 '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags), 656 '-DBOOTSTRAP_CMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
653 '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags),
654 '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags),
655 '-DCMAKE_INSTALL_PREFIX=' + LLVM_BUILD_DIR, 657 '-DCMAKE_INSTALL_PREFIX=' + LLVM_BUILD_DIR,
656 '-DCHROMIUM_TOOLS_SRC=%s' % os.path.join(CHROMIUM_DIR, 'tools', 'clang'), 658 '-DCHROMIUM_TOOLS=%s' % ','.join(chrome_tools),
657 '-DCHROMIUM_TOOLS=%s' % ';'.join(chrome_tools)] 659 ]
658 660
659 EnsureDirExists(LLVM_BUILD_DIR) 661 EnsureDirExists(LLVM_BUILD_DIR)
660 os.chdir(LLVM_BUILD_DIR) 662 os.chdir(LLVM_BUILD_DIR)
661 RmCmakeCache('.') 663 RmCmakeCache('.')
662 RunCommand(['cmake'] + cmake_args + [LLVM_DIR], 664 RunCommand(['cmake'] + cmake_args + [LLVM_DIR],
663 msvc_arch='x64', env=deployment_env) 665 msvc_arch='x64', env=deployment_env)
664 666
667 RunCommand(['ninja', 'stage2'], env=deployment_env, msvc_arch='x64')
668
669 if args.bootstrap:
670 global LLVM_BUILD_DIR
671 LLVM_BUILD_DIR = os.path.join(
672 LLVM_BUILD_DIR, 'tools', 'clang', 'stage2-bins')
673 elif args.enable_pgo:
674 global LLVM_BUILD_DIR
675 LLVM_BUILD_DIR = os.path.join(LLVM_BUILD_DIR, 'tools', 'clang',
676 'stage2-instrumented-bins', 'tools', 'clang', 'stage2-bins')
677 os.chdir(LLVM_BUILD_DIR)
678
665 if args.gcc_toolchain: 679 if args.gcc_toolchain:
666 # Copy in the right stdlibc++.so.6 so clang can start. 680 # Copy in the right stdlibc++.so.6 so clang can start.
667 if not os.path.exists(os.path.join(LLVM_BUILD_DIR, 'lib')): 681 if not os.path.exists(os.path.join(LLVM_BUILD_DIR, 'lib')):
668 os.mkdir(os.path.join(LLVM_BUILD_DIR, 'lib')) 682 os.mkdir(os.path.join(LLVM_BUILD_DIR, 'lib'))
669 libstdcpp = subprocess.check_output( 683 libstdcpp = subprocess.check_output(
670 [cxx] + cxxflags + ['-print-file-name=libstdc++.so.6']).rstrip() 684 [cxx] + cxxflags + ['-print-file-name=libstdc++.so.6']).rstrip()
671 CopyFile(libstdcpp, os.path.join(LLVM_BUILD_DIR, 'lib')) 685 CopyFile(libstdcpp, os.path.join(LLVM_BUILD_DIR, 'lib'))
672 686
673 RunCommand(['ninja'], msvc_arch='x64') 687 RunCommand(['ninja', 'cr-install'], msvc_arch='x64')
674 688
675 # Copy LTO-optimized lld, if any. 689 # Build & copy LTO-optimized lld, if any.
676 if args.bootstrap and args.lto_gold_plugin: 690 if args.lto_gold_plugin:
691 cc, cxx = GetNewCCAndCXX(LLVM_BUILD_DIR)
692 BuildLLVMgold(args, LLVM_BUILD_DIR, base_cmake_args,
693 binutils_incdir, cc, cxx)
677 CopyFile(os.path.join(LLVM_LTO_GOLD_PLUGIN_DIR, 'bin', 'lld'), 694 CopyFile(os.path.join(LLVM_LTO_GOLD_PLUGIN_DIR, 'bin', 'lld'),
678 os.path.join(LLVM_BUILD_DIR, 'bin')) 695 os.path.join(LLVM_BUILD_DIR, 'bin'))
679 696
680 if chrome_tools:
681 # If any Chromium tools were built, install those now.
682 RunCommand(['ninja', 'cr-install'], msvc_arch='x64')
683
684 if sys.platform == 'darwin': 697 if sys.platform == 'darwin':
685 # See http://crbug.com/256342 698 # See http://crbug.com/256342
686 RunCommand(['strip', '-x', os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')]) 699 RunCommand(['strip', '-x', os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')])
687 elif sys.platform.startswith('linux'): 700 elif sys.platform.startswith('linux'):
688 RunCommand(['strip', os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')]) 701 RunCommand(['strip', os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')])
689 702
690 VeryifyVersionOfBuiltClangMatchesVERSION() 703 VeryifyVersionOfBuiltClangMatchesVERSION()
691 704
692 # Do an out-of-tree build of compiler-rt. 705 # Do an out-of-tree build of compiler-rt.
693 # On Windows, this is used to get the 32-bit ASan run-time. 706 # On Windows, this is used to get the 32-bit ASan run-time.
694 # TODO(hans): Remove once the regular build above produces this. 707 # TODO(hans): Remove once the regular build above produces this.
695 # On Mac and Linux, this is used to get the regular 64-bit run-time. 708 # On Mac and Linux, this is used to get the regular 64-bit run-time.
696 # Do a clobbered build due to cmake changes. 709 # Do a clobbered build due to cmake changes.
710 Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', COMPILER_RT_DIR)
697 if os.path.isdir(COMPILER_RT_BUILD_DIR): 711 if os.path.isdir(COMPILER_RT_BUILD_DIR):
698 RmTree(COMPILER_RT_BUILD_DIR) 712 RmTree(COMPILER_RT_BUILD_DIR)
699 os.makedirs(COMPILER_RT_BUILD_DIR) 713 os.makedirs(COMPILER_RT_BUILD_DIR)
700 os.chdir(COMPILER_RT_BUILD_DIR) 714 os.chdir(COMPILER_RT_BUILD_DIR)
701 # TODO(thakis): Add this once compiler-rt can build with clang-cl (see 715 # TODO(thakis): Add this once compiler-rt can build with clang-cl (see
702 # above). 716 # above).
703 #if args.bootstrap and sys.platform == 'win32': 717 #if args.bootstrap and sys.platform == 'win32':
704 # The bootstrap compiler produces 64-bit binaries by default. 718 # The bootstrap compiler produces 64-bit binaries by default.
705 #cflags += ['-m32'] 719 #cflags += ['-m32']
706 #cxxflags += ['-m32'] 720 #cxxflags += ['-m32']
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 parser.add_argument('--print-clang-version', action='store_true', 875 parser.add_argument('--print-clang-version', action='store_true',
862 help='print current clang version (e.g. x.y.z) and exit.') 876 help='print current clang version (e.g. x.y.z) and exit.')
863 parser.add_argument('--run-tests', action='store_true', 877 parser.add_argument('--run-tests', action='store_true',
864 help='run tests after building; only for local builds') 878 help='run tests after building; only for local builds')
865 parser.add_argument('--extra-tools', nargs='*', default=[], 879 parser.add_argument('--extra-tools', nargs='*', default=[],
866 help='select additional chrome tools to build') 880 help='select additional chrome tools to build')
867 parser.add_argument('--without-android', action='store_false', 881 parser.add_argument('--without-android', action='store_false',
868 help='don\'t build Android ASan runtime (linux only)', 882 help='don\'t build Android ASan runtime (linux only)',
869 dest='with_android', 883 dest='with_android',
870 default=sys.platform.startswith('linux')) 884 default=sys.platform.startswith('linux'))
885 parser.add_argument('--enable-pgo', action='store_true',
886 help='build clang in 2 stages using PGO')
871 args = parser.parse_args() 887 args = parser.parse_args()
872 888
873 if args.lto_gold_plugin and not args.bootstrap: 889 if args.lto_gold_plugin and not args.enable_pgo:
874 print '--lto-gold-plugin requires --bootstrap' 890 print '--lto-gold-plugin requires --enable-pgo'
875 return 1 891 return 1
876 if args.lto_gold_plugin and not sys.platform.startswith('linux'): 892 if args.lto_gold_plugin and not sys.platform.startswith('linux'):
877 print '--lto-gold-plugin is only effective on Linux. Ignoring the option.' 893 print '--lto-gold-plugin is only effective on Linux. Ignoring the option.'
878 args.lto_gold_plugin = False 894 args.lto_gold_plugin = False
895 if args.enable_pgo:
896 if args.bootstrap:
897 print '--bootstrap makes no sense with --enable-pgo specified'
898 return 1
899 if not args.force_local_build:
900 print '--enable-pgo makes no sense without --force-local-build'
901 return 1
902 if sys.platform == 'win32':
903 print '--enable-pgo not supported on Windows'
879 904
880 if args.if_needed: 905 if args.if_needed:
881 # TODO(thakis): Can probably remove this and --if-needed altogether. 906 # TODO(thakis): Can probably remove this and --if-needed altogether.
882 if re.search(r'\b(make_clang_dir)=', os.environ.get('GYP_DEFINES', '')): 907 if re.search(r'\b(make_clang_dir)=', os.environ.get('GYP_DEFINES', '')):
883 print 'Skipping Clang update (make_clang_dir= was set in GYP_DEFINES).' 908 print 'Skipping Clang update (make_clang_dir= was set in GYP_DEFINES).'
884 return 0 909 return 0
885 910
886 # Get svn if we're going to use it to check the revision or do a local build. 911 # Get svn if we're going to use it to check the revision or do a local build.
887 if (use_head_revision or args.llvm_force_head_revision or 912 if (use_head_revision or args.llvm_force_head_revision or
888 args.force_local_build): 913 args.force_local_build):
(...skipping 25 matching lines...) Expand all
914 args.force_local_build = True 939 args.force_local_build = True
915 if 'OS=android' not in os.environ.get('GYP_DEFINES', ''): 940 if 'OS=android' not in os.environ.get('GYP_DEFINES', ''):
916 # Only build the Android ASan rt on ToT bots when targetting Android. 941 # Only build the Android ASan rt on ToT bots when targetting Android.
917 args.with_android = False 942 args.with_android = False
918 943
919 return UpdateClang(args) 944 return UpdateClang(args)
920 945
921 946
922 if __name__ == '__main__': 947 if __name__ == '__main__':
923 sys.exit(main()) 948 sys.exit(main())
OLDNEW
« no previous file with comments | « tools/clang/scripts/package.py ('k') | tools/clang/stage2.cmake » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698