build.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. from lib.util import electron_gyp, import_vs_env
  8. CONFIGURATIONS = ['Release', 'Debug']
  9. SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
  10. VENDOR_DIR = os.path.join(SOURCE_ROOT, 'vendor')
  11. LIBCC_SOURCE_ROOT = os.path.join(SOURCE_ROOT, 'vendor', 'libchromiumcontent')
  12. LIBCC_DIST_MAIN = os.path.join(LIBCC_SOURCE_ROOT, 'dist', 'main')
  13. GCLIENT_DONE = os.path.join(SOURCE_ROOT, '.gclient_done')
  14. def main():
  15. os.chdir(SOURCE_ROOT)
  16. # Update the VS build env.
  17. import_vs_env(get_target_arch())
  18. ninja = os.path.join('vendor', 'depot_tools', 'ninja')
  19. if sys.platform == 'win32':
  20. ninja += '.exe'
  21. args = parse_args()
  22. if args.ninja_path:
  23. ninja = args.ninja_path
  24. if args.libcc:
  25. if ('D' not in args.configuration
  26. or not os.path.exists(GCLIENT_DONE)
  27. or not os.path.exists(os.path.join(LIBCC_DIST_MAIN, 'build.ninja'))):
  28. sys.stderr.write('--libcc should only be used when '
  29. 'libchromiumcontent was built with bootstrap.py -d '
  30. '--debug_libchromiumcontent' + os.linesep)
  31. sys.exit(1)
  32. script = os.path.join(LIBCC_SOURCE_ROOT, 'script', 'build')
  33. subprocess.check_call([sys.executable, script, '-D', '-t',
  34. get_target_arch()])
  35. subprocess.check_call([ninja, '-C', LIBCC_DIST_MAIN])
  36. env = build_env()
  37. for config in args.configuration:
  38. build_path = os.path.join('out', config[0])
  39. ret = subprocess.call([ninja, '-C', build_path, args.target], env=env)
  40. if ret != 0:
  41. sys.exit(ret)
  42. def parse_args():
  43. parser = argparse.ArgumentParser(description='Build project')
  44. parser.add_argument('-c', '--configuration',
  45. help='Build with Release or Debug configuration',
  46. nargs='+',
  47. default=CONFIGURATIONS,
  48. required=False)
  49. parser.add_argument('-t', '--target',
  50. help='Build specified target',
  51. default=electron_gyp()['project_name%'],
  52. required=False)
  53. parser.add_argument('--libcc',
  54. help=(
  55. 'Build libchromiumcontent first. Should be used only '
  56. 'when libchromiumcontent as built with boostrap.py '
  57. '-d --debug_libchromiumcontent.'
  58. ),
  59. action='store_true', default=False)
  60. parser.add_argument('--ninja-path',
  61. help='Path of ninja command to use.',
  62. required=False)
  63. return parser.parse_args()
  64. if __name__ == '__main__':
  65. sys.exit(main())