| 
									
										
										
										
											2022-04-12 04:21:55 -07:00
										 |  |  | #!/usr/bin/env python3 | 
					
						
							| 
									
										
										
										
											2014-11-07 20:19:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 20:51:25 +08:00
										 |  |  | import glob | 
					
						
							| 
									
										
										
										
											2020-07-29 12:41:53 -07:00
										 |  |  | import os | 
					
						
							| 
									
										
										
										
											2020-08-05 14:03:50 -07:00
										 |  |  | import shutil | 
					
						
							| 
									
										
										
										
											2020-07-29 12:41:53 -07:00
										 |  |  | import subprocess | 
					
						
							| 
									
										
										
										
											2015-04-12 22:26:00 +08:00
										 |  |  | import sys | 
					
						
							| 
									
										
										
										
											2020-08-06 10:39:24 -07:00
										 |  |  | import tempfile | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def is_fs_case_sensitive(): | 
					
						
							|  |  |  |   with tempfile.NamedTemporaryFile(prefix='TmP') as tmp_file: | 
					
						
							|  |  |  |     return(not os.path.exists(tmp_file.name.lower())) | 
					
						
							| 
									
										
										
										
											2014-11-07 20:19:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-26 11:32:42 -07:00
										 |  |  | sys.path.append( | 
					
						
							|  |  |  |   os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + "/../..")) | 
					
						
							| 
									
										
										
										
											2019-06-24 10:18:04 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-04 02:32:57 -07:00
										 |  |  | from lib.config import PLATFORM | 
					
						
							|  |  |  | from lib.util import get_electron_branding, execute, store_artifact, \ | 
					
						
							| 
									
										
										
										
											2019-06-24 10:18:04 -07:00
										 |  |  |                      get_out_dir, ELECTRON_DIR | 
					
						
							| 
									
										
										
										
											2014-11-07 20:19:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-28 11:24:25 +10:00
										 |  |  | RELEASE_DIR = get_out_dir() | 
					
						
							| 
									
										
										
										
											2015-04-12 22:26:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 13:53:08 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | PROJECT_NAME = get_electron_branding()['project_name'] | 
					
						
							|  |  |  | PRODUCT_NAME = get_electron_branding()['product_name'] | 
					
						
							| 
									
										
										
										
											2018-11-14 12:47:01 -08:00
										 |  |  | SYMBOLS_DIR = os.path.join(RELEASE_DIR, 'breakpad_symbols') | 
					
						
							| 
									
										
										
										
											2018-05-23 12:53:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 20:19:26 +08:00
										 |  |  | PDB_LIST = [ | 
					
						
							| 
									
										
										
										
											2024-03-21 08:48:23 -05:00
										 |  |  |   os.path.join(RELEASE_DIR, f'{PROJECT_NAME}.exe.pdb') | 
					
						
							| 
									
										
										
										
											2014-11-07 20:19:26 +08:00
										 |  |  | ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-11 22:34:03 +02:00
										 |  |  | PDB_LIST += glob.glob(os.path.join(RELEASE_DIR, '*.dll.pdb')) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-29 12:41:53 -07:00
										 |  |  | NPX_CMD = "npx" | 
					
						
							|  |  |  | if sys.platform == "win32": | 
					
						
							|  |  |  |     NPX_CMD += ".cmd" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 20:19:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | def main(): | 
					
						
							| 
									
										
										
										
											2019-06-24 10:18:04 -07:00
										 |  |  |   os.chdir(ELECTRON_DIR) | 
					
						
							| 
									
										
										
										
											2020-08-17 14:52:08 -07:00
										 |  |  |   files = [] | 
					
						
							| 
									
										
										
										
											2018-05-23 12:53:48 -07:00
										 |  |  |   if PLATFORM == 'win32': | 
					
						
							|  |  |  |     for pdb in PDB_LIST: | 
					
						
							|  |  |  |       run_symstore(pdb, SYMBOLS_DIR, PRODUCT_NAME) | 
					
						
							|  |  |  |     files = glob.glob(SYMBOLS_DIR + '/*.pdb/*/*.pdb') | 
					
						
							| 
									
										
										
										
											2020-08-17 14:52:08 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   files += glob.glob(SYMBOLS_DIR + '/*/*/*.sym') | 
					
						
							| 
									
										
										
										
											2020-07-29 12:41:53 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   for symbol_file in files: | 
					
						
							|  |  |  |     print("Generating Sentry src bundle for: " + symbol_file) | 
					
						
							| 
									
										
										
										
											2020-11-23 21:26:54 -08:00
										 |  |  |     npx_env = os.environ.copy() | 
					
						
							|  |  |  |     npx_env['npm_config_yes'] = 'true' | 
					
						
							| 
									
										
										
										
											2020-10-19 04:55:27 -07:00
										 |  |  |     subprocess.check_output([ | 
					
						
							| 
									
										
										
										
											2023-06-08 16:31:15 -07:00
										 |  |  |       NPX_CMD, '@sentry/cli@1.62.0', 'difutil', 'bundle-sources', | 
					
						
							| 
									
										
										
										
											2020-11-23 21:26:54 -08:00
										 |  |  |       symbol_file], env=npx_env) | 
					
						
							| 
									
										
										
										
											2020-07-29 12:41:53 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   files += glob.glob(SYMBOLS_DIR + '/*/*/*.src.zip') | 
					
						
							| 
									
										
										
										
											2019-02-12 14:10:24 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-05 21:40:34 -07:00
										 |  |  |   # The file upload needs to be symbols/:symbol_name/:hash/:symbol | 
					
						
							| 
									
										
										
										
											2019-02-12 14:10:24 -08:00
										 |  |  |   os.chdir(SYMBOLS_DIR) | 
					
						
							|  |  |  |   files = [os.path.relpath(f, os.getcwd()) for f in files] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-18 17:18:35 -07:00
										 |  |  |   # The symbol server needs lowercase paths, it will fail otherwise | 
					
						
							|  |  |  |   # So lowercase all the file paths here | 
					
						
							| 
									
										
										
										
											2020-08-06 10:39:24 -07:00
										 |  |  |   if is_fs_case_sensitive(): | 
					
						
							|  |  |  |     for f in files: | 
					
						
							|  |  |  |       lower_f = f.lower() | 
					
						
							|  |  |  |       if lower_f != f: | 
					
						
							|  |  |  |         if os.path.exists(lower_f): | 
					
						
							|  |  |  |           shutil.rmtree(lower_f) | 
					
						
							|  |  |  |         lower_dir = os.path.dirname(lower_f) | 
					
						
							|  |  |  |         if not os.path.exists(lower_dir): | 
					
						
							|  |  |  |           os.makedirs(lower_dir) | 
					
						
							|  |  |  |         shutil.copy2(f, lower_f) | 
					
						
							| 
									
										
										
										
											2018-10-18 17:18:35 -07:00
										 |  |  |   files = [f.lower() for f in files] | 
					
						
							| 
									
										
										
										
											2020-08-05 14:03:50 -07:00
										 |  |  |   for f in files: | 
					
						
							|  |  |  |     assert os.path.exists(f) | 
					
						
							| 
									
										
										
										
											2014-11-07 20:19:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-04 02:32:57 -07:00
										 |  |  |   upload_symbols(files) | 
					
						
							| 
									
										
										
										
											2014-11-07 20:51:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 20:19:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | def run_symstore(pdb, dest, product): | 
					
						
							| 
									
										
										
										
											2024-02-28 00:40:42 +01:00
										 |  |  |   for attempt in range(2): | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |       execute(['symstore', 'add', '/r', '/f', pdb, '/s', dest, '/t', product]) | 
					
						
							|  |  |  |       break | 
					
						
							|  |  |  |     except Exception as e: | 
					
						
							|  |  |  |       print(f"An error occurred while adding '{pdb}' to SymStore: {str(e)}") | 
					
						
							|  |  |  |       if attempt == 0: | 
					
						
							|  |  |  |         print("Retrying...") | 
					
						
							| 
									
										
										
										
											2014-11-07 20:19:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-04 02:32:57 -07:00
										 |  |  | def upload_symbols(files): | 
					
						
							| 
									
										
										
										
											2022-05-05 21:40:34 -07:00
										 |  |  |   store_artifact(SYMBOLS_DIR, 'symbols', | 
					
						
							| 
									
										
										
										
											2014-11-10 23:33:56 +08:00
										 |  |  |         files) | 
					
						
							| 
									
										
										
										
											2014-11-07 20:51:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 20:19:26 +08:00
										 |  |  | if __name__ == '__main__': | 
					
						
							|  |  |  |   sys.exit(main()) |