Skip to content

Display within which cabal.project we build #8519

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

Closed
mgajda opened this issue Oct 9, 2022 · 10 comments · Fixed by #10507
Closed

Display within which cabal.project we build #8519

mgajda opened this issue Oct 9, 2022 · 10 comments · Fixed by #10507

Comments

@mgajda
Copy link

mgajda commented Oct 9, 2022

Describe the bug

The cabal behaves differently depending whether any of the ancestor directories has cabal.project or not.
Since we should not demand the user to only ever test builds within a fresh /tmp directory, and large builds
may easily have multiple cabal.projects, it would be nice to warn the user which cabal.project we use, or that there is none used in this case.

To Reproduce

Steps to reproduce the behavior:

$ git clone https://gitlab.com/migamake/homplexity
$ cabal new-build
$ cabal sdist
$ cd dist-newstyle/sdist
$ tar xzf homplexity-*.tar.gz
$ echo "Let's test the build...."
$ cd homplexity-*
$ cabal new-build

This build breaks.

If we do:

$ mkdir /tmp/homplexity-test
$ tar xzf $MYPATH/homplexity*.tar.gz
$ cabal new-build

We get a correct build.

The only difference is absence of the cabal.project file in the second case.

Expected behavior

cabal new-build should tell why its behaviour differs by indicating which cabal.project is used,
or printing no cabal project.

System information

  • any
  • cabal 3.4.1,0
  • ghc version -- does not matter
@ffaf1
Copy link
Collaborator

ffaf1 commented Oct 9, 2022

Do you propose a Using cabal.project at ~/some/folder/cabal.project before Resolving dependencies...?

@ulysses4ever ulysses4ever added type: enhancement re: project-file Concerning cabal.project files labels Oct 9, 2022
@ulysses4ever
Copy link
Collaborator

ulysses4ever commented Oct 9, 2022

Yes, very close discussion is in #7930. By all means please do this. I expect it to be a 1-line change.

@pigsinablanket
Copy link

pigsinablanket commented Nov 19, 2022

If you pass in --verbose=2, cabal will specify which cabal.project are being used.
https://github.com/haskell/cabal/blob/master/cabal-install/src/Distribution/Client/ProjectPlanning.hs#L344

    info verbosity
      $ unlines
      $ ("this build was affected by the following (project) config files:" :)
      $ [ "- " ++ path
        | Explicit path <- Set.toList $ projectConfigProvenance projectConfig
        ]

Should this be output by default?

@ulysses4ever
Copy link
Collaborator

@pigsinablanket brilliant! It should be a matter of changing info to notice in that snippet. Do you want to submit a PR? I expect a little annoyance with updating the testsuite, but it should be easy solve by supplying --accept when running the testsuite. This means that you have to run it locally though (as opposed to simply edit the line in GitHub web interface and be done with it).

@ulysses4ever
Copy link
Collaborator

3.10 is quickly approaching, and I hope to have this in it, so I add it to the project…

ulysses4ever added a commit to ulysses4ever/cabal that referenced this issue Nov 23, 2022
@pigsinablanket
Copy link

@pigsinablanket brilliant! It should be a matter of changing info to notice in that snippet. Do you want to submit a PR? I expect a little annoyance with updating the testsuite, but it should be easy solve by supplying --accept when running the testsuite. This means that you have to run it locally though (as opposed to simply edit the line in GitHub web interface and be done with it).

@ulysses4ever Running the tests locally with --accept worked, except in some tests it used the fully qualified path for the cabal.project instead of <ROOT> as it generates in other tests. Is there a reason the normalizer is not resolving the path?

Updating the cabal.out to use <ROOT> after running the testsuite with --accept didn't work.

 this build was affected by the following (project) config files:
-- <ROOT>/cabal.project
+- /home/daniel/git/cabal/cabal.project

@ulysses4ever
Copy link
Collaborator

@pigsinablanket interesting. I wouldn't expect manual editing of the result of --accept to work. Could you perhaps commit the result as is, submit the PR, and see what CI has to say about it, please?

Also, while we're at it, may I propose a slight rewording of the message? My preference, instead of

this build was affected by the following (project) config files:

to have

This build is affected by the following project file(s):

@ulysses4ever
Copy link
Collaborator

("result as is" meaning: commit exactly what --accept did)

pigsinablanket added a commit to pigsinablanket/cabal that referenced this issue Nov 24, 2022
* Print what cabal.project files get used

* Update testsuite
@gbaz gbaz added this to the Considered for 3.12 milestone Jun 8, 2023
@andreasabel
Copy link
Member

This isn't just a one-line change, as demonstrated by PR #8617, so I am removing the respective label.
What is left to do here is to only print the info when cabal is actually building something, not on side commands like cabal update, cabal info, or on installation from remote (cabal install --ignore-project Foo).

@juhp
Copy link
Collaborator

juhp commented Oct 19, 2023

I am afraid I honestly feel the current behavior (including the error message) is pretty terrible...

cabal build should not trip over just because there is a cabal.project in some upper directory.
Heavens cabal build doesn't even work in eg a src/ subdir anyway, shrug.
What is the use-case for the current behaviour actually?

ie if cabal build is run in a non-project package dir, couldn't it just ignore parent cabal.project?

ulysses4ever added a commit that referenced this issue Nov 3, 2024
ulysses4ever added a commit that referenced this issue Nov 7, 2024
@mergify mergify bot closed this as completed in a6082fc Nov 7, 2024
mergify bot added a commit that referenced this issue Nov 7, 2024
Print out which project file we're using by default (fix #8519)
mergify bot pushed a commit that referenced this issue Nov 7, 2024
Before it's only printed under `-v`.

(cherry picked from commit a6082fc)

# Conflicts:
#	cabal-testsuite/PackageTests/MultiRepl/CustomSetupKeepTempFiles/cabal.no.out
#	cabal-testsuite/PackageTests/MultiRepl/CustomSetupKeepTempFiles/cabal.yes.out
#	cabal-testsuite/PackageTests/MultiRepl/KeepTempFiles/cabal.no.out
#	cabal-testsuite/PackageTests/MultiRepl/KeepTempFiles/cabal.yes.out
#	cabal-testsuite/PackageTests/NewBuild/CmdClean/CleanSourceRepositoryPackage/cabal.out
ulysses4ever added a commit that referenced this issue Nov 7, 2024
Mikolaj pushed a commit that referenced this issue Nov 7, 2024
mergify bot added a commit that referenced this issue Nov 7, 2024
Backport #10507: Print out which project file we're using by default (fix #8519)
@ulysses4ever ulysses4ever linked a pull request Mar 30, 2025 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants