Browse Source

Merge pull request #2384 from pablocostass/1386_templates_check_name_clashes

Make rebar3 templates check for name clashes
pull/2389/head
Fred Hebert 4 years ago
committed by GitHub
parent
commit
98c6e808a4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions
  1. +16
    -0
      src/rebar_templater.erl

+ 16
- 0
src/rebar_templater.erl View File

@ -196,6 +196,21 @@ maybe_warn_about_name(Vars) ->
ok ok
end. end.
maybe_warn_about_name_clash(File) ->
case filename:extension(File) of
".erl" ->
Module0 = re:replace(filename:basename(File), "\\.erl$", "", [{return, list}]),
Module = list_to_atom(Module0),
try Module:module_info() of
_ -> ?WARN("The module definition of '~ts' in file ~ts "
"will clash with an existing Erlang module.",
[Module, File])
catch
_:_ -> ok
end;
_ -> ok
end.
validate_atom(Str) -> validate_atom(Str) ->
case io_lib:fread("~a", unicode:characters_to_list(Str)) of case io_lib:fread("~a", unicode:characters_to_list(Str)) of
{ok, [Atom], ""} -> {ok, [Atom], ""} ->
@ -258,6 +273,7 @@ execute_template([{template, From, To} | Terms], Files, {Template, Type, Cwd}, V
In = expand_path(From, Vars), In = expand_path(From, Vars),
Out = expand_path(To, Vars), Out = expand_path(To, Vars),
Tpl = load_file(Files, Type, filename:join(Cwd, In)), Tpl = load_file(Files, Type, filename:join(Cwd, In)),
maybe_warn_about_name_clash(Out),
case write_file(Out, render(Tpl, Vars), Force) of case write_file(Out, render(Tpl, Vars), Force) of
ok -> ok ->
ok; ok;

Loading…
Cancel
Save