Skip to content

Commit 045d863

Browse files
committed
Added repoRootNameOverride for include guard creation
1 parent f30a079 commit 045d863

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

wpiformat/README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Empty config groups can be omitted. Directory separators must be "/", not "\". D
4747

4848
Valid include guard patterns use capital letters, start with the repository name, include the path to the file and the file name itself, and have directory separators and hyphens replaced with underscores. The path to the file starts from the repository root by default. Other paths, such as include directories, can be specified in the group ``includeGuardRoots``. If a path matches, that string will be truncated from the include guard pattern.
4949

50+
The group ``repoRootNameOverride`` allows one to override the repository name used in include guards. This is useful for giving subprojects within one repository different repository roots in their include guards. Only specify one name in this group because subsequent names will be ignored.
51+
5052
The groups ``includeRelated``, ``includeCSys``, ``includeCppSys``, ``includeOtherLibs``, and ``includeProject`` correspond to the header groups in the style guide. If a header name matches a regex in one of the groups, it overrides the default ordering and is placed in the corresponding group. The groups of regexes are checked in order of include group precedence.
5153

5254
The regex for C system headers produces false positives on headers from "other libraries". Regexes for them should be added to ``includeOtherLibs``. Libraries with many headers generally group them within a folder, so a regex for just the folder will suffice.

wpiformat/wpiformat/includeguard.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,23 @@ def make_include_guard(self, config_file, name):
7979
config_file -- Config object
8080
name -- file name string
8181
"""
82-
repo_root = Task.get_repo_root()
82+
repo_root_name_override = config_file.group("repoRootNameOverride")
8383

84-
name = os.path.relpath(name, repo_root)
85-
guard_path = os.path.basename(repo_root) + os.sep
84+
repo_root = Task.get_repo_root()
85+
guard_root = os.path.relpath(name, repo_root)
86+
if not repo_root_name_override:
87+
guard_path = os.path.basename(repo_root) + os.sep
88+
else:
89+
guard_path = repo_root_name_override[0] + os.sep
8690
include_roots = config_file.group("includeGuardRoots")
8791

8892
if include_roots:
8993
for include_root in include_roots:
90-
if name.startswith(include_root):
91-
guard_path += name[len(include_root):]
94+
if guard_root.startswith(include_root):
95+
guard_path += guard_root[len(include_root):]
9296
return regex.sub("[^a-zA-Z0-9]", "_",
9397
guard_path).upper() + "_"
9498

9599
# No include guard roots matched, so append full name
96-
guard_path += name
100+
guard_path += guard_root
97101
return regex.sub("[^a-zA-Z0-9]", "_", guard_path).upper() + "_"

0 commit comments

Comments
 (0)