12 from lib.config import LIBCHROMIUMCONTENT_COMMIT, BASE_URL, PLATFORM, \
13 get_target_arch, get_zip_name
14 from lib.util import scoped_cwd, rm_rf, get_electron_version, make_zip, \
18 ELECTRON_VERSION = get_electron_version()
20 SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
21 DIST_DIR = os.path.join(SOURCE_ROOT, 'dist')
22 OUT_DIR = os.path.join(SOURCE_ROOT, 'out', 'R')
23 CHROMIUM_DIR = os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor',
24 'download', 'libchromiumcontent', 'static_library')
26 PROJECT_NAME = electron_gyp()['project_name%']
27 PRODUCT_NAME = electron_gyp()['product_name%']
33 '{0}.exe'.format(PROJECT_NAME), # 'electron.exe'
35 'pdf_viewer_resources.pak',
42 'blink_image_resources_200_percent.pak',
43 'content_resources_200_percent.pak',
44 'ui_resources_200_percent.pak',
45 'views_resources_200_percent.pak',
51 PROJECT_NAME, # 'electron'
53 'pdf_viewer_resources.pak',
57 'blink_image_resources_200_percent.pak',
58 'content_resources_200_percent.pak',
59 'ui_resources_200_percent.pak',
60 'views_resources_200_percent.pak',
65 TARGET_DIRECTORIES = {
67 '{0}.app'.format(PRODUCT_NAME),
87 copy_chrome_binary('chromedriver')
88 copy_chrome_binary('mksnapshot')
93 if PLATFORM != 'win32' and not args.no_api_docs:
94 create_api_json_schema()
96 if PLATFORM == 'linux':
101 create_chrome_binary_zip('chromedriver', ELECTRON_VERSION)
102 create_chrome_binary_zip('mksnapshot', ELECTRON_VERSION)
108 build = os.path.join(SOURCE_ROOT, 'script', 'build.py')
109 execute([sys.executable, build, '-c', 'Release'])
113 for binary in TARGET_BINARIES[PLATFORM]:
114 shutil.copy2(os.path.join(OUT_DIR, binary), DIST_DIR)
116 for directory in TARGET_DIRECTORIES[PLATFORM]:
117 shutil.copytree(os.path.join(OUT_DIR, directory),
118 os.path.join(DIST_DIR, directory),
122 def copy_chrome_binary(binary):
123 if PLATFORM == 'win32':
125 src = os.path.join(CHROMIUM_DIR, binary)
126 dest = os.path.join(DIST_DIR, binary)
128 # Copy file and keep the executable bit.
129 shutil.copyfile(src, dest)
130 os.chmod(dest, os.stat(dest).st_mode | stat.S_IEXEC)
134 shutil.copy2(os.path.join(CHROMIUM_DIR, '..', 'LICENSES.chromium.html'),
136 shutil.copy2(os.path.join(SOURCE_ROOT, 'LICENSE'), DIST_DIR)
138 def create_api_json_schema():
139 node_bin_dir = os.path.join(SOURCE_ROOT, 'node_modules', '.bin')
140 env = os.environ.copy()
141 env['PATH'] = os.path.pathsep.join([node_bin_dir, env['PATH']])
142 outfile = os.path.relpath(os.path.join(DIST_DIR, 'electron-api.json'))
143 execute(['electron-docs-linter', 'docs', '--outfile={0}'.format(outfile),
144 '--version={}'.format(ELECTRON_VERSION.replace('v', ''))],
147 def strip_binaries():
148 for binary in TARGET_BINARIES[PLATFORM]:
149 if binary.endswith('.so') or '.' not in binary:
150 strip_binary(os.path.join(DIST_DIR, binary))
153 def strip_binary(binary_path):
154 if get_target_arch() == 'arm':
155 strip = 'arm-linux-gnueabihf-strip'
158 execute([strip, binary_path])
161 def create_version():
162 version_path = os.path.join(SOURCE_ROOT, 'dist', 'version')
163 with open(version_path, 'w') as version_file:
164 version_file.write(ELECTRON_VERSION)
167 def create_symbols():
168 destination = os.path.join(DIST_DIR, '{0}.breakpad.syms'.format(PROJECT_NAME))
169 dump_symbols = os.path.join(SOURCE_ROOT, 'script', 'dump-symbols.py')
170 execute([sys.executable, dump_symbols, destination])
172 if PLATFORM == 'darwin':
173 dsyms = glob.glob(os.path.join(OUT_DIR, '*.dSYM'))
175 shutil.copytree(dsym, os.path.join(DIST_DIR, os.path.basename(dsym)))
176 elif PLATFORM == 'win32':
177 pdbs = glob.glob(os.path.join(OUT_DIR, '*.pdb'))
179 shutil.copy2(pdb, DIST_DIR)
182 def create_dist_zip():
183 dist_name = get_zip_name(PROJECT_NAME, ELECTRON_VERSION)
184 zip_file = os.path.join(SOURCE_ROOT, 'dist', dist_name)
186 with scoped_cwd(DIST_DIR):
187 files = TARGET_BINARIES[PLATFORM] + ['LICENSE', 'LICENSES.chromium.html',
189 dirs = TARGET_DIRECTORIES[PLATFORM]
190 make_zip(zip_file, files, dirs)
193 def create_chrome_binary_zip(binary, version):
194 dist_name = get_zip_name(binary, version)
195 zip_file = os.path.join(SOURCE_ROOT, 'dist', dist_name)
197 with scoped_cwd(DIST_DIR):
198 files = ['LICENSE', 'LICENSES.chromium.html']
199 if PLATFORM == 'win32':
200 files += [binary + '.exe']
203 make_zip(zip_file, files, [])
206 def create_ffmpeg_zip():
207 dist_name = get_zip_name('ffmpeg', ELECTRON_VERSION)
208 zip_file = os.path.join(SOURCE_ROOT, 'dist', dist_name)
210 if PLATFORM == 'darwin':
211 ffmpeg_name = 'libffmpeg.dylib'
212 elif PLATFORM == 'linux':
213 ffmpeg_name = 'libffmpeg.so'
214 elif PLATFORM == 'win32':
215 ffmpeg_name = 'ffmpeg.dll'
217 shutil.copy2(os.path.join(CHROMIUM_DIR, '..', 'ffmpeg', ffmpeg_name),
220 if PLATFORM == 'linux':
221 strip_binary(os.path.join(DIST_DIR, ffmpeg_name))
223 with scoped_cwd(DIST_DIR):
224 make_zip(zip_file, [ffmpeg_name, 'LICENSE', 'LICENSES.chromium.html'], [])
227 def create_symbols_zip():
228 dist_name = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, 'symbols')
229 zip_file = os.path.join(DIST_DIR, dist_name)
230 licenses = ['LICENSE', 'LICENSES.chromium.html', 'version']
232 with scoped_cwd(DIST_DIR):
233 dirs = ['{0}.breakpad.syms'.format(PROJECT_NAME)]
234 make_zip(zip_file, licenses, dirs)
236 if PLATFORM == 'darwin':
237 dsym_name = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, 'dsym')
238 with scoped_cwd(DIST_DIR):
239 dsyms = glob.glob('*.dSYM')
240 make_zip(os.path.join(DIST_DIR, dsym_name), licenses, dsyms)
241 elif PLATFORM == 'win32':
242 pdb_name = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, 'pdb')
243 with scoped_cwd(DIST_DIR):
244 pdbs = glob.glob('*.pdb')
245 make_zip(os.path.join(DIST_DIR, pdb_name), pdbs + licenses, [])
249 parser = argparse.ArgumentParser(description='Create Electron Distribution')
250 parser.add_argument('--no_api_docs',
252 help='Skip generating the Electron API Documentation!')
253 return parser.parse_args()
256 if __name__ == '__main__':