zip.py 2.4 KB

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