| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Presubmit script for changes affecting extensions docs server | 5 """Presubmit script for changes affecting extensions docs server |
| 6 | 6 |
| 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 for more details about the presubmit API built into gcl. | 8 for more details about the presubmit API built into gcl. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 # Run build_server so that files needed by tests are copied to the local | 11 # Run build_server so that files needed by tests are copied to the local |
| 12 # third_party directory. | 12 # third_party directory. |
| 13 import os | 13 import os |
| 14 import sys | 14 import sys |
| 15 SYS_PATH = sys.path[:] | |
| 16 try: | |
| 17 SERVER2_PATH = os.path.join('chrome', | |
| 18 'common', | |
| 19 'extensions', | |
| 20 'docs', | |
| 21 'server2') | |
| 22 if os.sep + 'src' in os.getcwd(): | |
| 23 # Is 'src' is in the path, we can find the server2/ directory from there. | |
| 24 sys.path.insert(0, os.path.join(os.getcwd().rsplit(os.sep + 'src', 1)[0], | |
| 25 'src', | |
| 26 SERVER2_PATH)) | |
| 27 else: | |
| 28 # Otherwise, we have to guess we're in the server2/ directory. | |
| 29 sys.path.insert(0, '.') | |
| 30 import build_server | |
| 31 build_server.main() | |
| 32 finally: | |
| 33 sys.path = SYS_PATH | |
| 34 | 15 |
| 35 WHITELIST = [ r'.+_test.py$' ] | 16 WHITELIST = [ r'.+_test.py$' ] |
| 36 # The integration tests are selectively run from the PRESUBMIT in | 17 # The integration tests are selectively run from the PRESUBMIT in |
| 37 # chrome/common/extensions. | 18 # chrome/common/extensions. |
| 38 BLACKLIST = [ r'integration_test.py$' ] | 19 BLACKLIST = [ r'integration_test.py$' ] |
| 39 | 20 |
| 21 def _BuildServer(input_api): |
| 22 try: |
| 23 sys.path.insert(0, input_api.PresubmitLocalPath()) |
| 24 import build_server |
| 25 build_server.main() |
| 26 finally: |
| 27 sys.path.pop(0) |
| 28 |
| 29 def _ImportAppYamlHelper(input_api): |
| 30 try: |
| 31 sys.path.insert(0, input_api.PresubmitLocalPath()) |
| 32 from app_yaml_helper import AppYamlHelper |
| 33 return AppYamlHelper |
| 34 finally: |
| 35 sys.path.pop(0) |
| 36 |
| 37 def _WarnIfAppYamlHasntChanged(input_api, output_api): |
| 38 app_yaml_path = os.path.join(input_api.PresubmitLocalPath(), 'app.yaml') |
| 39 if app_yaml_path in input_api.AbsoluteLocalPaths(): |
| 40 return [] |
| 41 return [output_api.PresubmitPromptOrNotify(''' |
| 42 ************************************************** |
| 43 CHANGE DETECTED IN SERVER2 WITHOUT APP.YAML UPDATE |
| 44 ************************************************** |
| 45 Maybe this is ok? Follow this simple guide: |
| 46 |
| 47 Q: Does this change any data that might get stored? |
| 48 * Did you add/remove/update a field to a data source? |
| 49 * Did you add/remove/update some data that gets sent to templates? |
| 50 * Is this change to support a new feature in the templates? |
| 51 * Does this change include changes to templates? |
| 52 Yes? Bump the middle version, i.e. 2-5-2 -> 2-6-2. |
| 53 THIS WILL CAUSE THE CURRENTLY RUNNING SERVER TO STOP UPDATING. |
| 54 PUSH THE NEW VERSION ASAP. |
| 55 No? Continue. |
| 56 |
| 57 Q: Is this a non-trivial change to the server? |
| 58 Yes? Bump the end version. |
| 59 Unlike above, the server will *not* stop updating. |
| 60 No? Are you sure? How much do you bet? This can't be rolled back... |
| 61 |
| 62 Q: Is this a spelling correction? New test? Better comments? |
| 63 Yes? Ok fine. Ignore this warning. |
| 64 No? I guess this presubmit check doesn't work. |
| 65 ''')] |
| 66 |
| 67 def _CheckYamlConsistency(input_api, output_api): |
| 68 app_yaml_path = os.path.join(input_api.PresubmitLocalPath(), 'app.yaml') |
| 69 cron_yaml_path = os.path.join(input_api.PresubmitLocalPath(), 'cron.yaml') |
| 70 if not (app_yaml_path in input_api.AbsoluteLocalPaths() or |
| 71 cron_yaml_path in input_api.AbsoluteLocalPaths()): |
| 72 return [] |
| 73 |
| 74 AppYamlHelper = _ImportAppYamlHelper(input_api) |
| 75 app_yaml_version = AppYamlHelper.ExtractVersion( |
| 76 input_api.ReadFile(app_yaml_path)) |
| 77 cron_yaml_version = AppYamlHelper.ExtractVersion( |
| 78 input_api.ReadFile(cron_yaml_path), key='target') |
| 79 |
| 80 if app_yaml_version == cron_yaml_version: |
| 81 return [] |
| 82 return [output_api.PresubmitError( |
| 83 'Versions of app.yaml (%s) and cron.yaml (%s) must match' % ( |
| 84 app_yaml_version, cron_yaml_version))] |
| 85 |
| 86 def _RunPresubmit(input_api, output_api): |
| 87 _BuildServer(input_api) |
| 88 return ( |
| 89 _WarnIfAppYamlHasntChanged(input_api, output_api) + |
| 90 _CheckYamlConsistency(input_api, output_api) + |
| 91 input_api.canned_checks.RunUnitTestsInDirectory( |
| 92 input_api, output_api, '.', whitelist=WHITELIST, blacklist=BLACKLIST) |
| 93 ) |
| 94 |
| 40 def CheckChangeOnUpload(input_api, output_api): | 95 def CheckChangeOnUpload(input_api, output_api): |
| 41 return input_api.canned_checks.RunUnitTestsInDirectory( | 96 return _RunPresubmit(input_api, output_api) |
| 42 input_api, output_api, '.', whitelist=WHITELIST, blacklist=BLACKLIST) | |
| 43 | 97 |
| 44 def CheckChangeOnCommit(input_api, output_api): | 98 def CheckChangeOnCommit(input_api, output_api): |
| 45 return input_api.canned_checks.RunUnitTestsInDirectory( | 99 return _RunPresubmit(input_api, output_api) |
| 46 input_api, output_api, '.', whitelist=WHITELIST, blacklist=BLACKLIST) | |
| OLD | NEW |