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
3 # found in the LICENSE file.
5 """Presubmit script for changes affecting extensions docs server
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into gcl.
11 # Run build_server so that files needed by tests are copied to the local
12 # third_party directory.
16 WHITELIST
= [ r
'.+_test.py$' ]
17 # The integration tests are selectively run from the PRESUBMIT in
18 # chrome/common/extensions.
19 BLACKLIST
= [ r
'integration_test.py$' ]
21 def _BuildServer(input_api
):
23 sys
.path
.insert(0, input_api
.PresubmitLocalPath())
29 def _ImportAppYamlHelper(input_api
):
31 sys
.path
.insert(0, input_api
.PresubmitLocalPath())
32 from app_yaml_helper
import AppYamlHelper
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():
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:
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 and zero out the end version, i.e. 2-5-2 -> 2-6-0.
53 THIS WILL CAUSE THE CURRENTLY RUNNING SERVER TO STOP UPDATING.
54 PUSH THE NEW VERSION ASAP.
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...
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.
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()):
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')
80 if app_yaml_version
== cron_yaml_version
:
82 return [output_api
.PresubmitError(
83 'Versions of app.yaml (%s) and cron.yaml (%s) must match' % (
84 app_yaml_version
, cron_yaml_version
))]
86 def _RunPresubmit(input_api
, output_api
):
87 _BuildServer(input_api
)
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
)
95 def CheckChangeOnUpload(input_api
, output_api
):
96 return _RunPresubmit(input_api
, output_api
)
98 def CheckChangeOnCommit(input_api
, output_api
):
99 return _RunPresubmit(input_api
, output_api
)