Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.1 KiB

  1. #!/usr/bin/env python
  2. import datetime
  3. import getopt
  4. import glob
  5. import os
  6. import pickle
  7. import shutil
  8. import sys
  9. import zipfile
  10. import re
  11. import subprocess as sp
  12. import pdb
  13. def ShowUsage():
  14. print "breakpad_build_symbols.py [options] bindirectory symboldirectory]"
  15. print "-f/--force Force rebuild of .sym files."
  16. #
  17. # Set program defaults.
  18. #
  19. g_bForce = False
  20. def main():
  21. global g_bForce
  22. try:
  23. opts, args = getopt.getopt( sys.argv[1:], "f", [ "force" ] )
  24. except getopt.GetoptError, e:
  25. print ""
  26. print "Argument error: ", e
  27. print ""
  28. ShowUsage()
  29. sys.exit(1)
  30. for o, a in opts:
  31. if o in ( "-f", "--force" ):
  32. g_bForce = True
  33. # now look for all files in the specified path
  34. print "building symbols for %s to %s" % ( args[ 0 ], args[ 1 ] )
  35. dump_syms = os.getcwd() + "/dump_syms"
  36. rebuildcount = 0
  37. visitcount = 0
  38. for root, dirs, files in os.walk(args[ 0 ]):
  39. for name in dirs:
  40. dsymdirname = os.path.join(root, name)
  41. #print "checking %s" % dsymdirname
  42. if dsymdirname[-5:] == '.dSYM':
  43. visitcount += 1
  44. dylibfiletime = os.path.getmtime( dsymdirname )
  45. # get the first line
  46. command = dump_syms + " -g " + dsymdirname
  47. p = sp.Popen( command, stdout=sp.PIPE, stderr=sp.PIPE, shell=True )
  48. firstline = p.communicate()[ 0 ];
  49. #line syntax
  50. # MODULE mac x86 59C9A56A5EB38C85A185BA60877C89610 engine.dylib
  51. tokens = firstline.split()
  52. if ( len( tokens ) != 5 ):
  53. continue
  54. rawlibname = tokens[ 4 ]
  55. # print "shortname %s\n" % rawlibname
  56. symdir = args[1] + "/" + tokens[ 4 ] + "/" + tokens[ 3 ]
  57. if not os.path.isdir( symdir ):
  58. os.makedirs( symdir )
  59. symfile = symdir + "/" + rawlibname + ".sym"
  60. if ( os.path.exists( symfile ) ):
  61. # check time stamp
  62. symfilefiletime = os.path.getmtime( symfile )
  63. symfilesize = os.path.getsize( symfile )
  64. # print " %s %d %d" % (symfile, dylibfiletime, symfilefiletime)
  65. if ( symfilefiletime >= dylibfiletime and not g_bForce and symfilesize > 0 ):
  66. continue
  67. # do full processing
  68. command = dump_syms + " " + dsymdirname
  69. p = sp.Popen( command, stdout=sp.PIPE, stderr=sp.PIPE, shell=True )
  70. symbols = p.communicate()[ 0 ]
  71. print " :%s" % symfile
  72. # print " %s" % symbols
  73. fd = open( symfile, 'wb' )
  74. fd.write( symbols )
  75. fd.close()
  76. # force time stamp
  77. os.utime( symfile, ( dylibfiletime, dylibfiletime ) )
  78. rebuildcount += 1
  79. print " rebuilt %d out of %d symbol files" % ( rebuildcount, visitcount )
  80. if __name__ == '__main__':
  81. main()