zip.py 2.4 KB

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