Mercurial > vim-crosoft
comparison scripts/list_sln_files.py @ 15:cfcac4ed7d21 default tip
Improve loading of solution files
- New argument to force a rebuild of the cache
- Gracefully handle missing projects in a solution
- Handle more different xml namespaces
- Support more edge cases
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 29 Aug 2023 12:59:54 -0700 |
parents | d5ddd9ffaf11 |
children |
comparison
equal
deleted
inserted
replaced
14:0aa61944e518 | 15:cfcac4ed7d21 |
---|---|
12 parser = argparse.ArgumentParser() | 12 parser = argparse.ArgumentParser() |
13 parser.add_argument('solution', | 13 parser.add_argument('solution', |
14 help="The path to the Visual Studio solution file.") | 14 help="The path to the Visual Studio solution file.") |
15 parser.add_argument('-c', '--cache', | 15 parser.add_argument('-c', '--cache', |
16 help="The solution cache file to load.") | 16 help="The solution cache file to load.") |
17 parser.add_argument('--rebuild-cache', | |
18 action='store_true', | |
19 help="Force rebuild the cache even if it is valid") | |
17 parser.add_argument('--list-cache', | 20 parser.add_argument('--list-cache', |
18 help=("If the solution cache is valid, use this " | 21 help=("If the solution cache is valid, use this " |
19 "pre-saved file list. Otherwise, compute the " | 22 "pre-saved file list. Otherwise, compute the " |
20 "file list and save it to the given path.")) | 23 "file list and save it to the given path.")) |
21 parser.add_argument('-p', '--project', | 24 parser.add_argument('-p', '--project', |
27 action='store_true', | 30 action='store_true', |
28 help="Show verbose information.") | 31 help="Show verbose information.") |
29 args = parser.parse_args(args) | 32 args = parser.parse_args(args) |
30 setup_logging(args.verbose) | 33 setup_logging(args.verbose) |
31 | 34 |
32 cache, loaded = SolutionCache.load_or_rebuild(args.solution, args.cache) | 35 cache, loaded = SolutionCache.load_or_rebuild(args.solution, args.cache, |
36 args.rebuild_cache) | |
33 if loaded and args.list_cache: | 37 if loaded and args.list_cache: |
34 caches_exist = True | 38 caches_exist = True |
35 try: | 39 try: |
36 cache_dt = os.path.getmtime(args.cache) | 40 cache_dt = os.path.getmtime(args.cache) |
37 list_cache_dt = os.path.getmtime(args.list_cache) | 41 list_cache_dt = os.path.getmtime(args.list_cache) |
59 itemtypes = args.type or ITEM_TYPE_SOURCE_FILES | 63 itemtypes = args.type or ITEM_TYPE_SOURCE_FILES |
60 items = [] | 64 items = [] |
61 | 65 |
62 for p in projs: | 66 for p in projs: |
63 ig = p.defaultitemgroup() | 67 ig = p.defaultitemgroup() |
68 if ig is None: | |
69 continue | |
64 for i in ig.get_items_of_types(itemtypes): | 70 for i in ig.get_items_of_types(itemtypes): |
65 file_path = os.path.abspath(os.path.join(p.absdirpath, i.include)) | 71 if i.include: |
66 print(file_path) | 72 file_path = os.path.abspath(os.path.join(p.absdirpath, i.include)) |
67 items.append(file_path + '\n') | 73 print(file_path) |
74 items.append(file_path + '\n') | |
68 | 75 |
69 if args.list_cache: | 76 if args.list_cache: |
70 logger.debug("Writing file list cache: %s" % args.list_cache) | 77 logger.debug("Writing file list cache: %s" % args.list_cache) |
71 with open(args.list_cache, 'w') as fp: | 78 with open(args.list_cache, 'w') as fp: |
72 fp.writelines(items) | 79 fp.writelines(items) |