From d71daa7bd8606b14eb0702b67f2b891c4f3201e5 Mon Sep 17 00:00:00 2001 From: Stephanie Kim Date: Mon, 18 Mar 2024 17:28:47 +0000 Subject: [PATCH] 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 Reviewed-by: Joanna Wang Commit-Queue: Stephanie Kim --- gclient.py | 15 ++++++++++++++- gclient_eval.py | 1 + testing_support/fake_repos.py | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gclient.py b/gclient.py index f245e3e41..10bf68c59 100755 --- a/gclient.py +++ b/gclient.py @@ -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) diff --git a/gclient_eval.py b/gclient_eval.py index 23b1b1826..08b12fdac 100644 --- a/gclient_eval.py +++ b/gclient_eval.py @@ -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, diff --git a/testing_support/fake_repos.py b/testing_support/fake_repos.py index 411970a1b..8038c9dc8 100755 --- a/testing_support/fake_repos.py +++ b/testing_support/fake_repos.py @@ -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, }, } """,