gen-toolchain-links.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. from collections import namedtuple
  11. PlatformInfo = namedtuple("PlatformInfo", [
  12. "platform_name",
  13. "platform_archive_suffix",
  14. "extension",
  15. "unpack_cmd",
  16. "unpack_code"
  17. ])
  18. def main():
  19. if len(sys.argv) != 4:
  20. print("Usage: gen-toolchain-links.py <versions file> <base download URL> <output directory>")
  21. sys.exit(1)
  22. out_dir = sys.argv[3]
  23. if not os.path.exists(out_dir):
  24. print("Creating directory %s" % out_dir)
  25. os.mkdir(out_dir)
  26. base_url = sys.argv[2]
  27. versions_file = sys.argv[1]
  28. version_vars = {}
  29. with open(versions_file) as f:
  30. for line in f:
  31. name, var = line.partition("=")[::2]
  32. version_vars[name.strip()] = var.strip()
  33. gcc_version = version_vars["CURRENT_TOOLCHAIN_GCC_VERSION"]
  34. toolchain_desc = version_vars["CURRENT_TOOLCHAIN_COMMIT_DESC_SHORT"]
  35. unpack_code_linux_macos = """
  36. ::
  37. mkdir -p ~/esp
  38. cd ~/esp
  39. tar -x{}f ~/Downloads/{}
  40. """
  41. scratch_build_code_linux_macos = """
  42. ::
  43. git clone https://github.com/espressif/crosstool-NG.git
  44. cd crosstool-NG
  45. git checkout {}
  46. git submodule update --init
  47. ./bootstrap && ./configure --enable-local && make
  48. """
  49. platform_info = [
  50. PlatformInfo("linux64", "linux-amd64", "tar.gz", "z", unpack_code_linux_macos),
  51. PlatformInfo("linux32", "linux-i686","tar.gz", "z", unpack_code_linux_macos),
  52. PlatformInfo("osx", "macos", "tar.gz", "z", unpack_code_linux_macos),
  53. PlatformInfo("win32", "win32", "zip", None, None)
  54. ]
  55. with open(os.path.join(out_dir, 'download-links.inc'), "w") as links_file:
  56. for p in platform_info:
  57. archive_name = 'xtensa-esp32-elf-gcc{}-{}-{}.{}'.format(
  58. gcc_version.replace('.', '_'), toolchain_desc, p.platform_archive_suffix, p.extension)
  59. print('.. |download_link_{}| replace:: {}{}'.format(
  60. p.platform_name, base_url, archive_name), file=links_file)
  61. if p.unpack_code is not None:
  62. with open(os.path.join(out_dir, 'unpack-code-%s.inc' % p.platform_name), "w") as f:
  63. print(p.unpack_code.format(p.unpack_cmd, archive_name), file=f)
  64. with open(os.path.join(out_dir, 'scratch-build-code.inc'), "w") as code_file:
  65. print(scratch_build_code_linux_macos.format(toolchain_desc), file=code_file)
  66. if __name__ == "__main__":
  67. main()