check-elixir-emqx-machine-boot-discrepancies.exs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env elixir
  2. defmodule CheckElixirEMQXMachineBootDiscrepancies do
  3. alias EMQXUmbrella.MixProject
  4. def main() do
  5. {:ok, _} = Application.ensure_all_started(:mix)
  6. File.cwd!()
  7. |> Path.join("mix.exs")
  8. |> Code.compile_file()
  9. inputs = MixProject.check_profile!()
  10. profile = Mix.env()
  11. # produce `rebar.config.rendered` to consult
  12. File.cwd!()
  13. |> Path.join("rebar3")
  14. |> System.cmd(["as", to_string(profile)],
  15. env: [{"DEBUG", "1"}]
  16. )
  17. mix_apps = mix_emqx_machine_applications(inputs.edition_type)
  18. rebar_apps = rebar_emqx_machine_applications(profile)
  19. {mix_missing, rebar_missing} = diff_apps(mix_apps, rebar_apps)
  20. if Enum.any?(mix_missing) do
  21. IO.puts(
  22. "For profile=#{profile}, edition=#{inputs.edition_type} " <>
  23. "rebar.config.erl has the following emqx_machine_boot_apps " <>
  24. "that are missing in mix.exs:"
  25. )
  26. IO.inspect(mix_missing, syntax_colors: [atom: :red])
  27. end
  28. if Enum.any?(rebar_missing) do
  29. IO.puts(
  30. "For profile=#{profile}, edition=#{inputs.edition_type} " <>
  31. "mix.exs has the following emqx_machine_boot_apps " <>
  32. "that are missing in rebar3.config.erl:"
  33. )
  34. IO.inspect(rebar_missing, syntax_colors: [atom: :red])
  35. end
  36. success? = Enum.empty?(mix_missing) and Enum.empty?(rebar_missing)
  37. if not success? do
  38. System.halt(1)
  39. else
  40. IO.puts(
  41. IO.ANSI.green() <>
  42. "Mix and Rebar emqx_machine_boot_apps OK!" <>
  43. IO.ANSI.reset()
  44. )
  45. end
  46. end
  47. defp mix_emqx_machine_applications(edition_type) do
  48. EMQXUmbrella.MixProject.emqx_machine_boot_apps(edition_type)
  49. end
  50. defp rebar_emqx_machine_applications(profile) do
  51. {:ok, props} =
  52. File.cwd!()
  53. |> Path.join("rebar.config.rendered")
  54. |> :file.consult()
  55. props[:profiles][profile][:relx][:overlay_vars][:emqx_machine_boot_apps]
  56. |> to_string()
  57. |> String.split(~r/,\s+/)
  58. |> Enum.map(&String.to_atom/1)
  59. end
  60. defp diff_apps(mix_apps, rebar_apps) do
  61. mix_missing = rebar_apps -- mix_apps
  62. rebar_missing = mix_apps -- rebar_apps
  63. {mix_missing, rebar_missing}
  64. end
  65. end
  66. CheckElixirEMQXMachineBootDiscrepancies.main()