zip_libcxx.py 1.6 KB

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