From e21308e44dcfe2e1a6da8386d2ef0c36792119f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Tue, 3 Sep 2013 20:32:44 +0200 Subject: scons2ninja: Support quoted flags. Change-Id: Iea4206b281400995734263fc39062196d2d0446f diff --git a/BuildTools/scons2ninja.py b/BuildTools/scons2ninja.py index 4a7631a..2666ae6 100755 --- a/BuildTools/scons2ninja.py +++ b/BuildTools/scons2ninja.py @@ -11,7 +11,7 @@ # ################################################################################ -import re, os, os.path, subprocess, sys, fnmatch +import re, os, os.path, subprocess, sys, fnmatch, shlex ################################################################################ # Helper methods & variables @@ -40,6 +40,12 @@ def is_list(l) : def escape(s) : return s.replace(' ', '$ ').replace(':', '$:') + +def quote_spaces(s) : + if ' ' in s : + return '"' + s + '"' + else : + return s def to_list(l) : if not l : @@ -114,7 +120,7 @@ def get_built_libs(libs, libpaths, outputs) : return result def parse_tool_command(line) : - command = line.split(' ') + command = shlex.split(line) flags = command[1:] tool = os.path.splitext(os.path.basename(command[0]))[0] if tool.startswith('clang++') or tool.startswith('g++') : @@ -173,7 +179,7 @@ class NinjaBuilder : for var, value in kwargs.iteritems() : if var in ['deps', 'order_deps'] : continue - value = self.to_string(value) + value = self.to_string(value, quote = True) if var.endswith("flags") : value = self.get_flags_variable(var, value) self._build += " " + var + " = " + value + "\n" @@ -195,9 +201,12 @@ class NinjaBuilder : result += self._build + "\n" return result - def to_string(self, lst) : + def to_string(self, lst, quote = False) : if is_list(lst) : - return ' '.join([escape(x) for x in lst]) + if quote : + return ' '.join([quote_spaces(x) for x in lst]) + else : + return ' '.join([escape(x) for x in lst]) if is_regexp(lst) : return ' '.join([escape(x) for x in self.targets if lst.match(x)]) return escape(lst) -- cgit v0.10.2-6-g49f6