From a05d47e3448229af2f72870337aa9b854ff3a0ed Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Wed, 9 May 2018 11:03:38 +0200 Subject: [PATCH] Adding a way to disable public_deps presubmit check. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is useful when someone is just moving code around or when there is a good reason to use public_deps. Example of the error message: ** Presubmit ERRORS ** public_deps is discouraged in WebRTC BUILD.gn files because it doesn't map well to downstream build systems. Used in: BUILD.gn (line 31). If you are not adding this code (e.g. you are just moving existing code) or you have a good reason, you can add a comment on the line that causes the problem: public_deps = [ # no-presubmit-check TODO(webrtc:8603) Bug: webrtc:8603 Change-Id: If2645b6ba60c7cbf5416450cf6e5a8c08bf4934e Reviewed-on: https://webrtc-review.googlesource.com/75508 Reviewed-by: Patrik Höglund Commit-Queue: Mirko Bonadei Cr-Commit-Position: refs/heads/master@{#23186} --- PRESUBMIT.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 048689e6ce..5a40612bfb 100755 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -444,14 +444,22 @@ def CheckNoStreamUsageIsAdded(input_api, output_api, return [output_api.PresubmitError(error_msg, errors)] return [] -def CheckPublicDepsIsNotUsed(gn_files, output_api): +def CheckPublicDepsIsNotUsed(gn_files, input_api, output_api): + """Checks that public_deps is not used without a good reason.""" result = [] - error_msg = ('public_deps is not allowed in WebRTC BUILD.gn files because ' - 'it doesn\'t map well to downstream build systems.\n' - 'Used in: %s (line %d).') + no_presubmit_check_re = input_api.re.compile( + r'# no-presubmit-check TODO\(webrtc:8603\)') + error_msg = ('public_deps is not recommended in WebRTC BUILD.gn files ' + 'because it doesn\'t map well to downstream build systems.\n' + 'Used in: %s (line %d).\n' + 'If you are not adding this code (e.g. you are just moving ' + 'existing code) or you have a good reason, you can add a ' + 'comment on the line that causes the problem:\n\n' + 'public_deps = [ # no-presubmit-check TODO(webrtc:8603)\n') for affected_file in gn_files: for (line_number, affected_line) in affected_file.ChangedContents(): - if 'public_deps' in affected_line: + if ('public_deps' in affected_line + and not no_presubmit_check_re.search(affected_line)): result.append( output_api.PresubmitError(error_msg % (affected_file.LocalPath(), line_number))) @@ -489,7 +497,7 @@ def CheckGnChanges(input_api, output_api): result.extend(CheckNoMixingSources(input_api, gn_files, output_api)) result.extend(CheckNoPackageBoundaryViolations(input_api, gn_files, output_api)) - result.extend(CheckPublicDepsIsNotUsed(gn_files, output_api)) + result.extend(CheckPublicDepsIsNotUsed(gn_files, input_api, output_api)) result.extend(CheckCheckIncludesIsNotUsed(gn_files, output_api)) return result