Mercurial > vim-crosoft
comparison scripts/vshelpers.py @ 10:f444739dd8af
Improvements to YCM dynamic flags.
- Fallback to a "companion" item (e.g. header/source) or a nearby item
when no flags are found for an item.
- Finding a "companion" is also exposed as a standalone script.
- Ability to pass extra clang flags, including some from a special
file found in the .vimcrosoft directory.
- Add support for PCH and other forced-include files.
- Add options for short/long args, or forcing forward slashes.
- Debugging/troubleshooting options, including dumping a batch file and
response file to run clang directly, and the ability to auto-load a
solution's last known environment when running in command line.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 24 Sep 2020 23:02:16 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:4ba6df1b2f97 | 10:f444739dd8af |
---|---|
1 import os.path | |
2 import logging | |
3 from vsutil import SolutionCache | |
4 | |
5 | |
6 logger = logging.getLogger(__name__) | |
7 | |
8 config_format = 2 # Keep in sync with vimcrosoft.vim | |
9 | |
10 | |
11 def load_vimcrosoft_auto_env(sln_file, build_env): | |
12 cache_file = os.path.join(os.path.dirname(sln_file), '.vimcrosoft', 'config.txt') | |
13 if not os.path.isfile(cache_file): | |
14 logger.warn("No Vimcrosoft cache file found, you will probably have to specify " | |
15 "all configuration values in the command line!") | |
16 return | |
17 | |
18 with open(cache_file, 'r', encoding='utf8') as fp: | |
19 lines = fp.readlines() | |
20 | |
21 tokens = [ | |
22 '_VimcrosoftConfigFormat', | |
23 '_VimcrosoftCurrentSolution', | |
24 'Configuration', | |
25 'Platform', | |
26 '_VimcrosoftActiveProject'] | |
27 for i, line in enumerate(lines): | |
28 token = tokens[i] | |
29 build_env[token] = line.strip() | |
30 | |
31 try: | |
32 found_conffmt = int(build_env['_VimcrosoftConfigFormat'].split('=')[-1]) | |
33 except: | |
34 raise Exception("Invalid Vimcrosoft cache file found.") | |
35 if found_conffmt != config_format: | |
36 raise Exception("Incompatible Vimcrosoft cache file found. " | |
37 "Expected format %d but got %d" % (config_format, found_conffmt)) | |
38 | |
39 logger.info("Loaded cached configuration|platform: %s|%s" % | |
40 (build_env['Configuration'], build_env['Platform'])) | |
41 | |
42 | |
43 def find_vimcrosoft_slncache(sln_file): | |
44 return os.path.join(os.path.dirname(sln_file), '.vimcrosoft', 'slncache.bin') | |
45 | |
46 | |
47 def get_solution_cache(solution, slncache=None): | |
48 if not solution: | |
49 raise Exception( | |
50 "No solution path was provided!") | |
51 | |
52 cache, loaded = SolutionCache.load_or_rebuild(solution, slncache) | |
53 if not loaded: | |
54 cache.build_cache() | |
55 if slncache: | |
56 logger.debug(f"Saving solution cache: {slncache}") | |
57 cache.save(slncache) | |
58 | |
59 return cache | |
60 | |
61 | |
62 def find_item_project(item_path, solution, slncache=None): | |
63 # Load the solution | |
64 cache = get_solution_cache(solution, slncache) | |
65 | |
66 # Find the primary file in the solution. | |
67 item_path_lower = item_path.lower() | |
68 projpath = None | |
69 for pp, pi in cache.index.items(): | |
70 if item_path_lower in pi: | |
71 projpath = pp | |
72 break | |
73 else: | |
74 raise Exception("File doesn't belong to the solution: %s" % item_path) | |
75 | |
76 # Find the project that our file belongs to. | |
77 proj = cache.slnobj.find_project_by_path(projpath) | |
78 if not proj: | |
79 raise Exception("Can't find project in solution: %s" % projpath) | |
80 | |
81 return cache, proj |