build.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env python
  2. import argparse
  3. import os
  4. import subprocess
  5. import sys
  6. from lib.config import MIPS64EL_GCC, get_target_arch, build_env, \
  7. enable_verbose_mode, is_verbose_mode
  8. from lib.util import electron_gyp, import_vs_env
  9. CONFIGURATIONS = ['Release', 'Debug']
  10. SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
  11. VENDOR_DIR = os.path.join(SOURCE_ROOT, 'vendor')
  12. LIBCC_SOURCE_ROOT = os.path.join(SOURCE_ROOT, 'vendor', 'libchromiumcontent')
  13. LIBCC_DIST_MAIN = os.path.join(LIBCC_SOURCE_ROOT, 'dist', 'main')
  14. GCLIENT_DONE = os.path.join(SOURCE_ROOT, '.gclient_done')
  15. def main():
  16. os.chdir(SOURCE_ROOT)
  17. args = parse_args()
  18. if args.verbose:
  19. enable_verbose_mode()
  20. # Update the VS build env.
  21. import_vs_env(get_target_arch())
  22. # decide which ninja executable to use
  23. ninja_path = args.ninja_path
  24. if not ninja_path:
  25. ninja_path = os.path.join('vendor', 'depot_tools', 'ninja')
  26. if sys.platform == 'win32':
  27. ninja_path += '.exe'
  28. # decide how to invoke ninja
  29. ninja = [ninja_path]
  30. if is_verbose_mode():
  31. ninja.append('-v')
  32. if args.libcc:
  33. if ('D' not in args.configuration
  34. or not os.path.exists(GCLIENT_DONE)
  35. or not os.path.exists(os.path.join(LIBCC_DIST_MAIN, 'build.ninja'))):
  36. sys.stderr.write('--libcc should only be used when '
  37. 'libchromiumcontent was built with bootstrap.py -d '
  38. '--debug_libchromiumcontent' + os.linesep)
  39. sys.exit(1)
  40. script = os.path.join(LIBCC_SOURCE_ROOT, 'script', 'build')
  41. subprocess.check_call([sys.executable, script, '-D', '-t',
  42. get_target_arch()])
  43. subprocess.check_call(ninja + ['-C', LIBCC_DIST_MAIN])
  44. env = build_env()
  45. for config in args.configuration:
  46. build_path = os.path.join('out', config[0])
  47. build_args = ['-C', build_path, args.target]
  48. if args.compdb:
  49. build_args += ['-t', 'compdb', 'cxx', 'cc']
  50. compdb = open(r'compile_commands.json','w')
  51. ret = subprocess.call(ninja + build_args, env=env, stdout=compdb)
  52. compdb.close()
  53. else:
  54. ret = subprocess.call(ninja + build_args, env=env)
  55. if ret != 0:
  56. sys.exit(ret)
  57. def parse_args():
  58. parser = argparse.ArgumentParser(description='Build project')
  59. parser.add_argument('-c', '--configuration',
  60. help='Build with Release or Debug configuration',
  61. nargs='+',
  62. default=CONFIGURATIONS,
  63. required=False)
  64. parser.add_argument('-v', '--verbose',
  65. action='store_true',
  66. default=False,
  67. help='Verbose output')
  68. parser.add_argument('-t', '--target',
  69. help='Build specified target',
  70. default=electron_gyp()['project_name%'],
  71. required=False)
  72. parser.add_argument('--libcc',
  73. help=(
  74. 'Build libchromiumcontent first. Should be used only '
  75. 'when libchromiumcontent as built with boostrap.py '
  76. '-d --debug_libchromiumcontent.'
  77. ),
  78. action='store_true', default=False)
  79. parser.add_argument('--ninja-path',
  80. help='Path of ninja command to use.',
  81. required=False)
  82. parser.add_argument('--compdb',
  83. help=(
  84. 'Generate JSON compilation database. This will not '
  85. 'trigger actual build. '
  86. ),
  87. action='store_true', default=False)
  88. return parser.parse_args()
  89. if __name__ == '__main__':
  90. sys.exit(main())