diff options
Diffstat (limited to 'fix_includes.py')
-rwxr-xr-x | fix_includes.py | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/fix_includes.py b/fix_includes.py index 7600361..69b7003 100755 --- a/fix_includes.py +++ b/fix_includes.py @@ -82,9 +82,7 @@ All files mentioned in the include-what-you-use script are modified, unless filenames are specified on the commandline, in which case only those files are modified. -The exit code is the number of files that were modified (or that would -be modified if --dry_run was specified) unless that number exceeds 100, -in which case 100 is returned. +The exit code is non-zero if a critical error occurs, otherwise zero. """ _COMMENT_RE = re.compile(r'\s*//.*') @@ -2309,11 +2307,12 @@ def ProcessIWYUOutput(f, files_to_process, flags, cwd): # seen for them. (We have to wait until we're all done, since a .h # file may have a contentful change when #included from one .cc # file, but not another, and we need to have merged them above.) - for filename in iwyu_output_records: - if not iwyu_output_records[filename].HasContentfulChanges(): - print('(skipping %s: iwyu reports no contentful changes)' % filename) - # Mark that we're skipping this file by setting the record to None - iwyu_output_records[filename] = None + if not flags.update_comments: + for filename in iwyu_output_records: + if not iwyu_output_records[filename].HasContentfulChanges(): + print('(skipping %s: iwyu reports no contentful changes)' % filename) + # Mark that we're skipping this file by setting the record to None + iwyu_output_records[filename] = None # Now do all the fixing, and return the number of files modified contentful_records = [ior for ior in iwyu_output_records.values() if ior] @@ -2373,6 +2372,12 @@ def main(argv): help='Put comments after the #include lines') parser.add_option('--nocomments', action='store_false', dest='comments') + parser.add_option('--update_comments', action='store_true', default=False, + help=('Update #include comments, even if no #include lines' + ' are added or removed')) + parser.add_option('--noupdate_comments', action='store_false', + dest='update_comments') + parser.add_option('--safe_headers', action='store_true', default=True, help=('Do not remove unused #includes/fwd-declares from' ' header files; just add new ones [default]')) @@ -2440,14 +2445,18 @@ def main(argv): not flags.separate_project_includes.endswith('/')): flags.separate_project_includes += os.path.sep + if flags.update_comments: + flags.comments = True + if flags.sort_only: if not files_to_modify: sys.exit('FATAL ERROR: -s flag requires a list of filenames') - return SortIncludesInFiles(files_to_modify, flags) + SortIncludesInFiles(files_to_modify, flags) else: - return ProcessIWYUOutput(sys.stdin, files_to_modify, flags, cwd=os.getcwd()) + ProcessIWYUOutput(sys.stdin, files_to_modify, flags, cwd=os.getcwd()) + + return 0 if __name__ == '__main__': - num_files_fixed = main(sys.argv) - sys.exit(min(num_files_fixed, 100)) + sys.exit(main(sys.argv)) |