##// END OF EJS Templates
wix: functionality to automate building WiX installers...
wix: functionality to automate building WiX installers Like we did for Inno Setup, we want to make it easier to produce WiX installers. This commit does that. We introduce a new hgpackaging.wix module for performing all the high-level tasks required to produce WiX installers. This required miscellaneous enhancements to existing code in hgpackaging, including support for signing binaries. A new build.py script for calling into the module APIs has been created. It behaves very similarly to the Inno Setup build.py script. Unlike Inno Setup, we didn't have code in the repo previously to generate WiX installers. It appears that all existing automation for building WiX installers lives in the https://bitbucket.org/tortoisehg/thg-winbuild repository - most notably in its setup.py file. My strategy for inventing the code in this commit was to step through the code in that repo's setup.py and observe what it was doing. Despite the length of setup.py in that repository, the actual amount of steps required to produce a WiX installer is actually quite low. It consists of a basic py2exe build plus invocations of candle.exe and light.exe to produce the MSI. One rabbit hole that gave me fits was locating the Visual Studio 9 C Runtime merge modules. These merge modules are only present on your system if you have a full Visual Studio 2008 installation. Fortunately, I have a copy of Visual Studio 2008 and was able to install all the required updates. I then uploaded these merge modules to a personal repository on GitHub. That is where the added code references them from. We probably don't need to ship the merge modules. But that is for another day. The installs from the MSIs produced with the new automation differ from the last official MSI in the following ways: * Our HTML manual pages have UNIX line endings instead of Windows. * We ship modules in the mercurial.pure package. It appears the upstream packaging code is not including this package due to omission (they supply an explicit list of packages that has drifted out of sync with our setup.py). * We do not ship various distutils.* modules. This is because virtualenvs have a custom distutils/__init__.py that automagically imports distutils from its original location and py2exe gets confused by this. We don't use distutils in core Mercurial and don't provide a usable python.exe, so this omission should be acceptable. * The version of the enum package is different and we ship an enum.pyc instead of an enum/__init__.py. * The version of the docutils package is different and we ship a different set of files. * The version of Sphinx is drastically newer and we ship a number of files the old version did not. (I'm not sure why we ship Sphinx - I think it is a side-effect of the way the THG code was installing dependencies.) * We ship the idna package (dependent of requests which is a dependency of newer versions of Sphinx). * The version of imagesize is different and we ship an imagesize.pyc instead of an imagesize/__init__.pyc. * The version of the jinja2 package is different and the sets of files differs. * We ship the packaging package, which is a dependency for Sphinx. * The version of the pygments package is different and the sets of files differs. * We ship the requests package, which is a dependency for Sphinx. * We ship the snowballstemmer package, which is a dependency for Sphinx. * We ship the urllib3 package, which is a dependency for requests, which is a dependency for Sphinx. * We ship a newer version of the futures package, which includes a handful of extra modules that match Python 3 module names. # no-check-commit because foo_bar naming Differential Revision: https://phab.mercurial-scm.org/D6097

File last commit:

r41020:6a372f94 default
r42087:4371f543 default
Show More
hgclient.py
147 lines | 4.0 KiB | text/x-python | PythonLexer
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 # A minimal client for Mercurial's command server
Pulkit Goyal
hgclient: use absolute_import and print_function
r28355 from __future__ import absolute_import, print_function
Yuya Nishihara
py3: rewrite StringIO fallback for Python 3
r40353
import io
Pulkit Goyal
hgclient: use absolute_import and print_function
r28355 import os
Yuya Nishihara
py3: reinvent print() function for contrib/hgclient.py
r40352 import re
Pulkit Goyal
hgclient: use absolute_import and print_function
r28355 import signal
import socket
import struct
import subprocess
import sys
import time
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566
Yuya Nishihara
py3: work around unicode stdio streams in contrib/hgclient.py
r40351 if sys.version_info[0] >= 3:
stdout = sys.stdout.buffer
stderr = sys.stderr.buffer
Yuya Nishihara
py3: rewrite StringIO fallback for Python 3
r40353 stringio = io.BytesIO
Yuya Nishihara
py3: reinvent print() function for contrib/hgclient.py
r40352 def bprint(*args):
# remove b'' as well for ease of test migration
pargs = [re.sub(br'''\bb(['"])''', br'\1', b'%s' % a) for a in args]
stdout.write(b' '.join(pargs) + b'\n')
Yuya Nishihara
py3: work around unicode stdio streams in contrib/hgclient.py
r40351 else:
Yuya Nishihara
py3: rewrite StringIO fallback for Python 3
r40353 import cStringIO
Yuya Nishihara
py3: work around unicode stdio streams in contrib/hgclient.py
r40351 stdout = sys.stdout
stderr = sys.stderr
Yuya Nishihara
py3: rewrite StringIO fallback for Python 3
r40353 stringio = cStringIO.StringIO
Yuya Nishihara
py3: reinvent print() function for contrib/hgclient.py
r40352 bprint = print
Yuya Nishihara
py3: work around unicode stdio streams in contrib/hgclient.py
r40351
Yuya Nishihara
commandserver: add experimental option to use separate message channel...
r40625 def connectpipe(path=None, extraargs=()):
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 cmdline = [b'hg', b'serve', b'--cmdserver', b'pipe']
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 if path:
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 cmdline += [b'-R', path]
Yuya Nishihara
commandserver: add experimental option to use separate message channel...
r40625 cmdline.extend(extraargs)
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566
Matt Harbison
py3: convert popen() command arguments in hgclient to str on Windows...
r41020 def tonative(cmdline):
if os.name != r'nt':
return cmdline
return [arg.decode("utf-8") for arg in cmdline]
server = subprocess.Popen(tonative(cmdline), stdin=subprocess.PIPE,
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 stdout=subprocess.PIPE)
return server
Yuya Nishihara
test-commandserver: add connector for unix domain socket server...
r22993 class unixconnection(object):
def __init__(self, sockpath):
self.sock = sock = socket.socket(socket.AF_UNIX)
sock.connect(sockpath)
self.stdin = sock.makefile('wb')
self.stdout = sock.makefile('rb')
def wait(self):
self.stdin.close()
self.stdout.close()
self.sock.close()
class unixserver(object):
def __init__(self, sockpath, logpath=None, repopath=None):
self.sockpath = sockpath
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 cmdline = [b'hg', b'serve', b'--cmdserver', b'unix', b'-a', sockpath]
Yuya Nishihara
test-commandserver: add connector for unix domain socket server...
r22993 if repopath:
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 cmdline += [b'-R', repopath]
Yuya Nishihara
test-commandserver: add connector for unix domain socket server...
r22993 if logpath:
stdout = open(logpath, 'a')
stderr = subprocess.STDOUT
else:
stdout = stderr = None
self.server = subprocess.Popen(cmdline, stdout=stdout, stderr=stderr)
# wait for listen()
while self.server.poll() is None:
if os.path.exists(sockpath):
break
time.sleep(0.1)
def connect(self):
return unixconnection(self.sockpath)
def shutdown(self):
os.kill(self.server.pid, signal.SIGTERM)
self.server.wait()
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 def writeblock(server, data):
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 server.stdin.write(struct.pack(b'>I', len(data)))
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 server.stdin.write(data)
server.stdin.flush()
def readchannel(server):
data = server.stdout.read(5)
if not data:
raise EOFError
channel, length = struct.unpack('>cI', data)
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 if channel in b'IL':
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 return channel, length
else:
return channel, server.stdout.read(length)
def sep(text):
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 return text.replace(b'\\', b'/')
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566
Yuya Nishihara
py3: work around unicode stdio streams in contrib/hgclient.py
r40351 def runcommand(server, args, output=stdout, error=stderr, input=None,
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 outfilter=lambda x: x):
Yuya Nishihara
py3: reinvent print() function for contrib/hgclient.py
r40352 bprint(b'*** runcommand', b' '.join(args))
Yuya Nishihara
py3: work around unicode stdio streams in contrib/hgclient.py
r40351 stdout.flush()
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 server.stdin.write(b'runcommand\n')
writeblock(server, b'\0'.join(args))
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566
if not input:
timeless
test-commandserver: handle cStringIO.StringIO/io.StringIO divergence
r28836 input = stringio()
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566
while True:
ch, data = readchannel(server)
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 if ch == b'o':
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 output.write(outfilter(data))
output.flush()
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 elif ch == b'e':
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 error.write(data)
error.flush()
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 elif ch == b'I':
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 writeblock(server, input.read(data))
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 elif ch == b'L':
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 writeblock(server, input.readline(data))
Yuya Nishihara
commandserver: add experimental option to use separate message channel...
r40625 elif ch == b'm':
bprint(b"message: %r" % data)
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 elif ch == b'r':
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 ret, = struct.unpack('>i', data)
if ret != 0:
Yuya Nishihara
py3: reinvent print() function for contrib/hgclient.py
r40352 bprint(b' [%d]' % ret)
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 return ret
else:
Yuya Nishihara
py3: reinvent print() function for contrib/hgclient.py
r40352 bprint(b"unexpected channel %c: %r" % (ch, data))
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 if ch.isupper():
return
Yuya Nishihara
test-commandserver: allow check() to make connection in different way...
r22992 def check(func, connect=connectpipe):
Yuya Nishihara
py3: work around unicode stdio streams in contrib/hgclient.py
r40351 stdout.flush()
Yuya Nishihara
test-commandserver: remove unused repopath argument from check()...
r22991 server = connect()
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 try:
return func(server)
finally:
server.stdin.close()
server.wait()
Yuya Nishihara
commandserver: add experimental option to use separate message channel...
r40625
def checkwith(connect=connectpipe, **kwargs):
def wrap(func):
return check(func, lambda: connect(**kwargs))
return wrap