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

Verbatim imports put at bottom of stanza first time #522

Open
brandon-leapyear opened this issue Sep 20, 2022 · 2 comments
Open

Verbatim imports put at bottom of stanza first time #522

brandon-leapyear opened this issue Sep 20, 2022 · 2 comments

Comments

@brandon-leapyear
Copy link

#490 moves import lines to the top of the stanza, but it only happens the first time hpack is called.

Repro:

  1. Run rm *.cabal
  2. Add verbatim: { import: ... } line to a stanza
  3. Run hpack
  4. Cabal file incorrectly has import line at bottom
  5. Run hpack again
  6. Cabal file correctly has import line moved to top
@sol
Copy link
Owner

sol commented Sep 21, 2022

Hi @brandon-leapyear 👋 thanks for reporting this!

This is something we want to fix. I am away from my computer for the next couple of days. Still, I took a quick look at the code. From what I understand, these are the underlying issues:

  1. I did not add a test with Always render imports as the first field of a section (fixes #486) #490. Our acceptance tests accept any field order, so adding an acceptance test may require some extra work. We have existing tests for field sorting in:
    it "keeps existing field order" $ do
    However the code added in #490 is not covered by those tests.
  2. We only sort stanza fields if we already have an existing fieldOrder (and by extension only when we already have a .cabal-file):
    Stanza name fields : xs | Just fieldOrder <- lookup name sectionsFieldOrder -> Stanza name (sortFieldsBy fieldOrder fields) : go xs

@sol sol added the bug label Sep 21, 2022
@brandon-leapyear
Copy link
Author

brandon-leapyear commented Sep 21, 2022

This is an old work account. Please reference @brandonchinn178 for all future communication


Makes sense! I don't know if you have any end-to-end tests, but I think a simple end-to-end test for this could be:

  1. In an empty directory, create package.yaml that imports a common stanza adding a dependency (e.g. aeson or containers) + write a library file using that dependency (such that a cabal file lacking that dependency would fail to build)
  2. In that directory, run hpack and cabal
  3. Build should succeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants