zip.py 2.5 KB

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