-
Notifications
You must be signed in to change notification settings - Fork 701
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
Consistent resolution of project root w.r.t --project-file path #7749
Conversation
Could you add a changelog entry? It'd be nice to have a test too, but I'm not sure if that's doable with the current test infrastructure |
I see some tests that directly use |
Just an update: the fix above has a bug & is wrong when |
Yes, seems to be used only for tests. |
@pranaysashank: hi! how is it going? |
Hi, I didn't get time to come back to this and it completely slipped off my radar. The PR works except in tests where the argument |
Sure, why not. I'm sure there are explicit ways of changing directory available. |
- This commit sets the ProjectRoot consistently for both absolute and relative --project-file pats. The ProjectRoot is set as the directory where the --project-file is located. - Before this change relative project files are rooted to where the project file is resolved, when recursively searching upward from the current directory, and not where it is located. Previous behaviour is as follows, gitpod ~/0/1/2/foo $ tree ~/0 /home/gitpod/0 └── 1 ├── 2 │ └── foo │ ├── app │ │ └── Main.hs │ ├── CHANGELOG.md │ └── foo.cabal └── cabal.project and inside foo let's run $ pwd /home/gitpod/0/1/2/foo $ cabal build all --project-file ../cabal.project which builds the project setting the project root at 2 using the project file at 1 $ ls ~/0/1 ~/0/1/2 /home/gitpod/0/1: 2 cabal.project /home/gitpod/0/1/2: dist-newstyle foo However, if the cabal.project file was instead in 0 directory, cabal would fail to build since the resolved project root is at 1 and cabal fails to find a package at 1/foo gitpod ~/0/1/2/foo $ mv ~/0/1/cabal.project ~/0/ gitpod ~/0/1/2/foo $ cabal build all --project-file ../cabal.project When using configuration(s) from /home/gitpod/0/1/../cabal.project, the following errors occurred: The package location 'foo' does not exist. This beaviour is almost never what we want.
- It's not used anywhere other than in tests and complicates implementation.
49004bf
to
34ec8b7
Compare
The tests are failing because it couldn't find the directory, likely because we are running the tests from the outer directory. So, this works
but not
Is there a way to change directory in the tests correctly in both the scenarios? |
Wow, I had no idea one can even do
Perhaps let's just switch this to
or
or
work fine? |
No none of those work, I need to be in In the same IntegrationTests2 file, there is also a function |
Actually, the CI script I had in mind changes to that directory:
it's the other one that doesn't:
Would it work to just slip |
And you may be right that
and I wasn't able to find there calls to any code that goes up the directory hierarchy to find the real project root. I might have missed something, though. Anyway, if |
Yep, that should work |
Or one could try something like
though I'm not sure in what order to next the quotes, etc. |
yes although --test-options usually doesn't work for me with patterns, that's why I used test-option twice and passed the flags individually in my comment above |
Yes, I have the same problem. Would that be a bug or do we lack some obvious shell trick to make it work? |
It's a bug in
but not this
because, > splitArgs "-p 'find root'"
["-p","'find","root'"] --test-options is annoying for another reason which is that every time you change them, cabal re-configures the packages in the project. |
Yay, great findings. Could you file both issues? If not, I will do that, because they are important usability hiccups and both seem reasonably easily fixable. |
baddf99
to
79c441e
Compare
I've created a PR that moves towards consistency in a different way here: #8454. |
Could I ask for help reviewing the PR fixing this issue (#8454)? Even a cursory look and a comment whether this might fix your use case (bonus points for checking out and confirming) would be very much appreciated. |
@Mikolaj From reading the description and comments in that PR, it doesn't look like it's related to this issue / PR. This PR fixes the project resolution when the project file is passed as a relative path. The open question listed in the --project-dir PR (#8454) is what this PR fixes but the issue is a bit more complicated than child directory being the project root (as mentioned in the open question), the main issue was what I wrote in the second point in description of this PR
I haven't checked if this behaviour was fixed in a recent release / HEAD. This PR gives the same behaviour desired in the open question i.e. with this fix |
@pranaysashank: my bad, I assumed this is one of the issues potentially fixed by #8454, while this is a PR fixing a related issue. Thank you for you remarks, though. |
A new proposal dropped at #8454. Could you kindly voice your opinion? |
@pranaysashank shall we close this PR? :) |
This commit sets the ProjectRoot consistently for both absolute
and relative
--project-file
paths. The ProjectRoot is set as thedirectory where the
--project-file
is located.Before this change relative project files are rooted to where the
project file is resolved, when recursively searching upward from
the current directory, and not where it is located.
Previous behaviour is as follows. With the following directory layout:
and inside foo let's run
which builds the project setting the project root at
2
usingthe project file at
1
However, if the cabal.project file was instead in
0
directory,cabal would fail to build since the resolved project root is at
1
and cabal fails to find a package at1/foo
This behaviour is almost never what we want.
See #7695
Please include the following checklist in your PR:
Please also shortly describe how you tested your change. Bonus points for added tests!