From e68b989af50b57e4e91585542ecfff9e5857bdee Mon Sep 17 00:00:00 2001 From: evhub Date: Fri, 11 Jul 2014 14:47:52 -0700 Subject: [PATCH] Fix VSProject item sorting: * Use object type in the sort key * Call _key recursively over containers * Prevent passing of iterators to xsorted * Fix VSProject generator with new sorting --- site_scons/site_tools/VSProject.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/site_scons/site_tools/VSProject.py b/site_scons/site_tools/VSProject.py index 396d6eb2c..9d6e54d03 100644 --- a/site_scons/site_tools/VSProject.py +++ b/site_scons/site_tools/VSProject.py @@ -94,15 +94,21 @@ def is_subdir(child, parent): '''Determine if child is a subdirectory of parent''' return os.path.commonprefix([parent, child]) == parent -def xsorted(*args, **kwargs): +def xsorted(tosort, **kwargs): '''Performs sorted in a deterministic manner.''' - if not 'key' in kwargs: - def _lower(item): - if isinstance(item, str): - return (item.lower(), item) - return (item, item) - kwargs['key'] = _lower - return sorted(*args, **kwargs) + if 'key' in kwargs: + map(kwargs['key'], tosort) + def _key(item): + if isinstance(item, (str, unicode)): + return ("s", item.upper(), item) + elif isinstance(item, (list, tuple)): + return ("c", map(_key, item)) + elif isinstance(item, dict): + return ("d", xsorted(item.keys()), xsorted(item.values())) + else: + return ("x", item) + kwargs['key'] = _key + return sorted(tosort, **kwargs) def itemList(items, sep): if type(items) == str: # Won't work in Python 3. @@ -608,7 +614,7 @@ class _ProjectGenerator(object): targets = config.target for target in targets: _walk(target, items) - self.items = xsorted(items.itervalues(), key=lambda x: x.path()) + self.items = xsorted(items.values(), key=lambda x: x.path()) def makeListTag(self, items, prefix, tag, attrs, inherit=True): '''Builds an XML tag string from a list of items. If items is @@ -717,7 +723,7 @@ class _ProjectGenerator(object): props = ' True\r\n' elif item.builder() == 'Object': props = '' - for config, output in xsorted(item.node.iteritems()): + for config, output in xsorted(item.node.items()): name = config.name env = output.get_build_env() variant = config.variant @@ -727,7 +733,7 @@ class _ProjectGenerator(object): ''' Condition="'$(Configuration)|$(Platform)'=='%(variant)s|%(platform)s'"''' % locals(), True) elif item.builder() == 'Protoc': - for config, output in xsorted(item.node.iteritems()): + for config, output in xsorted(item.node.items()): name = config.name out_dir = os.path.relpath(os.path.dirname(str(output)), self.project_dir) cpp_out = winpath(out_dir)