5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 This script is intended to execute a single build target. This script should be
28 called by ninja, passing the port, ninja dir, and build target via arguments.
29 The script then executes a simple get request to the scons daemon which is listening
30 on from localhost on the set port.
44 ninja_builddir
= pathlib
.Path(sys
.argv
[2])
45 daemon_dir
= pathlib
.Path(tempfile
.gettempdir()) / (
46 "scons_daemon_" + str(hashlib
.md5(str(ninja_builddir
).encode()).hexdigest())
48 os
.makedirs(daemon_dir
, exist_ok
=True)
51 filename
=daemon_dir
/ "scons_daemon_request.log",
53 format
="%(asctime)s %(message)s",
58 def log_error(msg
) -> None:
65 if not os
.path
.exists(daemon_dir
/ "pidfile"):
66 if sys
.argv
[3] != '--exit':
67 logging
.debug(f
"ERROR: Server pid not found {daemon_dir / 'pidfile'} for request {sys.argv[3]}")
70 logging
.debug("WARNING: Unnecessary request to shutdown server, it's already shutdown.")
73 logging
.debug(f
"Sending request: {sys.argv[3]}")
74 conn
= http
.client
.HTTPConnection(
75 "127.0.0.1", port
=int(sys
.argv
[1]), timeout
=60
77 if sys
.argv
[3] == '--exit':
78 conn
.request("GET", "/?exit=1")
80 conn
.request("GET", "/?build=" + sys
.argv
[3])
85 response
= conn
.getresponse()
86 except (http
.client
.RemoteDisconnected
, http
.client
.ResponseNotReady
, socket
.timeout
):
88 except http
.client
.HTTPException
:
89 log_error(f
"Error: {traceback.format_exc()}")
93 status
= response
.status
95 log_error(msg
.decode("utf-8"))
98 logging
.debug(f
"Request Done: {sys.argv[3]}")
101 except ConnectionRefusedError
:
102 logging
.debug(f
"Server refused connection to build {sys.argv[3]}, maybe it was too busy, tring again: {traceback.format_exc()}")
106 log_error(f
"Failed to send command: {traceback.format_exc()}")
113 # indent-tabs-mode:nil
115 # vim: set expandtab tabstop=4 shiftwidth=4: