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

Don't write out the cabal file if it matches the old one #555

Closed

Conversation

Gabriella439
Copy link

The motivation behind this change is avoid the --force option from triggering an unnecessary reload of ghcid if nothing changed.

The context is that at work we use hpack --force to correct manual edits that users might make to the .cabal file, and we run hpack --force whenever users enter our Nix shell. If a user uses direnv on top of that then hpack --force runs every time they cd to the project directory.

However, suppose that they load ghcid in one window and then cd to the project directory in another window. This causes hpack --force to run and even if nothing changed the mwb.cabal file is touched which causes ghcid to reload (which is expensive). This change fixes that.

The motivation behind this change is avoid the `--force` option from triggering
an unnecessary reload of `ghcid` if nothing changed.

The context is that at work we use `hpack --force` to correct manual edits
that users might make to the `.cabal` file, and we run `hpack --force`
whenever users enter our Nix shell.  If a user uses `direnv` on top of that
then `hpack --force` runs every time they `cd` to the project directory.

However, suppose that they load `ghcid` in one window and then `cd` to the
project directory in another window.  This causes `hpack --force` to run and
even if nothing changed the `mwb.cabal` file is touched which causes `ghcid`
to reload (which is expensive).  This change fixes that.
@Gabriella439
Copy link
Author

Note that I could also structure this to check if the new/old cabal files are textually identical instead of the abstract syntax being identical. However, that would be a slightly more invasive change so I wanted to propose this first to solicit feedback.

@sol
Copy link
Owner

sol commented Aug 4, 2023

we run hpack --force whenever users enter our Nix shell.

What is the reason that you use --force in the first place? If you can remove the --force option then I think things would already work for your use case.

Do you have a modification hash in the generated .cabal file? If yes, then run hpack --no-hash --force once to get rid of it. After that hpack should work just fine, even with manual modifications and without --force.

Or is it, that you use different versions of hpack across the team?

Note that I could also structure this to check if the new/old cabal files are textually identical instead of the abstract syntax being identical.

Yes, if we do anything here, then we would want textual comparison. But please hold back for a second. This code is already more complicated than it should be. We might want to remove support for modification hashes (and possibly even the hpack min version check) first, before doing anything here.

sol added a commit that referenced this pull request Aug 4, 2023
@sol
Copy link
Owner

sol commented Aug 4, 2023

@Gabriella439 please take a look at #557. Does this work for you?

sol added a commit that referenced this pull request Aug 4, 2023
sol added a commit that referenced this pull request Aug 4, 2023
@Gabriella439
Copy link
Author

Yeah, #557 looks good to me. To answer your prior question, we would use --force so that if the user made any manual modification to the .cabal file then we'd correct and override that modification.

sol added a commit that referenced this pull request Aug 6, 2023
@sol
Copy link
Owner

sol commented Aug 6, 2023

@sol sol closed this Aug 6, 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.

2 participants