zip.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. # On Windows, this binary doesn't exist (the crashpad handler is built-in).
  25. # On MacOS, the binary is called 'chrome_crashpad_handler' and is inside the
  26. # app bundle.
  27. # On Linux, we don't use crashpad, but this binary is still built for some
  28. # reason. Exclude it from the zip.
  29. './crashpad_handler',
  30. ]
  31. def skip_path(dep, dist_zip, target_cpu):
  32. # Skip specific paths and extensions as well as the following special case:
  33. # snapshot_blob.bin is a dependency of mksnapshot.zip because
  34. # v8_context_generator needs it, but this file does not get generated for arm
  35. # and arm 64 binaries of mksnapshot since they are built on x64 hardware.
  36. # Consumers of arm and arm64 mksnapshot can generate snapshot_blob.bin
  37. # themselves by running mksnapshot.
  38. should_skip = (
  39. any(dep.startswith(path) for path in PATHS_TO_SKIP) or
  40. any(dep.endswith(ext) for ext in EXTENSIONS_TO_SKIP) or
  41. ('arm' in target_cpu and dist_zip == 'mksnapshot.zip' and dep == 'snapshot_blob.bin'))
  42. if should_skip:
  43. print("Skipping {}".format(dep))
  44. return should_skip
  45. def execute(argv):
  46. try:
  47. output = subprocess.check_output(argv, stderr=subprocess.STDOUT)
  48. return output
  49. except subprocess.CalledProcessError as e:
  50. print(e.output)
  51. raise e
  52. def main(argv):
  53. dist_zip, runtime_deps, target_cpu, target_os, flatten_val = argv
  54. should_flatten = flatten_val == "true"
  55. dist_files = set()
  56. with open(runtime_deps) as f:
  57. for dep in f.readlines():
  58. dep = dep.strip()
  59. if not skip_path(dep, dist_zip, target_cpu):
  60. dist_files.add(dep)
  61. if sys.platform == 'darwin' and not should_flatten:
  62. execute(['zip', '-r', '-y', dist_zip] + list(dist_files))
  63. else:
  64. with zipfile.ZipFile(dist_zip, 'w', zipfile.ZIP_DEFLATED, allowZip64=True) as z:
  65. for dep in dist_files:
  66. if os.path.isdir(dep):
  67. for root, dirs, files in os.walk(dep):
  68. for file in files:
  69. z.write(os.path.join(root, file))
  70. else:
  71. basename = os.path.basename(dep)
  72. dirname = os.path.dirname(dep)
  73. arcname = os.path.join(dirname, 'chrome-sandbox') if basename == 'chrome_sandbox' else dep
  74. z.write(dep, os.path.basename(arcname) if should_flatten else arcname)
  75. if __name__ == '__main__':
  76. sys.exit(main(sys.argv[1:]))