From: stevenknight Date: Wed, 17 Apr 2002 20:17:55 +0000 (+0000) Subject: Fix win32LinkGenerator. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f346864beb0b2ee217a58008f38123d7313d943e;p=scons.git Fix win32LinkGenerator. git-svn-id: http://scons.tigris.org/svn/scons/trunk@336 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index 929dbc9a..a0b11577 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -135,25 +135,21 @@ Object = SCons.Builder.Builder(name = 'Object', src_builder = [CFile, CXXFile]) def win32LinkGenerator(env, target, source, **kw): - args = [] - for a in [env['LINKFLAGS'], - '/OUT:' + str(target[0]), - env['_LIBDIRFLAGS'], - env['_LIBFLAGS'], - map(lambda x: str(x), source)]: - if SCons.Util.is_List(a): - args.extend(a) - else: - args.append(a) - argstring = string.join(args, " ") - if len(argstring) <= 2048: - return env['LINK'] + " " + argstring + cmd = env.subst_list([ '$LINK', '$LINKFLAGS', '/OUT:' + str(target[0]) ])[0] + cmd.extend(['$('] + env.subst_list('$_LIBDIRFLAGS')[0] + ['$)']) + cmd.extend(env.subst_list('$_LIBFLAGS')[0]) + cmd.extend(map(lambda x: str(x), source)) + cmdlen = reduce(lambda x, y: x + len(y), cmd, 0) + len(cmd) + if cmdlen <= 2048: + return [cmd] else: import tempfile tmp = tempfile.mktemp() - open(tmp, 'w').write(argstring + "\n") - return [ env['LINK'] + " @" + tmp, - "del " + tmp, ] + args = filter(lambda x: x != '$(' and x != '$)', cmd[1:]) + args = map(SCons.Util.quote_spaces, args) + open(tmp, 'w').write(string.join(args, " ") + "\n") + return [ [cmd[0], '@' + tmp], + ['del', tmp] ] kw = { 'name' : 'Program', diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 1f27ff89..0abbd1e7 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -139,6 +139,12 @@ class PathList(UserList.UserList): # suffix and basepath. return self.__class__([ UserList.UserList.__getitem__(self, item), ]) +def quote_spaces(arg): + if ' ' in arg or '\t' in arg: + return '"%s"' % arg + else: + return arg + _cv = re.compile(r'\$([_a-zA-Z]\w*|{[^}]*})') _space_sep = re.compile(r'[\t ]+(?![^{]*})') diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index fdffe4d0..b4245069 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -177,8 +177,16 @@ class UtilTestCase(unittest.TestCase): assert len(cmd_list) == 1, cmd_list assert cmd_list[0] == ['test', '3', '2', '4', 'test'], cmd_list - - + def test_quote_spaces(self): + """Testing the quote_spaces() method...""" + q = quote_spaces('x') + assert q == 'x', q + + q = quote_spaces('x x') + assert q == '"x x"', q + + q = quote_spaces('x\tx') + assert q == '"x\tx"', q def test_render_tree(self): class Node: diff --git a/test/long-lines.py b/test/long-lines.py index 6df229cf..bde101a3 100644 --- a/test/long-lines.py +++ b/test/long-lines.py @@ -40,7 +40,7 @@ test.write('SConstruct', """ linkflags = r'%s' while len(linkflags) <= 8100: linkflags = linkflags + r' %s' -env = Environment(LINKFLAGS = linkflags) +env = Environment(LINKFLAGS = '$LINKXXX', LINKXXX = linkflags) env.Program(target = 'foo', source = 'foo.c') """ % (linkflag, linkflag))