zip.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. # Skip because it is an output of //ui/gl that we don't need.
  15. 'angledata',
  16. # Skip because these are outputs that we don't need.
  17. './libVkICD_mock_',
  18. # Skip because these are outputs that we don't need.
  19. './VkICD_mock_',
  20. # Skip because its an output of create_bundle from //build/config/mac/rules.gni
  21. # that we don't need
  22. 'Electron.dSYM',
  23. # Refs https://chromium-review.googlesource.com/c/angle/angle/+/2425197.
  24. # Remove this when Angle themselves remove the file: https://issuetracker.google.com/issues/168736059
  25. 'gen/angle/angle_commit.h',
  26. # //chrome/browser:resources depends on this via
  27. # //chrome/browser/resources/ssl/ssl_error_assistant, but we don't need to
  28. # ship it.
  29. 'pyproto',
  30. # On Windows, this binary doesn't exist (the crashpad handler is built-in).
  31. # On MacOS, the binary is called 'chrome_crashpad_handler' and is inside the
  32. # app bundle.
  33. # On Linux, we don't use crashpad, but this binary is still built for some
  34. # reason. Exclude it from the zip.
  35. './crashpad_handler',
  36. # Skip because these are outputs that we don't need.
  37. 'resources/inspector',
  38. ]
  39. def skip_path(dep, dist_zip, target_cpu):
  40. # Skip specific paths and extensions as well as the following special case:
  41. # snapshot_blob.bin is a dependency of mksnapshot.zip because
  42. # v8_context_generator needs it, but this file does not get generated for arm
  43. # and arm 64 binaries of mksnapshot since they are built on x64 hardware.
  44. # Consumers of arm and arm64 mksnapshot can generate snapshot_blob.bin
  45. # themselves by running mksnapshot.
  46. should_skip = (
  47. any(dep.startswith(path) for path in PATHS_TO_SKIP) or
  48. any(dep.endswith(ext) for ext in EXTENSIONS_TO_SKIP) or
  49. ('arm' in target_cpu and dist_zip == 'mksnapshot.zip' and dep == 'snapshot_blob.bin'))
  50. if should_skip:
  51. print("Skipping {}".format(dep))
  52. return should_skip
  53. def execute(argv):
  54. try:
  55. output = subprocess.check_output(argv, stderr=subprocess.STDOUT)
  56. return output
  57. except subprocess.CalledProcessError as e:
  58. print(e.output)
  59. raise e
  60. def main(argv):
  61. dist_zip, runtime_deps, target_cpu, target_os, flatten_val = argv
  62. should_flatten = flatten_val == "true"
  63. dist_files = set()
  64. with open(runtime_deps) as f:
  65. for dep in f.readlines():
  66. dep = dep.strip()
  67. if not skip_path(dep, dist_zip, target_cpu):
  68. dist_files.add(dep)
  69. if sys.platform == 'darwin' and not should_flatten:
  70. execute(['zip', '-r', '-y', dist_zip] + list(dist_files))
  71. else:
  72. with zipfile.ZipFile(dist_zip, 'w', zipfile.ZIP_DEFLATED, allowZip64=True) as z:
  73. for dep in dist_files:
  74. if os.path.isdir(dep):
  75. for root, dirs, files in os.walk(dep):
  76. for file in files:
  77. z.write(os.path.join(root, file))
  78. else:
  79. basename = os.path.basename(dep)
  80. dirname = os.path.dirname(dep)
  81. arcname = os.path.join(dirname, 'chrome-sandbox') if basename == 'chrome_sandbox' else dep
  82. z.write(dep, os.path.basename(arcname) if should_flatten else arcname)
  83. if __name__ == '__main__':
  84. sys.exit(main(sys.argv[1:]))