zip.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import os
  4. import subprocess
  5. import sys
  6. import zipfile
  7. EXTENSIONS_TO_SKIP = [
  8. '.pdb',
  9. '.mojom.js',
  10. '.mojom-lite.js',
  11. '.info'
  12. ]
  13. PATHS_TO_SKIP = [
  14. 'angledata', #Skipping because it is an output of //ui/gl that we don't need
  15. './libVkICD_mock_', #Skipping because these are outputs that we don't need
  16. './VkICD_mock_', #Skipping because these are outputs that we don't need
  17. # Skipping because its an output of create_bundle from //build/config/mac/rules.gni
  18. # that we don't need
  19. 'Electron.dSYM',
  20. # //chrome/browser:resources depends on this via
  21. # //chrome/browser/resources/ssl/ssl_error_assistant, but we don't need to
  22. # ship it.
  23. 'pyproto',
  24. ]
  25. def skip_path(dep, dist_zip, target_cpu):
  26. # Skip specific paths and extensions as well as the following special case:
  27. # snapshot_blob.bin is a dependency of mksnapshot.zip because
  28. # v8_context_generator needs it, but this file does not get generated for arm
  29. # and arm 64 binaries of mksnapshot since they are built on x64 hardware.
  30. # Consumers of arm and arm64 mksnapshot can generate snapshot_blob.bin
  31. # themselves by running mksnapshot.
  32. should_skip = (
  33. any(dep.startswith(path) for path in PATHS_TO_SKIP) or
  34. any(dep.endswith(ext) for ext in EXTENSIONS_TO_SKIP) or
  35. ('arm' in target_cpu and dist_zip == 'mksnapshot.zip' and dep == 'snapshot_blob.bin'))
  36. if should_skip:
  37. print("Skipping {}".format(dep))
  38. return should_skip
  39. def execute(argv):
  40. try:
  41. output = subprocess.check_output(argv, stderr=subprocess.STDOUT)
  42. return output
  43. except subprocess.CalledProcessError as e:
  44. print(e.output)
  45. raise e
  46. def main(argv):
  47. dist_zip, runtime_deps, target_cpu, target_os, flatten_val = argv
  48. should_flatten = flatten_val == "true"
  49. dist_files = set()
  50. with open(runtime_deps) as f:
  51. for dep in f.readlines():
  52. dep = dep.strip()
  53. if not skip_path(dep, dist_zip, target_cpu):
  54. dist_files.add(dep)
  55. if sys.platform == 'darwin' and not should_flatten:
  56. execute(['zip', '-r', '-y', dist_zip] + list(dist_files))
  57. else:
  58. with zipfile.ZipFile(dist_zip, 'w', zipfile.ZIP_DEFLATED, allowZip64=True) as z:
  59. for dep in dist_files:
  60. if os.path.isdir(dep):
  61. for root, dirs, files in os.walk(dep):
  62. for file in files:
  63. z.write(os.path.join(root, file))
  64. else:
  65. basename = os.path.basename(dep)
  66. dirname = os.path.dirname(dep)
  67. arcname = os.path.join(dirname, 'chrome-sandbox') if basename == 'chrome_sandbox' else dep
  68. z.write(dep, os.path.basename(arcname) if should_flatten else arcname)
  69. if __name__ == '__main__':
  70. sys.exit(main(sys.argv[1:]))