Skip to content

Commit

Permalink
Make escript_incl_extra work with _checkouts
Browse files Browse the repository at this point in the history
When developing `relx` and testing changes with `rebar3`, it is convenient to make `relx` a checkout dependency.

However, the current implementation of `escript_incl_extra` expects the output directory of `relx` to be under `_build/<profile>/lib/`, which is not the case if `relx` is a checkout dependency.

Instead of making a breaking change to `escript_incl_extra`, introduce a new config parameter instead.
  • Loading branch information
mxxk committed Aug 1, 2021
1 parent 1105538 commit 6d78d19
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
10 changes: 3 additions & 7 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
{escript_wrappers_windows, ["cmd", "powershell"]}.
{escript_comment, "%%Rebar3 3.16.1\n"}.
{escript_emu_args, "%%! +sbtu +A1\n"}.
%% escript_incl_extra is for internal rebar-private use only.
%% escript_incl_priv is for internal rebar-private use only.
%% Do not use outside rebar. Config interface is not stable.
{escript_incl_extra, [{"relx/priv/templates/*", "_build/default/lib/"},
{"rebar/priv/templates/*", "_build/default/lib/"}]}.
{escript_incl_priv, [{relx, "templates/*"},
{rebar, "templates/*"}]}.

{overrides, [{add, relx, [{erl_opts, [{d, 'RLX_LOG', rebar_log}]}]}]}.

Expand Down Expand Up @@ -67,10 +67,6 @@
{bootstrap, []},

{prod, [
{escript_incl_extra, [
{"relx/priv/templates/*", "_build/prod/lib/"},
{"rebar/priv/templates/*", "_build/prod/lib/"}
]},
{erl_opts, [no_debug_info]},
{overrides, [
{override, erlware_commons, [
Expand Down
20 changes: 18 additions & 2 deletions src/rebar_prv_escriptize.erl
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,26 @@ get_app_beams(App, Path) ->
load_files(Prefix, "*.app", Path).

get_extra(State) ->
Extra = rebar_state:get(State, escript_incl_extra, []),
AllApps = rebar_state:all_deps(State) ++ rebar_state:project_apps(State),
InclPriv = rebar_state:get(State, escript_incl_priv, []),
InclPrivPaths = lists:map(fun(Entry) ->
resolve_incl_priv(Entry, AllApps)
end, InclPriv),
% `escript_incl_extra` is kept for historical reasons as its internal use in
% rebar3 has been replaced with `escript_incl_priv`.
InclExtraPaths = rebar_state:get(State, escript_incl_extra, []),
lists:foldl(fun({Wildcard, Dir}, Files) ->
load_files(Wildcard, Dir) ++ Files
end, [], Extra).
end, [], InclPrivPaths ++ InclExtraPaths).

% Converts a wildcard path relative to an app (e.g., `priv/*`) into a wildcard
% path with with the app name included (e.g., `relx/priv/*`).
resolve_incl_priv({AppName, PrivWildcard}, AllApps) when is_atom(AppName) ->
{ok, AppInfo} =
rebar_app_utils:find(rebar_utils:to_binary(AppName), AllApps),
AppOutDir = rebar_app_info:out_dir(AppInfo),
Wildcard = filename:join([atom_to_list(AppName), "priv", PrivWildcard]),
{Wildcard, filename:dirname(AppOutDir)}.

load_files(Wildcard, Dir) ->
load_files("", Wildcard, Dir).
Expand Down

0 comments on commit 6d78d19

Please sign in to comment.