浏览代码

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>
Stephanie Kim 1 年之前
父节点
当前提交
53870d4056
共有 4 个文件被更改,包括 37 次插入14 次删除
  1. 19 12
      gclient.py
  2. 1 0
      gclient_eval.py
  3. 7 0
      testing_support/fake_repos.py
  4. 10 2
      tests/gclient_gcs_smoketest.py

+ 19 - 12
gclient.py

@@ -760,6 +760,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
                                   bucket=dep_value['bucket'],
                                   bucket=dep_value['bucket'],
                                   object_name=dep_value['object_name'],
                                   object_name=dep_value['object_name'],
                                   sha256sum=dep_value['sha256sum'],
                                   sha256sum=dep_value['sha256sum'],
+                                  output_file=dep_value.get('output_file'),
                                   custom_vars=self.custom_vars,
                                   custom_vars=self.custom_vars,
                                   should_process=should_process,
                                   should_process=should_process,
                                   relative=use_relative_paths,
                                   relative=use_relative_paths,
@@ -2503,10 +2504,11 @@ class GcsDependency(Dependency):
     """A Dependency object that represents a single GCS bucket and object"""
     """A Dependency object that represents a single GCS bucket and object"""
 
 
     def __init__(self, parent, name, bucket, object_name, sha256sum,
     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.bucket = bucket
         self.object_name = object_name
         self.object_name = object_name
         self.sha256sum = sha256sum
         self.sha256sum = sha256sum
+        self.output_file = output_file
         url = 'gs://{bucket}/{object_name}'.format(
         url = 'gs://{bucket}/{object_name}'.format(
             bucket=self.bucket,
             bucket=self.bucket,
             object_name=self.object_name,
             object_name=self.object_name,
@@ -2581,7 +2583,8 @@ class GcsDependency(Dependency):
 
 
         # Directory of the extracted tarfile contents
         # Directory of the extracted tarfile contents
         output_dir = os.path.join(root_dir, self.name)
         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):
         if not self.IsDownloadNeeded(output_dir, output_file):
             return
             return
@@ -2601,16 +2604,20 @@ class GcsDependency(Dependency):
         os.makedirs(output_dir)
         os.makedirs(output_dir)
 
 
         if os.getenv('GCLIENT_TEST') == '1':
         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:
         else:
             gcs_url = 'gs://%s/%s' % (self.bucket, self.object_name)
             gcs_url = 'gs://%s/%s' % (self.bucket, self.object_name)
             gsutil = download_from_google_storage.Gsutil(
             gsutil = download_from_google_storage.Gsutil(

+ 1 - 0
gclient_eval.py

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

+ 7 - 0
testing_support/fake_repos.py

@@ -903,6 +903,13 @@ deps = {
             'dep_type': 'gcs',
             'dep_type': 'gcs',
             'sha256sum': 'abcd123',
             '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':
                 'origin':
                 'git/repo_22@1\n'
                 'git/repo_22@1\n'

+ 10 - 2
tests/gclient_gcs_smoketest.py

@@ -47,6 +47,10 @@ class GClientSmokeGcs(gclient_smoketest_base.GClientSmokeBase):
             'abcd123\n',
             'abcd123\n',
             'src/gcs_dep/extracted_dir/extracted_file':
             'src/gcs_dep/extracted_dir/extracted_file':
             'extracted text',
             '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)
         self.assertTree(tree)
 
 
@@ -115,7 +119,9 @@ class GClientSmokeGcs(gclient_smoketest_base.GClientSmokeBase):
         results = self.gclient(['revinfo'])
         results = self.gclient(['revinfo'])
         out = ('src: %(base)srepo_22\n'
         out = ('src: %(base)srepo_22\n'
                'src/another_gcs_dep: gs://456bucket/Linux/llvmfile.tar.gz\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,
                    'base': self.git_base,
                })
                })
         self.check((out, '', 0), results)
         self.check((out, '', 0), results)
@@ -127,7 +133,9 @@ class GClientSmokeGcs(gclient_smoketest_base.GClientSmokeBase):
         out = (
         out = (
             'src: %(base)srepo_22@%(hash1)s\n'
             'src: %(base)srepo_22@%(hash1)s\n'
             'src/another_gcs_dep: gs://456bucket/Linux/llvmfile.tar.gz@None\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,
                 'base': self.git_base,
                 'hash1': self.githash('repo_22', 1),
                 'hash1': self.githash('repo_22', 1),
             })
             })