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

Monitor also ghc.shim file on Windows #10853

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jasagredo
Copy link
Collaborator

@jasagredo jasagredo commented Mar 25, 2025

On Linux, when changing the compiler cabal says:

File monitor 'compiler' changed: file /home/javier/.ghcup/bin/ghc

On Windows after this fix it will say:

File monitor 'compiler' changed: file C:\ghcup\bin\ghc.shim

which actually is the file that changes when GHCup switches versions.

QA

$ cabal init -n -m
$ cabal build dry-run
$ ghcup set ghc $OTHERVERSION
$ cabal build dry-run -v3
...
File monitor 'compiler' changed: file C:\ghcup\bin\ghc.shim

Template Α: This PR modifies behaviour or interface

Include the following checklist in your PR:

@jasagredo jasagredo linked an issue Mar 25, 2025 that may be closed by this pull request
@jasagredo jasagredo force-pushed the js/detect-change-compiler-windows branch 2 times, most recently from 4045609 to ebad40d Compare March 25, 2025 22:09
@jasagredo
Copy link
Collaborator Author

I think adding a test that tests multiple GHC versions changing is out of the capabilities of the test setup, so I ask for permission to merge this without a test.

@jasagredo jasagredo force-pushed the js/detect-change-compiler-windows branch from ebad40d to e5e5884 Compare March 25, 2025 22:14
@jasagredo jasagredo requested a review from mpickering March 25, 2025 22:14
@jasagredo jasagredo requested a review from hasufell March 25, 2025 22:21
@hasufell
Copy link
Member

To be honest... this is a huge hack.

Cabal shouldn't be required to know about this. It's an implementation detail of GHCup.

The culprit is that windows doesn't have reliable symbolic link support.

What cabal should really care about is the GHC version or even ABI. Can we not run ghc --numeric-version instead of hashing the file contents?

@jasagredo
Copy link
Collaborator Author

It is indeed a big hack. I am open to suggestions.

I think changing the whole mechanism for detecting changes from files changing to output of commands sounds like a big task, but it might indeed be the right way of solving this.

@@ -989,6 +989,9 @@ programsMonitorFiles progdb =
monitorFileSearchPath
(programMonitorFiles prog)
(programPath prog)
++ if programId prog == "ghc" && buildOS == Windows
then [monitorFile $ programPath prog -<.> "shim"]
Copy link
Member

Choose a reason for hiding this comment

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

what if the file doesn't exist?

@Kleidukos
Copy link
Member

@jasagredo Considering the tricky nature of this PR, I think it would have been better to discuss it in a ticket beforehand and gather feedback from all parties.

@mpickering
Copy link
Collaborator

@jasagredo I do agree this is a bit hacky but it might be the best thing to do.

If you want to implement it like this, the correct way to do so would be to add this path to programMonitorFiles for ghc.

The other alternative, is to modify the caching logic for this step. Firstly you would need to split up the configCompilerEx function into two parts.

  • The first part just calls requireProgramVersion to get the path to the ghcProg and ghcVersion.
  • The second part (cached) does everything else that configure currently does.

How does that sound to you?

@jasagredo
Copy link
Collaborator Author

@Kleidukos Feel free to continue the discussion in the linked issue. I just thought it would be better for discussion to have the proposed change somewhere as it is barely 3 lines of code.

@jasagredo
Copy link
Collaborator Author

jasagredo commented Mar 26, 2025

If you want to implement it like this, the correct way to do so would be to add this path to programMonitorFiles for ghc.

The way programMonitorFiles is used there it is assumed already that those files must be non-existent, see the function called:

-- | Creates a list of files to monitor when you search for a file which
-- unsuccessfully looked in @notFoundAtPaths@ before finding it at
-- @foundAtPath@.
monitorFileSearchPath :: [FilePath] -> FilePath -> [MonitorFilePath]
monitorFileSearchPath notFoundAtPaths foundAtPath =
  monitorFile foundAtPath
    : map monitorNonExistentFile notFoundAtPaths

So we would have to use some other new field for this.

@jasagredo
Copy link
Collaborator Author

An unrelated note: programMonitorFiles sounds like files that we want to monitor, like in this case ghc.shim. I think the use of this field would actually fit better with the name programMonitorsNotFoundAt.

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

Successfully merging this pull request may close these issues.

Changing the compiler on Windows is not detected
4 participants