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

Expand and unify --keep-temp-files #10292

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

9999years
Copy link
Collaborator

@9999years 9999years commented Aug 29, 2024

This is blocking #9367.

Currently, cabal repl has a --keep-temp-files option, and cabal.project has a keep-temp-files option but it only affects Haddock builds.

This patch adds --keep-temp-files to CommonSetupFlags, making it available to all commands. The expanded --keep-temp-files flag is used for the cabal repl command and Haddock builds (retaining compatibility with the previous behavior). The flag will also be used for response files; see #9367.

Template Α: This PR modifies behaviour or interface

Include the following checklist in your PR:

  • Patches conform to the coding conventions.
  • Any changes that could be relevant to users have been recorded in the changelog.
  • The documentation has been updated, if necessary.
  • Manual QA notes have been included.
  • Tests have been added. (Ask for help if you don’t know how to write them! Ask for an exemption if tests are too complex for too little coverage!)

Depends-on: #10395
Depends-on: #10392
Depends-on: #10391
Depends-on: #10390
Depends-on: #10389
Depends-on: #10394
Depends-on: #10388
Depends-on: #10393

@9999years 9999years force-pushed the rebeccat/keep-temp-files branch 4 times, most recently from 69f0104 to 1e05052 Compare September 5, 2024 00:56
@9999years 9999years marked this pull request as ready for review September 5, 2024 16:29
@9999years 9999years added the merge me Tell Mergify Bot to merge label Sep 6, 2024
@sheaf
Copy link
Collaborator

sheaf commented Sep 8, 2024

One concern I have is that CommonSetupFlags is meant to be for flags common to all Setup invocations (it's a Cabal library concept). I don't think cabal-install should directly be re-using it unless it is for the purpose of invoking Setup.

I don't fully understand how the haddock-project command was implemented. I thought it was supposed to be a cabal-install-only concept, yet I see that there is a fair amount of code related to "haddock project" in the Cabal library as well, which doesn't really make sense to me.

I'm not objecting to this PR (which I am happy to see), but I would like to make sure that you have taken into consideration the logical separation between the Cabal library and cabal-install.

@9999years
Copy link
Collaborator Author

One concern I have is that CommonSetupFlags is meant to be for flags common to all Setup invocations ...

Yes, I wasn't entirely sure where to put this flag. There seem to be a lot of flags that are shared between multiple commands (like --enable-split-objs or --builddir or --with-compiler or --package-db etc. etc. etc. — in fact, diffing the --help messages for cabal build and cabal install reveals that the vast majority of the flags are identical). These flags seem to be placed in essentially random places in the code (if there's a schema for these decisions, it's not documented in any place I looked).

I picked CommonSetupFlags because it's already passed to all the places I need it in #9367. I think that adding it to (e.g.) the build flags or install flags or configure flags specifically would result in a much more invasive change. However, if there's some place you know it should be, I can look into moving it.

@9999years 9999years force-pushed the rebeccat/keep-temp-files branch 2 times, most recently from e0ea1a0 to 4156c93 Compare September 16, 2024 23:59
{ -- Cabal < 3.13 does not support the --working-dir flag.
setupWorkingDir = NoFlag
, -- Or the --keep-temp-files flag.
setupKeepTempFiles = NoFlag
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure this is accurate, some commands did support --keep-tmp-files before?

What happens if you are using repl -keep-tmp-files with an older Cabal version? Is that broken by this patch?

Copy link
Collaborator

@geekosaur geekosaur Sep 25, 2024

Choose a reason for hiding this comment

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

Some commands did, in an ad hoc fashion; my understanding is that the point of this patch is to extend that to all commands and ensure they behave consistently.

Copy link
Collaborator

Choose a reason for hiding this comment

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

See also #10209.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added a test that I believe will exercise this case and run it with --boot-cabal-lib:

https://github.com/MercuryTechnologies/cabal/blob/8255fc1e83df0f9f5f29222b128815ce37978cc6/cabal-testsuite/PackageTests/MultiRepl/CustomSetupKeepTempFiles/cabal.test.hs

Let me know if this is sufficient, or if I missed a detail.

Here's the patch to validate.sh I used:

diff --git a/validate.sh b/validate.sh
index b22e033f8..40c4bfcb1 100755
--- a/validate.sh
+++ b/validate.sh
@@ -505,7 +505,7 @@ CMD="$($CABALLISTBIN cabal-install:test:integration-tests2) -j1 --hide-successes
 step_cli_suite() {
 print_header "cabal-install: cabal-testsuite"
 
-CMD="$($CABALLISTBIN cabal-testsuite:exe:cabal-tests) --builddir=$CABAL_TESTSUITE_BDIR --with-cabal=$($CABALLISTBIN cabal-install:exe:cabal) $TESTSUITEJOBS  --with-ghc=$HC --hide-successes --intree-cabal-lib=$PWD --test-tmp=$PWD/testdb $RTSOPTS"
+CMD="$($CABALLISTBIN cabal-testsuite:exe:cabal-tests) --builddir=$CABAL_TESTSUITE_BDIR --with-cabal=$($CABALLISTBIN cabal-install:exe:cabal) $TESTSUITEJOBS  --with-ghc=$HC --hide-successes --boot-cabal-lib $RTSOPTS PackageTests/MultiRepl/CustomSetupKeepTempFiles/cabal.test.hs"
 (cd cabal-testsuite && timed $CMD) || exit 1
 }

@mpickering
Copy link
Collaborator

I think the patch looks good, apart from I think it won't work if you are using a custom setup built with an older version of Cabal. See my comment.

@geekosaur
Copy link
Collaborator

We need an old-ghcs test job with custom setup, as we already have backward compatibility breakage that leaked through (#10379).

9999years added a commit to MercuryTechnologies/cabal that referenced this pull request Sep 27, 2024
This lets the `--keep-temp-files` options to `cabal haddock` and `cabal
repl` work with an older Cabal version.

Pointed out by @mpickering:
haskell#10292 (comment)
9999years added a commit to MercuryTechnologies/cabal that referenced this pull request Sep 27, 2024
This lets the `--keep-temp-files` options to `cabal haddock` and `cabal
repl` work with an older Cabal version.

Pointed out by @mpickering:
haskell#10292 (comment)
@9999years 9999years mentioned this pull request Sep 27, 2024
2 tasks
9999years added a commit to MercuryTechnologies/cabal that referenced this pull request Sep 27, 2024
This lets the `--keep-temp-files` options to `cabal haddock` and `cabal
repl` work with an older Cabal version.

Pointed out by @mpickering:
haskell#10292 (comment)
In haskell#10292, we will move the `--keep-temp-files` setting into
`CommonSetupFlags` and out of `ReplFlags`/`HaddockFlags`. This means
that the flag-filtering behavior (which adapts flags from new versions
of `cabal-install` to old version of `Cabal`) will need to know which
command is being run to provide the correct `CommonSetupFlags`.

Therefore, this change adds several new `filterFooFlags` functions to
provide this behavior, and removes the `commonFlags` used for all
subcommands in `Distribution.Client.ProjectBuilding.UnpackedPackage`.
@9999years
Copy link
Collaborator Author

This PR has gotten too large to effectively review, so I've split out many of the changes into separate, smaller PRs:

Once those PRs are all merged, this change will only have ~100 lines to review.

Currently, `cabal repl` has a `--keep-temp-files` option, and
`cabal.project` has a `keep-temp-files` option but it only effects
Haddock builds.

This patch adds `--keep-temp-files` to `CommonSetupFlags`, making it
available to all commands. The expanded `--keep-temp-files` flag is used
for the `cabal repl` command and Haddock builds (retaining compatibility
with the previous behavior) but is also used to determine when to keep
response files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Tell Mergify Bot to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants