Skip to content

fix: directory module name checking#7601

Merged
rgrinberg merged 4 commits intoocaml:mainfrom
Alizter:ps/branch/test__directory_module_name_checking
Apr 27, 2023
Merged

fix: directory module name checking#7601
rgrinberg merged 4 commits intoocaml:mainfrom
Alizter:ps/branch/test__directory_module_name_checking

Conversation

@Alizter
Copy link
Copy Markdown
Collaborator

@Alizter Alizter commented Apr 21, 2023

fix #7600

@Alizter Alizter force-pushed the ps/branch/test__directory_module_name_checking branch from 3f8011b to 5ed2981 Compare April 21, 2023 16:05
Copy link
Copy Markdown
Collaborator

@anmonteiro anmonteiro left a comment

Choose a reason for hiding this comment

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

Could we mangle invalid names instead of erroring?

@Alizter
Copy link
Copy Markdown
Collaborator Author

Alizter commented Apr 21, 2023

@anmonteiro If we mangle, how is the user supposed to refer to it in their file?

Unless you are thinking of doing some name mangling with certain rules. It seems pretty complicated next to just renaming your source directory. I guess having a rule like foo-bar -> foo_bar is pretty sensible.

@anmonteiro
Copy link
Copy Markdown
Collaborator

I think it'd be beneficial to support some of those directories and document / log the mangling scheme. For melange specifically, we'll probably want to have directories called [id] and (layout) (check https://beta.nextjs.org/docs/routing/defining-routes).

@Alizter
Copy link
Copy Markdown
Collaborator Author

Alizter commented Apr 21, 2023

I suppose another solution would be to make the module name of a directory configurable from a stanza. So we could do

(subdir foo-bar (qualified_name foo_bar))

That way when Dune wants to give module names corresponding to directories, it would query a naming map which would be overridden with these stanzas. That way you can name your directories whatever you want and not worry about name mangling.

Another benefit of this is that it allows users to give a module name directly to say src/.

With such a feature, we would of course need to keep in mind the eventuality that OCaml adds namespaces, but I don't see that happening any time soon.

@anmonteiro
Copy link
Copy Markdown
Collaborator

I like a solution along those lines. We could even reuse include_subdirs for it:

(include_subdirs 
  (mode qualified)
  ((src foo) (src/invalid-[module]-name invalid_module_name)))

@anmonteiro
Copy link
Copy Markdown
Collaborator

(And it goes without saying: I don't think these should be implemented in this PR). The bug fix is sensible and looks good to me.

@Alizter
Copy link
Copy Markdown
Collaborator Author

Alizter commented Apr 21, 2023

@anmonteiro Can you open a ticket with this feature request then?

@Alizter Alizter force-pushed the ps/branch/test__directory_module_name_checking branch from 5ed2981 to b8ccca1 Compare April 21, 2023 20:25
@anmonteiro
Copy link
Copy Markdown
Collaborator

#7605

@Alizter Alizter force-pushed the ps/branch/test__directory_module_name_checking branch from b8ccca1 to f2cf2aa Compare April 21, 2023 23:08
Alizter added 2 commits April 22, 2023 01:27
Signed-off-by: Ali Caglayan <alizter@gmail.com>
Signed-off-by: Ali Caglayan <alizter@gmail.com>
@Alizter Alizter force-pushed the ps/branch/test__directory_module_name_checking branch from f2cf2aa to 51e0205 Compare April 21, 2023 23:28
@Niols
Copy link
Copy Markdown
Contributor

Niols commented Apr 22, 2023

I think the feature request in #7605 makes a lot of sense. I guess two other solutions to a directory with a malformed module name would be:

  1. The directory in question contains only data and one uses (data_only_dirs bar-baz) (or data_only_dirs on an ancestor of the directory with a malformed module name).

  2. The directory in question could be ignored altogether. (Is there a stanza for this?)

Should I open feature requests for those as well?

@Alizter
Copy link
Copy Markdown
Collaborator Author

Alizter commented Apr 23, 2023

  1. The directory in question contains only data and one uses (data_only_dirs bar-baz) (or data_only_dirs on an ancestor of the directory with a malformed module name).

I am not sure what exactly you mean here. Could you open an issue explaining this further?

  1. The directory in question could be ignored altogether. (Is there a stanza for this?)

You can use the (dirs) stanza to remove a directory from Dunes vision. Something like (dirs :standard \ ignored_dir).

@Niols
Copy link
Copy Markdown
Contributor

Niols commented Apr 23, 2023

cf #7620 for two examples. One is your suggestion for (dirs), which I didn't know about, and which works like a charm. The other one uses (data_only_dirs), hoping that Dune will be fine with a directory then having an invalid module name. This is however not the case. I will open a feature request for this.

@Niols
Copy link
Copy Markdown
Contributor

Niols commented Apr 25, 2023

Feature request in question: #7628.

@Alizter
Copy link
Copy Markdown
Collaborator Author

Alizter commented Apr 25, 2023

@rgrinberg can this be merged?

@rgrinberg
Copy link
Copy Markdown
Member

Yes

@rgrinberg rgrinberg merged commit 4612b42 into ocaml:main Apr 27, 2023
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.

Internal error with (include_subdirs qualified) and directories having illegal module names

4 participants