PageRenderTime 25ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/make-installer.py

https://bitbucket.org/genericcontainer/goblin-camp/
Python | 73 lines | 54 code | 18 blank | 1 comment | 13 complexity | e5116dac2dbbc03f53fb71c971b28081 MD5 | raw file
Possible License(s): GPL-3.0
  1. # A tool to create NSIS installer out of the release build.
  2. from __future__ import with_statement
  3. import sys, os, shutil, subprocess, re
  4. gatherDLLs = __import__('gather-dlls')
  5. here = os.path.dirname(os.path.realpath(__file__))
  6. root = os.path.normpath(here + '/..')
  7. VERSION_RE = re.compile(r'^constant\s+GC_VERSION\s+:\s+(.*?)\s+;$', re.M)
  8. if len(sys.argv) < 2:
  9. print 'Usage: make-installer x86/x64'
  10. sys.exit(1)
  11. arch = sys.argv[1]
  12. with open(os.path.join(root, 'Jamroot'), 'r') as fp:
  13. version = VERSION_RE.search(fp.read()).group(1)
  14. out = os.path.join(root, 'build', 'installer-{0}'.format(arch))
  15. src = os.path.join(root, 'build', 'bin-release-{0}'.format(arch))
  16. baseNSI = os.path.join(here, 'installer', 'base.nsi')
  17. outNSI = os.path.join(out, 'goblin-camp.nsi')
  18. redist = os.path.join(here, 'installer', 'redists')
  19. if not os.path.exists(os.path.join(src, 'goblin-camp.exe')):
  20. print '** Create the release build first.'
  21. sys.exit(1)
  22. try:
  23. os.makedirs(out)
  24. except OSError:
  25. pass
  26. dlls = gatherDLLs.FindMeDLLs(os.path.join(src, 'goblin-camp.exe'))
  27. dlls.copy()
  28. manifest = { 'install': [], 'uninstall': [], 'uninstall-dirs': [] }
  29. for root, dirs, files in os.walk(src):
  30. root = root[len(src) + 1:].strip()
  31. manifest['install'].append('SetOutPath "$INSTDIR\\{0}"'.format(root))
  32. for dn in dirs:
  33. manifest['uninstall-dirs'].insert(0, 'RMDir "$INSTDIR\\{0}"'.format(os.path.join(root, dn)))
  34. for fn in files:
  35. if fn[-3:] not in ('exe', 'dat', '.py', 'png', 'txt', 'dll', 'zip'): continue
  36. manifest['install'].append('File "{0}\\{1}"'.format(src, os.path.join(root, fn)))
  37. manifest['uninstall'].append('Delete "$INSTDIR\\{0}"'.format(os.path.join(root, fn)))
  38. with open(baseNSI, 'r') as fp:
  39. nsi = fp.read()
  40. nsi = nsi.replace('%%_GC_PLATFORM_%%', arch)
  41. nsi = nsi.replace('%%_GC_VERSION_%%', version)
  42. nsi = nsi.replace('%%_GC_REDIST_%%', redist)
  43. nsi = nsi.replace('%%_GC_SOURCE_%%', src)
  44. nsi = nsi.replace('%%_GC_INSTALL_MANIFEST_%%', '\n'.join(manifest['install']))
  45. nsi = nsi.replace('%%_GC_UNINSTALL_MANIFEST_%%', '\n'.join(manifest['uninstall']))
  46. nsi = nsi.replace('%%_GC_UNINSTALL_MANIFEST_DIRS_%%', '\n'.join(manifest['uninstall-dirs']))
  47. with open(outNSI, 'w') as fp:
  48. fp.write(nsi)
  49. command = ['makensis', '/V3']
  50. if gatherDLLs.CRT_2008 in dlls.crts:
  51. command.append('/DGC_BUNDLE_MSVC2008')
  52. if gatherDLLs.CRT_2010 in dlls.crts:
  53. command.append('/DGC_BUNDLE_MSVC2010')
  54. command.append(outNSI)
  55. subprocess.call(command, shell = True)