1
0

build_debug.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python
  2. # usage: build_debug.py <input_dir> <output_file_name>
  3. # does the exact opposite of txtsplit.py
  4. import os
  5. import sys
  6. import io
  7. import xml.etree.ElementTree as ET
  8. assert len(sys.argv) == 3, "usage:\nbuild_debug.py <input_dir> <output_file_name>"
  9. idir = str(sys.argv[1])
  10. oname = str(sys.argv[2])
  11. # read the project xml file first
  12. # let's do this later in order to implement directory structure
  13. tree = ET.parse('glife.qproj')
  14. root = tree.getroot()
  15. ofile = io.open(oname, 'w', encoding='utf-16', newline='\r\n')
  16. for location in root.iter('Location'):
  17. iname = location.attrib['name']
  18. iname = iname.replace("$","_")
  19. try:
  20. ifile = io.open(os.path.join(idir,iname + '.qsrc'), 'rt', encoding='utf-8')
  21. text = ifile.readline()
  22. locname = text.strip('#').strip()
  23. text += u"if arrpos('$trace_locations', '{0}') > -1:\n".format(locname)
  24. text += u" copyarr '$trace_args', '$ARGS'\n"
  25. text += u" copyarr 'trace_args', 'ARGS'\n"
  26. text += u" gs 'debug_tools', 'trace', 'direct', '{0}'\n".format(locname)
  27. text += u"end\n"
  28. text += ifile.read()
  29. # make sure there's a line at the end of file
  30. # (why wouldn't there be one? WINDOWS!
  31. if text[-1] != u'\n':
  32. text += u'\n\n'
  33. ofile.write(text)
  34. ifile.close()
  35. except IOError:
  36. print("WARNING: missing location %s" % iname)
  37. pass
  38. import subprocess
  39. git_hash = ''
  40. try:
  41. git = subprocess.run(["git", "-C", idir, "rev-parse", "--short=10", "HEAD"], capture_output=True, encoding='utf-8')
  42. except:
  43. pass
  44. else:
  45. git_hash = git.stdout.strip()
  46. import datetime as dt
  47. ofile.write(u"#addbuilddate" + '\n')
  48. ofile.write(str(dt.datetime.now(dt.UTC).strftime("$builddate = '%d %B %Y, %H:%M %Z'")) + '\n')
  49. if git_hash != '':
  50. ofile.write(u"$git_hash = '" + git_hash + "'\n")
  51. ofile.write(u"--- addbuilddate ---------------------------------" + '\n')
  52. ofile.close()