From 495fcb30d65cfc1d69c079dcb45e042cc7e25f5f Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Thu, 31 Oct 2019 12:49:32 +0100 Subject: [PATCH 1/3] WIP: AE_DISABLE_CUCKOO env var support revert rebar.lock to original --- rebar.config.script | 20 ++++++++++++++++++++ src/aeminer.app.src.script | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 rebar.config.script create mode 100644 src/aeminer.app.src.script diff --git a/rebar.config.script b/rebar.config.script new file mode 100644 index 0000000..87c02e4 --- /dev/null +++ b/rebar.config.script @@ -0,0 +1,20 @@ +%% -*- mode:erlang; erlang-indent-level:4; indent-tabs-mode:nil -*- +io:fwrite("Running ~p~n", [SCRIPT]). +case os:getenv("AE_DISABLE_CUCKOO") =/= false of + true -> + RemoveApps = [aecuckoo, aecuckooprebuilt], + RemovePlugins = [rebar_aecuckooprebuilt_dep], + {_, Deps} = lists:keyfind(deps, 1, CONFIG), + NewDeps = [D || D <- Deps, + not lists:member(element(1,D), RemoveApps)], + Plugins = proplists:get_value(plugins, CONFIG, []), + CONFIG1 = lists:keyreplace(deps, 1, CONFIG, {deps, NewDeps}), + Plugins1 = [P || P <- Plugins, + not lists:member(element(1,P), RemovePlugins)], + CONFIG2 = lists:keystore(plugins, 1, CONFIG1, {plugins, Plugins1}), + io:fwrite("CONFIG2 = ~p~n", [CONFIG2]), + CONFIG2; + false -> + io:fwrite("Using cuckoo~n", []), + CONFIG +end. diff --git a/src/aeminer.app.src.script b/src/aeminer.app.src.script new file mode 100644 index 0000000..a4b3ce7 --- /dev/null +++ b/src/aeminer.app.src.script @@ -0,0 +1,18 @@ +%% -*- mode:erlang; erlang-indent-level:4; indent-tabs-mode:nil -*- + +RemoveApps = [aecuckoo, aecuckooprebuilt]. +Base = filename:basename(SCRIPT, ".script"). +Dir = filename:dirname(SCRIPT). +{ok, [{application,_,Opts} = App]} = file:consult(filename:join(Dir, Base)). +case os:getenv("AE_DISABLE_CUCKOO") =/= false of + true -> + {_, Apps} = lists:keyfind(applications, 1, Opts), + Env = proplists:get_value(env, Opts, []), + Env1 = lists:keystore(use_cuckoo, 1, Env, {use_cuckoo, false}), + Apps1 = Apps -- RemoveApps, + Opts1 = lists:keyreplace(applications, 1, Opts, {applications, Apps1}), + Opts2 = lists:keystore(env, 1, Opts1, {env, Env1}), + setelement(3, App, Opts2); + false -> + App +end. -- 2.30.2 From a7b1a70e422a93f3e43fa492e1bed80e21abb83c Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Thu, 31 Oct 2019 15:26:25 +0100 Subject: [PATCH 2/3] Filter rebar.lock if disabling cuckoo --- rebar.lock.script | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 rebar.lock.script diff --git a/rebar.lock.script b/rebar.lock.script new file mode 100644 index 0000000..534e836 --- /dev/null +++ b/rebar.lock.script @@ -0,0 +1,29 @@ +%% -*- erlang -*- + +FilterCheck = (os:getenv("AE_DISABLE_CUCKOO") =/= false), +RemoveApps = [<<"aecuckoo">>, <<"aecuckooprebuilt">>], + +Filter = fun(Apps) -> + case FilterCheck of + false -> + Apps; + true -> + lists:foldl( + fun(App, Acc) -> + lists:keydelete(App, 1, Acc) + end, + Apps, + RemoveApps + ) + end + end, + +case CONFIG of + [] -> + %% no lock file present, usually during unlock/upgrade + CONFIG; + [{Version, Deps}, [{pkg_hash, Pkgs}]] -> + Deps1 = Filter(Deps), + Pkgs1 = Filter(Pkgs), + [{Version, Deps1}, [{pkg_hash, Pkgs1}]] +end. -- 2.30.2 From d2ccf9429de230e09fd4819aae87e9d278c93124 Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Fri, 1 Nov 2019 14:02:01 +0100 Subject: [PATCH 3/3] remove debug printouts --- rebar.config.script | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/rebar.config.script b/rebar.config.script index 87c02e4..7e98f6d 100644 --- a/rebar.config.script +++ b/rebar.config.script @@ -1,5 +1,4 @@ %% -*- mode:erlang; erlang-indent-level:4; indent-tabs-mode:nil -*- -io:fwrite("Running ~p~n", [SCRIPT]). case os:getenv("AE_DISABLE_CUCKOO") =/= false of true -> RemoveApps = [aecuckoo, aecuckooprebuilt], @@ -11,10 +10,7 @@ case os:getenv("AE_DISABLE_CUCKOO") =/= false of CONFIG1 = lists:keyreplace(deps, 1, CONFIG, {deps, NewDeps}), Plugins1 = [P || P <- Plugins, not lists:member(element(1,P), RemovePlugins)], - CONFIG2 = lists:keystore(plugins, 1, CONFIG1, {plugins, Plugins1}), - io:fwrite("CONFIG2 = ~p~n", [CONFIG2]), - CONFIG2; + lists:keystore(plugins, 1, CONFIG1, {plugins, Plugins1}); false -> - io:fwrite("Using cuckoo~n", []), CONFIG end. -- 2.30.2