zip.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. 'swiftshader', #Skipping because it is an output of //ui/gl that we don't need
  12. './libVkLayer_', #Skipping because these are outputs that we don't need
  13. './VkLayerLayer_', #Skipping because these are outputs that we don't need
  14. ]
  15. def skip_path(dep):
  16. should_skip = (
  17. any(dep.startswith(path) for path in PATHS_TO_SKIP) or
  18. any(dep.endswith(ext) for ext in EXTENSIONS_TO_SKIP))
  19. if should_skip:
  20. print("Skipping {}".format(dep))
  21. return should_skip
  22. def execute(argv):
  23. try:
  24. output = subprocess.check_output(argv, stderr=subprocess.STDOUT)
  25. return output
  26. except subprocess.CalledProcessError as e:
  27. print e.output
  28. raise e
  29. def main(argv):
  30. dist_zip, runtime_deps, target_cpu, target_os = argv
  31. dist_files = set()
  32. with open(runtime_deps) as f:
  33. for dep in f.readlines():
  34. dep = dep.strip()
  35. dist_files.add(dep)
  36. if sys.platform == 'darwin':
  37. execute(['zip', '-r', '-y', dist_zip] + list(dist_files))
  38. else:
  39. with zipfile.ZipFile(dist_zip, 'w', zipfile.ZIP_DEFLATED) as z:
  40. for dep in dist_files:
  41. if skip_path(dep):
  42. continue
  43. if os.path.isdir(dep):
  44. for root, dirs, files in os.walk(dep):
  45. for file in files:
  46. z.write(os.path.join(root, file))
  47. else:
  48. z.write(dep)
  49. if __name__ == '__main__':
  50. sys.exit(main(sys.argv[1:]))