create-dist.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. #!/usr/bin/env python
  2. import glob
  3. import os
  4. import re
  5. import shutil
  6. import subprocess
  7. import sys
  8. import stat
  9. from lib.config import LIBCHROMIUMCONTENT_COMMIT, BASE_URL, PLATFORM, \
  10. get_target_arch, get_chromedriver_version, \
  11. get_zip_name
  12. from lib.util import scoped_cwd, rm_rf, get_electron_version, make_zip, \
  13. execute, electron_gyp
  14. ELECTRON_VERSION = get_electron_version()
  15. SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
  16. DIST_DIR = os.path.join(SOURCE_ROOT, 'dist')
  17. OUT_DIR = os.path.join(SOURCE_ROOT, 'out', 'R')
  18. CHROMIUM_DIR = os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor',
  19. 'download', 'libchromiumcontent', 'static_library')
  20. PROJECT_NAME = electron_gyp()['project_name%']
  21. PRODUCT_NAME = electron_gyp()['product_name%']
  22. TARGET_BINARIES = {
  23. 'darwin': [
  24. ],
  25. 'win32': [
  26. '{0}.exe'.format(PROJECT_NAME), # 'electron.exe'
  27. 'content_shell.pak',
  28. 'd3dcompiler_47.dll',
  29. 'icudtl.dat',
  30. 'libEGL.dll',
  31. 'libGLESv2.dll',
  32. 'ffmpeg.dll',
  33. 'node.dll',
  34. 'blink_image_resources_200_percent.pak',
  35. 'content_resources_200_percent.pak',
  36. 'ui_resources_200_percent.pak',
  37. 'views_resources_200_percent.pak',
  38. 'xinput1_3.dll',
  39. 'natives_blob.bin',
  40. 'snapshot_blob.bin',
  41. ],
  42. 'linux': [
  43. PROJECT_NAME, # 'electron'
  44. 'content_shell.pak',
  45. 'icudtl.dat',
  46. 'libffmpeg.so',
  47. 'libnode.so',
  48. 'blink_image_resources_200_percent.pak',
  49. 'content_resources_200_percent.pak',
  50. 'ui_resources_200_percent.pak',
  51. 'views_resources_200_percent.pak',
  52. 'natives_blob.bin',
  53. 'snapshot_blob.bin',
  54. ],
  55. }
  56. TARGET_DIRECTORIES = {
  57. 'darwin': [
  58. '{0}.app'.format(PRODUCT_NAME),
  59. ],
  60. 'win32': [
  61. 'resources',
  62. 'locales',
  63. ],
  64. 'linux': [
  65. 'resources',
  66. 'locales',
  67. ],
  68. }
  69. def main():
  70. rm_rf(DIST_DIR)
  71. os.makedirs(DIST_DIR)
  72. force_build()
  73. create_symbols()
  74. copy_binaries()
  75. copy_chrome_binary('chromedriver')
  76. copy_chrome_binary('mksnapshot')
  77. copy_license()
  78. if PLATFORM != 'win32':
  79. create_api_json_schema()
  80. if PLATFORM == 'linux':
  81. strip_binaries()
  82. create_version()
  83. create_dist_zip()
  84. create_chrome_binary_zip('chromedriver', get_chromedriver_version())
  85. create_chrome_binary_zip('mksnapshot', ELECTRON_VERSION)
  86. create_ffmpeg_zip()
  87. create_symbols_zip()
  88. def force_build():
  89. build = os.path.join(SOURCE_ROOT, 'script', 'build.py')
  90. execute([sys.executable, build, '-c', 'Release'])
  91. def copy_binaries():
  92. for binary in TARGET_BINARIES[PLATFORM]:
  93. shutil.copy2(os.path.join(OUT_DIR, binary), DIST_DIR)
  94. for directory in TARGET_DIRECTORIES[PLATFORM]:
  95. shutil.copytree(os.path.join(OUT_DIR, directory),
  96. os.path.join(DIST_DIR, directory),
  97. symlinks=True)
  98. def copy_chrome_binary(binary):
  99. if PLATFORM == 'win32':
  100. binary += '.exe'
  101. src = os.path.join(CHROMIUM_DIR, binary)
  102. dest = os.path.join(DIST_DIR, binary)
  103. # Copy file and keep the executable bit.
  104. shutil.copyfile(src, dest)
  105. os.chmod(dest, os.stat(dest).st_mode | stat.S_IEXEC)
  106. def copy_license():
  107. shutil.copy2(os.path.join(CHROMIUM_DIR, '..', 'LICENSES.chromium.html'),
  108. DIST_DIR)
  109. shutil.copy2(os.path.join(SOURCE_ROOT, 'LICENSE'), DIST_DIR)
  110. def create_api_json_schema():
  111. outfile = os.path.relpath(os.path.join(DIST_DIR, 'electron-api.json'))
  112. execute(['electron-docs-linter', 'docs', '--outfile={0}'.format(outfile),
  113. '--version={}'.format(ELECTRON_VERSION.replace('v', ''))])
  114. def strip_binaries():
  115. for binary in TARGET_BINARIES[PLATFORM]:
  116. if binary.endswith('.so') or '.' not in binary:
  117. strip_binary(os.path.join(DIST_DIR, binary))
  118. def strip_binary(binary_path):
  119. if get_target_arch() == 'arm':
  120. strip = 'arm-linux-gnueabihf-strip'
  121. else:
  122. strip = 'strip'
  123. execute([strip, binary_path])
  124. def create_version():
  125. version_path = os.path.join(SOURCE_ROOT, 'dist', 'version')
  126. with open(version_path, 'w') as version_file:
  127. version_file.write(ELECTRON_VERSION)
  128. def create_symbols():
  129. destination = os.path.join(DIST_DIR, '{0}.breakpad.syms'.format(PROJECT_NAME))
  130. dump_symbols = os.path.join(SOURCE_ROOT, 'script', 'dump-symbols.py')
  131. execute([sys.executable, dump_symbols, destination])
  132. if PLATFORM == 'darwin':
  133. dsyms = glob.glob(os.path.join(OUT_DIR, '*.dSYM'))
  134. for dsym in dsyms:
  135. shutil.copytree(dsym, os.path.join(DIST_DIR, os.path.basename(dsym)))
  136. elif PLATFORM == 'win32':
  137. pdbs = glob.glob(os.path.join(OUT_DIR, '*.pdb'))
  138. for pdb in pdbs:
  139. shutil.copy2(pdb, DIST_DIR)
  140. def create_dist_zip():
  141. dist_name = get_zip_name(PROJECT_NAME, ELECTRON_VERSION)
  142. zip_file = os.path.join(SOURCE_ROOT, 'dist', dist_name)
  143. with scoped_cwd(DIST_DIR):
  144. files = TARGET_BINARIES[PLATFORM] + ['LICENSE', 'LICENSES.chromium.html',
  145. 'version']
  146. dirs = TARGET_DIRECTORIES[PLATFORM]
  147. make_zip(zip_file, files, dirs)
  148. def create_chrome_binary_zip(binary, version):
  149. dist_name = get_zip_name(binary, version)
  150. zip_file = os.path.join(SOURCE_ROOT, 'dist', dist_name)
  151. with scoped_cwd(DIST_DIR):
  152. files = ['LICENSE', 'LICENSES.chromium.html']
  153. if PLATFORM == 'win32':
  154. files += [binary + '.exe']
  155. else:
  156. files += [binary]
  157. make_zip(zip_file, files, [])
  158. def create_ffmpeg_zip():
  159. dist_name = get_zip_name('ffmpeg', ELECTRON_VERSION)
  160. zip_file = os.path.join(SOURCE_ROOT, 'dist', dist_name)
  161. if PLATFORM == 'darwin':
  162. ffmpeg_name = 'libffmpeg.dylib'
  163. elif PLATFORM == 'linux':
  164. ffmpeg_name = 'libffmpeg.so'
  165. elif PLATFORM == 'win32':
  166. ffmpeg_name = 'ffmpeg.dll'
  167. shutil.copy2(os.path.join(CHROMIUM_DIR, '..', 'ffmpeg', ffmpeg_name),
  168. DIST_DIR)
  169. if PLATFORM == 'linux':
  170. strip_binary(os.path.join(DIST_DIR, ffmpeg_name))
  171. with scoped_cwd(DIST_DIR):
  172. make_zip(zip_file, [ffmpeg_name, 'LICENSE', 'LICENSES.chromium.html'], [])
  173. def create_symbols_zip():
  174. dist_name = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, 'symbols')
  175. zip_file = os.path.join(DIST_DIR, dist_name)
  176. licenses = ['LICENSE', 'LICENSES.chromium.html', 'version']
  177. with scoped_cwd(DIST_DIR):
  178. dirs = ['{0}.breakpad.syms'.format(PROJECT_NAME)]
  179. make_zip(zip_file, licenses, dirs)
  180. if PLATFORM == 'darwin':
  181. dsym_name = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, 'dsym')
  182. with scoped_cwd(DIST_DIR):
  183. dsyms = glob.glob('*.dSYM')
  184. make_zip(os.path.join(DIST_DIR, dsym_name), licenses, dsyms)
  185. elif PLATFORM == 'win32':
  186. pdb_name = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, 'pdb')
  187. with scoped_cwd(DIST_DIR):
  188. pdbs = glob.glob('*.pdb')
  189. make_zip(os.path.join(DIST_DIR, pdb_name), pdbs + licenses, [])
  190. if __name__ == '__main__':
  191. sys.exit(main())