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

Per package/component cabal clean (add support for targets) #7506

Open
michaelpj opened this issue Aug 4, 2021 · 10 comments
Open

Per package/component cabal clean (add support for targets) #7506

michaelpj opened this issue Aug 4, 2021 · 10 comments

Comments

@michaelpj
Copy link
Collaborator

cabal clean is both simple and effective, by virtue of just deleting everything. However, in a multi-package project, I usually want to clean just one package or component that I'm working on.

Of course, the current implementation works for this, but once you accrue a few local packages and a few source-repository-packages, redoing all the work instead of just the last bit becomes painful.

At the moment I work around this by deleting targeted fragments of dist-newstyle/build. This works, but:

  • it's clumsy
  • it's not discoverable
  • it's probably not comprehensively cleaning the package (I have no idea if it gets all the files!)

I think it would be nice to provide a per package/component cabal clean, and hopefully it would just be a matter of listing all the relevant files and deleting them.

@Mikolaj
Copy link
Member

Mikolaj commented Aug 4, 2021

I guess we'd need to delete the package or component files and the common files. The trouble is identifying those, in particular if they are not generated with cabal build but only with some other commands or with some specific options.

What does cabal clean do exactly? Only remove dist-newstyle or anything else?

@Mikolaj
Copy link
Member

Mikolaj commented Aug 4, 2021

I see there is option

-s, --save-config              Save configuration, only remove build artifacts

I wonder what's 'configuration' and 'artifacts' and if there is anything more. Code-diving would help.

@fendor
Copy link
Collaborator

fendor commented Aug 4, 2021

I see there is option

-s, --save-config              Save configuration, only remove build artifacts

I wonder what's 'configuration' and 'artifacts' and if there is anything more. Code-diving would help.

As far as I can tell, that flag is just being ignored, but the code path should delete only dist-newstyle/build which is still not fine-grained enough for the proposed feature.

@Mikolaj
Copy link
Member

Mikolaj commented Aug 4, 2021

As far as I can tell, that flag is just being ignored

OK, so we discovered a bug as well.

@fendor
Copy link
Collaborator

fendor commented Aug 4, 2021

Looks rather intentional to me:

but the commit message itself gives no indication whether it really is intentional

@Mikolaj
Copy link
Member

Mikolaj commented Aug 4, 2021

May it be that 'configuration' is only cabal.project.local, which is not removed by cabal clean and that's why cabal clean never removes configuration in the new v2- world? If so, we should mark the -s flag "deprecated; configuration is always saved now" once v1- commands are removed.

However, if 'configuration' is cabal.project.local and artifacts are dist-newstyle/build, is there anything else? E.g., any kind of caches? E.g., when downloading packages form repos?

@fendor
Copy link
Collaborator

fendor commented Aug 4, 2021

I think currently cabal clean considers everything in dist-newstyle/build as build artefacts (which makes sense) and other files, e.g. dist-newstyle/cache is configuration.

However, the help message from Setup.hs actually tells us roughly that:

-s --save-configure Do not remove the configuration file (dist/setup-config)
                     during cleaning. Saves need to reconfigure.

Not exactly the same flag but looks similar. Maybe --save-config is a remnant from Setup.hs that doesn't make much sense in cabal v2 world? I would argue at least in that sense.


Regarding the issue, I think there are two ways of tackling this:

  • Calling Setup.hs clean for each component listed on the command line
  • Basically call the functions from Cabal manually (assuming there are no Buildhooks) with the right parameters Just checked, there is a postClean Hook. Only method one remains.

@TeofilC
Copy link
Collaborator

TeofilC commented Dec 8, 2021

As I mentioned on #7857, I'd be interested in trying to implement this.

On the other ticket:

  • @gbaz made the good point that when cleaning a component, we want to also clean anything that depends on it.
  • @bacchanalia mentioned this overlaps with their work on Better support for running scripts. #7851. So, it seems to me like it would make sense to wait until that's merged to avoid conflicts

@bacchanalia
Copy link
Collaborator

@TeofilC #7851 has been merged, so you should be clear if you want to work on this.

@jneira jneira changed the title Per package/component cabal clean Per package/component cabal clean (add support for targets) May 1, 2022
@jneira
Copy link
Member

jneira commented May 11, 2022

cabal clean serves as a simple workaround for lot of problems hard to fix properly. Having a more fine grained cleaning would make the workaround more attractive

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

No branches or pull requests

6 participants