diff options
author | David <dlesl@users.noreply.github.com> | 2021-05-31 18:49:58 +0200 |
---|---|---|
committer | Raphael Megzari <raphael@megzari.com> | 2021-06-09 12:14:12 +0900 |
commit | ae2f75ef8949f5174325e655adefa1b86e80befb (patch) | |
tree | 74d8e443549bee300fae31d21f6f539dd5b69e58 /pkgs/development | |
parent | 1ecc68dc93fbc470790a720d30d71c6b06e0960d (diff) |
rebar3WithPlugins: add ability to ignore dependencies
Diffstat (limited to 'pkgs/development')
3 files changed, 48 insertions, 11 deletions
diff --git a/pkgs/development/beam-modules/rebar3-release.nix b/pkgs/development/beam-modules/rebar3-release.nix index 80082945e4c9e..98d10cb87c4fb 100644 --- a/pkgs/development/beam-modules/rebar3-release.nix +++ b/pkgs/development/beam-modules/rebar3-release.nix @@ -51,20 +51,12 @@ let inherit src; + REBAR_IGNORE_DEPS = beamDeps != [ ]; + configurePhase = '' runHook preConfigure ${lib.optionalString (checkouts != null) "cp --no-preserve=all -R ${checkouts}/_checkouts ."} - ${# Prevent rebar3 from trying to manage deps - lib.optionalString (beamDeps != [ ]) '' - erl -noshell -eval ' - {ok, Terms0} = file:consult("rebar.config"), - Terms = lists:keydelete(deps, 1, Terms0), - ok = file:write_file("rebar.config", [io_lib:format("~tp.~n", [T]) || T <- Terms]), - init:stop(0) - ' - rm -f rebar.lock - ''} runHook postConfigure ''; diff --git a/pkgs/development/tools/build-managers/rebar3/default.nix b/pkgs/development/tools/build-managers/rebar3/default.nix index d551b98b5b848..ba4641552feb8 100644 --- a/pkgs/development/tools/build-managers/rebar3/default.nix +++ b/pkgs/development/tools/build-managers/rebar3/default.nix @@ -118,9 +118,11 @@ let {ok, _} = zip:extract(Archive, [{cwd, "'$out/lib'"}]), init:stop(0) ' + cp ${./rebar_ignore_deps.erl} rebar_ignore_deps.erl + erlc -o $out/lib/rebar/ebin rebar_ignore_deps.erl mkdir -p $out/bin makeWrapper ${erlang}/bin/erl $out/bin/rebar3 \ - --set REBAR_GLOBAL_PLUGINS "${toString globalPluginNames}" \ + --set REBAR_GLOBAL_PLUGINS "${toString globalPluginNames} rebar_ignore_deps" \ --suffix-each ERL_LIBS ":" "$out/lib ${toString pluginLibDirs}" \ --add-flags "+sbtu +A1 -noshell -boot start_clean -s rebar3 main -extra" ''; diff --git a/pkgs/development/tools/build-managers/rebar3/rebar_ignore_deps.erl b/pkgs/development/tools/build-managers/rebar3/rebar_ignore_deps.erl new file mode 100644 index 0000000000000..3e0ae67c4539b --- /dev/null +++ b/pkgs/development/tools/build-managers/rebar3/rebar_ignore_deps.erl @@ -0,0 +1,43 @@ +%% This module, when loaded as a plugin, overrides the default `install_deps` +%% provider and erases the dependencies from the rebar3 state, when +%% REBAR_IGNORE_DEPS is true. + +-module(rebar_ignore_deps). + +-export([init/1, do/1, format_error/1]). + +init(State0) -> + case os:getenv("REBAR_IGNORE_DEPS", "") of + "" -> + {ok, State0}; + _ -> + do_init(State0) + end. + +do_init(State0) -> + State1 = rebar_state:allow_provider_overrides(State0, true), + Provider = providers:create( + [ + {name, install_deps}, %% override the default install_deps provider + {module, ?MODULE}, + {bare, false}, + {deps, [app_discovery]}, + {example, undefined}, + {opts, []}, + {short_desc, ""}, + {desc, ""} + ]), + State2 = rebar_state:add_provider(State1, Provider), + {ok, rebar_state:allow_provider_overrides(State2, false)}. + +do(State0) -> + io:format("Ignoring deps...~n"), + Profiles = rebar_state:current_profiles(State0), + State = lists:foldl(fun(P, Acc0) -> + Acc = rebar_state:set(Acc0, {deps, P}, []), + rebar_state:set(Acc, {parsed_deps, P}, []) + end, State0, Profiles), + {ok, State}. + +format_error(Reason) -> + io_lib:format("~p", [Reason]). |