zip.py 2.1 KB

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