Skip to content

Re-run pre-build rules when necessary#4923

Draft
sheaf wants to merge 2 commits intohaskell:masterfrom
sheaf:hooks-integration
Draft

Re-run pre-build rules when necessary#4923
sheaf wants to merge 2 commits intohaskell:masterfrom
sheaf:hooks-integration

Conversation

@sheaf
Copy link
Copy Markdown
Contributor

@sheaf sheaf commented May 4, 2026

Companion to Cabal PR #11776.

This PR allow HLS to re-run pre-build rules when needed. That is, when either:

  • the files monitored by the pre-build rules change (causing recompilation of the set of pre-build rules), or
  • the file dependencies of a pre-build rule changes.

The existing logic in Cabal handles recompilation logic and only re-runs rules that are stale. See Cabal PR #11731 for more information on pre-build rule staleness.

sheaf added 2 commits May 4, 2026 12:36
This adds a new 'globWatchers' alongside the 'filesMap' for watching
glob patterns. This is used for cradle dependencies, so that HLS
reloads the cradle when these change.

The intended usage is to allow HLS to re-run the Cabal pre-build stage
when dependent files are modified, in particular with build-type: Hooks
and pre-build rules (but that part is left to a separate commit).
HLS now reads the pre-build rule monitor manifest file to determine
which files and file globs to monitor in order to detect when to re-run
pre-build rules.
Comment on lines +3 to +10
-- Use a version of Cabal that writes the pre-build rule manifest.
--
-- TODO: remove this.
source-repository-package
type: git
location: https://github.com/sheaf/cabal.git
subdir: Cabal-syntax Cabal Cabal-hooks
tag: 2a320cac93255683829768517ceadcd25cbf8f11
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I need to pin the Cabal version for the tests to ensure the pre-build rule manifest file is being written. I'm not sure whether there's a better way to do this? We need to guarantee we use the right Cabal library when compiling SetupHooks (or defaultMainWithSetupHooks setupHooks if we are falling back to the Setup CLI, e.g. because of an old cabal-install that is incompatible with this newer version of the Cabal library).

The fact that we need to compile SetupHooks against this version of Cabal also means the test is a bit slow to run as it needs to build Cabal-syntax, Cabal and Cabal-hooks.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We can run this test only if we can ensure the cabal-install version is recent enough and then ensure in CI the cabal version is new :)

@sheaf
Copy link
Copy Markdown
Contributor Author

sheaf commented May 4, 2026

Failing on Windows with MAX_PATH issues:

[26](https://github.com/haskell/haskell-language-server/actions/runs/25335333234/job/74279060001?pr=4923#step:7:627)
      Incorrect number of diagnostics for Uri {getUri = "file:///C:/hls-tests/extra-dir-177268041277/Lib.hs"}, expected [] but got [Diagnostic {_range = Range {_start = Position {_line = 0, _character = 0}, _end = Position {_line = 1, _character = 0}}, _severity = Just DiagnosticSeverity_Error, _code = Nothing, _codeDescription = Nothing, _source = Just "cradle", _message = "Failed to run \"cabal\" \"--builddir=C:\\hls-tests\\extra-dir-177268041278\\hie-bios\\dist-extra-dir-177268041277-46f4005854aceb29731f2d9725b5d4ba\" \"v2-repl\" \"--keep-temp-files\" \"--with-repl\" \"C:\\hls-tests\\extra-dir-177268041278\\hie-bios\\repl-wrapper-3dd8f256c63c7a9566653d0fd2b05e9d.exe\" \"Lib.hs\" in directory \"C:\\hls-tests\\extra-dir-177268041277\". Consult the logs for full command and error.\nFailed command: \"cabal\" \"--builddir=C:\\hls-tests\\extra-dir-177268041278\\hie-bios\\dist-extra-dir-177268041277-46f4005854aceb29731f2d9725b5d4ba\" \"v2-repl\" \"--keep-temp-files\" \"--with-repl\" \"C:\\hls-tests\\extra-dir-177268041278\\hie-bios\\repl-wrapper-3dd8f256c63c7a9566653d0fd2b05e9d.exe\" \"Lib.hs\"\n\nFrom [https://github.com/sheaf/cabal\n](https://github.com/sheaf/cabal/n) * branch                2a320cac93255683829768517ceadcd25cbf8f11 -> FETCH_HEAD\nwarning: unable to access 'cabal-install-solver/tests/UnitTests/Distribution/Solver/Modular/.gitattributes': Filename too long\nerror: unable to create file cabal-install-solver/tests/UnitTests/Distribution/Solver/Modular/MessageUtils.hs: Filename too long\nwarning: unable to access 'cabal-install/parser-tests/Tests/files/haddock-all-overwrite-false/.gitattributes': Filename too long\nerror: unable to create file cabal-install/parser-tests/Tests/files/haddock-all-overwrite-false/cabal.project: Filename too long\nwarning: unable to access 'cabal-install/parser-tests/Tests/files/haddock-all-overwrite-true/.gitattributes': Filename too long\nerror: unable to create file cabal-install/parser-tests/Tests/files/haddock-all-overwrite-true/cabal.project: Filename too long\nwarning: unable to access 'cabal-install/parser-tests/Tests/files/project-config-all-packages/.gitattributes': Filename too long\nerror: unable to create file cabal-install/parser-tests/Tests/files/project-config-all-packages/cabal.project: Filename too long\nwarning: unable to access 'cabal-install/parser-tests/Tests/files/project-config-build-only/.gitattributes': Filename too long\nfatal: cannot create directory at 'cabal-install/parser-tests/Tests/files/project-config-local-packages': Filename too long\n\n\nProcess Environment:\n", _tags = Nothing, _relatedInformation = Just [DiagnosticRelatedInformation {_location = Location {_uri = Uri {getUri = "file:///C:/hls-tests/extra-dir-177268041277/Lib.hs"}, _range = Range {_start = Position {_line = 0, _character = 0}, _end = Position {_line = 1, _character = 0}}}, _message = "GhcSession"}], _data_ = Just (Object (fromList [("cradleDependencies",Array [String "C:\\hls-tests\\extra-dir-177268041277\\setup-hooks-test.cabal",String "C:\\hls-tests\\extra-dir-177268041277\\cabal.project",String "C:\\hls-tests\\extra-dir-177268041277\\cabal.project.local"]),("structuredCradleError",Null)]))}]

Not sure why the test is hanging on Linux, I will investigate tomorrow.

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