1 # Copyright 2014 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 """Top-level presubmit script for memory_inspector.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
8 details on the presubmit API built into depot_tools.
12 def _CommonChecks(input_api
, output_api
):
14 blacklist
= [r
'classification_rules.*']
15 output
.extend(input_api
.canned_checks
.RunPylint(
16 input_api
, output_api
, black_list
=blacklist
,
18 input_api
.os_path
.join(input_api
.PresubmitLocalPath(), '..', '..',
21 output
.extend(input_api
.canned_checks
.RunUnitTests(
24 [input_api
.os_path
.join(input_api
.PresubmitLocalPath(), 'run_tests')]))
26 if input_api
.is_committing
:
27 output
.extend(input_api
.canned_checks
.PanProjectChecks(input_api
,
33 def _CheckPrebuiltsAreUploaded(input_api
, output_api
):
34 """Checks that the SHA1 files in prebuilts/ reference existing objects on GCS.
36 This is to avoid that somebody accidentally checks in some new XXX.sha1 files
37 into prebuilts/ without having previously uploaded the corresponding binaries
38 to the cloud storage bucket. This can happen if the developer has a consistent
39 local copy of the binary. This check verifies (through a HTTP HEAD request)
40 that the GCS bucket has an object for each .sha1 file in prebuilts and raises
41 a presubmit error, listing the missing files, if not.
45 old_sys_path
= sys
.path
47 sys
.path
= [input_api
.PresubmitLocalPath()] + sys
.path
48 from memory_inspector
import constants
50 sys
.path
= old_sys_path
52 for f
in input_api
.os_listdir(constants
.PREBUILTS_PATH
):
53 if not f
.endswith('.sha1'):
55 prebuilt_sha_path
= input_api
.os_path
.join(constants
.PREBUILTS_PATH
, f
)
56 with
open(prebuilt_sha_path
) as sha_file
:
57 sha
= sha_file
.read().strip()
58 url
= constants
.PREBUILTS_BASE_URL
+ sha
59 request
= urllib2
.Request(url
)
60 request
.get_method
= lambda : 'HEAD'
62 urllib2
.urlopen(request
, timeout
=5)
63 except Exception as e
:
64 if isinstance(e
, urllib2
.HTTPError
) and e
.code
== 404:
65 missing_files
+= [prebuilt_sha_path
]
67 return [output_api
.PresubmitError('HTTP Error while checking %s' % url
,
70 return [output_api
.PresubmitError(
71 'Some prebuilts have not been uploaded. Perhaps you forgot to '
72 'upload_to_google_storage.py?', missing_files
)]
76 def CheckChangeOnUpload(input_api
, output_api
):
78 results
.extend(_CommonChecks(input_api
, output_api
))
79 results
.extend(_CheckPrebuiltsAreUploaded(input_api
, output_api
))
83 def CheckChangeOnCommit(input_api
, output_api
):
84 return _CommonChecks(input_api
, output_api
)