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

Fix default Nix configuration option in generated ~/.cabal/config file #8878

Merged
merged 16 commits into from
May 18, 2023

Conversation

cbclemmer
Copy link
Collaborator

@cbclemmer cbclemmer commented Mar 28, 2023


Please include the following checklist in your PR:

Please also shortly describe how you tested your change. Bonus points for added tests!

Should close #8864

In PR #8522, I did not test the default generated config, and made an incorrect assumption about its contents. This led to the Nix configuration option being uncommented in the ~/.cabal/config file when generated for a user for the first time.

In this PR, I have updated the default value of the Nix configuration option to be empty. This causes the pretty print function, which writes the default config, to comment out the Nix configuration option. This change ensures compatibility, allowing newer Cabal versions to generate configuration files suitable for older Cabal versions.

@ulysses4ever
Copy link
Collaborator

Thank you!

@chreekat
Copy link
Collaborator

chreekat commented Apr 5, 2023

Just an observation from a non-maintainer: one thing that would make this patch more valuable than it already is would be to add some documentation to the test, and maybe clarify the comment on the implementation (why do we "need to return PP.empty from viewAsFieldDescr").


defaultConfigFile <- readFile (basedir </> "nix-config/default-config")
True @=? isInfixOf "-- nix:\n" defaultConfigFile

Copy link
Collaborator

Choose a reason for hiding this comment

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

can we generalize this test to ensure that essentially all options are commented out in the default config, not just nix?

Copy link
Collaborator

Choose a reason for hiding this comment

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

i.e. the repo perhaps and a few other things should not be commented, but it would be much better to have a much more uniform test.

@Mikolaj
Copy link
Member

Mikolaj commented Apr 19, 2023

Could we move this forward? The world needs this PR.

@Mikolaj
Copy link
Member

Mikolaj commented May 4, 2023

@mergify rebase

@mergify
Copy link
Contributor

mergify bot commented May 4, 2023

rebase

✅ Branch has been successfully rebased

@Mikolaj
Copy link
Member

Mikolaj commented May 4, 2023

Let me prod the CI...

@Mikolaj
Copy link
Member

Mikolaj commented May 4, 2023

Failed again. Rerunning failed jobs...

@Mikolaj
Copy link
Member

Mikolaj commented May 4, 2023

@cbclemmer: it seems, the new test started failing on Windows after updating to new GHC or after some changes of setup of the CI machines. Are you able to guess what's going on with this access denied problem? The path is looking funny, but I'm not sure what I'm looking at.

@cbclemmer
Copy link
Collaborator Author

@Mikolaj I added a test that will update cabal-install/tests/IntegrationTests2/config/default-config with whatever the current default is and I'm not sure why it's failing. It must have something to do with the CI file permissions because the test works on my machine

@Mikolaj
Copy link
Member

Mikolaj commented May 5, 2023

Uhoh. Let's try to debug. Does anybody have any ideas? The error is

Exception: tests\IntegrationTests2\config/default-config.tmp: renameFile:renamePath:MoveFileEx "\\\\?\\D:\\a\\cabal\\cabal\\cabal-install\\tests\\IntegrationTests2\\config\\default-config.tmp" Just "\\\\?\\D:\\a\\cabal\\cabal\\cabal-install\\tests\\IntegrationTests2\\config\\default-config": permission denied (Access is denied.)

Printing both paths aligned:

Exception: tests\IntegrationTests2\config/default-config.tmp: renameFile:renamePath:MoveFileEx 
"\\\\?\\D:\\a\\cabal\\cabal\\cabal-install\\tests\\IntegrationTests2\\config\\default-config.tmp" Just 
"\\\\?\\D:\\a\\cabal\\cabal\\cabal-install\\tests\\IntegrationTests2\\config\\default-config": permission denied (Access is denied.)

shows they differ just by the .tmp. Do you recognize the paths? Should the \\config\\ directory exist by that point?

@cbclemmer
Copy link
Collaborator Author

@Mikolaj The file should be committed and present at that time, but I've also tried it with the file and it gives the same error. The test that fails writes the file to the folder, so it would override it. Now that I think of it, the nix flag test does the same thing in the test above it so it may not have closed the file handle properly. I've added a commit that will remove the reference to the default config in the nix test, that may help

@Mikolaj
Copy link
Member

Mikolaj commented May 5, 2023

I guess that's progress?

Test Default Flags:             FAIL
      tests\IntegrationTests2.hs:1975:
      expected: True
       but got: False

@Mikolaj
Copy link
Member

Mikolaj commented May 11, 2023

@cbclemmer: Joking aside. is this test result now explainable?

@cbclemmer
Copy link
Collaborator Author

@Mikolaj Sorry, I've been super busy lately but recently I have had more time. The issue was that Windows used a different setting for that parameter than Linux. To fix this I first changed the test to compare the strings on the assertion rather than an auxiliary function, which let me see what the matching line said and allowed me to come to the explanation above. Then to fix it I just compared the string before the colon so that the system differences for the values (and the ones that included the user's home directory) would not be tested because that's not the point of this test anyway. Then I went through all of the default config values and ensured that they are all present and tested for whether they are commented or not. The only drawback to my approach is that it does not test whether specific options are under a heading, but it does test whether they are indented or not. Everything should be good to go now.

@Mikolaj
Copy link
Member

Mikolaj commented May 15, 2023

Good sleuthing. Would you set the squash+merge_me label?

@cbclemmer cbclemmer added squash+merge me Tell Mergify Bot to squash-merge and removed attention: needs-review labels May 16, 2023
@cbclemmer
Copy link
Collaborator Author

@Mikolaj Done

@mergify mergify bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label May 18, 2023
@mergify mergify bot merged commit 9bf415a into haskell:master May 18, 2023
@Mikolaj
Copy link
Member

Mikolaj commented May 18, 2023

Thank you again!

@Mikolaj
Copy link
Member

Mikolaj commented May 18, 2023

@mergify backport 3.10

@mergify
Copy link
Contributor

mergify bot commented May 18, 2023

backport 3.10

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request May 18, 2023
#8878)

* default to commented line for nix config

* Fix whitespace

* Remove vscode folder

* Remove default config file for test

* Remove test generated file

* Add changelog

* Add test for default config values

* Remove config file

* Remove parsing file

* Add config file back for tests

* Remove reference to default config to try to get the new test to pass

* Rewrite test to be more verbose WIP

* Stop testing for values and only test for whether it is commented or not

* Fill out rest of tests WIP

* Clean up

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 9bf415a)
mergify bot added a commit that referenced this pull request May 19, 2023
Fix default Nix configuration option in generated ~/.cabal/config file (backport #8878)
kylixafonso pushed a commit to kylixafonso/cabal that referenced this pull request May 21, 2023
haskell#8878)

* default to commented line for nix config

* Fix whitespace

* Remove vscode folder

* Remove default config file for test

* Remove test generated file

* Add changelog

* Add test for default config values

* Remove config file

* Remove parsing file

* Add config file back for tests

* Remove reference to default config to try to get the new test to pass

* Rewrite test to be more verbose WIP

* Stop testing for values and only test for whether it is commented or not

* Fill out rest of tests WIP

* Clean up

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days squash+merge me Tell Mergify Bot to squash-merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fresh ~/.cabal/config written by cabal 3.10 crashes any older cabal
5 participants