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

dune init project is broken due to project/workspace root detection #4960

Closed
shonfeder opened this issue Oct 2, 2021 · 4 comments · Fixed by #5041
Closed

dune init project is broken due to project/workspace root detection #4960

shonfeder opened this issue Oct 2, 2021 · 4 comments · Fixed by #5041
Assignees
Milestone

Comments

@shonfeder
Copy link
Collaborator

Expected Behavior

dune init proj foo should initialize a new project in the directory foo.

Actual Behavior

$ dune init proj foo
Error: I cannot find the root of the current workspace/project.
If you would like to create a new dune project, you can type:

    dune init project NAME

Otherwise, please make sure to run dune inside an existing project or
workspace. For more information about how dune identifies the root of the
current workspace/project, please refer to
https://dune.readthedocs.io/en/stable/usage.html#finding-the-root

A workaround is

$ touch dune-project
$ dune init proj foo

but, obviously, this is broken behavior.

Reproduction

I don't know how we can test this in our current CI/cram set up, since those all exist within a dune project.

Specifications

  • Version of dune (output of dune --version): 3.0+alpha-867-gf22e56c
  • Version of ocaml (output of ocamlc --version): version 4.11.1
  • Operating system (distribution and version): Ubuntu 21.04
@ghost
Copy link

ghost commented Oct 4, 2021

Must be because of #4921. The solution here should be to move root detection to later on in dune init. And in fact, dune init project should probably not detect the root at all given that it is creating a new project.

I don't know how we can test this in our current CI/cram set up, since those all exist within a dune project.

It's a bit tedious indeed. Dune detects when it is run from inside dune (via the environment variable INSIDE_DUNE) and behave differently. For instance, it disables root detection and use the current working directory as root. This is to avoid the inner dune scanning up the file system and picking up arbitrary files.

@rgrinberg rgrinberg added this to the 3.0 milestone Oct 6, 2021
@shonfeder shonfeder removed their assignment Oct 7, 2021
@shonfeder
Copy link
Collaborator Author

Sorry @bobot: afaict the breakage here is unrelated to any changes I made and I don't have the bandwidth to pick up the bug fix.

From my brief look, the root detection mechanism will need to non-trivial reworking. In order not to break the project initialization, the root detection in https://github.com/ocaml/dune/blob/main/bin/workspace_root.ml#L65-L94 will need some way of communicating an override that is determined after CLI parsing (afaik, since the parser is applicative, we don't have access to intermediate values until the entire command has been parsed).

@shonfeder
Copy link
Collaborator Author

dune init project should probably not detect the root at all given that it is creating a new project.

Dune init is only calling Common.term, but because the root detection is embedded in the parser for the common options, the root detection is forced upon it.

@bobot
Copy link
Collaborator

bobot commented Oct 8, 2021

No problem, thanks for the analysis!

@ghost ghost assigned rgrinberg Oct 20, 2021
@rgrinberg rgrinberg linked a pull request Oct 21, 2021 that will close this issue
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 a pull request may close this issue.

3 participants