Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make rebar3 templates check for name clashes #2384

Merged
merged 2 commits into from
Oct 6, 2020

Conversation

pablocostass
Copy link
Contributor

This commit changes rebar3 to check for name clashes of the
modules created from its templates with existing Erlang modules
to produce a non-blocking warning for each clashing module.

It does so by checking if any of the modules that will be created
is already defined in the path and, to do so, reimplements the function
code:all_available/0 when rebar3 is used with a version of Erlang/OTP
older than 23.0, as said function was added in that release.

Should close #1386.

@pablocostass
Copy link
Contributor Author

The CI is failing because I messed up with the conditional definition of the all_available/0 function. Furthermore, I just realized that in order to fix it I would probably have to either:

  1. Redefine twice the implementation of that function (the first time if OTP_RELEASE is not defined and the second time if the macro ?OTP_RELEASE outputs a version <= 23)
  2. Forget about conditional definitions and always use the reimplementation of code:all_available/0, leaving a TODO note of removing that chunk of code in favor of simply calling the builtin function once it's defined in OTP 23.0

@ferd
Copy link
Collaborator

ferd commented Oct 5, 2020

Would it be simpler to translate the name to an atom then calling module_info() on that atom within a try...catch ?

@pablocostass
Copy link
Contributor Author

pablocostass commented Oct 5, 2020

Yes, it would be! Why didn't I think of doing that? Thanks for the suggestion @ferd, I'll commit the changes later

This commit changes rebar3 to check for name clashes of the
modules created from its templates with existing Erlang modules
to produce a non-blocking warning for each clashing module.
@pablocostass pablocostass force-pushed the 1386_templates_check_name_clashes branch from 96fed13 to 9a9f2d2 Compare October 5, 2020 22:47
Copy link
Collaborator

@ferd ferd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one small change to make it safest

src/rebar_templater.erl Outdated Show resolved Hide resolved
@pablocostass
Copy link
Contributor Author

Got it

@pablocostass
Copy link
Contributor Author

@ferd Windows CI crashed while installing Erlang. Can you restart the whole thing? :)

@ferd
Copy link
Collaborator

ferd commented Oct 6, 2020

yep I'm watching it

@ferd ferd merged commit 98c6e80 into erlang:master Oct 6, 2020
@pablocostass pablocostass deleted the 1386_templates_check_name_clashes branch October 7, 2020 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rebar3 templates should check for name clashes
2 participants