verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1 | # Copyright 2012 the V8 project authors. All rights reserved. |
| 2 | # Redistribution and use in source and binary forms, with or without |
| 3 | # modification, are permitted provided that the following conditions are |
| 4 | # met: |
| 5 | # |
| 6 | # * Redistributions of source code must retain the above copyright |
| 7 | # notice, this list of conditions and the following disclaimer. |
| 8 | # * Redistributions in binary form must reproduce the above |
| 9 | # copyright notice, this list of conditions and the following |
| 10 | # disclaimer in the documentation and/or other materials provided |
| 11 | # with the distribution. |
| 12 | # * Neither the name of Google Inc. nor the names of its |
| 13 | # contributors may be used to endorse or promote products derived |
| 14 | # from this software without specific prior written permission. |
| 15 | # |
| 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | """Top-level presubmit script for V8. |
| 29 | |
| 30 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 31 | for more details about the presubmit API built into gcl. |
| 32 | """ |
| 33 | |
machenbach@chromium.org | 196eb60 | 2014-06-04 00:06:13 +0000 | [diff] [blame] | 34 | import sys |
| 35 | |
| 36 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 37 | def _V8PresubmitChecks(input_api, output_api): |
| 38 | """Runs the V8 presubmit checks.""" |
| 39 | import sys |
| 40 | sys.path.append(input_api.os_path.join( |
| 41 | input_api.PresubmitLocalPath(), 'tools')) |
| 42 | from presubmit import CppLintProcessor |
| 43 | from presubmit import SourceProcessor |
machenbach@chromium.org | 08e7569 | 2014-06-25 00:05:37 +0000 | [diff] [blame] | 44 | from presubmit import CheckGeneratedRuntimeTests |
machenbach@chromium.org | 9d72b8d | 2014-08-07 08:39:21 +0000 | [diff] [blame^] | 45 | from presubmit import CheckExternalReferenceRegistration |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 46 | |
| 47 | results = [] |
| 48 | if not CppLintProcessor().Run(input_api.PresubmitLocalPath()): |
| 49 | results.append(output_api.PresubmitError("C++ lint check failed")) |
| 50 | if not SourceProcessor().Run(input_api.PresubmitLocalPath()): |
| 51 | results.append(output_api.PresubmitError( |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 52 | "Copyright header, trailing whitespaces and two empty lines " \ |
| 53 | "between declarations check failed")) |
machenbach@chromium.org | 08e7569 | 2014-06-25 00:05:37 +0000 | [diff] [blame] | 54 | if not CheckGeneratedRuntimeTests(input_api.PresubmitLocalPath()): |
| 55 | results.append(output_api.PresubmitError( |
| 56 | "Generated runtime tests check failed")) |
machenbach@chromium.org | 9d72b8d | 2014-08-07 08:39:21 +0000 | [diff] [blame^] | 57 | if not CheckExternalReferenceRegistration(input_api.PresubmitLocalPath()): |
| 58 | results.append(output_api.PresubmitError( |
| 59 | "External references registration check failed")) |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 60 | return results |
| 61 | |
| 62 | |
machenbach@chromium.org | 196eb60 | 2014-06-04 00:06:13 +0000 | [diff] [blame] | 63 | def _CheckUnwantedDependencies(input_api, output_api): |
| 64 | """Runs checkdeps on #include statements added in this |
| 65 | change. Breaking - rules is an error, breaking ! rules is a |
| 66 | warning. |
| 67 | """ |
| 68 | # We need to wait until we have an input_api object and use this |
| 69 | # roundabout construct to import checkdeps because this file is |
| 70 | # eval-ed and thus doesn't have __file__. |
| 71 | original_sys_path = sys.path |
| 72 | try: |
| 73 | sys.path = sys.path + [input_api.os_path.join( |
| 74 | input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')] |
| 75 | import checkdeps |
| 76 | from cpp_checker import CppChecker |
| 77 | from rules import Rule |
| 78 | finally: |
| 79 | # Restore sys.path to what it was before. |
| 80 | sys.path = original_sys_path |
| 81 | |
| 82 | added_includes = [] |
| 83 | for f in input_api.AffectedFiles(): |
| 84 | if not CppChecker.IsCppFile(f.LocalPath()): |
| 85 | continue |
| 86 | |
| 87 | changed_lines = [line for line_num, line in f.ChangedContents()] |
| 88 | added_includes.append([f.LocalPath(), changed_lines]) |
| 89 | |
| 90 | deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath()) |
| 91 | |
| 92 | error_descriptions = [] |
| 93 | warning_descriptions = [] |
| 94 | for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes( |
| 95 | added_includes): |
| 96 | description_with_path = '%s\n %s' % (path, rule_description) |
| 97 | if rule_type == Rule.DISALLOW: |
| 98 | error_descriptions.append(description_with_path) |
| 99 | else: |
| 100 | warning_descriptions.append(description_with_path) |
| 101 | |
| 102 | results = [] |
| 103 | if error_descriptions: |
| 104 | results.append(output_api.PresubmitError( |
| 105 | 'You added one or more #includes that violate checkdeps rules.', |
| 106 | error_descriptions)) |
| 107 | if warning_descriptions: |
| 108 | results.append(output_api.PresubmitPromptOrNotify( |
| 109 | 'You added one or more #includes of files that are temporarily\n' |
| 110 | 'allowed but being removed. Can you avoid introducing the\n' |
| 111 | '#include? See relevant DEPS file(s) for details and contacts.', |
| 112 | warning_descriptions)) |
| 113 | return results |
| 114 | |
| 115 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 116 | def _CommonChecks(input_api, output_api): |
| 117 | """Checks common to both upload and commit.""" |
| 118 | results = [] |
| 119 | results.extend(input_api.canned_checks.CheckOwners( |
| 120 | input_api, output_api, source_file_filter=None)) |
machenbach@chromium.org | d0bddc6 | 2014-07-07 00:05:07 +0000 | [diff] [blame] | 121 | results.extend(input_api.canned_checks.CheckPatchFormatted( |
| 122 | input_api, output_api)) |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 123 | results.extend(_V8PresubmitChecks(input_api, output_api)) |
machenbach@chromium.org | 196eb60 | 2014-06-04 00:06:13 +0000 | [diff] [blame] | 124 | results.extend(_CheckUnwantedDependencies(input_api, output_api)) |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 125 | return results |
| 126 | |
| 127 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 128 | def _SkipTreeCheck(input_api, output_api): |
| 129 | """Check the env var whether we want to skip tree check. |
| 130 | Only skip if src/version.cc has been updated.""" |
| 131 | src_version = 'src/version.cc' |
machenbach@chromium.org | 4ddd2f1 | 2014-01-14 08:13:44 +0000 | [diff] [blame] | 132 | FilterFile = lambda file: file.LocalPath() == src_version |
| 133 | if not input_api.AffectedSourceFiles( |
| 134 | lambda file: file.LocalPath() == src_version): |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 135 | return False |
| 136 | return input_api.environ.get('PRESUBMIT_TREE_CHECK') == 'skip' |
| 137 | |
| 138 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 139 | def _CheckChangeLogFlag(input_api, output_api): |
| 140 | """Checks usage of LOG= flag in the commit message.""" |
| 141 | results = [] |
| 142 | if input_api.change.BUG and not 'LOG' in input_api.change.tags: |
| 143 | results.append(output_api.PresubmitError( |
| 144 | 'An issue reference (BUG=) requires a change log flag (LOG=). ' |
| 145 | 'Use LOG=Y for including this commit message in the change log. ' |
| 146 | 'Use LOG=N or leave blank otherwise.')) |
| 147 | return results |
| 148 | |
| 149 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 150 | def CheckChangeOnUpload(input_api, output_api): |
| 151 | results = [] |
| 152 | results.extend(_CommonChecks(input_api, output_api)) |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 153 | results.extend(_CheckChangeLogFlag(input_api, output_api)) |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 154 | return results |
| 155 | |
| 156 | |
| 157 | def CheckChangeOnCommit(input_api, output_api): |
| 158 | results = [] |
| 159 | results.extend(_CommonChecks(input_api, output_api)) |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 160 | results.extend(_CheckChangeLogFlag(input_api, output_api)) |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 161 | results.extend(input_api.canned_checks.CheckChangeHasDescription( |
| 162 | input_api, output_api)) |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 163 | if not _SkipTreeCheck(input_api, output_api): |
| 164 | results.extend(input_api.canned_checks.CheckTreeIsOpen( |
| 165 | input_api, output_api, |
| 166 | json_url='http://v8-status.appspot.com/current?format=json')) |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 167 | return results |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 168 | |
| 169 | |
| 170 | def GetPreferredTryMasters(project, change): |
| 171 | return { |
| 172 | 'tryserver.v8': { |
machenbach@chromium.org | 63a7c9f | 2014-04-01 00:04:36 +0000 | [diff] [blame] | 173 | 'v8_linux_rel': set(['defaulttests']), |
machenbach@chromium.org | ed1a631 | 2014-04-02 00:05:15 +0000 | [diff] [blame] | 174 | 'v8_linux_dbg': set(['defaulttests']), |
| 175 | 'v8_linux_nosnap_rel': set(['defaulttests']), |
| 176 | 'v8_linux_nosnap_dbg': set(['defaulttests']), |
| 177 | 'v8_linux64_rel': set(['defaulttests']), |
| 178 | 'v8_linux_arm_dbg': set(['defaulttests']), |
| 179 | 'v8_linux_arm64_rel': set(['defaulttests']), |
machenbach@chromium.org | aa107b2 | 2014-05-15 00:04:44 +0000 | [diff] [blame] | 180 | 'v8_linux_layout_dbg': set(['defaulttests']), |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 181 | 'v8_mac_rel': set(['defaulttests']), |
| 182 | 'v8_win_rel': set(['defaulttests']), |
machenbach@chromium.org | 70d29e1 | 2014-07-11 07:33:43 +0000 | [diff] [blame] | 183 | 'v8_win64_rel': set(['defaulttests']), |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 184 | }, |
| 185 | } |