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 |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 45 | |
| 46 | results = [] |
| 47 | if not CppLintProcessor().Run(input_api.PresubmitLocalPath()): |
| 48 | results.append(output_api.PresubmitError("C++ lint check failed")) |
| 49 | if not SourceProcessor().Run(input_api.PresubmitLocalPath()): |
| 50 | results.append(output_api.PresubmitError( |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 51 | "Copyright header, trailing whitespaces and two empty lines " \ |
| 52 | "between declarations check failed")) |
machenbach@chromium.org | 08e7569 | 2014-06-25 00:05:37 +0000 | [diff] [blame^] | 53 | if not CheckGeneratedRuntimeTests(input_api.PresubmitLocalPath()): |
| 54 | results.append(output_api.PresubmitError( |
| 55 | "Generated runtime tests check failed")) |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 56 | return results |
| 57 | |
| 58 | |
machenbach@chromium.org | 196eb60 | 2014-06-04 00:06:13 +0000 | [diff] [blame] | 59 | def _CheckUnwantedDependencies(input_api, output_api): |
| 60 | """Runs checkdeps on #include statements added in this |
| 61 | change. Breaking - rules is an error, breaking ! rules is a |
| 62 | warning. |
| 63 | """ |
| 64 | # We need to wait until we have an input_api object and use this |
| 65 | # roundabout construct to import checkdeps because this file is |
| 66 | # eval-ed and thus doesn't have __file__. |
| 67 | original_sys_path = sys.path |
| 68 | try: |
| 69 | sys.path = sys.path + [input_api.os_path.join( |
| 70 | input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')] |
| 71 | import checkdeps |
| 72 | from cpp_checker import CppChecker |
| 73 | from rules import Rule |
| 74 | finally: |
| 75 | # Restore sys.path to what it was before. |
| 76 | sys.path = original_sys_path |
| 77 | |
| 78 | added_includes = [] |
| 79 | for f in input_api.AffectedFiles(): |
| 80 | if not CppChecker.IsCppFile(f.LocalPath()): |
| 81 | continue |
| 82 | |
| 83 | changed_lines = [line for line_num, line in f.ChangedContents()] |
| 84 | added_includes.append([f.LocalPath(), changed_lines]) |
| 85 | |
| 86 | deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath()) |
| 87 | |
| 88 | error_descriptions = [] |
| 89 | warning_descriptions = [] |
| 90 | for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes( |
| 91 | added_includes): |
| 92 | description_with_path = '%s\n %s' % (path, rule_description) |
| 93 | if rule_type == Rule.DISALLOW: |
| 94 | error_descriptions.append(description_with_path) |
| 95 | else: |
| 96 | warning_descriptions.append(description_with_path) |
| 97 | |
| 98 | results = [] |
| 99 | if error_descriptions: |
| 100 | results.append(output_api.PresubmitError( |
| 101 | 'You added one or more #includes that violate checkdeps rules.', |
| 102 | error_descriptions)) |
| 103 | if warning_descriptions: |
| 104 | results.append(output_api.PresubmitPromptOrNotify( |
| 105 | 'You added one or more #includes of files that are temporarily\n' |
| 106 | 'allowed but being removed. Can you avoid introducing the\n' |
| 107 | '#include? See relevant DEPS file(s) for details and contacts.', |
| 108 | warning_descriptions)) |
| 109 | return results |
| 110 | |
| 111 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 112 | def _CommonChecks(input_api, output_api): |
| 113 | """Checks common to both upload and commit.""" |
| 114 | results = [] |
| 115 | results.extend(input_api.canned_checks.CheckOwners( |
| 116 | input_api, output_api, source_file_filter=None)) |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 117 | results.extend(_V8PresubmitChecks(input_api, output_api)) |
machenbach@chromium.org | 196eb60 | 2014-06-04 00:06:13 +0000 | [diff] [blame] | 118 | results.extend(_CheckUnwantedDependencies(input_api, output_api)) |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 119 | return results |
| 120 | |
| 121 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 122 | def _SkipTreeCheck(input_api, output_api): |
| 123 | """Check the env var whether we want to skip tree check. |
| 124 | Only skip if src/version.cc has been updated.""" |
| 125 | src_version = 'src/version.cc' |
machenbach@chromium.org | 4ddd2f1 | 2014-01-14 08:13:44 +0000 | [diff] [blame] | 126 | FilterFile = lambda file: file.LocalPath() == src_version |
| 127 | if not input_api.AffectedSourceFiles( |
| 128 | lambda file: file.LocalPath() == src_version): |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 129 | return False |
| 130 | return input_api.environ.get('PRESUBMIT_TREE_CHECK') == 'skip' |
| 131 | |
| 132 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 133 | def _CheckChangeLogFlag(input_api, output_api): |
| 134 | """Checks usage of LOG= flag in the commit message.""" |
| 135 | results = [] |
| 136 | if input_api.change.BUG and not 'LOG' in input_api.change.tags: |
| 137 | results.append(output_api.PresubmitError( |
| 138 | 'An issue reference (BUG=) requires a change log flag (LOG=). ' |
| 139 | 'Use LOG=Y for including this commit message in the change log. ' |
| 140 | 'Use LOG=N or leave blank otherwise.')) |
| 141 | return results |
| 142 | |
| 143 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 144 | def CheckChangeOnUpload(input_api, output_api): |
| 145 | results = [] |
| 146 | results.extend(_CommonChecks(input_api, output_api)) |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 147 | results.extend(_CheckChangeLogFlag(input_api, output_api)) |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 148 | return results |
| 149 | |
| 150 | |
| 151 | def CheckChangeOnCommit(input_api, output_api): |
| 152 | results = [] |
| 153 | results.extend(_CommonChecks(input_api, output_api)) |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 154 | results.extend(_CheckChangeLogFlag(input_api, output_api)) |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 155 | results.extend(input_api.canned_checks.CheckChangeHasDescription( |
| 156 | input_api, output_api)) |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 157 | if not _SkipTreeCheck(input_api, output_api): |
| 158 | results.extend(input_api.canned_checks.CheckTreeIsOpen( |
| 159 | input_api, output_api, |
| 160 | json_url='http://v8-status.appspot.com/current?format=json')) |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 161 | return results |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 162 | |
| 163 | |
| 164 | def GetPreferredTryMasters(project, change): |
| 165 | return { |
| 166 | 'tryserver.v8': { |
machenbach@chromium.org | 63a7c9f | 2014-04-01 00:04:36 +0000 | [diff] [blame] | 167 | 'v8_linux_rel': set(['defaulttests']), |
machenbach@chromium.org | ed1a631 | 2014-04-02 00:05:15 +0000 | [diff] [blame] | 168 | 'v8_linux_dbg': set(['defaulttests']), |
| 169 | 'v8_linux_nosnap_rel': set(['defaulttests']), |
| 170 | 'v8_linux_nosnap_dbg': set(['defaulttests']), |
| 171 | 'v8_linux64_rel': set(['defaulttests']), |
| 172 | 'v8_linux_arm_dbg': set(['defaulttests']), |
| 173 | 'v8_linux_arm64_rel': set(['defaulttests']), |
machenbach@chromium.org | aa107b2 | 2014-05-15 00:04:44 +0000 | [diff] [blame] | 174 | 'v8_linux_layout_dbg': set(['defaulttests']), |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 175 | 'v8_mac_rel': set(['defaulttests']), |
| 176 | 'v8_win_rel': set(['defaulttests']), |
| 177 | }, |
| 178 | } |