wix.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/python
  2. # encoding: utf-8
  3. # vim: tabstop=4 noexpandtab
  4. """
  5. Windows Installer XML Tool (WiX)
  6. .wxs --- candle ---> .wxobj --- light ---> .msi
  7. bld(features='wix', some.wxs, gen='some.msi', candleflags=[..], lightflags=[..])
  8. bld(features='wix', source=['bundle.wxs','WixBalExtension'], gen='setup.exe', candleflags=[..])
  9. """
  10. import os, copy
  11. from waflib import TaskGen
  12. from waflib import Task
  13. from waflib.Utils import winreg
  14. class candle(Task.Task):
  15. run_str = '${CANDLE} -nologo ${CANDLEFLAGS} -out ${TGT} ${SRC[0].abspath()}',
  16. class light(Task.Task):
  17. run_str = "${LIGHT} -nologo -b ${SRC[0].parent.abspath()} ${LIGHTFLAGS} -out ${TGT} ${SRC[0].abspath()}"
  18. @TaskGen.feature('wix')
  19. @TaskGen.before_method('process_source')
  20. def wix(self):
  21. #X.wxs -> ${SRC} for CANDLE
  22. #X.wxobj -> ${SRC} for LIGHT
  23. #X.dll -> -ext X in ${LIGHTFLAGS}
  24. #X.wxl -> wixui.wixlib -loc X.wxl in ${LIGHTFLAGS}
  25. wxobj = []
  26. wxs = []
  27. exts = []
  28. wxl = []
  29. rest = []
  30. for x in self.source:
  31. if x.endswith('.wxobj'):
  32. wxobj.append(x)
  33. elif x.endswith('.wxs'):
  34. wxobj.append(self.path.find_or_declare(x[:-4]+'.wxobj'))
  35. wxs.append(x)
  36. elif x.endswith('.dll'):
  37. exts.append(x[:-4])
  38. elif '.' not in x:
  39. exts.append(x)
  40. elif x.endswith('.wxl'):
  41. wxl.append(x)
  42. else:
  43. rest.append(x)
  44. self.source = self.to_nodes(rest) #.wxs
  45. cndl = self.create_task('candle', self.to_nodes(wxs), self.to_nodes(wxobj))
  46. lght = self.create_task('light', self.to_nodes(wxobj), self.path.find_or_declare(self.gen))
  47. cndl.env.CANDLEFLAGS = copy.copy(getattr(self,'candleflags',[]))
  48. lght.env.LIGHTFLAGS = copy.copy(getattr(self,'lightflags',[]))
  49. for x in wxl:
  50. lght.env.append_value('LIGHTFLAGS','wixui.wixlib')
  51. lght.env.append_value('LIGHTFLAGS','-loc')
  52. lght.env.append_value('LIGHTFLAGS',x)
  53. for x in exts:
  54. cndl.env.append_value('CANDLEFLAGS','-ext')
  55. cndl.env.append_value('CANDLEFLAGS',x)
  56. lght.env.append_value('LIGHTFLAGS','-ext')
  57. lght.env.append_value('LIGHTFLAGS',x)
  58. #wix_bin_path()
  59. def wix_bin_path():
  60. basekey = r"SOFTWARE\Microsoft\.NETFramework\AssemblyFolders"
  61. query = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, basekey)
  62. cnt=winreg.QueryInfoKey(query)[0]
  63. thiskey = r'C:\Program Files (x86)\WiX Toolset v3.10\SDK'
  64. for i in range(cnt-1,-1,-1):
  65. thiskey = winreg.EnumKey(query,i)
  66. if 'WiX' in thiskey:
  67. break
  68. winreg.CloseKey(query)
  69. return os.path.normpath(winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE, basekey+r'\\'+thiskey)+'..\\bin')
  70. def configure(ctx):
  71. path_list=[wix_bin_path()]
  72. ctx.find_program('candle', var='CANDLE', mandatory=True, path_list = path_list)
  73. ctx.find_program('light', var='LIGHT', mandatory=True, path_list = path_list)