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

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

Issue 2793343002: Add --enable-pgo option to build clang with PGO
Patch Set: Add --enable-pgo option to build clang with PGO Created 3 years, 8 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
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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 tool detection logic munges them in a weird way.""" 276 tool detection logic munges them in a weird way."""
277 assert not any(i in os.path.basename(CHROME_TOOLS_SHIM_DIR) for i in '-_') 277 assert not any(i in os.path.basename(CHROME_TOOLS_SHIM_DIR) for i in '-_')
278 os.mkdir(CHROME_TOOLS_SHIM_DIR) 278 os.mkdir(CHROME_TOOLS_SHIM_DIR)
279 with file(os.path.join(CHROME_TOOLS_SHIM_DIR, 'CMakeLists.txt'), 'w') as f: 279 with file(os.path.join(CHROME_TOOLS_SHIM_DIR, 'CMakeLists.txt'), 'w') as f:
280 f.write('# Automatically generated by tools/clang/scripts/update.py. ' + 280 f.write('# Automatically generated by tools/clang/scripts/update.py. ' +
281 'Do not edit.\n') 281 'Do not edit.\n')
282 f.write('# Since tools/clang is located in another directory, use the \n') 282 f.write('# Since tools/clang is located in another directory, use the \n')
283 f.write('# two arg version to specify where build artifacts go. CMake\n') 283 f.write('# two arg version to specify where build artifacts go. CMake\n')
284 f.write('# disallows reuse of the same binary dir for multiple source\n') 284 f.write('# disallows reuse of the same binary dir for multiple source\n')
285 f.write('# dirs, so the build artifacts need to go into a subdirectory.\n') 285 f.write('# dirs, so the build artifacts need to go into a subdirectory.\n')
286 f.write('# dirs, so the build artifacts need to go into a subdirectory.\n')
Nico 2017/04/07 15:58:53 Also a good change, but also unrelated.
287 f.write('if (CHROMIUM_TOOLS_SRC)\n') 286 f.write('if (CHROMIUM_TOOLS_SRC)\n')
288 f.write(' add_subdirectory(${CHROMIUM_TOOLS_SRC} ' + 287 f.write(' add_subdirectory(${CHROMIUM_TOOLS_SRC} ' +
289 '${CMAKE_CURRENT_BINARY_DIR}/a)\n') 288 '${CMAKE_CURRENT_BINARY_DIR}/a)\n')
290 f.write('endif (CHROMIUM_TOOLS_SRC)\n') 289 f.write('endif (CHROMIUM_TOOLS_SRC)\n')
291 290
292 291
293 def DownloadHostGcc(args): 292 def DownloadHostGcc(args):
294 """Downloads gcc 4.8.5 and makes sure args.gcc_toolchain is set.""" 293 """Downloads gcc 4.8.5 and makes sure args.gcc_toolchain is set."""
295 if not sys.platform.startswith('linux') or args.gcc_toolchain: 294 if not sys.platform.startswith('linux') or args.gcc_toolchain:
296 return 295 return
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 return vs_version 368 return vs_version
370 369
371 370
372 def CopyDiaDllTo(target_dir): 371 def CopyDiaDllTo(target_dir):
373 # This script always wants to use the 64-bit msdia*.dll. 372 # This script always wants to use the 64-bit msdia*.dll.
374 dia_path = os.path.join(GetVSVersion().Path(), 'DIA SDK', 'bin', 'amd64') 373 dia_path = os.path.join(GetVSVersion().Path(), 'DIA SDK', 'bin', 'amd64')
375 dia_dll = os.path.join(dia_path, DIA_DLL[GetVSVersion().ShortName()]) 374 dia_dll = os.path.join(dia_path, DIA_DLL[GetVSVersion().ShortName()])
376 CopyFile(dia_dll, target_dir) 375 CopyFile(dia_dll, target_dir)
377 376
378 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 lto_cflags = ['-flto=thin']
410 lto_ldflags = ['-fuse-ld=lld']
411 if args.gcc_toolchain:
412 # Tell the bootstrap compiler to use a specific gcc prefix to search
413 # for standard library headers and shared object files.
414 lto_cflags += ['--gcc-toolchain=' + args.gcc_toolchain]
415 lto_cmake_args = base_cmake_args + [
416 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir,
417 '-DCMAKE_C_COMPILER=' + cc,
418 '-DCMAKE_CXX_COMPILER=' + cxx,
419 '-DCMAKE_C_FLAGS=' + ' '.join(lto_cflags),
420 '-DCMAKE_CXX_FLAGS=' + ' '.join(lto_cflags),
421 '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(lto_ldflags),
422 '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(lto_ldflags),
423 '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(lto_ldflags)]
424
425 # We need to use the proper binutils which support LLVM Gold plugin.
426 lto_env = os.environ.copy()
427 lto_env['PATH'] = BINUTILS_BIN_DIR + os.pathsep + lto_env.get('PATH', '')
428
429 RmCmakeCache('.')
430 RunCommand(['cmake'] + lto_cmake_args + [LLVM_DIR], env=lto_env)
431 RunCommand(['ninja', 'LLVMgold', 'lld'], env=lto_env)
432
433
379 def VeryifyVersionOfBuiltClangMatchesVERSION(): 434 def VeryifyVersionOfBuiltClangMatchesVERSION():
380 """Checks that `clang --version` outputs VERSION. If this fails, VERSION 435 """Checks that `clang --version` outputs VERSION. If this fails, VERSION
381 in this file is out-of-date and needs to be updated (possibly in an 436 in this file is out-of-date and needs to be updated (possibly in an
382 `if use_head_revision:` block in main() first).""" 437 `if use_head_revision:` block in main() first)."""
383 clang = os.path.join(LLVM_BUILD_DIR, 'bin', 'clang') 438 clang = os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')
384 if sys.platform == 'win32': 439 if sys.platform == 'win32':
385 # TODO: Parse `clang-cl /?` output for built clang's version and check that 440 # TODO: Parse `clang-cl /?` output for built clang's version and check that
386 # to check the binary we're actually shipping? But clang-cl.exe is just 441 # to check the binary we're actually shipping? But clang-cl.exe is just
387 # a copy of clang.exe, so this does check the same thing. 442 # a copy of clang.exe, so this does check the same thing.
388 clang += '.exe' 443 clang += '.exe'
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 512
458 Checkout('LLVM', LLVM_REPO_URL + '/llvm/trunk', LLVM_DIR) 513 Checkout('LLVM', LLVM_REPO_URL + '/llvm/trunk', LLVM_DIR)
459 Checkout('Clang', LLVM_REPO_URL + '/cfe/trunk', CLANG_DIR) 514 Checkout('Clang', LLVM_REPO_URL + '/cfe/trunk', CLANG_DIR)
460 if sys.platform != 'darwin': 515 if sys.platform != 'darwin':
461 Checkout('LLD', LLVM_REPO_URL + '/lld/trunk', LLD_DIR) 516 Checkout('LLD', LLVM_REPO_URL + '/lld/trunk', LLD_DIR)
462 elif os.path.exists(LLD_DIR): 517 elif os.path.exists(LLD_DIR):
463 # In case someone sends a tryjob that temporary adds lld to the checkout, 518 # In case someone sends a tryjob that temporary adds lld to the checkout,
464 # make sure it's not around on future builds. 519 # make sure it's not around on future builds.
465 RmTree(LLD_DIR) 520 RmTree(LLD_DIR)
466 Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', COMPILER_RT_DIR) 521 Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', COMPILER_RT_DIR)
522 if args.enable_pgo and sys.platform != 'win32':
523 # PGO requires compiler-rt.
524 Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk',
525 os.path.join(LLVM_DIR, 'projects', 'compiler-rt'))
Nico 2017/04/07 15:58:53 IIRC package.py packages based on blacklists inste
matthewtff.asm 2017/04/11 12:14:43 The only diff I've got is one header file: lib/cla
467 if sys.platform == 'darwin': 526 if sys.platform == 'darwin':
468 # clang needs a libc++ checkout, else -stdlib=libc++ won't find includes 527 # clang needs a libc++ checkout, else -stdlib=libc++ won't find includes
469 # (i.e. this is needed for bootstrap builds). 528 # (i.e. this is needed for bootstrap builds).
470 Checkout('libcxx', LLVM_REPO_URL + '/libcxx/trunk', LIBCXX_DIR) 529 Checkout('libcxx', LLVM_REPO_URL + '/libcxx/trunk', LIBCXX_DIR)
471 # We used to check out libcxxabi on OS X; we no longer need that. 530 # We used to check out libcxxabi on OS X; we no longer need that.
472 if os.path.exists(LIBCXXABI_DIR): 531 if os.path.exists(LIBCXXABI_DIR):
473 RmTree(LIBCXXABI_DIR) 532 RmTree(LIBCXXABI_DIR)
474 533
475 cc, cxx = None, None 534 cc, cxx = None, None
476 libstdcpp = None 535 libstdcpp = None
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 RunCommand(['ninja'], msvc_arch='x64') 582 RunCommand(['ninja'], msvc_arch='x64')
524 if args.run_tests: 583 if args.run_tests:
525 if sys.platform == 'win32': 584 if sys.platform == 'win32':
526 CopyDiaDllTo(os.path.join(LLVM_BOOTSTRAP_DIR, 'bin')) 585 CopyDiaDllTo(os.path.join(LLVM_BOOTSTRAP_DIR, 'bin'))
527 RunCommand(['ninja', 'check-all'], msvc_arch='x64') 586 RunCommand(['ninja', 'check-all'], msvc_arch='x64')
528 RunCommand(['ninja', 'install'], msvc_arch='x64') 587 RunCommand(['ninja', 'install'], msvc_arch='x64')
529 if args.gcc_toolchain: 588 if args.gcc_toolchain:
530 # Copy that gcc's stdlibc++.so.6 to the build dir, so the bootstrap 589 # Copy that gcc's stdlibc++.so.6 to the build dir, so the bootstrap
531 # compiler can start. 590 # compiler can start.
532 CopyFile(libstdcpp, os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'lib')) 591 CopyFile(libstdcpp, os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'lib'))
533 592 cc, cxx = GetNewCCAndCXX(LLVM_BOOTSTRAP_INSTALL_DIR)
534 if sys.platform == 'win32':
535 cc = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang-cl.exe')
536 cxx = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang-cl.exe')
537 # CMake has a hard time with backslashes in compiler paths:
538 # https://stackoverflow.com/questions/13050827
539 cc = cc.replace('\\', '/')
540 cxx = cxx.replace('\\', '/')
541 else:
542 cc = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang')
543 cxx = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang++')
544 593
545 if args.gcc_toolchain: 594 if args.gcc_toolchain:
546 # Tell the bootstrap compiler to use a specific gcc prefix to search 595 # Tell the bootstrap compiler to use a specific gcc prefix to search
547 # for standard library headers and shared object files. 596 # for standard library headers and shared object files.
548 cflags = ['--gcc-toolchain=' + args.gcc_toolchain] 597 cflags = ['--gcc-toolchain=' + args.gcc_toolchain]
549 cxxflags = ['--gcc-toolchain=' + args.gcc_toolchain] 598 cxxflags = ['--gcc-toolchain=' + args.gcc_toolchain]
550 print 'Building final compiler' 599 print 'Building final compiler'
551 600
552 # Build LLVM gold plugin with LTO. That speeds up the linker by ~10%.
553 # We only use LTO for Linux now.
554 if args.bootstrap and args.lto_gold_plugin: 601 if args.bootstrap and args.lto_gold_plugin:
Nico 2017/04/07 15:58:53 This is now never true (assuming we default to PGO
555 print 'Building LTO LLVM Gold plugin' 602 BuildLLVMgold(args, LLVM_BOOTSTRAP_INSTALL_DIR, binutils_incdir,
556 if os.path.exists(LLVM_LTO_GOLD_PLUGIN_DIR): 603 base_cmake_args, cc, cxx)
557 RmTree(LLVM_LTO_GOLD_PLUGIN_DIR)
558 EnsureDirExists(LLVM_LTO_GOLD_PLUGIN_DIR)
559 os.chdir(LLVM_LTO_GOLD_PLUGIN_DIR)
560
561 # Create a symlink to LLVMgold.so build in the previous step so that ar
562 # and ranlib could find it while linking LLVMgold.so with LTO.
563 EnsureDirExists(BFD_PLUGINS_DIR)
564 RunCommand(['ln', '-sf',
565 os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'lib', 'LLVMgold.so'),
566 os.path.join(BFD_PLUGINS_DIR, 'LLVMgold.so')])
567
568 lto_cflags = ['-flto=thin']
569 lto_ldflags = ['-fuse-ld=lld']
570 if args.gcc_toolchain:
571 # Tell the bootstrap compiler to use a specific gcc prefix to search
572 # for standard library headers and shared object files.
573 lto_cflags += ['--gcc-toolchain=' + args.gcc_toolchain]
574 lto_cmake_args = base_cmake_args + [
575 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir,
576 '-DCMAKE_C_COMPILER=' + cc,
577 '-DCMAKE_CXX_COMPILER=' + cxx,
578 '-DCMAKE_C_FLAGS=' + ' '.join(lto_cflags),
579 '-DCMAKE_CXX_FLAGS=' + ' '.join(lto_cflags),
580 '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(lto_ldflags),
581 '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(lto_ldflags),
582 '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(lto_ldflags)]
583
584 # We need to use the proper binutils which support LLVM Gold plugin.
585 lto_env = os.environ.copy()
586 lto_env['PATH'] = BINUTILS_BIN_DIR + os.pathsep + lto_env.get('PATH', '')
587
588 RmCmakeCache('.')
589 RunCommand(['cmake'] + lto_cmake_args + [LLVM_DIR], env=lto_env)
590 RunCommand(['ninja', 'LLVMgold', 'lld'], env=lto_env)
591
592 604
593 # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is 605 # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is
594 # needed, on OS X it requires libc++. clang only automatically links to libc++ 606 # needed, on OS X it requires libc++. clang only automatically links to libc++
595 # when targeting OS X 10.9+, so add stdlib=libc++ explicitly so clang can run 607 # when targeting OS X 10.9+, so add stdlib=libc++ explicitly so clang can run
596 # on OS X versions as old as 10.7. 608 # on OS X versions as old as 10.7.
597 deployment_target = '' 609 deployment_target = ''
598 610
599 if sys.platform == 'darwin' and args.bootstrap: 611 if sys.platform == 'darwin' and (args.bootstrap or args.enable_pgo):
600 # When building on 10.9, /usr/include usually doesn't exist, and while 612 # When building on 10.9, /usr/include usually doesn't exist, and while
601 # Xcode's clang automatically sets a sysroot, self-built clangs don't. 613 # Xcode's clang automatically sets a sysroot, self-built clangs don't.
602 cflags = ['-isysroot', subprocess.check_output( 614 cflags = ['-isysroot', subprocess.check_output(
603 ['xcrun', '--show-sdk-path']).rstrip()] 615 ['xcrun', '--show-sdk-path']).rstrip()]
604 cxxflags = ['-stdlib=libc++'] + cflags 616 cxxflags = ['-stdlib=libc++'] + cflags
605 ldflags += ['-stdlib=libc++'] 617 ldflags += ['-stdlib=libc++']
606 deployment_target = '10.7' 618 deployment_target = '10.7'
607 # Running libc++ tests takes a long time. Since it was only needed for 619 if not args.enable_pgo:
Nico 2017/04/07 15:58:53 Why this change?
matthewtff.asm 2017/04/11 12:14:43 We need to build clang with libcxx checked out in
608 # the install step above, don't build it as part of the main build. 620 # Running libc++ tests takes a long time. Since it was only needed for
609 # This makes running package.py over 10% faster (30 min instead of 34 min) 621 # the install step above, don't build it as part of the main build.
610 RmTree(LIBCXX_DIR) 622 # This makes running package.py over 10% faster (30 min instead of 34 min)
623 RmTree(LIBCXX_DIR)
611 624
612 # Build clang. 625 # Build clang.
613 626
614 # If building at head, define a macro that plugins can use for #ifdefing 627 # If building at head, define a macro that plugins can use for #ifdefing
615 # out code that builds at head, but not at CLANG_REVISION or vice versa. 628 # out code that builds at head, but not at CLANG_REVISION or vice versa.
616 if use_head_revision: 629 if use_head_revision:
617 cflags += ['-DLLVM_FORCE_HEAD_REVISION'] 630 cflags += ['-DLLVM_FORCE_HEAD_REVISION']
618 cxxflags += ['-DLLVM_FORCE_HEAD_REVISION'] 631 cxxflags += ['-DLLVM_FORCE_HEAD_REVISION']
619 632
620 # Build PDBs for archival on Windows. Don't use RelWithDebInfo since it 633 # Build PDBs for archival on Windows. Don't use RelWithDebInfo since it
(...skipping 10 matching lines...) Expand all
631 deployment_env = os.environ.copy() 644 deployment_env = os.environ.copy()
632 deployment_env['MACOSX_DEPLOYMENT_TARGET'] = deployment_target 645 deployment_env['MACOSX_DEPLOYMENT_TARGET'] = deployment_target
633 646
634 cmake_args = [] 647 cmake_args = []
635 # TODO(thakis): Unconditionally append this to base_cmake_args instead once 648 # TODO(thakis): Unconditionally append this to base_cmake_args instead once
636 # compiler-rt can build with clang-cl on Windows (http://llvm.org/PR23698) 649 # compiler-rt can build with clang-cl on Windows (http://llvm.org/PR23698)
637 cc_args = base_cmake_args if sys.platform != 'win32' else cmake_args 650 cc_args = base_cmake_args if sys.platform != 'win32' else cmake_args
638 if cc is not None: cc_args.append('-DCMAKE_C_COMPILER=' + cc) 651 if cc is not None: cc_args.append('-DCMAKE_C_COMPILER=' + cc)
639 if cxx is not None: cc_args.append('-DCMAKE_CXX_COMPILER=' + cxx) 652 if cxx is not None: cc_args.append('-DCMAKE_CXX_COMPILER=' + cxx)
640 chrome_tools = list(set(['plugins', 'blink_gc_plugin'] + args.extra_tools)) 653 chrome_tools = list(set(['plugins', 'blink_gc_plugin'] + args.extra_tools))
654
655
656 if args.enable_pgo:
657 pgo_cache_path = os.path.join(
658 LLVM_DIR, 'tools', 'clang', 'cmake', 'caches', 'PGO.cmake')
659 pgo_stage2_cache = os.path.join(
660 CHROMIUM_DIR, 'tools', 'clang', 'PGO-stage2.cmake')
661 cmake_args += [
662 '-DBOOTSTRAP_BOOTSTRAP_CHROMIUM_TOOLS=%s' % ','.join(chrome_tools),
663 '-DCMAKE_VERBOSE_MAKEFILE=ON',
664 '-DBOOTSTRAP_CMAKE_VERBOSE_MAKEFILE=ON',
665 '-DBOOTSTRAP_BOOTSTRAP_CMAKE_VERBOSE_MAKEFILE=ON',
666 '-DPGO_BUILD_CONFIGURATION=%s' % pgo_stage2_cache,
667 '-C', pgo_cache_path,
668 '-DBOOTSTRAP_LLVM_BINUTILS_INCDIR=' + binutils_incdir,
669 '-DBOOTSTRAP_CMAKE_C_FLAGS=' + ' '.join(cflags),
670 '-DBOOTSTRAP_CMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
671 '-DBOOTSTRAP_BOOTSTRAP_LLVM_BINUTILS_INCDIR=' + binutils_incdir,
672 '-DBOOTSTRAP_BOOTSTRAP_CMAKE_C_FLAGS=' + ' '.join(cflags),
673 '-DBOOTSTRAP_BOOTSTRAP_CMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
674 '-DBOOTSTRAP_BOOTSTRAP_CMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags),
675 '-DBOOTSTRAP_BOOTSTRAP_CMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags),
676 '-DBOOTSTRAP_BOOTSTRAP_CMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags),
677 ]
641 cmake_args += base_cmake_args + [ 678 cmake_args += base_cmake_args + [
642 '-DLLVM_ENABLE_THREADS=OFF', 679 '-DLLVM_ENABLE_THREADS=OFF',
643 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir, 680 '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir,
644 '-DCMAKE_C_FLAGS=' + ' '.join(cflags), 681 '-DCMAKE_C_FLAGS=' + ' '.join(cflags),
645 '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags), 682 '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
646 '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags), 683 '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags),
647 '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags), 684 '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags),
648 '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags), 685 '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags),
649 '-DCMAKE_INSTALL_PREFIX=' + LLVM_BUILD_DIR, 686 '-DCMAKE_INSTALL_PREFIX=' + LLVM_BUILD_DIR,
650 # TODO(thakis): Remove this once official builds pass -Wl,--build-id 687 # TODO(thakis): Remove this once official builds pass -Wl,--build-id
651 # explicitly, https://crbug.com/622775 688 # explicitly, https://crbug.com/622775
652 '-DENABLE_LINKER_BUILD_ID=ON', 689 '-DENABLE_LINKER_BUILD_ID=ON',
653 '-DCHROMIUM_TOOLS_SRC=%s' % os.path.join(CHROMIUM_DIR, 'tools', 'clang'), 690 '-DCHROMIUM_TOOLS_SRC=%s' % os.path.join(CHROMIUM_DIR, 'tools', 'clang'),
654 '-DCHROMIUM_TOOLS=%s' % ';'.join(chrome_tools)] 691 '-DCHROMIUM_TOOLS=%s' % ','.join(chrome_tools)]
655 692
656 EnsureDirExists(LLVM_BUILD_DIR) 693 EnsureDirExists(LLVM_BUILD_DIR)
657 os.chdir(LLVM_BUILD_DIR) 694 os.chdir(LLVM_BUILD_DIR)
658 RmCmakeCache('.') 695 RmCmakeCache('.')
659 RunCommand(['cmake'] + cmake_args + [LLVM_DIR], 696 RunCommand(['cmake'] + cmake_args + [LLVM_DIR],
660 msvc_arch='x64', env=deployment_env) 697 msvc_arch='x64', env=deployment_env)
661 698
699 ninja_target = 'stage2' if args.enable_pgo else 'all'
700 RunCommand(['ninja', ninja_target], env=deployment_env, msvc_arch='x64')
701
702 if args.enable_pgo:
703 global LLVM_BUILD_DIR
704 LLVM_BUILD_DIR = os.path.join(LLVM_BUILD_DIR, 'tools', 'clang',
705 'stage2-instrumented-bins', 'tools', 'clang', 'stage2-bins')
706
662 if args.gcc_toolchain: 707 if args.gcc_toolchain:
663 # Copy in the right stdlibc++.so.6 so clang can start. 708 # Copy in the right stdlibc++.so.6 so clang can start.
664 if not os.path.exists(os.path.join(LLVM_BUILD_DIR, 'lib')): 709 if not os.path.exists(os.path.join(LLVM_BUILD_DIR, 'lib')):
665 os.mkdir(os.path.join(LLVM_BUILD_DIR, 'lib')) 710 os.mkdir(os.path.join(LLVM_BUILD_DIR, 'lib'))
666 libstdcpp = subprocess.check_output( 711 libstdcpp = subprocess.check_output(
667 [cxx] + cxxflags + ['-print-file-name=libstdc++.so.6']).rstrip() 712 [cxx] + cxxflags + ['-print-file-name=libstdc++.so.6']).rstrip()
668 CopyFile(libstdcpp, os.path.join(LLVM_BUILD_DIR, 'lib')) 713 CopyFile(libstdcpp, os.path.join(LLVM_BUILD_DIR, 'lib'))
669 714
670 RunCommand(['ninja'], msvc_arch='x64')
671
672 # Copy LTO-optimized lld, if any.
673 if args.bootstrap and args.lto_gold_plugin:
674 CopyFile(os.path.join(LLVM_LTO_GOLD_PLUGIN_DIR, 'bin', 'lld'),
675 os.path.join(LLVM_BUILD_DIR, 'bin'))
676
677 if chrome_tools: 715 if chrome_tools:
678 # If any Chromium tools were built, install those now. 716 # If any Chromium tools were built, install those now.
679 RunCommand(['ninja', 'cr-install'], msvc_arch='x64') 717 RunCommand(['ninja', 'cr-install'], msvc_arch='x64')
680 718
719 # Copy LTO-optimized lld, if any.
720 if args.lto_gold_plugin:
721 if args.enable_pgo:
722 cc, cxx = GetNewCCAndCXX(LLVM_BUILD_DIR)
723 BuildLLVMgold(args, LLVM_BUILD_DIR, base_cmake_args,
724 binutils_incdir, cc, cxx)
725 if args.bootstrap or args.enable_pgo:
726 CopyFile(os.path.join(LLVM_LTO_GOLD_PLUGIN_DIR, 'bin', 'lld'),
727 os.path.join(LLVM_BUILD_DIR, 'bin'))
728
681 if sys.platform == 'darwin': 729 if sys.platform == 'darwin':
682 # See http://crbug.com/256342 730 # See http://crbug.com/256342
683 RunCommand(['strip', '-x', os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')]) 731 RunCommand(['strip', '-x', os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')])
684 elif sys.platform.startswith('linux'): 732 elif sys.platform.startswith('linux'):
685 RunCommand(['strip', os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')]) 733 RunCommand(['strip', os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')])
686 734
687 VeryifyVersionOfBuiltClangMatchesVERSION() 735 VeryifyVersionOfBuiltClangMatchesVERSION()
688 736
689 # Do an out-of-tree build of compiler-rt. 737 # Do an out-of-tree build of compiler-rt.
690 # On Windows, this is used to get the 32-bit ASan run-time. 738 # On Windows, this is used to get the 32-bit ASan run-time.
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 parser.add_argument('--print-clang-version', action='store_true', 906 parser.add_argument('--print-clang-version', action='store_true',
859 help='print current clang version (e.g. x.y.z) and exit.') 907 help='print current clang version (e.g. x.y.z) and exit.')
860 parser.add_argument('--run-tests', action='store_true', 908 parser.add_argument('--run-tests', action='store_true',
861 help='run tests after building; only for local builds') 909 help='run tests after building; only for local builds')
862 parser.add_argument('--extra-tools', nargs='*', default=[], 910 parser.add_argument('--extra-tools', nargs='*', default=[],
863 help='select additional chrome tools to build') 911 help='select additional chrome tools to build')
864 parser.add_argument('--without-android', action='store_false', 912 parser.add_argument('--without-android', action='store_false',
865 help='don\'t build Android ASan runtime (linux only)', 913 help='don\'t build Android ASan runtime (linux only)',
866 dest='with_android', 914 dest='with_android',
867 default=sys.platform.startswith('linux')) 915 default=sys.platform.startswith('linux'))
916 parser.add_argument('--enable-pgo', action='store_true',
917 help='build clang in 2 stages using PGO')
868 args = parser.parse_args() 918 args = parser.parse_args()
869 919
870 if args.lto_gold_plugin and not args.bootstrap: 920 if args.lto_gold_plugin and (not args.bootstrap and not args.enable_pgo):
871 print '--lto-gold-plugin requires --bootstrap' 921 print '--lto-gold-plugin requires --bootstrap or --enable-pgo'
872 return 1 922 return 1
873 if args.lto_gold_plugin and not sys.platform.startswith('linux'): 923 if args.lto_gold_plugin and not sys.platform.startswith('linux'):
874 print '--lto-gold-plugin is only effective on Linux. Ignoring the option.' 924 print '--lto-gold-plugin is only effective on Linux. Ignoring the option.'
875 args.lto_gold_plugin = False 925 args.lto_gold_plugin = False
926 if args.enable_pgo:
927 if args.bootstrap:
928 print '--bootstrap makes no sense with --enable-pgo specified'
929 return 1
930 if not args.force_local_build:
931 print '--enable-pgo makes no sense without --force-local-build'
932 return 1
933 if sys.platform == 'win32':
934 print '--enable-pgo not supported on Windows'
876 935
877 if args.if_needed: 936 if args.if_needed:
878 # TODO(thakis): Can probably remove this and --if-needed altogether. 937 # TODO(thakis): Can probably remove this and --if-needed altogether.
879 if re.search(r'\b(make_clang_dir)=', os.environ.get('GYP_DEFINES', '')): 938 if re.search(r'\b(make_clang_dir)=', os.environ.get('GYP_DEFINES', '')):
880 print 'Skipping Clang update (make_clang_dir= was set in GYP_DEFINES).' 939 print 'Skipping Clang update (make_clang_dir= was set in GYP_DEFINES).'
881 return 0 940 return 0
882 941
883 # Get svn if we're going to use it to check the revision or do a local build. 942 # Get svn if we're going to use it to check the revision or do a local build.
884 if (use_head_revision or args.llvm_force_head_revision or 943 if (use_head_revision or args.llvm_force_head_revision or
885 args.force_local_build): 944 args.force_local_build):
(...skipping 25 matching lines...) Expand all
911 args.force_local_build = True 970 args.force_local_build = True
912 if 'OS=android' not in os.environ.get('GYP_DEFINES', ''): 971 if 'OS=android' not in os.environ.get('GYP_DEFINES', ''):
913 # Only build the Android ASan rt on ToT bots when targetting Android. 972 # Only build the Android ASan rt on ToT bots when targetting Android.
914 args.with_android = False 973 args.with_android = False
915 974
916 return UpdateClang(args) 975 return UpdateClang(args)
917 976
918 977
919 if __name__ == '__main__': 978 if __name__ == '__main__':
920 sys.exit(main()) 979 sys.exit(main())
OLDNEW
« tools/clang/scripts/package.py ('K') | « tools/clang/scripts/package.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698