Add Cygwin support.
1 # vim: set ts=8 sts=2 sw=2 tw=99 et:
3 # This file is part of AMBuild.
5 # AMBuild is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # AMBuild is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with AMBuild. If not, see <http://www.gnu.org/licenses/>.
19 from ambuild2 import util
21 if util.IsWindows() or util.IsCygwin():
22 # Cygwin doesn't support SCM_RIGHTS (which, I guess, is actually unused)
23 # but more importantly posix_spawn(), so we just cheat and use WinAPI
24 # directly, ignoring the sketchy Unix layer.
25 from . import windows as ipc_impl
27 from . import linux as ipc_impl
29 from . import bsd as ipc_impl
32 if hasattr(select, 'poll'):
33 from . import generic_poll as ipc_impl
35 raise Exception('Unknown platform: ' + util.Platform())
37 ProcessManager = ipc_impl.ProcessManager
38 MessagePump = ipc_impl.MessagePump
40 if util.IsWindows() or util.IsCygwin():
41 from . windows import NamedPipe as Channel
43 from . posix_proc import SocketChannel as Channel
45 class ChildWrapperListener(process.MessageListener):
46 def __init__(self, mp, channel):
47 super(ChildWrapperListener, self).__init__()
49 self.channel = channel
52 def receiveMessage(self, channel, message):
53 if message == process.Special.Close:
54 self.listener.receiveClose(channel)
57 if message['id'] == '__start__':
58 listener_type = message['listener_type']
59 args = message['args']
61 if 'channels' in message:
62 channels = message['channels']
64 self.listener = listener_type(self.mp, self.channel, *(args + channels))
67 self.listener.receiveMessage(channel, message)
69 def receiveError(self, channel, error):
71 self.listener.receiveError(error)
73 sys.stderr.write('[{0}] Parent process died, terminating...\n'.format(os.getpid()))
76 def child_main(channel):
78 listener = ChildWrapperListener(mp, channel)
79 mp.addChannel(channel, listener)
83 sys.stdout.write('[{0}] Child process terminating abnormally.\n'.format(os.getpid()))
85 # sys.stdout.write('[{0}] Child process terminating normally.\n'.format(os.getpid()))