check_missing_reboot_apps.exs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env elixir
  2. alias EMQXUmbrella.MixProject
  3. {:ok, _} = Application.ensure_all_started(:mix)
  4. # note: run from the project root
  5. File.cwd!()
  6. |> Path.join("mix.exs")
  7. |> Code.compile_file()
  8. inputs = MixProject.check_profile!()
  9. profile = Mix.env()
  10. # need to use this information because we might have compiled all
  11. # applications in the test profile, and thus filter what's in the
  12. # release lib directory.
  13. rel_apps = MixProject.applications(inputs.release_type, inputs.edition_type)
  14. apps =
  15. rel_apps
  16. |> Keyword.keys()
  17. |> Enum.filter(&(to_string(&1) =~ "emqx"))
  18. |> Enum.reject(&(&1 in [:emqx_mix]))
  19. :xref.start(:xref)
  20. :xref.set_default(:xref, warnings: false)
  21. rel_dir = ~c"_build/#{profile}/lib/"
  22. :xref.add_release(:xref, rel_dir)
  23. {:ok, calls} = :xref.q(:xref, ~c"(App) (XC | [#{Enum.join(apps, ",")}] || mria:create_table/_)")
  24. emqx_calls =
  25. calls
  26. |> Enum.map(&elem(&1, 0))
  27. |> Enum.filter(&(to_string(&1) =~ "emqx_"))
  28. |> MapSet.new()
  29. Path.wildcard(rel_dir ++ "*/ebin")
  30. |> Enum.each(fn dir ->
  31. dir
  32. |> to_charlist()
  33. |> :code.add_pathz()
  34. end)
  35. Path.wildcard(rel_dir ++ "*")
  36. |> Enum.map(fn dir ->
  37. dir
  38. |> Path.basename()
  39. |> String.to_atom()
  40. |> Application.load()
  41. end)
  42. reboot_apps = :emqx_machine_boot.sorted_reboot_apps() |> MapSet.new()
  43. missing_reboot_apps = MapSet.difference(emqx_calls, reboot_apps)
  44. if MapSet.size(missing_reboot_apps) != 0 do
  45. IO.puts(
  46. :stderr,
  47. IO.ANSI.format([
  48. :red,
  49. "Some applications are missing from `emqx_machine_boot:sorted_reboot_apps/0`!\n",
  50. "Missing applications:\n",
  51. Enum.map(missing_reboot_apps, fn app ->
  52. " * #{app}\n"
  53. end),
  54. "\n",
  55. :green,
  56. "Hint: maybe add them to `emqx_machine_boot:basic_reboot_apps_edition/1`\n",
  57. "\n",
  58. :yellow,
  59. "Applications that call `mria:create_table` need to be added to that list;\n",
  60. " otherwise, when a node joins a cluster, it might lose tables.\n"
  61. ])
  62. )
  63. System.halt(1)
  64. end