Optional output_file field in GCS dep

When an 'output_file' arg is included, the downloaded object from GCS
will be downloaded in that path.

Example:
```
'src/buildtools/linux': {
  'bucket': 'bucket123',
  'object_name': 'clang-format-version123',
  'dep_type': 'gcs',
  'sha256sum': 'abcd123',
  'output_file': 'clang-format',
}
```
The GCS object will be downloaded at src/buildtools/linux/clang-format

Bug: b/324418194
Change-Id: I1049abeb09a1027c5477d955e50611d43015d0a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5353387
Commit-Queue: Stephanie Kim <kimstephanie@google.com>
Reviewed-by: Joanna Wang <jojwang@chromium.org>
changes/87/5353387/5
Stephanie Kim 1 year ago committed by LUCI CQ
parent b3d7b07503
commit 53870d4056

@ -760,6 +760,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
bucket=dep_value['bucket'],
object_name=dep_value['object_name'],
sha256sum=dep_value['sha256sum'],
output_file=dep_value.get('output_file'),
custom_vars=self.custom_vars,
should_process=should_process,
relative=use_relative_paths,
@ -2503,10 +2504,11 @@ class GcsDependency(Dependency):
"""A Dependency object that represents a single GCS bucket and object"""
def __init__(self, parent, name, bucket, object_name, sha256sum,
custom_vars, should_process, relative, condition):
output_file, custom_vars, should_process, relative, condition):
self.bucket = bucket
self.object_name = object_name
self.sha256sum = sha256sum
self.output_file = output_file
url = 'gs://{bucket}/{object_name}'.format(
bucket=self.bucket,
object_name=self.object_name,
@ -2581,7 +2583,8 @@ class GcsDependency(Dependency):
# Directory of the extracted tarfile contents
output_dir = os.path.join(root_dir, self.name)
output_file = os.path.join(output_dir, gcs_file_name)
output_file = os.path.join(output_dir, self.output_file
or gcs_file_name)
if not self.IsDownloadNeeded(output_dir, output_file):
return
@ -2601,16 +2604,20 @@ class GcsDependency(Dependency):
os.makedirs(output_dir)
if os.getenv('GCLIENT_TEST') == '1':
# Create fake tar file and extracted tar contents
tmpdir = tempfile.mkdtemp()
copy_dir = os.path.join(tmpdir, self.name, 'extracted_dir')
if os.path.exists(copy_dir):
shutil.rmtree(copy_dir)
os.makedirs(copy_dir)
with open(os.path.join(copy_dir, 'extracted_file'), 'w+') as f:
f.write('extracted text')
with tarfile.open(output_file, "w:gz") as tar:
tar.add(copy_dir, arcname=os.path.basename(copy_dir))
if 'no-extract' in output_file:
with open(output_file, 'w+') as f:
f.write('non-extractable file')
else:
# Create fake tar file and extracted tar contents
tmpdir = tempfile.mkdtemp()
copy_dir = os.path.join(tmpdir, self.name, 'extracted_dir')
if os.path.exists(copy_dir):
shutil.rmtree(copy_dir)
os.makedirs(copy_dir)
with open(os.path.join(copy_dir, 'extracted_file'), 'w+') as f:
f.write('extracted text')
with tarfile.open(output_file, "w:gz") as tar:
tar.add(copy_dir, arcname=os.path.basename(copy_dir))
else:
gcs_url = 'gs://%s/%s' % (self.bucket, self.object_name)
gsutil = download_from_google_storage.Gsutil(

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

@ -903,6 +903,13 @@ deps = {
'dep_type': 'gcs',
'sha256sum': 'abcd123',
},
'src/gcs_dep_with_output_file': {
'bucket': '789bucket',
'object_name': 'clang-format-version123',
'dep_type': 'gcs',
'sha256sum': 'abcd123',
'output_file': 'clang-format-no-extract',
},
}"""),
'origin':
'git/repo_22@1\n'

@ -47,6 +47,10 @@ class GClientSmokeGcs(gclient_smoketest_base.GClientSmokeBase):
'abcd123\n',
'src/gcs_dep/extracted_dir/extracted_file':
'extracted text',
'src/gcs_dep_with_output_file/hash':
'abcd123\n',
'src/gcs_dep_with_output_file/clang-format-no-extract':
'non-extractable file',
})
self.assertTree(tree)
@ -115,7 +119,9 @@ class GClientSmokeGcs(gclient_smoketest_base.GClientSmokeBase):
results = self.gclient(['revinfo'])
out = ('src: %(base)srepo_22\n'
'src/another_gcs_dep: gs://456bucket/Linux/llvmfile.tar.gz\n'
'src/gcs_dep: gs://123bucket/deadbeef\n' % {
'src/gcs_dep: gs://123bucket/deadbeef\n'
'src/gcs_dep_with_output_file: '
'gs://789bucket/clang-format-version123\n' % {
'base': self.git_base,
})
self.check((out, '', 0), results)
@ -127,7 +133,9 @@ class GClientSmokeGcs(gclient_smoketest_base.GClientSmokeBase):
out = (
'src: %(base)srepo_22@%(hash1)s\n'
'src/another_gcs_dep: gs://456bucket/Linux/llvmfile.tar.gz@None\n'
'src/gcs_dep: gs://123bucket/deadbeef@None\n' % {
'src/gcs_dep: gs://123bucket/deadbeef@None\n'
'src/gcs_dep_with_output_file: '
'gs://789bucket/clang-format-version123@None\n' % {
'base': self.git_base,
'hash1': self.githash('repo_22', 1),
})

Loading…
Cancel
Save