diff --git a/gclient.py b/gclient.py index 4eef76f95..f245e3e41 100755 --- a/gclient.py +++ b/gclient.py @@ -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( diff --git a/gclient_eval.py b/gclient_eval.py index 6aa3626c7..23b1b1826 100644 --- a/gclient_eval.py +++ b/gclient_eval.py @@ -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, }), diff --git a/testing_support/fake_repos.py b/testing_support/fake_repos.py index becb10c77..411970a1b 100755 --- a/testing_support/fake_repos.py +++ b/testing_support/fake_repos.py @@ -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' diff --git a/tests/gclient_gcs_smoketest.py b/tests/gclient_gcs_smoketest.py index 77b916323..376a77bbc 100644 --- a/tests/gclient_gcs_smoketest.py +++ b/tests/gclient_gcs_smoketest.py @@ -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), })