From a51bbd87018178249ca83d43b3ef4d06e6bbfec9 Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Thu, 8 Mar 2018 16:15:45 +0100 Subject: [PATCH] Adding PRESUBMIT check to stop using istream, ostream and sstream. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WebRTC would like to stop using std::stringstream (in favor of rtc::SimpleStringStream) and in order to avoid to introduce new dependencies on it (and on other streams), this CL adds a PRESUBMIT check. The check will trigger anytime an #include of istream, ostream or sstream is detected. It also ensures that new usages of types defined in these headers are not introduced in the codebase. Bug: webrtc:8982 Change-Id: I3e44d6a53772f25405234f10d4cf0a7209fedf99 No-Try: True Reviewed-on: https://webrtc-review.googlesource.com/60542 Commit-Queue: Mirko Bonadei Reviewed-by: Tommi Reviewed-by: Patrik Höglund Cr-Commit-Position: refs/heads/master@{#22343} --- PRESUBMIT.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 506ffadc6c..6360cb51e0 100755 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -403,6 +403,48 @@ def CheckNoPackageBoundaryViolations(input_api, gn_files, output_api): long_text='\n\n'.join(str(err) for err in errors))] return [] + +def _ReportErrorFileAndLineNumber(filename, line_num): + """Default error formatter for _FindNewViolationsOfRule.""" + return '%s (line %s)' % (filename, line_num) + + +def CheckNoStreamUsageIsAdded(input_api, output_api, + error_formatter=_ReportErrorFileAndLineNumber): + """Make sure that no more dependencies on stringstream are added.""" + error_msg = ('Usage of , and in WebRTC is ' + 'deprecated.\n' + 'This includes the following types:\n' + 'std::istringstream, std::ostringstream, std::wistringstream, ' + 'std::wostringstream,\n' + 'std::wstringstream, std::ostream, std::wostream, std::istream,' + 'std::wistream,\n' + 'std::iostream, std::wiostream.\n' + 'If you are not adding this code (e.g. you are just moving ' + 'existing code),\n' + 'you can add a comment on the line that causes the problem:\n\n' + '#include // no-presubmit-check TODO(webrtc:8982)\n' + 'std::ostream& F() { // no-presubmit-check TODO(webrtc:8982)\n' + '\n' + 'If you are adding new code, please consider using ' + 'rtc::SimpleStringBuilder (rtc_base/string/string_builder.h).\n' + 'Affected files:\n') + errors = [] # 2-element tuples with (file, line number) + include_re = input_api.re.compile(r'#include <(i|o|s)stream>') + usage_re = input_api.re.compile(r'std::(w|i|o|io|wi|wo|wio)(string)*stream') + no_presubmit_re = input_api.re.compile( + r' // no-presubmit-check TODO\(webrtc:8982\)') + for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): + if f.LocalPath() == 'PRESUBMIT.py': + continue + for line_num, line in f.ChangedContents(): + if ((include_re.search(line) or usage_re.search(line)) + and not no_presubmit_re.search(line)): + errors.append(error_formatter(f.LocalPath(), line_num)) + if errors: + return [output_api.PresubmitError(error_msg, errors)] + return [] + def CheckPublicDepsIsNotUsed(gn_files, output_api): result = [] error_msg = ('public_deps is not allowed in WebRTC BUILD.gn files because ' @@ -732,6 +774,7 @@ def CommonChecks(input_api, output_api): results.extend(CheckUsageOfGoogleProtobufNamespace(input_api, output_api)) results.extend(CheckOrphanHeaders(input_api, output_api)) results.extend(CheckNewlineAtTheEndOfProtoFiles(input_api, output_api)) + results.extend(CheckNoStreamUsageIsAdded(input_api, output_api)) return results