stack: prefer a committed .cabal over re-running hpack (#626, #767) - #2547
Open
hamishmack wants to merge 1 commit into
Open
stack: prefer a committed .cabal over re-running hpack (#626, #767)#2547hamishmack wants to merge 1 commit into
hamishmack wants to merge 1 commit into
Conversation
In the stack path, findCabalFiles UsePackageYamlFirst always re-rendered a package.yaml through hpack whenever it existed, even when the package directory also contained a committed .cabal file. This discarded the committed file and historically failed outright when the .cabal had been hand-modified or was produced by a newer hpack. The cabalProject path already prefers a committed .cabal (call-cabal-project-to-nix.nix skips hpack when a .cabal exists). Mirror that in the stack path: use the on-disk .cabal when present, falling back to hpack only when there is no .cabal. --ignore-package-yaml continues to force cabal-only discovery. Adds a self-contained (no external tools/network) test-suite stack-project-tests exercising findCabalFiles.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In the stack path,
findCabalFiles UsePackageYamlFirst(nix-tools/nix-tools/lib/Stack2nix/Project.hs) unconditionally re-rendered apackage.yamlthrough hpack whenever it existed — even when the package directory also contained a committed.cabalfile. This discards the committed file and historically failed outright with errors like ".cabal was generated with a newer version of hpack, please upgrade" (#626) or ".cabal was modified manually, please use --force" (#767).The cabal path already prefers a committed
.cabal(lib/call-cabal-project-to-nix.nixskips hpack for apackage.yamlwhen a.cabalexists — "Ignoring $hpackFile as $cabalFile exists"). This change mirrors that policy in the stack path: use the on-disk.cabalwhen present, and fall back to hpack only when there is no.cabal.--ignore-package-yaml(IgnorePackageYaml) continues to force cabal-only discovery.Tests
Adds a self-contained test-suite
stack-project-tests(only touches a temp dir — no external tools, no network, no extra test-framework deps) asserting thatfindCabalFiles:.cabalwhen both files exist (the Do not call hpack if .cabal exists #626/.cabal was modified manually, please use --force to overwrite. #767 regression),package.yamlexists,.cabalwhen only a.cabalexists,package.yamlunderIgnorePackageYaml.Verification
.cabalpresent vs. absent); the missing-dir / no-package.yamlbehaviour is unchanged.cabal checkpasses (only pre-existing PVP upper-bound warnings, unrelated to this change).Notes
findCabalFilesinplan2nix/Plan2Nix/Project.hsis left as-is: the cabal path already handles this at the Nix layer, and de-duplicating the two copies is out of scope here (related to the cache-module dedup theme in Drop duplicate code #1689).--use-package-yamlopt-out (to force stack's regenerate-always behaviour) was considered but skipped to keep the change minimal; it isn't offered on the cabal path either. Easy to add later if wanted.Closes #626.
Closes #767.