14 """Patches the spawn() command for windows compilers.
16 Windows has an 8191 character command line limit, but some compilers
17 support an @command_file directive where command_file is a file
18 containing the full command line.
21 from distutils
import ccompiler
28 MAX_COMMAND_LENGTH = 8191
30 _classic_spawn = ccompiler.CCompiler.spawn
34 command_length =
sum([
len(arg)
for arg
in command])
35 if os.name ==
'nt' and command_length > MAX_COMMAND_LENGTH:
38 print(
'Command line length exceeded, using command file')
39 print(
' '.join(command))
40 temporary_directory = tempfile.mkdtemp()
41 command_filename = os.path.abspath(
42 os.path.join(temporary_directory,
'command'))
43 with open(command_filename,
'w')
as command_file:
45 '"' + arg.replace(
'\\',
'\\\\') +
'"' for arg
in command[1:]
47 command_file.write(
' '.join(escaped_args))
48 modified_command = command[:1] + [
'@{}'.
format(command_filename)]
52 shutil.rmtree(temporary_directory)
58 """Monkeypatching is dumb, but it's either that or we become maintainers of
59 something much, much bigger."""
60 ccompiler.CCompiler.spawn = _commandfile_spawn