kconfig_reference.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Extension to generate the KConfig reference list
  2. import os.path
  3. import subprocess
  4. import sys
  5. from .util import copy_if_modified
  6. def setup(app):
  7. # The idf_build_system extension will emit this event once it
  8. # has parsed the IDF project's information
  9. app.connect('idf-info', generate_reference)
  10. return {'parallel_read_safe': True, 'parallel_write_safe': True, 'version': '0.1'}
  11. def generate_reference(app, project_description):
  12. build_dir = os.path.dirname(app.doctreedir.rstrip(os.sep))
  13. # Generate 'kconfig.inc' file from components' Kconfig files
  14. print('Generating kconfig.inc from kconfig contents')
  15. kconfig_inc_path = '{}/inc/kconfig.inc'.format(build_dir)
  16. temp_sdkconfig_path = '{}/sdkconfig.tmp'.format(build_dir)
  17. kconfigs = project_description['config_environment']['COMPONENT_KCONFIGS'].split(';')
  18. kconfig_projbuilds = project_description['config_environment']['COMPONENT_KCONFIGS_PROJBUILD'].split(';')
  19. sdkconfig_renames = set()
  20. # TODO: this should be generated in project description as well, if possible
  21. for k in kconfigs + kconfig_projbuilds:
  22. component_dir = os.path.dirname(k)
  23. sdkconfig_rename = os.path.join(component_dir, 'sdkconfig.rename')
  24. if os.path.exists(sdkconfig_rename):
  25. sdkconfig_renames.add(sdkconfig_rename)
  26. kconfigs_source_path = '{}/inc/kconfigs_source.in'.format(build_dir)
  27. kconfig_projbuilds_source_path = '{}/inc/kconfig_projbuilds_source.in'.format(build_dir)
  28. prepare_kconfig_files_args = [sys.executable,
  29. '{}/tools/kconfig_new/prepare_kconfig_files.py'.format(app.config.idf_path),
  30. '--env', 'COMPONENT_KCONFIGS={}'.format(' '.join(kconfigs)),
  31. '--env', 'COMPONENT_KCONFIGS_PROJBUILD={}'.format(' '.join(kconfig_projbuilds)),
  32. '--env', 'COMPONENT_KCONFIGS_SOURCE_FILE={}'.format(kconfigs_source_path),
  33. '--env', 'COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE={}'.format(kconfig_projbuilds_source_path),
  34. ]
  35. subprocess.check_call(prepare_kconfig_files_args)
  36. confgen_args = [sys.executable,
  37. '{}/tools/kconfig_new/confgen.py'.format(app.config.idf_path),
  38. '--kconfig', './Kconfig',
  39. '--sdkconfig-rename', './sdkconfig.rename',
  40. '--config', temp_sdkconfig_path,
  41. '--env', 'COMPONENT_KCONFIGS={}'.format(' '.join(kconfigs)),
  42. '--env', 'COMPONENT_KCONFIGS_PROJBUILD={}'.format(' '.join(kconfig_projbuilds)),
  43. '--env', 'COMPONENT_SDKCONFIG_RENAMES={}'.format(' '.join(sdkconfig_renames)),
  44. '--env', 'COMPONENT_KCONFIGS_SOURCE_FILE={}'.format(kconfigs_source_path),
  45. '--env', 'COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE={}'.format(kconfig_projbuilds_source_path),
  46. '--env', 'IDF_PATH={}'.format(app.config.idf_path),
  47. '--env', 'IDF_TARGET={}'.format(app.config.idf_target),
  48. '--output', 'docs', kconfig_inc_path + '.in'
  49. ]
  50. subprocess.check_call(confgen_args, cwd=app.config.idf_path)
  51. copy_if_modified(kconfig_inc_path + '.in', kconfig_inc_path)