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

Warn if builddir is going to be ignored #8949

Merged
merged 4 commits into from
May 31, 2023

Conversation

andreabedini
Copy link
Collaborator

Closes: #7941


Please include the following checklist in your PR:

Bonus points for added automated tests!

@ulysses4ever
Copy link
Collaborator

Terrific! I'll take a look later but in the meantime: does it also address #8947?

@andreabedini
Copy link
Collaborator Author

andreabedini commented May 22, 2023

@ulysses4ever This PR addresses #7941 that is: builddir is ignored without a warning. It does not address or attempts to solve #8947 & #5271 since that is a more complex issue.

Note to myself. I am only warning about builddir beign not supported in project files but it seems also not supported in the global config? I need to double check.

@andreabedini andreabedini self-assigned this May 22, 2023
@ulysses4ever
Copy link
Collaborator

I was unclear, i guess, when i referenced #8947. I'm asking to check if this warning will be printed when builddir comes not from a project file (which was your original motivation, afaiu) but from the global config. In my mind, this is very likely, but maybe I'm utterly wrong.

@andreabedini
Copy link
Collaborator Author

I was unclear, i guess, when i referenced #8947. I'm asking to check if this warning will be printed when builddir comes not from a project file (which was your original motivation, afaiu) but from the global config.

It was indeed my original motivation but on a second reading I realised builddir is ignored also from the global config. As it stands this change will not warn on the global config, because readGlobalConfig calls the old loadConfig rather than readProjectFileSkeleton.

I can make the warning appear irrespectively from where buildir is set by moving the check. I will do that.

@andreabedini andreabedini force-pushed the warn-on-ignored-builddir branch from de0ad02 to 74c46ae Compare May 22, 2023 14:15
@andreabedini
Copy link
Collaborator Author

@ulysses4ever I have corrected the manual too. As far as I can tell everytime the manual says "This option cannot be specified via a cabal.project file" it means the global config file too, effectively meaning "can only be specified from the command line".

Copy link
Collaborator

@ulysses4ever ulysses4ever left a comment

Choose a reason for hiding this comment

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

Terrific!

@ulysses4ever
Copy link
Collaborator

As far as I can tell everytime the manual says "This option cannot be specified via a cabal.project file" it means the global config file too, effectively meaning "can only be specified from the command line".

Maybe we should update the other places like that (to say "only command line"). I think it'd read much clearer.

@andreabedini
Copy link
Collaborator Author

andreabedini commented May 23, 2023

Maybe we should update the other places like that (to say "only command line"). I think it'd read much clearer.

If you agree with my interpretation, yes, I can definitely do that. This is how I think it works:

establishProjectBaseContext verbosity cliConfig currentCommand = do
    projectRoot <- either throwIO return =<< findProjectRoot verbosity mprojectDir mprojectFile
    establishProjectBaseContextWithRoot verbosity cliConfig projectRoot currentCommand
  where
    mprojectDir    = Setup.flagToMaybe projectConfigProjectDir
    mprojectFile   = Setup.flagToMaybe projectConfigProjectFile
    ProjectConfigShared { projectConfigProjectDir, projectConfigProjectFile } = projectConfigShared cliConfig

-- which calls

establishProjectBaseContextWithRoot verbosity cliConfig projectRoot currentCommand = do
    let haddockOutputDir = flagToMaybe (packageConfigHaddockOutputDir (projectConfigLocalPackages cliConfig))
    let distDirLayout = defaultDistDirLayout projectRoot mdistDirectory haddockOutputDir

    httpTransport <- configureTransport verbosity
                     (fromNubList . projectConfigProgPathExtra $ projectConfigShared cliConfig)
                     (flagToMaybe . projectConfigHttpTransport $ projectConfigBuildOnly cliConfig)

    (projectConfig, localPackages) <-
      rebuildProjectConfig verbosity
                           httpTransport
                           distDirLayout
                           cliConfig
    ...

-- which calls

rebuildProjectConfig verbosity httpTransport DistDirLayout {...} cliConfig = do
    ...
    (projectConfig, localPackages) <-
      runRebuild distProjectRootDirectory
      $ ...
      $ do
          ...
          projectConfig <- instantiateProjectConfigSkeletonFetchingCompiler ...
          localPackages <- phaseReadLocalPackages (projectConfig <> cliConfig)
          return (projectConfig, localPackages)
    ...
    return (projectConfig <> cliConfig, localPackages)
  • You can see that: projectConfigProjectDir, projectConfigProjectFile, packageConfigHaddockOutputDir, projectConfigProgPathExtra, projectConfigHttpTransport are effective only when set through the command line (cliConfig).
  • All the configurations are eventually merged into a single ProjectConfig but only after the above settings are used.

If we want to be able to read those settings from a global configuration file, we would need to move them out from ProjectConfig to a separate object which can be read at the very start; and somehow incorporate these "initial settings" with the other "project settings" in the global configuration file. But I'd suggest we do that only after we finish the transition to the new parser (see #6101 and #8889).

@ulysses4ever If you agree with the above analysis, I will change what the manual says about the above mentioned options (projectConfigProjectDir, projectConfigProjectFile, packageConfigHaddockOutputDir, projectConfigProgPathExtra and projectConfigHttpTransport)

@ulysses4ever
Copy link
Collaborator

@andreabedini this is an astonishingly clear description, thank you! It matches what I was able to discern myself about project config. I am in total support of improving the manual as discussed.

I also think your description would be nice to put somewhere. Either comments in some source file (e.g. ProjectOrchestration.hs) or the wiki here. The former probably has a much higher chance to be read by someone. It may be a sort of a GHC Note in the source...

@andreabedini
Copy link
Collaborator Author

@ulysses4ever Done. I added a note about the interaction between --http-transport and --extra-prog-path. I decided to leave --haddock-output-dir alone because I am not sure about it. It seems to be fixed in the distDirLayout but then it's also used later on.

@ulysses4ever
Copy link
Collaborator

Andrea, while we're on it (the famous last words...), what do you think about defaulting packages to the current directory even if a project file is present? This has been requested numerous times. At least, #8679 and #5850. I think it's pretty clear that having the same default, whether you have a project file or not, is a better UX. Maybe we could rip this band aid in this pr too?

@ulysses4ever
Copy link
Collaborator

@andreasabel since this PR addresses the issue you opened (#7941), would you mind giving it a review if time allows?

Copy link
Member

@andreasabel andreasabel left a comment

Choose a reason for hiding this comment

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

Great, thanks!

@andreasabel andreasabel added re: project-file Concerning cabal.project files re: builddir labels May 27, 2023
@andreabedini
Copy link
Collaborator Author

Andrea, while we're on it (the famous last words...), what do you think about defaulting packages to the current directory even if a project file is present? This has been requested numerous times. At least, #8679 and #5850. I think it's pretty clear that having the same default, whether you have a project file or not, is a better UX. Maybe we could rip this band aid in this pr too?

I suggest we leave that for another PR. I commented on that thread.

@ulysses4ever
Copy link
Collaborator

ulysses4ever commented May 27, 2023

Sounds good, thank you. Please, feel free to apply the squash+merge label as soon as you feel comfortable.

@andreabedini andreabedini force-pushed the warn-on-ignored-builddir branch from 3e39727 to 179cbf0 Compare May 27, 2023 15:22
@andreabedini andreabedini added the squash+merge me Tell Mergify Bot to squash-merge label May 27, 2023
@andreabedini andreabedini force-pushed the warn-on-ignored-builddir branch from 179cbf0 to 7203776 Compare May 29, 2023 07:09
Passing --ignore-project made cabal use `defaultProject` which is not
quite identical to the one used when cabal.project is missing
(`defaultImplifictProjectConfig`). There is no reason the two should be
different.
builddir can only be specified from the command line.

Closes: haskell#7941
@andreabedini andreabedini force-pushed the warn-on-ignored-builddir branch from 7203776 to d02be62 Compare May 29, 2023 07:37
@andreabedini andreabedini force-pushed the warn-on-ignored-builddir branch from d02be62 to 0ba2fe8 Compare May 29, 2023 13:55
@mergify mergify bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label May 31, 2023
@mergify mergify bot merged commit eaa38b6 into haskell:master May 31, 2023
@andreabedini andreabedini deleted the warn-on-ignored-builddir branch May 31, 2023 16:37
@andreabedini andreabedini restored the warn-on-ignored-builddir branch July 10, 2023 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days re: builddir re: project-file Concerning cabal.project files squash+merge me Tell Mergify Bot to squash-merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Entry builddir: <dir> silently ignored from cabal.project
4 participants