Require size_bytes for first class GCS dep

GCS deps will require a size_bytes field of type `int`. If gclient
sees that the actual byte size is different than the noted size, it
will raise an exception.

Bug: b/328065441
Change-Id: If61496eae39cd372966d7e64ba4a84759708c60b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5367540
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Joanna Wang <jojwang@chromium.org>
Commit-Queue: Stephanie Kim <kimstephanie@google.com>
changes/40/5367540/4
Stephanie Kim 1 year ago committed by LUCI CQ
parent 59c1900dd6
commit d71daa7bd8

@ -761,6 +761,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
object_name=dep_value['object_name'],
sha256sum=dep_value['sha256sum'],
output_file=dep_value.get('output_file'),
size_bytes=dep_value['size_bytes'],
custom_vars=self.custom_vars,
should_process=should_process,
relative=use_relative_paths,
@ -2504,11 +2505,13 @@ class GcsDependency(Dependency):
"""A Dependency object that represents a single GCS bucket and object"""
def __init__(self, parent, name, bucket, object_name, sha256sum,
output_file, custom_vars, should_process, relative, condition):
output_file, size_bytes, custom_vars, should_process, relative,
condition):
self.bucket = bucket
self.object_name = object_name
self.sha256sum = sha256sum
self.output_file = output_file
self.size_bytes = size_bytes
url = 'gs://{bucket}/{object_name}'.format(
bucket=self.bucket,
object_name=self.object_name,
@ -2625,10 +2628,13 @@ class GcsDependency(Dependency):
gsutil.check_call('cp', gcs_url, output_file)
calculated_sha256sum = ''
calculated_size_bytes = None
if os.getenv('GCLIENT_TEST') == '1':
calculated_sha256sum = 'abcd123'
calculated_size_bytes = 10000
else:
calculated_sha256sum = self.GetSha256Sum(output_file)
calculated_size_bytes = os.path.getsize(output_file)
if calculated_sha256sum != self.sha256sum:
raise Exception('sha256sum does not match calculated hash. '
@ -2637,6 +2643,13 @@ class GcsDependency(Dependency):
calculated=calculated_sha256sum,
))
if calculated_size_bytes != self.size_bytes:
raise Exception('size_bytes does not match calculated size bytes. '
'{original} vs {calculated}'.format(
original=self.size_bytes,
calculated=calculated_size_bytes,
))
if tarfile.is_tarfile(output_file):
with tarfile.open(output_file, 'r:*') as tar:
tar.extractall(path=output_dir)

@ -136,6 +136,7 @@ _GCLIENT_DEPS_SCHEMA = _NodeDictSchema({
'bucket': str,
'object_name': str,
'sha256sum': str,
'size_bytes': int,
schema.Optional('output_file'): str,
schema.Optional('condition'): str,
schema.Optional('dep_type', default='gcs'): str,

@ -896,12 +896,14 @@ deps = {
'object_name': 'deadbeef',
'dep_type': 'gcs',
'sha256sum': 'abcd123',
'size_bytes': 10000,
},
'src/another_gcs_dep': {
'bucket': '456bucket',
'object_name': 'Linux/llvmfile.tar.gz',
'dep_type': 'gcs',
'sha256sum': 'abcd123',
'size_bytes': 10000,
},
'src/gcs_dep_with_output_file': {
'bucket': '789bucket',
@ -909,6 +911,7 @@ deps = {
'dep_type': 'gcs',
'sha256sum': 'abcd123',
'output_file': 'clang-format-no-extract',
'size_bytes': 10000,
},
}"""),
'origin':
@ -943,6 +946,7 @@ deps = {
'object_name': 'path_to_file.tar.gz',
'dep_type': 'gcs',
'sha256sum': 'abcd123',
'size_bytes': 10000,
},
}
""",

Loading…
Cancel
Save