gen-toolchain-links.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # This script generates toolchain download links and toolchain unpacking
  5. # code snippets based on information found in $IDF_PATH/tools/toolchain_versions.mk
  6. #
  7. from __future__ import print_function
  8. import sys
  9. import os
  10. def main():
  11. if len(sys.argv) != 4:
  12. print("Usage: gen-toolchain-links.py <versions file> <base download URL> <output directory>")
  13. sys.exit(1)
  14. out_dir = sys.argv[3]
  15. if not os.path.exists(out_dir):
  16. print("Creating directory %s" % out_dir)
  17. os.mkdir(out_dir)
  18. base_url = sys.argv[2]
  19. versions_file = sys.argv[1]
  20. version_vars = {}
  21. with open(versions_file) as f:
  22. for line in f:
  23. name, var = line.partition("=")[::2]
  24. version_vars[name.strip()] = var.strip()
  25. gcc_version = version_vars["CURRENT_TOOLCHAIN_GCC_VERSION"]
  26. toolchain_desc = version_vars["CURRENT_TOOLCHAIN_COMMIT_DESC_SHORT"]
  27. unpack_code_linux_macos = """
  28. ::
  29. mkdir -p ~/esp
  30. cd ~/esp
  31. tar -x{}f ~/Downloads/{}
  32. """
  33. scratch_build_code_linux_macos = """
  34. ::
  35. git clone -b xtensa-1.22.x https://github.com/espressif/crosstool-NG.git
  36. cd crosstool-NG
  37. ./bootstrap && ./configure --enable-local && make install
  38. """
  39. platform_info = [["linux64", "tar.gz", "z", unpack_code_linux_macos],
  40. ["linux32", "tar.gz", "z", unpack_code_linux_macos],
  41. ["macos", "tar.gz", "z", unpack_code_linux_macos],
  42. ["win32", "zip", None, None]]
  43. with open(os.path.join(out_dir, 'download-links.inc'), "w") as links_file:
  44. for p in platform_info:
  45. platform_name = p[0]
  46. extension = p[1]
  47. unpack_cmd = p[2]
  48. unpack_code = p[3]
  49. archive_name = 'xtensa-esp32-elf-{}-{}-{}.{}'.format(
  50. platform_name, toolchain_desc, gcc_version, extension)
  51. print('.. |download_link_{}| replace:: {}{}'.format(
  52. platform_name, base_url, archive_name), file=links_file)
  53. if unpack_code is not None:
  54. with open(os.path.join(out_dir, 'unpack-code-%s.inc' % platform_name), "w") as f:
  55. print(unpack_code.format(unpack_cmd, archive_name), file=f)
  56. with open(os.path.join(out_dir, 'scratch-build-code.inc'), "w") as code_file:
  57. print(scratch_build_code_linux_macos, file=code_file)
  58. if __name__ == "__main__":
  59. main()