summaryrefslogtreecommitdiffstats
path: root/long_gcc.py
blob: 20ca2a7f77e438ba2caa8ed0d0ac49c98f7237c0 (plain) (blame)
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
#! /usr/bin/env python
# encoding: utf-8

"""
def build(bld):
	bld.load('long_gcc')
"""

import os, tempfile
from waflib import Task

def exec_command(self, cmd, **kw):
	# workaround for command line length limit:
	# http://support.microsoft.com/kb/830473
	tmp = None
	try:
		if not isinstance(cmd, str) and len(str(cmd)) > 8192:
			(fd, tmp) = tempfile.mkstemp(dir=self.generator.bld.bldnode.abspath())
			flat = ['"%s"' % x.replace('\\', '\\\\').replace('"', '\\"') for x in cmd[1:]]
			try:
				os.write(fd, ' '.join(flat).encode())
			finally:
				if tmp:
					os.close(fd)
			# Line may be very long:
			# Logs.debug('runner:' + ' '.join(flat))
			cmd = [cmd[0], '@' + tmp]
		ret = super(self.__class__, self).exec_command(cmd, **kw)
	finally:
		if tmp:
			os.remove(tmp)
	return ret

def wrap_class(class_name):
	cls = Task.classes.get(class_name)
	if not cls:
		return None
	derived_class = type(class_name, (cls,), {})
	derived_class.exec_command = exec_command
	if hasattr(cls, 'hcode'):
		derived_class.hcode = cls.hcode
	return derived_class

for k in 'c cxx cprogram cxxprogram cshlib cxxshlib cstlib cxxstlib'.split():
	wrap_class(k)