Converts a list split source file paths into a vcproj folder hierarchy. Arguments: sources: A list of source file paths split. prefix: A list of source file path layers meant to apply to each of sources. excluded: A set of excluded files. msvs_version: A MSVSVersion obje
(
sources, prefix=None, excluded=None, list_excluded=True, msvs_version=None
)
| 193 | |
| 194 | |
| 195 | def _ConvertSourcesToFilterHierarchy( |
| 196 | sources, prefix=None, excluded=None, list_excluded=True, msvs_version=None |
| 197 | ): |
| 198 | """Converts a list split source file paths into a vcproj folder hierarchy. |
| 199 | |
| 200 | Arguments: |
| 201 | sources: A list of source file paths split. |
| 202 | prefix: A list of source file path layers meant to apply to each of sources. |
| 203 | excluded: A set of excluded files. |
| 204 | msvs_version: A MSVSVersion object. |
| 205 | |
| 206 | Returns: |
| 207 | A hierarchy of filenames and MSVSProject.Filter objects that matches the |
| 208 | layout of the source tree. |
| 209 | For example: |
| 210 | _ConvertSourcesToFilterHierarchy([['a', 'bob1.c'], ['b', 'bob2.c']], |
| 211 | prefix=['joe']) |
| 212 | --> |
| 213 | [MSVSProject.Filter('a', contents=['joe\\a\\bob1.c']), |
| 214 | MSVSProject.Filter('b', contents=['joe\\b\\bob2.c'])] |
| 215 | """ |
| 216 | if not prefix: |
| 217 | prefix = [] |
| 218 | result = [] |
| 219 | excluded_result = [] |
| 220 | folders = OrderedDict() |
| 221 | # Gather files into the final result, excluded, or folders. |
| 222 | for s in sources: |
| 223 | if len(s) == 1: |
| 224 | filename = _NormalizedSource("\\".join(prefix + s)) |
| 225 | if filename in excluded: |
| 226 | excluded_result.append(filename) |
| 227 | else: |
| 228 | result.append(filename) |
| 229 | elif msvs_version and not msvs_version.UsesVcxproj(): |
| 230 | # For MSVS 2008 and earlier, we need to process all files before walking |
| 231 | # the sub folders. |
| 232 | if not folders.get(s[0]): |
| 233 | folders[s[0]] = [] |
| 234 | folders[s[0]].append(s[1:]) |
| 235 | else: |
| 236 | contents = _ConvertSourcesToFilterHierarchy( |
| 237 | [s[1:]], |
| 238 | prefix + [s[0]], |
| 239 | excluded=excluded, |
| 240 | list_excluded=list_excluded, |
| 241 | msvs_version=msvs_version, |
| 242 | ) |
| 243 | contents = MSVSProject.Filter(s[0], contents=contents) |
| 244 | result.append(contents) |
| 245 | # Add a folder for excluded files. |
| 246 | if excluded_result and list_excluded: |
| 247 | excluded_folder = MSVSProject.Filter( |
| 248 | "_excluded_files", contents=excluded_result |
| 249 | ) |
| 250 | result.append(excluded_folder) |
| 251 | |
| 252 | if msvs_version and msvs_version.UsesVcxproj(): |
no test coverage detected