Skip to content

Commit

Permalink
fix: Visual Studio's compiler / preprocessor uses a different format …
Browse files Browse the repository at this point in the history
…for the resulting included files
  • Loading branch information
sindre-nistad committed Jan 10, 2025
1 parent 53dec19 commit 71554a8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ def _add_file(repl: str, file_regex):
if file.suffix in ['.cpp', '.c']:
_add_file(r'.h\1', source_regex)

_name_pattern = r'[<"](?P<name>([a-z]:[\\/])?[\w\\/._-]+)[>"]'
_name_group = r'(?P<name>([a-z]:[\\/])?[\w\\/._-]+)'
_name_pattern = r'[<"]' + _name_group + '[>"]'
include_pattern = re.compile(r'^ *# *include *' + _name_pattern, re.IGNORECASE)
define_pattern = re.compile(r'^ *# *define \w+ *(\\\n)? *' + _name_pattern, re.IGNORECASE | re.MULTILINE)
completely_preprocessed_pattern = re.compile(r'^ *# *\d+ *' + _name_pattern + r'( \d+)*', re.IGNORECASE)
msvc_include_pattern = re.compile(r'^Note: including file: +' + _name_group, re.IGNORECASE)
while len(files_to_be_inspected) > 0:

file = files_to_be_inspected.pop().resolve()
Expand Down Expand Up @@ -118,6 +120,8 @@ def _add_file(repl: str, file_regex):
match = define_pattern.search(previous_line + line)
if not match:
match = completely_preprocessed_pattern.search(line)
if not match:
match = msvc_include_pattern.search(line)
if match:
item = Path(match.group('name'))
if (file.parent / item).is_file():
Expand Down

0 comments on commit 71554a8

Please sign in to comment.