summaryrefslogtreecommitdiffstats
path: root/remoting/tools/dark_and_candle_and_light.py
blob: 68598757913b7cb47acf650416479bbe86d41dbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Run 'dark', 'candle', and 'light', to confirm that an msi can be unpacked
repacked successfully."""

from optparse import OptionParser
import os
import subprocess
import sys

def run(command):
  popen = subprocess.Popen(
      command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  out, _ = popen.communicate()
  return popen.returncode, out

def main():
  parser = OptionParser()
  parser.add_option('--wix_path', dest='wix_path')
  parser.add_option('--input', dest='input')
  parser.add_option('--intermediate_dir', dest='intermediate_dir')
  parser.add_option('--output', dest='output')
  options, args = parser.parse_args()
  if args:
    parser.error("no positional arguments expected")
  parameters = dict(options.__dict__)

  parameters['basename'] = os.path.splitext(os.path.basename(options.output))[0]

  dark_template = ('"%(wix_path)s\\dark" ' +
                   '-nologo ' +
                   '"%(input)s" ' +
                   '-o "%(intermediate_dir)s/%(basename)s.wxs" ' +
                   '-x "%(intermediate_dir)s"')
  (rc, out) = run(dark_template % parameters)
  if rc:
    for line in out.splitlines():
      print line
    print 'dark.exe returned %d' % rc
    return rc

  candle_template = ('"%(wix_path)s\\candle" ' +
                   '-nologo ' +
                     '"%(intermediate_dir)s/%(basename)s.wxs" ' +
                     '-o "%(intermediate_dir)s/%(basename)s.wixobj" ' +
                     '-ext "%(wix_path)s\\WixFirewallExtension.dll"')
  (rc, out) = run(candle_template % parameters)
  if rc:
    for line in out.splitlines():
      print line
    print 'candle.exe returned %d' % rc
    return rc

  light_template = ('"%(wix_path)s\\light" ' +
                   '-nologo ' +
                    '"%(intermediate_dir)s/%(basename)s.wixobj" ' +
                    '-o "%(output)s" ' +
                    '-ext "%(wix_path)s\\WixFirewallExtension.dll" ' +
                    '-sw1076 ')
  (rc, out) = run(light_template % parameters)
  if rc:
    for line in out.splitlines():
      print line
    print 'candle.exe returned %d' % rc
    return rc

  return 0

if __name__ == "__main__":
  sys.exit(main())