aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar David Garcia Quintas <dgq@google.com>2016-03-17 22:26:22 -0700
committerGravatar David Garcia Quintas <dgq@google.com>2016-03-17 22:26:22 -0700
commit3c5def57f65ac92a94f4a78f58fde9ed52aa8e1c (patch)
tree5a4da089d95bd8c5108a4a6e55b94291d65a30ae /tools
parent5b385dcbcbaf891fc4f16eda69dff40b5879b1f8 (diff)
addressed pr comments
Diffstat (limited to 'tools')
-rwxr-xr-xtools/distrib/check_include_guards.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/tools/distrib/check_include_guards.py b/tools/distrib/check_include_guards.py
index b61e32f2f4..cf24199169 100755
--- a/tools/distrib/check_include_guards.py
+++ b/tools/distrib/check_include_guards.py
@@ -95,56 +95,59 @@ class GuardValidator(object):
fcontents = load(fpath)
match = self.ifndef_re.search(fcontents)
- if match.lastindex != 1:
+ if match.lastindex is None:
# No ifndef. Request manual addition with hints
self.fail(fpath, match.re, match.string, '', '', False)
+ return False # failed
# Does the guard end with a '_H'?
running_guard = match.group(1)
if not running_guard.endswith('_H'):
fcontents = self.fail(fpath, match.re, match.string, match.group(1),
valid_guard, fix)
- save(fpath, fcontents)
+ if fix: save(fpath, fcontents)
# Is it the expected one based on the file path?
if running_guard != valid_guard:
fcontents = self.fail(fpath, match.re, match.string, match.group(1),
valid_guard, fix)
- save(fpath, fcontents)
+ if fix: save(fpath, fcontents)
# Is there a #define? Is it the same as the #ifndef one?
match = self.define_re.search(fcontents)
- if match.lastindex != 1:
+ if match.lastindex is None:
# No define. Request manual addition with hints
self.fail(fpath, match.re, match.string, '', '', False)
+ return False # failed
# Is the #define guard the same as the #ifndef guard?
if match.group(1) != running_guard:
fcontents = self.fail(fpath, match.re, match.string, match.group(1),
valid_guard, fix)
- save(fpath, fcontents)
+ if fix: save(fpath, fcontents)
# Is there a properly commented #endif?
endif_re = self.endif_cpp_re if cpp_header else self.endif_c_re
- matches = endif_re.findall(fcontents)
- if not matches:
+ flines = fcontents.rstrip().splitlines()
+ match = endif_re.search(flines[-1])
+ if not match:
# No endif. Check if we have the last line as just '#endif' and if so
# replace it with a properly commented one.
- flines = fcontents.splitlines()
if flines[-1] == '#endif':
flines[-1] = ('#endif' +
(' // {}\n'.format(valid_guard) if cpp_header
else ' /* {} */\n'.format(valid_guard)))
- fcontents = '\n'.join(flines)
- save(fpath, fcontents)
+ if fix:
+ fcontents = '\n'.join(flines)
+ save(fpath, fcontents)
else:
# something else is wrong, bail out
self.fail(fpath, endif_re, match.string, '', '', False)
- elif matches[-1] != running_guard:
+ elif match.group(1) != running_guard:
# Is the #endif guard the same as the #ifndef and #define guards?
fcontents = self.fail(fpath, endif_re, fcontents, matches[-1],
valid_guard, fix)
- save(fpath, fcontents)
+ if fix: save(fpath, fcontents)
return not self.failed # Did the check succeed? (ie, not failed)