phoenixframework / phoenix

Peace of mind from prototype to production
https://www.phoenixframework.org
MIT License
21.35k stars 2.87k forks source link

Support arbitrary module name capitalization #536

Closed ammmir closed 9 years ago

ammmir commented 9 years ago

I'd like to use a module name capitalized as "ABfoo" instead of "Abfoo". If you create a new project and rename all the generated "Abfoo" to "ABfoo" Phoenix fails to start:

15:18:17.838 [error] beam/beam_load.c(1250): Error loading module 'Elixir.Abfoo.Router':
  module name in object code is Elixir.ABfoo.Router

15:18:17.840 [error] Loading of /private/tmp/abfoo/_build/dev/lib/abfoo/ebin/Elixir.Abfoo.Router.beam failed: :badfile
chrismccord commented 9 years ago

I think this is an issue where you renamed a module and the vm is confused. Can you rm -rf _build then retry?

To use the ABfoo name, you need your OTP app name to be :a_bfoo. What is the value of the :app key in project in mix.exs? We would need to provide extra configuration if you wanted to use a different module than the camel-cased version of the OTP app, but I'm not sure that is the issue here. Let me know. Thanks

ammmir commented 9 years ago

@chrismccord Ah, thanks, it was the OTP app name that I didn't update, using :a_bfoo resolves it :)

Just curious, is it because you need to resolve the module name to an actual OTP app name and don't want to have to annotate (eg. @otp_application :abfoo) the router with it?

joshuaclayton commented 8 years ago

@chrismccord I just ran into a similar error with an external dependency, specifically https://github.com/elixytics/ua_inspector:

mix ua_inspector.download.databases                                                          ☺ 2.2.2

23:10:05.536 [error] Loading of /Users/joshuaclayton/dev/personal/redirect_to/_build/dev/lib/ua_inspector/ebin/Elixir.Mix.Tasks.UAInspector.Download.Databases.beam failed: :badfile

23:10:05.536 [error] beam/beam_load.c(1278): Error loading module 'Elixir.Mix.Tasks.UAInspector.Download.Databases':
  module name in object code is Elixir.Mix.Tasks.UaInspector.Download.Databases

** (UndefinedFunctionError) undefined function: Mix.Tasks.UAInspector.Download.Databases.run/1 (module Mix.Tasks.UAInspector.Download.Databases is not available)
    Mix.Tasks.UAInspector.Download.Databases.run([])
    (mix) lib/mix/cli.ex:55: Mix.CLI.run_task/2
    (elixir) lib/code.ex:363: Code.require_file/2

Having configured based on their readme, is there anything else I could do to get this to work? I'd removed the _build directory to no avail.

chrismccord commented 8 years ago

@joshuaclayton what happens if you edit your /deps/ua_inspector repo and change this line https://github.com/elixytics/ua_inspector/blob/master/mix.exs#L8 to app: :u_a_inspector, then mix deps.compile ua_inspector ?

joshuaclayton commented 8 years ago

@chrismccord appreciate the quick response! I've made the update but am seeing a new error:

mix ua_inspector.download.databases                                                          ☹ 2.2.2
Unchecked dependencies for environment dev:
* ua_inspector (Hex package)
  could not find an app file at _build/dev/lib/ua_inspector/ebin/ua_inspector.app. This may happen if the dependency was not yet compiled, or you specified the wrong application name in your deps, or the dependency indeed has no app file (then you can pass app: false as option)
** (Mix) Can't continue due to errors on dependencies

I'm admittedly new to Elixir, but I'd also tried to update the deps app in ROOT/mix.exs to reflect the new name:

{:ua_inspector, "~> 0.9", app: :u_a_inspector},

It didn't have any impact on the output, and I've confirmed that it's generating u_a_inspector.app in the appropriate directory.

Would it help if I create a new repo to reproduce?

josevalim commented 8 years ago

Phoenix does not impose any naming rules. If you are having conflicts like above, is because you are defining a module named "ABC" and calling it as "ABc" or something of sorts. As long as you are consistent, you should be fine.

Regarding ua_inspector, Mix does impose names for its tasks, which Elixir version are you using?

joshuaclayton commented 8 years ago

@josevalim I'm on 1.1.1 for Elixir+Mix. I'm able to recreate on this repo: https://github.com/joshuaclayton/ua-inspector-phoenix-debug

mneudert commented 8 years ago

@joshuaclayton To chime in on the problem regarding UAInspector:

The problem you encountered was created initially after Elixir 1.0.3 (elixir-lang/elixir#2891 I think) changed the way of resolving task names with underscores. However my hack around this was too hacky and depended on (case sensitive!) two beam files:

This worked perfectly fine on my system.

But as brought to my attention in elixytics/ua_inspector#2 it obviously breaks when using a case insensitive file system. Like Windows or (most?) MacOS installations.

This has since been fixed and should not be a problem anymore :)