gen_toolchain_links.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Generate toolchain download links from toolchain info makefile
  2. from __future__ import print_function
  3. import os.path
  4. from collections import namedtuple
  5. from .util import copy_if_modified
  6. BASE_URL = 'https://dl.espressif.com/dl/'
  7. PlatformInfo = namedtuple("PlatformInfo", [
  8. "platform_name",
  9. "platform_archive_suffix",
  10. "extension",
  11. "unpack_cmd",
  12. "unpack_code"
  13. ])
  14. def setup(app):
  15. # we don't actually need idf-info, just a convenient event to trigger this on
  16. app.connect('idf-info', generate_toolchain_download_links)
  17. return {'parallel_read_safe': True, 'parallel_write_safe': True, 'version': '0.1'}
  18. def generate_toolchain_download_links(app, project_description):
  19. print("Generating toolchain download links")
  20. toolchain_tmpdir = '{}/toolchain_inc'.format(app.config.build_dir)
  21. toolchain_versions = os.path.join(app.config.idf_path, "tools/toolchain_versions.mk")
  22. gen_toolchain_links(toolchain_versions, toolchain_tmpdir)
  23. copy_if_modified(toolchain_tmpdir, '{}/inc'.format(app.config.build_dir))
  24. def gen_toolchain_links(versions_file, out_dir):
  25. version_vars = {}
  26. with open(versions_file) as f:
  27. for line in f:
  28. name, var = line.partition("=")[::2]
  29. version_vars[name.strip()] = var.strip()
  30. gcc_version = version_vars["CURRENT_TOOLCHAIN_GCC_VERSION"]
  31. toolchain_desc = version_vars["CURRENT_TOOLCHAIN_COMMIT_DESC_SHORT"]
  32. unpack_code_linux_macos = """
  33. ::
  34. mkdir -p ~/esp
  35. cd ~/esp
  36. tar -x{}f ~/Downloads/{}
  37. """
  38. scratch_build_code_linux_macos = """
  39. ::
  40. git clone https://github.com/espressif/crosstool-NG.git
  41. cd crosstool-NG
  42. git checkout {}
  43. git submodule update --init
  44. ./bootstrap && ./configure --enable-local && make
  45. """
  46. platform_info = [
  47. PlatformInfo("linux64", "linux-amd64", "tar.gz", "z", unpack_code_linux_macos),
  48. PlatformInfo("linux32", "linux-i686","tar.gz", "z", unpack_code_linux_macos),
  49. PlatformInfo("osx", "macos", "tar.gz", "z", unpack_code_linux_macos),
  50. PlatformInfo("win32", "win32", "zip", None, None)
  51. ]
  52. try:
  53. os.mkdir(out_dir)
  54. except OSError:
  55. pass
  56. with open(os.path.join(out_dir, 'download-links.inc'), "w") as links_file:
  57. for p in platform_info:
  58. archive_name = 'xtensa-esp32-elf-gcc{}-{}-{}.{}'.format(
  59. gcc_version.replace('.', '_'), toolchain_desc, p.platform_archive_suffix, p.extension)
  60. print('.. |download_link_{}| replace:: {}{}'.format(
  61. p.platform_name, BASE_URL, archive_name), file=links_file)
  62. if p.unpack_code is not None:
  63. with open(os.path.join(out_dir, 'unpack-code-%s.inc' % p.platform_name), "w") as f:
  64. print(p.unpack_code.format(p.unpack_cmd, archive_name), file=f)
  65. with open(os.path.join(out_dir, 'scratch-build-code.inc'), "w") as code_file:
  66. print(scratch_build_code_linux_macos.format(toolchain_desc), file=code_file)