Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: pylib/gyp/MSVSNew.py

Issue 10943017: Ensure that all entries in .sln files are sorted. (Closed) Base URL: https://gyp.googlecode.com/svn/trunk
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 Google Inc. All rights reserved. 1 # Copyright (c) 2012 Google Inc. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """New implementation of Visual Studio project generation for SCons.""" 5 """New implementation of Visual Studio project generation for SCons."""
6 6
7 import os 7 import os
8 import random 8 import random
9 9
10 import gyp.common 10 import gyp.common
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 # Calculate a MD5 signature for the seed and name. 52 # Calculate a MD5 signature for the seed and name.
53 d = _new_md5(str(seed) + str(name)).hexdigest().upper() 53 d = _new_md5(str(seed) + str(name)).hexdigest().upper()
54 # Convert most of the signature to GUID form (discard the rest) 54 # Convert most of the signature to GUID form (discard the rest)
55 guid = ('{' + d[:8] + '-' + d[8:12] + '-' + d[12:16] + '-' + d[16:20] 55 guid = ('{' + d[:8] + '-' + d[8:12] + '-' + d[12:16] + '-' + d[16:20]
56 + '-' + d[20:32] + '}') 56 + '-' + d[20:32] + '}')
57 return guid 57 return guid
58 58
59 #------------------------------------------------------------------------------ 59 #------------------------------------------------------------------------------
60 60
61 61
62 class MSVSFolder(object): 62 class MSVSSolutionEntry(object):
63 def __cmp__(self, other):
64 # Sort by name then guid (so things are in order on vs2008).
65 return cmp((self.name, self.get_guid()), (other.name, other.get_guid()))
66
67
68 class MSVSFolder(MSVSSolutionEntry):
63 """Folder in a Visual Studio project or solution.""" 69 """Folder in a Visual Studio project or solution."""
64 70
65 def __init__(self, path, name = None, entries = None, 71 def __init__(self, path, name = None, entries = None,
66 guid = None, items = None): 72 guid = None, items = None):
67 """Initializes the folder. 73 """Initializes the folder.
68 74
69 Args: 75 Args:
70 path: Full path to the folder. 76 path: Full path to the folder.
71 name: Name of the folder. 77 name: Name of the folder.
72 entries: List of folder entries to nest inside this folder. May contain 78 entries: List of folder entries to nest inside this folder. May contain
73 Folder or Project objects. May be None, if the folder is empty. 79 Folder or Project objects. May be None, if the folder is empty.
74 guid: GUID to use for folder, if not None. 80 guid: GUID to use for folder, if not None.
75 items: List of solution items to include in the folder project. May be 81 items: List of solution items to include in the folder project. May be
76 None, if the folder does not directly contain items. 82 None, if the folder does not directly contain items.
77 """ 83 """
78 if name: 84 if name:
79 self.name = name 85 self.name = name
80 else: 86 else:
81 # Use last layer. 87 # Use last layer.
82 self.name = os.path.basename(path) 88 self.name = os.path.basename(path)
83 89
84 self.path = path 90 self.path = path
85 self.guid = guid 91 self.guid = guid
86 92
87 # Copy passed lists (or set to empty lists) 93 # Copy passed lists (or set to empty lists)
88 self.entries = list(entries or []) 94 self.entries = sorted(list(entries or []))
89 self.items = list(items or []) 95 self.items = list(items or [])
90 96
91 self.entry_type_guid = ENTRY_TYPE_GUIDS['folder'] 97 self.entry_type_guid = ENTRY_TYPE_GUIDS['folder']
92 98
93 def get_guid(self): 99 def get_guid(self):
94 if self.guid is None: 100 if self.guid is None:
95 # Use consistent guids for folders (so things don't regenerate). 101 # Use consistent guids for folders (so things don't regenerate).
96 self.guid = MakeGuid(self.path, seed='msvs_folder') 102 self.guid = MakeGuid(self.path, seed='msvs_folder')
97 return self.guid 103 return self.guid
98 104
99 105
100 #------------------------------------------------------------------------------ 106 #------------------------------------------------------------------------------
101 107
102 108
103 class MSVSProject(object): 109 class MSVSProject(MSVSSolutionEntry):
104 """Visual Studio project.""" 110 """Visual Studio project."""
105 111
106 def __init__(self, path, name = None, dependencies = None, guid = None, 112 def __init__(self, path, name = None, dependencies = None, guid = None,
107 spec = None, build_file = None, config_platform_overrides = None, 113 spec = None, build_file = None, config_platform_overrides = None,
108 fixpath_prefix = None): 114 fixpath_prefix = None):
109 """Initializes the project. 115 """Initializes the project.
110 116
111 Args: 117 Args:
112 path: Absolute path to the project file. 118 path: Absolute path to the project file.
113 name: Name of project. If None, the name will be the same as the base 119 name: Name of project. If None, the name will be the same as the base
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 # If this entry has been visited, nothing to do. 228 # If this entry has been visited, nothing to do.
223 if e in all_entries: 229 if e in all_entries:
224 continue 230 continue
225 231
226 all_entries.add(e) 232 all_entries.add(e)
227 233
228 # If this is a folder, check its entries too. 234 # If this is a folder, check its entries too.
229 if isinstance(e, MSVSFolder): 235 if isinstance(e, MSVSFolder):
230 entries_to_check += e.entries 236 entries_to_check += e.entries
231 237
232 # Sort by name then guid (so things are in order on vs2008). 238 all_entries = sorted(all_entries)
233 def NameThenGuid(a, b):
234 if a.name < b.name: return -1
235 if a.name > b.name: return 1
236 if a.get_guid() < b.get_guid(): return -1
237 if a.get_guid() > b.get_guid(): return 1
238 return 0
239
240 all_entries = sorted(all_entries, NameThenGuid)
241 239
242 # Open file and print header 240 # Open file and print header
243 f = writer(self.path) 241 f = writer(self.path)
244 f.write('Microsoft Visual Studio Solution File, ' 242 f.write('Microsoft Visual Studio Solution File, '
245 'Format Version %s\r\n' % self.version.SolutionVersion()) 243 'Format Version %s\r\n' % self.version.SolutionVersion())
246 f.write('# %s\r\n' % self.version.Description()) 244 f.write('# %s\r\n' % self.version.Description())
247 245
248 # Project entries 246 # Project entries
249 sln_root = os.path.split(self.path)[0] 247 sln_root = os.path.split(self.path)[0]
250 for e in all_entries: 248 for e in all_entries:
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 for e in all_entries: 330 for e in all_entries:
333 if not isinstance(e, MSVSFolder): 331 if not isinstance(e, MSVSFolder):
334 continue # Does not apply to projects, only folders 332 continue # Does not apply to projects, only folders
335 for subentry in e.entries: 333 for subentry in e.entries:
336 f.write('\t\t%s = %s\r\n' % (subentry.get_guid(), e.get_guid())) 334 f.write('\t\t%s = %s\r\n' % (subentry.get_guid(), e.get_guid()))
337 f.write('\tEndGlobalSection\r\n') 335 f.write('\tEndGlobalSection\r\n')
338 336
339 f.write('EndGlobal\r\n') 337 f.write('EndGlobal\r\n')
340 338
341 f.close() 339 f.close()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698