2024-03-12 15:39:44 +01:00
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import glob
|
|
|
|
import zipfile
|
2024-03-21 16:18:10 +01:00
|
|
|
import requests
|
2024-03-29 14:58:06 +01:00
|
|
|
import shutil
|
2024-03-12 15:39:44 +01:00
|
|
|
|
|
|
|
database = "valentina"
|
|
|
|
|
|
|
|
def debug_extension():
|
|
|
|
platform = sys.platform
|
|
|
|
if platform == "darwin":
|
|
|
|
debug_ext = ".dSYM"
|
|
|
|
elif platform == "win32":
|
|
|
|
debug_ext = ".pdb"
|
|
|
|
elif platform == "linux":
|
|
|
|
debug_ext = ".debug"
|
|
|
|
else:
|
|
|
|
print(f"Unsupported platform {platform}")
|
|
|
|
return "uknown"
|
|
|
|
|
|
|
|
return debug_ext
|
|
|
|
|
|
|
|
def generate_sym_files(install_root):
|
|
|
|
sym_files = []
|
|
|
|
|
|
|
|
platform = sys.platform
|
|
|
|
debug_ext = debug_extension()
|
|
|
|
|
|
|
|
debug_files = glob.glob(os.path.join(install_root, "**", "*" + debug_ext), recursive=True)
|
|
|
|
|
2024-03-25 15:23:21 +01:00
|
|
|
if not debug_files:
|
|
|
|
print("No debug files found.")
|
|
|
|
|
2024-03-12 15:39:44 +01:00
|
|
|
for debug_file in debug_files:
|
|
|
|
print(f"Generating symbols for: {os.path.basename(debug_file)}")
|
|
|
|
|
2024-03-21 16:18:10 +01:00
|
|
|
sym_file = os.path.splitext(debug_file)[0] + ".sym"
|
2024-04-11 09:48:46 +02:00
|
|
|
dump_syms_cmd = ["dump_syms", '-o', sym_file, '--inlines', debug_file]
|
2024-03-21 16:18:10 +01:00
|
|
|
subprocess.run(dump_syms_cmd, check=True)
|
2024-03-12 15:39:44 +01:00
|
|
|
|
2024-04-29 16:03:21 +02:00
|
|
|
sym_files.append((debug_file, sym_file))
|
2024-03-12 15:39:44 +01:00
|
|
|
|
|
|
|
return sym_files
|
|
|
|
|
2024-03-28 13:53:26 +01:00
|
|
|
def generate_version_string(val_version, commit_hash, qt_version, multibundle):
|
2024-03-12 15:39:44 +01:00
|
|
|
# Determine the platform
|
|
|
|
platform = sys.platform
|
2024-03-28 13:53:26 +01:00
|
|
|
multibundle_str = ""
|
|
|
|
|
2024-03-12 15:39:44 +01:00
|
|
|
if platform == "win32":
|
|
|
|
platform_str = "windows"
|
|
|
|
elif platform == "darwin":
|
|
|
|
platform_str = "macos"
|
2024-03-28 13:53:26 +01:00
|
|
|
|
|
|
|
if multibundle:
|
|
|
|
multibundle_str = "-multibundle"
|
2024-03-12 15:39:44 +01:00
|
|
|
elif platform == "linux":
|
|
|
|
platform_str = "linux"
|
|
|
|
else:
|
|
|
|
platform_str = "unknown"
|
|
|
|
|
|
|
|
# Generate the version string
|
2024-03-28 13:53:26 +01:00
|
|
|
version_string = f"{val_version}-{commit_hash}-Qt_{qt_version}-{platform_str}{multibundle_str}"
|
2024-03-12 15:39:44 +01:00
|
|
|
return version_string
|
|
|
|
|
|
|
|
def get_app_name(sym_file):
|
|
|
|
# Get the base name of the symbol file without extension
|
2024-03-21 16:18:10 +01:00
|
|
|
base_name = os.path.basename(sym_file).split(".sym")[0].lower()
|
2024-03-12 15:39:44 +01:00
|
|
|
|
|
|
|
# Determine the platform
|
|
|
|
platform = sys.platform
|
|
|
|
if platform == "linux":
|
|
|
|
if base_name.startswith("lib"):
|
|
|
|
base_name = base_name[3:]
|
|
|
|
return base_name.split(".so")[0]
|
|
|
|
elif platform == "darwin":
|
|
|
|
if base_name.endswith(".framework"):
|
|
|
|
return base_name.split(".framework")[0]
|
2024-03-26 19:33:21 +01:00
|
|
|
elif base_name.endswith(".app"):
|
|
|
|
return base_name.split(".app")[0]
|
2024-03-12 15:39:44 +01:00
|
|
|
|
|
|
|
return base_name
|
|
|
|
|
2024-03-28 13:53:26 +01:00
|
|
|
def upload_symbols(install_root, val_version, commit_hash, qt_version, clean=False, multibundle=False):
|
2024-03-12 15:39:44 +01:00
|
|
|
# Platform-specific commands for generating and uploading symbol files
|
|
|
|
platform = sys.platform
|
|
|
|
sym_files = generate_sym_files(install_root)
|
2024-03-25 15:23:21 +01:00
|
|
|
|
|
|
|
if not sym_files:
|
|
|
|
print("No symbol files found. Exiting upload process.")
|
|
|
|
return
|
|
|
|
|
2024-03-28 13:53:26 +01:00
|
|
|
app_version = generate_version_string(val_version, commit_hash, qt_version, multibundle)
|
2024-03-12 15:39:44 +01:00
|
|
|
print(f"Uploading symbols for version {app_version}")
|
|
|
|
|
|
|
|
for _, sym_file in sym_files:
|
|
|
|
app_name = get_app_name(sym_file)
|
|
|
|
print(f"Uploading symbols for application {app_name}")
|
|
|
|
|
2024-03-21 16:18:10 +01:00
|
|
|
sym_file_name = os.path.basename(sym_file)
|
|
|
|
url = f"https://{database}.bugsplat.com/post/bp/symbol/breakpadsymbols.php?appName={app_name}&appVer={app_version}&code_file={sym_file_name}"
|
2024-03-12 15:39:44 +01:00
|
|
|
|
2024-03-28 14:51:46 +01:00
|
|
|
with open(sym_file, 'rb') as symbol_file:
|
|
|
|
files = {'symbol_file': (f'{sym_file_name}', symbol_file)}
|
|
|
|
response = requests.post(url, files=files)
|
2024-03-21 16:18:10 +01:00
|
|
|
|
|
|
|
if response.status_code == 200:
|
2024-03-12 15:39:44 +01:00
|
|
|
print(f"Symbol file '{sym_file}' uploaded successfully.")
|
2024-03-21 16:18:10 +01:00
|
|
|
else:
|
|
|
|
print("Request failed with status code:", response.status_code)
|
|
|
|
print("Server response:")
|
|
|
|
print(response.text)
|
2024-03-12 15:39:44 +01:00
|
|
|
|
|
|
|
# Cleanup if requested
|
|
|
|
if clean:
|
|
|
|
debug_ext = debug_extension()
|
|
|
|
for debug_file, sym_file in sym_files:
|
2024-03-28 06:22:44 +01:00
|
|
|
try:
|
|
|
|
os.remove(sym_file)
|
|
|
|
print(f"Symbol file '{sym_file}' removed.")
|
|
|
|
except PermissionError as e:
|
|
|
|
print(f"PermissionError removing '{sym_file}': {e}")
|
|
|
|
|
|
|
|
try:
|
2024-03-29 14:58:06 +01:00
|
|
|
if sys.platform == "darwin":
|
|
|
|
shutil.rmtree(debug_file)
|
|
|
|
else:
|
|
|
|
os.remove(debug_file)
|
2024-03-28 06:22:44 +01:00
|
|
|
print(f"Debug file '{debug_file}' removed.")
|
|
|
|
except PermissionError as e:
|
|
|
|
print(f"PermissionError removing '{debug_file}': {e}")
|
2024-03-12 15:39:44 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
# Command-line usage: python symupload.py /path/to/install_root/folder 0_7_52 abcdef123456 6_6 --clean
|
|
|
|
# - First argument: Path to the install root folder
|
|
|
|
# - Second argument: Valentina version
|
|
|
|
# - Third argument: Commit git hash
|
|
|
|
# - Fourth argument: Qt version
|
|
|
|
# - Optional argument: --clean (Clean up after upload)
|
2024-03-28 13:53:26 +01:00
|
|
|
# - Optional argument: --multibundle (Mark multibundle version. Has effect only on macos)
|
2024-03-12 15:39:44 +01:00
|
|
|
|
|
|
|
# Parse command-line arguments
|
|
|
|
parser = argparse.ArgumentParser(description="Upload symbols to BugSplat.")
|
|
|
|
parser.add_argument("install_root", type=str, help="Path to the installation folder")
|
|
|
|
parser.add_argument("val_version", type=str, help="Valentina version")
|
|
|
|
parser.add_argument("hash", type=str, help="Commit git hash")
|
|
|
|
parser.add_argument("qt_version", type=str, help="Qt version")
|
|
|
|
parser.add_argument("--clean", action="store_true", help="Clean up after upload")
|
2024-03-28 13:53:26 +01:00
|
|
|
parser.add_argument("--multibundle", type=str, default="false", choices=["true", "false"], help="Mark multibundle version. Has effect only on Macos")
|
2024-03-12 15:39:44 +01:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2024-03-28 13:53:26 +01:00
|
|
|
multibundle = (args.multibundle == "true")
|
|
|
|
|
2024-03-12 15:39:44 +01:00
|
|
|
# Call install_package function with provided arguments
|
2024-03-28 13:53:26 +01:00
|
|
|
upload_symbols(args.install_root, args.val_version, args.hash, args.qt_version, args.clean, multibundle)
|