explorer.lua 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import("core.project.config")
  2. import("core.project.project")
  3. import("core.base.json")
  4. function main ()
  5. config.load()
  6. -- read all the files from the target
  7. local explorer_targets = {}
  8. for name, target in pairs((project.targets())) do
  9. local explorer_target = {}
  10. explorer_target.name = name
  11. explorer_target.kind = target:kind()
  12. explorer_target.scriptdir = target:scriptdir()
  13. local group = target:get("group")
  14. if group then
  15. explorer_target.group = group
  16. else
  17. explorer_target.group = ""
  18. end
  19. if not target:is_phony() then
  20. local explorer_files = {}
  21. for _, headerfile in pairs(target:headerfiles()) do
  22. table.insert(explorer_files, headerfile)
  23. end
  24. for _, sourcefile in pairs(target:sourcefiles()) do
  25. table.insert(explorer_files, sourcefile)
  26. end
  27. explorer_target.files = explorer_files
  28. end
  29. table.insert(explorer_targets, explorer_target)
  30. end
  31. -- read all the options from the target
  32. local explorer_options = {}
  33. for name, option in pairs((project.options())) do
  34. local explorer_option = {}
  35. local show
  36. if option.showmenu then
  37. showmenu = option:showmenu()
  38. show = showmenu ~= false
  39. else
  40. show = option:get("showmenu")
  41. end
  42. if show then
  43. explorer_option.name = name
  44. explorer_option.value = option:value() or option:get("default")
  45. local explorer_option_values = {}
  46. for _, value in ipairs(option:get("values")) do
  47. table.insert(explorer_option_values, value)
  48. end
  49. if #explorer_option_values > 0 then
  50. explorer_option.values = explorer_option_values
  51. end
  52. table.insert(explorer_options, explorer_option)
  53. end
  54. end
  55. -- print explorer data
  56. if json.mark_as_array then
  57. if explorer_targets then
  58. json.mark_as_array(explorer_targets)
  59. end
  60. if explorer_options then
  61. json.mark_as_array(explorer_options)
  62. end
  63. end
  64. local explorer_data = {targets = explorer_targets, options = explorer_options}
  65. local jsondata = json.encode(explorer_data)
  66. print(jsondata)
  67. end