From 7c687e5ebc22a924f76e7d099f3522459d481af8 Mon Sep 17 00:00:00 2001 From: Matteo Cafasso Date: Sun, 21 Jan 2024 22:42:03 +0200 Subject: [PATCH] Fix plugin build logic For reasons to me unknown, the build logic was unable to package and run the plugin against the broker anymore. As the build logic is incredibly overengineerd and complicated, the following hacks were done to make it work. 1. We target against a fixed (and stable version) by switching from the main branch to the versioned one. 2. We build the `.ez` archive ourselves via `mix` and copy both the plugin and its dependencies within the `plugins` folder. 3. We override an internal variable `EXTRA_DIST_EZS` to avoid RMQ Makefiles from removing the copied plugins. This logic is brittle to say the least, I am not sure for how long I will manage to maintain this package as every time things are more complicated and less documented... Signed-off-by: Matteo Cafasso --- .github/workflows/action.yml | 10 ++++------ Makefile | 22 +++++++++++++++++----- mix.exs | 28 +++++++++------------------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index eda6d0d..71bf93a 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -7,6 +7,8 @@ jobs: matrix: erlang: - 1:25.3-1 + elixir: + - 1.13.4-1 steps: - uses: actions/checkout@v2 - name: Install Erlang @@ -17,13 +19,9 @@ jobs: sudo apt install -y --allow-downgrades esl-erlang=${{ matrix.erlang }} - name: Install Elixir run: | - sudo apt install -y elixir=1.13.4-1 - - name: Install RMQ requirements - run: | - wget https://github.com/rabbitmq/mix_task_archive_deps/releases/download/0.5.0/mix_task_archive_deps-0.5.0.ez - mix archive.install --force ./mix_task_archive_deps-0.5.0.ez - rm mix_task_archive_deps-0.5.0.ez + sudo apt install -y elixir=${{ matrix.elixir }} - name: Run tests run: | git checkout -b v3.12.x + make make tests diff --git a/Makefile b/Makefile index 21dab10..0341c61 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,37 @@ PROJECT = rabbitmq_message_deduplication -BUILD_DEPS = rabbitmq_cli DEPS = rabbit_common rabbit TEST_DEPS = rabbitmq_ct_helpers rabbitmq_ct_client_helpers amqp_client DEP_PLUGINS = rabbit_common/mk/rabbitmq-plugin.mk +DEP_EARLY_PLUGINS = rabbit_common/mk/rabbitmq-early-plugin.mk +# Mix customizations + +MIX_ENV ?= dev override MIX := mix elixir_srcs := mix.exs +# RMQ `dist` target removes anything within the `plugins` folder +# which is not managed by erlang.mk. +# We need to instruct the `rabbitmq-dist:do-dist` target to not +# remove our plugin and related dependencies. +ELIXIR_VERSION := $(shell elixir --version | grep Elixir | cut -d ' ' -f 2) +PROJECT_VERSION := $(shell git describe --tags --abbrev=0) +EXTRA_DIST_EZS := plugins/elixir-$(ELIXIR_VERSION).ez plugins/$(PROJECT)-$(PROJECT_VERSION).ez + app:: $(elixir_srcs) deps $(MIX) make_all + cp -r _build/$(MIX_ENV)/archives/elixir-*.ez plugins/ + cp -r _build/$(MIX_ENV)/archives/$(PROJECT)-*.ez plugins/ tests:: $(elixir_srcs) deps MIX_ENV=test $(MIX) make_tests -# FIXME: Use erlang.mk patched for RabbitMQ, while waiting for PRs to be -# reviewed and merged. +clean:: + @rm -fr _build -ERLANG_MK_REPO = https://github.com/rabbitmq/erlang.mk.git -ERLANG_MK_COMMIT = rabbitmq-tmp +# erlang.mk modules include rabbitmq-components.mk include erlang.mk diff --git a/mix.exs b/mix.exs index 7a30e60..02fea0a 100644 --- a/mix.exs +++ b/mix.exs @@ -15,22 +15,6 @@ defmodule RabbitMQ.MessageDeduplicationPlugin.Mixfile do deps_path: deps_dir, deps: deps(deps_dir), aliases: aliases(), - xref: [ - exclude: [ - :amqqueue, - :rabbit_amqqueue, - :rabbit_backing_queue, - :rabbit_exchange, - :rabbit_router, - :rabbit_binary_parser, - :rabbit_exchange_type, - :rabbit_log, - :rabbit_misc, - :rabbit_policy_validator, - :rabbit_registry, - :rabbit_policy - ] - ] ] end @@ -42,12 +26,16 @@ defmodule RabbitMQ.MessageDeduplicationPlugin.Mixfile do [ applications: applications, + registered: [RabbitMQMessageDeduplication], mod: {RabbitMQMessageDeduplication, []} ] end defp deps(deps_dir) do [ + { + :mix_task_archive_deps, "~> 1.0" + }, { :rabbit, path: Path.join(deps_dir, "rabbit"), @@ -72,14 +60,16 @@ defmodule RabbitMQ.MessageDeduplicationPlugin.Mixfile do "deps.compile" ], make_app: [ + "make_deps", "compile" ], make_all: [ - "deps.get", - "deps.compile", - "compile" + "make_app", + "archive.build.elixir", + "archive.build.all" ], make_tests: [ + "make_deps", "test" ] ]