Repository navigation
Description
I'd like to share an idea and get feedback as to whether such a change would be accepted in Cabal. Currently, selection of which components to build is done as part of the build step. I know of at least three issues with this:
- Dependencies for components we don't want to build must still be present. Consider a .cabal file with 2 executables: A has very few dependencies, and B has many dependencies. In order to build executable A, we have to provide all of the dependencies for B. (Related: dependencies are checked even if buildable is False #1725)
- Suppose a package has a library and two executables. If you build the library and one executable and then run the copy command, it will fail since the second executable is not present (see: copy command fails when building only some components #2780)
- If an executable relies on a library in the cabal file, there's no way to say "use the already installed version of the library, and don't rebuild the library here." This can be useful for avoiding unnecessary recompilation, especially in the presence of changing cabal_macros.h files (see: Disable library building, only build other components #2775)
My proposal: add a new command line option to the configure command, which will take a command-separated list of components to include, ignoring all other components. E.g.:
runghc Setup.hs configure --components=lib,exe:foo,test:bar,bench:baz
The semantics would be: all further commands run will implicitly filter out all non-listed components from the .cabal file.
An alternative- and possibly simpler- implementation that would be a bit hairier but still probably work would be providing a --cabal-file argument that would force Cabal to read from a given .cabal file. Then we could create temporary .cabal files with the necessary components stripped out.
Can someone comment on whether such a patch would be accepted, and give any insight into best approach to implementing if so?
Activity
23Skidoo commentedon Aug 30, 2015
This seems reasonable to me, and we already do this for benchmarks and test suites. Default behaviour could be the same as it is now.
/cc @dcoutts
snoyberg commentedon Sep 8, 2015
@23Skidoo Just to confirm: do we need to wait for @dcoutts to sign off on this proposal, or is this an acceptable idea to start implementing?
23Skidoo commentedon Sep 8, 2015
Duncan seems to be busy right now.
I think it's fine to start implementing as long as the patch is backwards-compatible, i.e.
cabal configure; cabal build exe:foostill works as before (butcabal configure --components=lib; cabal build exe:foofails like it now does for disabled test suites).snoyberg commentedon Sep 8, 2015
Cool, sounds like a reasonable requirement for the new feature.
phadej commentedon Oct 5, 2015
Could the first stage be to provide
--enable-library,--enable-executablesand disable counterparts to be consistent with existing--enable-testsand--enable-benchmarks?One immediate feature would be to be able to run tests against installed library, with
when test suite depends on the library and not
hs-source-dirs: test src.Either this first stage, or original issue could be doable task for this week hackathon?
ezyang commentedon Dec 21, 2015
@dcoutts hasn't responded here, but based on communication with him at last ICFP, my understanding is that Duncan is keen to resolve issues 1 and 2 differently, by having Cabal continue to configure all components by default, but making it non-fatal if some components cannot be configured. (And then fixing copy to not attempt to copy components which failed configuration.)
This doesn't fix 3, but maybe you just need a different flag to override internal dependencies.
ezyang commentedon Jan 19, 2016
(I guess I should add, my natural inclination is to do everything per component.)
ezyang commentedon Apr 5, 2016
@phadej You are right. In fact, this should be very straightforward to implement. Here's how to do it:
exeEnabledandlibraryEnabledfields toExecutableandLibrarydata types inDistribution.PackageDescription, and then updateallBuildInfoand other use sites oftestEnabledandbenchmarkEnabledto respect these new fields.configureFinalizedPackageinDistribution.Simple.Configureto also update libraries/executables based on the new flag you introduce. For simple flags like--enable-executablesit will look exactly just like the current code; if you want to implement--componentyou'll have to look more closely at the name of the component.Willing to advise someone who want so to do this.
One-component configure, fixes #2802.
One-component configure, fixes #2802.
One-component configure, fixes #2802.
One-component configure, fixes #2802.
One-component configure, fixes #2802.
6 remaining items
One-component configure, fixes haskell#2802.
One-component configure, fixes haskell#2802.
One-component configure, fixes haskell#2802.
ezyang commentedon Aug 12, 2016
CC @mgsloan. I just realized that my patchset doesn't solve this feature request in its entirety, because it only supports configuring a single component at a time, rather than multiple components. I suppose it would not be too difficult to extend the patchset to also support multiple components, but if you can configure one component at a time, is it still necessary?
By the way,
--cabal-filewas implemented in #3553.dcoutts commentedon Aug 12, 2016
For our general sanity I suggest we stick with one. This isn't useful as a human interface anyway, only as a machine for tools.
One-component configure, fixes haskell#2802.
One-component configure, fixes haskell#2802.
One-component configure, fixes haskell#2802.
One-component configure, fixes haskell#2802.
One-component configure, fixes haskell#2802.
One-component configure, fixes haskell#2802.
One-component configure, fixes haskell#2802.
One-component configure, fixes haskell#2802.