zip_libcxx.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import os
  4. import subprocess
  5. import sys
  6. import zipfile
  7. def execute(argv):
  8. try:
  9. output = subprocess.check_output(argv, stderr=subprocess.STDOUT)
  10. return output
  11. except subprocess.CalledProcessError as e:
  12. print(e.output)
  13. raise e
  14. def get_object_files(base_path, archive_name):
  15. archive_file = os.path.join(base_path, archive_name)
  16. output = execute(['nm', '-g', archive_file]).decode('ascii')
  17. object_files = set()
  18. lines = output.split("\n")
  19. for line in lines:
  20. if line.startswith(base_path):
  21. object_file = line.split(":")[0]
  22. object_files.add(object_file)
  23. if line.startswith('nm: '):
  24. object_file = line.split(":")[1].lstrip()
  25. object_files.add(object_file)
  26. return list(object_files) + [archive_file]
  27. def main(argv):
  28. dist_zip, = argv
  29. out_dir = os.path.dirname(dist_zip)
  30. base_path_libcxx = os.path.join(out_dir, 'obj/buildtools/third_party/libc++')
  31. base_path_libcxxabi = os.path.join(out_dir, 'obj/buildtools/third_party/libc++abi')
  32. object_files_libcxx = get_object_files(base_path_libcxx, 'libc++.a')
  33. object_files_libcxxabi = get_object_files(base_path_libcxxabi, 'libc++abi.a')
  34. with zipfile.ZipFile(
  35. dist_zip, 'w', zipfile.ZIP_DEFLATED, allowZip64=True
  36. ) as z:
  37. object_files_libcxx.sort()
  38. for object_file in object_files_libcxx:
  39. z.write(object_file, os.path.relpath(object_file, base_path_libcxx))
  40. for object_file in object_files_libcxxabi:
  41. z.write(object_file, os.path.relpath(object_file, base_path_libcxxabi))
  42. if __name__ == '__main__':
  43. sys.exit(main(sys.argv[1:]))