update_binaries.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python3
  2. # Copyright 2021 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. import logging
  6. import os
  7. import subprocess
  8. import shutil
  9. import sys
  10. import tempfile
  11. from zipfile import ZipFile
  12. DIR_SOURCE_ROOT = os.path.abspath(
  13. os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
  14. sys.path.append(os.path.join(DIR_SOURCE_ROOT, 'build'))
  15. import find_depot_tools
  16. CAST_CORE_ROOT = os.path.abspath(
  17. os.path.join(DIR_SOURCE_ROOT, 'third_party', 'cast_core', 'prebuilts'))
  18. CAST_CORE_ZIP_PATH_TEMPLATE = (
  19. 'gs://castlite-release-artifacts/{version}/third_party/castlite' \
  20. '/cast_core_qa_sdk_runtime_vizio_castos_armv7a' \
  21. '/sdk_runtime_vizio_castos_armv7a.tgz')
  22. SIGNATURE_FILE = '.version'
  23. RUNTIME_ROOT = os.path.abspath(
  24. os.path.join(DIR_SOURCE_ROOT, 'third_party', 'cast_web_runtime'))
  25. RUNTIME_ZIP_PATH_TEMPLATE = (
  26. 'gs://gtv-eureka/internal/1.56core/core_runtime-eng/{version}' \
  27. '/core_runtime_package.zip')
  28. def DownloadFromCloudStorage(url, output_dir):
  29. """Fetches a file from GCS and put it in |output_dir|."""
  30. cmd = [
  31. os.path.join(find_depot_tools.DEPOT_TOOLS_PATH, 'gsutil.py'), 'cp', url,
  32. output_dir
  33. ]
  34. task = subprocess.check_call(cmd,
  35. stdout=subprocess.DEVNULL,
  36. stderr=subprocess.DEVNULL)
  37. def MakeCleanDirectory(directory_name):
  38. if os.path.exists(directory_name):
  39. shutil.rmtree(directory_name)
  40. os.mkdir(directory_name)
  41. def UpdateBinaryIfNecessary(name, version_file, output_dir, gcs_path_template):
  42. """Update the binary at |output_dir| if necessary by comparing versions."""
  43. version = open(os.path.join(os.path.dirname(__file__),
  44. version_file)).read().strip()
  45. signature_file_path = os.path.join(output_dir, SIGNATURE_FILE)
  46. current_signature = (open(signature_file_path, 'r').read().strip()
  47. if os.path.exists(signature_file_path) else '')
  48. if current_signature != version:
  49. logging.info('Downloading {} version {}...'.format(name, version))
  50. MakeCleanDirectory(output_dir)
  51. DownloadFromCloudStorage(gcs_path_template.format(version=version),
  52. output_dir)
  53. with open(signature_file_path, 'w') as f:
  54. f.write(version)
  55. def main():
  56. UpdateBinaryIfNecessary('Cast Core', 'cast_core.version', CAST_CORE_ROOT,
  57. CAST_CORE_ZIP_PATH_TEMPLATE)
  58. UpdateBinaryIfNecessary('Cast Web Runtime', 'runtime.version', RUNTIME_ROOT,
  59. RUNTIME_ZIP_PATH_TEMPLATE)
  60. return 0
  61. if __name__ == '__main__':
  62. sys.exit(main())