From 9ce3217f14d36172e3268b5bb606f5f710d67119 Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Wed, 2 Sep 2026 07:06:06 +0200 Subject: [PATCH] Update to use improved gmplugin_rebar3 --- .gitignore | 1 + Makefile | 9 +++------ README.md | 9 ++++++--- lib/gajumaru | 2 +- rebar.config | 29 ++++++++++++++++++++++++----- src/gmplugin_hello.erl | 37 +++++++++++++++++++++++++++++++++++++ src/gmplugin_hello_app.erl | 34 ---------------------------------- 7 files changed, 72 insertions(+), 49 deletions(-) create mode 100644 src/gmplugin_hello.erl diff --git a/.gitignore b/.gitignore index cba9edc..1560852 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .rebar3 +gajumaru _build _checkouts _vendor diff --git a/Makefile b/Makefile index 4c427de..fc98f37 100644 --- a/Makefile +++ b/Makefile @@ -14,23 +14,20 @@ all: compile init: submodules -submodules: +submodules: gajumaru git submodule init git submodule update + ln -sfn $(GAJUMARU_LIB) gajumaru compile: rebar3 compile -build-my-plugin: compile - rebar3 gm_plugin - # adapted from gmp_ix -build-gm-with-my-plugin: build-my-plugin +build-gm-with-my-plugin: init compile cp _build/default/$(APP_NAME).ez $(GAJUMARU_LIB)/plugins cd $(GAJUMARU_LIB) && make prod-build cp -rvf gmconfig/$(TARGET_NETWORK)/gajumaru/* $(BUILD_DIR) - fresh-console: build-gm-with-my-plugin console console: diff --git a/README.md b/README.md index 39e61dd..8e09485 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,15 @@ make fresh-console ``` ``` -(gajumaru@localhost)1> gmplugin_hello_app:hello(). +(gajumaru@localhost)1> gmplugin_hello:hello(). "hello, world" -(gajumaru@localhost)2> gmplugin_hello_app:network_id(). +(gajumaru@localhost)2> gmplugin_hello:network_id(). <<"localnet">> -(gajumaru@localhost)3> gmplugin_hello_app:height(). +(gajumaru@localhost)3> gmplugin_hello:height(). {ok,1} +(gajumaru@localhost)4> gmplugin_hello:top_block_hash(). +<<180,29,45,232,36,109,241,141,132,206,55,120,13,156,229, + 68,76,166,229,246,220,199,45,20,244,161,153,164,72,...>> ``` diff --git a/lib/gajumaru b/lib/gajumaru index 752c8d0..0af93a9 160000 --- a/lib/gajumaru +++ b/lib/gajumaru @@ -1 +1 @@ -Subproject commit 752c8d0ae5546ce42e3ec1bd4326606459975e20 +Subproject commit 0af93a953796e732374a0d87f02321ee124e36c1 diff --git a/rebar.config b/rebar.config index b38b613..c9306a2 100644 --- a/rebar.config +++ b/rebar.config @@ -1,16 +1,35 @@ +%%% -*- mode: erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*- {erl_opts, [debug_info]}. -% there's some bug somewhere... this list must be nonempty for some reason +%% When we want to use dependencies that are already in the gajumaru +%% code base, we use the `{gm, App}` notation. The build plugin will +%% consult the rebar.lock file of the gajumaru root and fetch the +%% right version of `App`. +%% {deps, [ {gmserialization, {gm, gmserialization}} ]}. -{project_apps_dir, "lib/gajumaru/apps"}. +{plugins, + [ + {gmplugin_rebar3, + {git, "https://git.qpq.swiss/QPQ-AG/gmplugin_rebar3.git", + {branch,"master"}}} + ]}. -{plugins, [ - {gmplugin_rebar3, {git, "https://git.qpq.swiss/QPQ-AG/gmplugin_rebar3.git", {branch,"master"}}} - ]}. +%% These provider hooks inform the gmplugin_rebar3 provider. +%% The pre-erlc_compile hook is needed if our code includes .hrl files +%% from the gajumaru core (which it does, for demo purposes). +%% The post-compile hook produces the packaged plugin. +%% +{provider_hooks, [ + {pre, [{erlc_compile, gm_setup}]}, + {post, [{compile, gm_plugin}]} +]}. +%% This gajumaru root is used unless we run `make init`, which updates the +%% submodules and creates a top-level symlink to lib/gajumaru. +%% {gajumaru_root, {git, "https://git.qpq.swiss/QPQ-AG/gajumaru", "master"}}. diff --git a/src/gmplugin_hello.erl b/src/gmplugin_hello.erl new file mode 100644 index 0000000..f1b7943 --- /dev/null +++ b/src/gmplugin_hello.erl @@ -0,0 +1,37 @@ +%%% -*- mode:erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*- +-module(gmplugin_hello). + +-export([ + hello/0, + network_id/0, + height/0, + top_block_hash/0 +]). + +%% When including a .hrl file from the gajumaru core, we simply give +%% the name (not -include_lib(), as this would require us to build +%% the code base first.) The build plugin ensures that all core +%% includes are available in the compiler's include path. +%% +-include("blocks.hrl"). + +-spec hello() -> string(). +hello() -> + "hello, world". + +-spec network_id() -> binary(). +network_id() -> + aec_governance:get_network_id(). + + +-spec height() -> {ok, Height :: pos_integer()} + | {error, no_top_block}. +height() -> + case aec_chain:top_height() of + undefined -> {error, no_top_block}; + Height -> {ok, Height} + end. + +-spec top_block_hash() -> block_header_hash(). +top_block_hash() -> + aec_chain:top_block_hash(). diff --git a/src/gmplugin_hello_app.erl b/src/gmplugin_hello_app.erl index b8f0de5..7d0b072 100644 --- a/src/gmplugin_hello_app.erl +++ b/src/gmplugin_hello_app.erl @@ -10,42 +10,8 @@ -export([start/2, stop/1]). -% tests --export([ - hello/0, - network_id/0, - height/0 -]). - start(_StartType, _StartArgs) -> gmplugin_hello_sup:start_link(). stop(_State) -> ok. - -%% internal functions - - -%% --spec hello() -> string(). - -hello() -> - "hello, world". - - - --spec network_id() -> binary(). - -network_id() -> - aec_governance:get_network_id(). - - - --spec height() -> {ok, Height :: pos_integer()} - | {error, no_top_block}. - -height() -> - case aec_chain:top_height() of - undefined -> {error, no_top_block}; - Height -> {ok, Height} - end.