Skip to content

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

Open

Description

@michaelpj

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.

Activity

  1. Mikolaj commented on Aug 4, 2021

    @Mikolaj
    Member

    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?

  2. Mikolaj commented on Aug 4, 2021

    @Mikolaj
    Member

    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.

  3. fendor commented on Aug 4, 2021

    @fendor
    Collaborator

    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.

  4. Mikolaj commented on Aug 4, 2021

    @Mikolaj
    Member

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

    OK, so we discovered a bug as well.

  5. fendor commented on Aug 4, 2021

    @fendor
    Collaborator

    Looks rather intentional to me:

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

  6. Mikolaj commented on Aug 4, 2021

    @Mikolaj
    Member

    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?

  7. fendor commented on Aug 4, 2021

    @fendor
    Collaborator

    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.
  8. TeofilC commented on Dec 8, 2021

    @TeofilC
    Member

    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
  9. bacchanalia commented on Jan 2, 2022

    @bacchanalia
    Collaborator

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

  10. changed the title [-]Per package/component `cabal clean`[/-] [+]Per package/component `cabal clean` (add support for targets)[/+] on May 1, 2022
  11. jneira commented on May 11, 2022

    @jneira
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions