Skip to content

Commit

Permalink
Merge pull request #9958 from rabbitmq/mergify/bp/v3.11.x/pr-9957
Browse files Browse the repository at this point in the history
Revert elixir json switch (backport #9952) (backport #9957)
  • Loading branch information
michaelklishin authored Nov 21, 2023
2 parents 3e9167f + 165aa60 commit 4b16c4f
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 18 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ exports_files([
# gazelle:exclude deps/gun
# gazelle:exclude deps/inet_tcp_proxy
# gazelle:exclude deps/jose
# gazelle:exclude deps/json
# gazelle:exclude deps/meck
# gazelle:exclude deps/observer_cli
# gazelle:exclude deps/osiris
Expand Down
8 changes: 8 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ erlang_package.git_package(
repository = "michaelklishin/erlang-jose",
)

erlang_package.hex_package(
name = "json",
build_file = "@rabbitmq-server//bazel:BUILD.json",
sha256 = "9abf218dbe4ea4fcb875e087d5f904ef263d012ee5ed21d46e9dbca63f053d16",
version = "1.4.1",
)

erlang_package.hex_package(
name = "thoas",
build_file = "@rabbitmq-server//bazel:BUILD.thoas",
Expand Down Expand Up @@ -361,6 +368,7 @@ use_repo(
"getopt",
"gun",
"jose",
"json",
"observer_cli",
"prometheus",
"ranch",
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ XREF_EXTRA_APP_DIRS = $(filter-out deps/rabbitmq_cli/_build/dev/lib/rabbit_commo
# protocols directly.
XREF_IGNORE = [ \
{'Elixir.CSV.Encode',impl_for,1}, \
{'Elixir.JSON.Decoder',impl_for,1}, \
{'Elixir.JSON.Encoder',impl_for,1}, \
{'Elixir.RabbitMQ.CLI.Core.DataCoercion',impl_for,1}]

# Include Elixir libraries in the Xref checks.
Expand Down
10 changes: 10 additions & 0 deletions deps/rabbitmq_cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ mix_archive_build(
archives = ["@hex//:archive"],
)

mix_archive_build(
name = "json_ez",
srcs = ["@json//:sources"],
out = "json.ez",
archives = ["@hex//:archive"],
)

# Note: All the various rabbitmq-* scripts are just copies of rabbitmqctl
rabbitmqctl(
name = "rabbitmqctl",
Expand All @@ -32,6 +39,7 @@ rabbitmqctl(
license_files = glob(["LICENSE*"]),
source_deps = {
"@csv//:sources": "csv",
"@json//:sources": "json",
},
visibility = ["//visibility:public"],
deps = [
Expand Down Expand Up @@ -101,6 +109,7 @@ plt(
],
ez_deps = [
":csv_ez",
":json_ez",
],
ignore_warnings = True,
libs = [":elixir"],
Expand Down Expand Up @@ -142,6 +151,7 @@ rabbitmqctl_test(
source_deps = {
"@amqp//:sources": "amqp",
"@csv//:sources": "csv",
"@json//:sources": "json",
"@temp//:sources": "temp",
"@x509//:sources": "x509",
},
Expand Down
3 changes: 2 additions & 1 deletion deps/rabbitmq_cli/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
PROJECT = rabbitmq_cli

BUILD_DEPS = rabbit_common
DEPS = csv observer_cli stdout_formatter
DEPS = csv json observer_cli stdout_formatter
TEST_DEPS = amqp amqp_client temp x509 rabbit

dep_amqp = hex 3.3.0
dep_csv = hex 3.2.0
dep_json = hex 1.4.1
dep_temp = hex 0.4.7
dep_x509 = hex 0.8.8

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ExportDefinitionsCommand do
end)
end)

{:ok, json} = :rabbit_json.try_encode(map)
{:ok, json} = JSON.encode(map)
json
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ImportDefinitionsCommand do
#

defp deserialise(bin, "json") do
:rabbit_json.try_decode(bin)
JSON.decode(bin)
end

defp deserialise(bin, "erlang") do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ListUserLimitsCommand do

val ->
Enum.map(val, fn {user, val} ->
{:ok, val_encoded} = :rabbit_json.try_encode(Map.new(val))
{:ok, val_encoded} = JSON.encode(Map.new(val))
[user: user, limits: val_encoded]
end)
end
Expand All @@ -56,7 +56,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ListUserLimitsCommand do
{:badrpc, node}

val when is_list(val) or is_map(val) ->
{:ok, val_encoded} = :rabbit_json.try_encode(Map.new(val))
{:ok, val_encoded} = JSON.encode(Map.new(val))
val_encoded
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ListVhostLimitsCommand do

val ->
Enum.map(val, fn {vhost, val} ->
{:ok, val_encoded} = :rabbit_json.try_encode(Map.new(val))
{:ok, val_encoded} = JSON.encode(Map.new(val))
[vhost: vhost, limits: val_encoded]
end)
end
Expand All @@ -54,7 +54,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ListVhostLimitsCommand do
{:badrpc, node}

val when is_list(val) or is_map(val) ->
:rabbit_json.try_encode(Map.new(val))
JSON.encode(Map.new(val))
end
end

Expand Down
2 changes: 1 addition & 1 deletion deps/rabbitmq_cli/lib/rabbitmq/cli/formatters/json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule RabbitMQ.CLI.Formatters.Json do
end

def format_output(output, _opts) do
{:ok, json} = :rabbit_json.try_encode(keys_to_atoms(output))
{:ok, json} = JSON.encode(keys_to_atoms(output))
json
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule RabbitMQ.CLI.Formatters.JsonStream do
end

def format_output(output, _opts) do
{:ok, json} = :rabbit_json.try_encode(output)
{:ok, json} = JSON.encode(keys_to_atoms(output))
json
end

Expand Down
6 changes: 3 additions & 3 deletions deps/rabbitmq_cli/lib/rabbitmqctl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ defmodule RabbitMQCtl do
end

defp format_error({:error, :check_failed, err}, %{formatter: "json"}, _) when is_map(err) do
{:ok, res} = :rabbit_json.try_encode(err)
{:ok, res} = JSON.encode(err)
{:error, ExitCodes.exit_unavailable(), res}
end

Expand All @@ -578,12 +578,12 @@ defmodule RabbitMQCtl do

# Catch all clauses
defp format_error({:error, err}, %{formatter: "json"}, _) when is_map(err) do
{:ok, res} = :rabbit_json.try_encode(err)
{:ok, res} = JSON.encode(err)
{:error, ExitCodes.exit_unavailable(), res}
end

defp format_error({:error, exit_code, err}, %{formatter: "json"}, _) when is_map(err) do
{:ok, res} = :rabbit_json.try_encode(err)
{:ok, res} = JSON.encode(err)
{:error, exit_code, res}
end

Expand Down
5 changes: 5 additions & 0 deletions deps/rabbitmq_cli/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ defmodule RabbitMQCtl.MixfileBase do
exclude: [
CSV,
CSV.Encode,
JSON,
:mnesia,
:msacc,
:observer_cli,
Expand Down Expand Up @@ -140,6 +141,10 @@ defmodule RabbitMQCtl.MixfileBase do
is_bazel = System.get_env("IS_BAZEL") != nil

[
{
:json,
path: Path.join(deps_dir, "json")
},
{
:csv,
path: Path.join(deps_dir, "csv")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ defmodule ExportDefinitionsCommandTest do
{:ok, nil} = @command.run([valid_file_path()], context[:opts])

{:ok, bin} = File.read(valid_file_path())
{:ok, map} = :rabbit_json.try_decode(bin)
{:ok, map} = JSON.decode(bin)
assert Map.has_key?(map, "rabbitmq_version")
end

Expand All @@ -128,7 +128,7 @@ defmodule ExportDefinitionsCommandTest do
clear_parameter("/", "federation-upstream", "up-1")

{:ok, bin} = File.read(valid_file_path())
{:ok, map} = :rabbit_json.try_decode(bin)
{:ok, map} = JSON.decode(bin)
assert Map.has_key?(map, "rabbitmq_version")
params = map["parameters"]
assert is_map(hd(params)["value"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,6 @@ defmodule SetUserLimitsCommandTest do

defp assert_limits(context, definition) do
limits = get_user_limits(context[:user])
assert {:ok, limits} == :rabbit_json.try_decode(definition)
assert {:ok, limits} == JSON.decode(definition)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@ defmodule SetVhostLimitsCommandTest do

defp assert_limits(context) do
limits = get_vhost_limits(context[:vhost])
assert {:ok, limits} == :rabbit_json.try_decode(context[:definition])
assert {:ok, limits} == JSON.decode(context[:definition])
end
end
4 changes: 2 additions & 2 deletions deps/rabbitmq_cli/test/json_formatting.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule JSONFormattingTest do
error_check(command, exit_ok())
end)

{:ok, doc} = :rabbit_json.try_decode(output)
{:ok, doc} = JSON.decode(output)

assert Map.has_key?(doc, "memory")
assert Map.has_key?(doc, "file_descriptors")
Expand All @@ -53,7 +53,7 @@ defmodule JSONFormattingTest do
error_check(command, exit_ok())
end)

{:ok, doc} = :rabbit_json.try_decode(output)
{:ok, doc} = JSON.decode(output)

assert Enum.member?(doc["disk_nodes"], node)
assert Map.has_key?(doc["listeners"], node)
Expand Down
1 change: 1 addition & 0 deletions deps/rabbitmq_cli/test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ true = Code.append_path(Path.join([System.get_env("DEPS_DIR"), "rabbit_common",
true = Code.append_path(Path.join([System.get_env("DEPS_DIR"), "rabbit", "ebin"]))

true = Code.append_path(Path.join(["_build", Atom.to_string(Mix.env()), "lib", "amqp", "ebin"]))
true = Code.append_path(Path.join(["_build", Atom.to_string(Mix.env()), "lib", "json", "ebin"]))
true = Code.append_path(Path.join(["_build", Atom.to_string(Mix.env()), "lib", "x509", "ebin"]))

if function_exported?(Mix, :ensure_application!, 1) do
Expand Down
10 changes: 10 additions & 0 deletions dist.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,15 @@ def source_archive(
prefix = "deps",
)

pkg_files(
name = "json-files",
srcs = [
"@json//:sources",
],
strip_prefix = "",
prefix = "deps/json",
)

pkg_files(
name = "csv-files",
srcs = [
Expand All @@ -349,6 +358,7 @@ def source_archive(
extension = extension,
srcs = [
":deps-files",
":json-files",
":csv-files",
Label("@rabbitmq-server//:root-licenses"),
],
Expand Down

0 comments on commit 4b16c4f

Please sign in to comment.