tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

packagesymbols.py (2554B)


      1 #!/usr/bin/env python
      2 # This Source Code Form is subject to the terms of the Mozilla Public
      3 # License, v. 2.0. If a copy of the MPL was not distributed with this
      4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      5 
      6 
      7 import argparse
      8 import os
      9 import subprocess
     10 import sys
     11 import zipfile
     12 
     13 
     14 class ProcError(Exception):
     15    def __init__(self, returncode, stderr):
     16        self.returncode = returncode
     17        self.stderr = stderr
     18 
     19 
     20 def check_output(command):
     21    proc = subprocess.Popen(
     22        command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True
     23    )
     24    stdout, stderr = proc.communicate()
     25    if proc.returncode != 0:
     26        raise ProcError(proc.returncode, stderr)
     27    return stdout
     28 
     29 
     30 def process_file(dump_syms, path):
     31    try:
     32        stdout = check_output([dump_syms, path])
     33    except ProcError as e:
     34        print('Error: running "%s %s": %s' % (dump_syms, path, e.stderr))
     35        return None, None, None
     36    bits = stdout.splitlines()[0].split(" ", 4)
     37    if len(bits) != 5:
     38        return None, None, None
     39    _, platform, cpu_arch, debug_id, debug_file = bits
     40    if debug_file.lower().endswith(".pdb"):
     41        sym_file = debug_file[:-4] + ".sym"
     42    else:
     43        sym_file = debug_file + ".sym"
     44    filename = os.path.join(debug_file, debug_id, sym_file)
     45    debug_filename = os.path.join(debug_file, debug_id, debug_file)
     46    return filename, stdout, debug_filename
     47 
     48 
     49 def main():
     50    parser = argparse.ArgumentParser()
     51    parser.add_argument("dump_syms", help="Path to dump_syms binary")
     52    parser.add_argument("files", nargs="+", help="Path to files to dump symbols from")
     53    parser.add_argument(
     54        "--symbol-zip",
     55        default="symbols.zip",
     56        help="Name of zip file to put dumped symbols in",
     57    )
     58    parser.add_argument(
     59        "--no-binaries",
     60        action="store_true",
     61        default=False,
     62        help="Don't store binaries in zip file",
     63    )
     64    args = parser.parse_args()
     65    count = 0
     66    with zipfile.ZipFile(args.symbol_zip, "w", zipfile.ZIP_DEFLATED) as zf:
     67        for f in args.files:
     68            filename, contents, debug_filename = process_file(args.dump_syms, f)
     69            if not (filename and contents):
     70                print("Error dumping symbols")
     71                sys.exit(1)
     72            zf.writestr(filename, contents)
     73            count += 1
     74            if not args.no_binaries:
     75                zf.write(f, debug_filename)
     76                count += 1
     77    print("Added %d files to %s" % (count, args.symbol_zip))
     78 
     79 
     80 if __name__ == "__main__":
     81    main()