Repository navigation
Description
( this is a project task description for the upcoming https://github.com/haskell/cabal/wiki/Hackathon2015 )
One complaint about the .cabal format is that there's avoidable duplication when multiple stanzas requiring to repeat some shared properties are involved (most notably build-depends)
Here's an example how common stanzas could be used:
name: thispkg
version: 1.2.3
cabal-version: >=2.0
-- ...
flag small_base
description: Choose the new smaller, split-up base package.
-- unnamed global common stanza included implicitly in all library/executable/benchmark/test stanzas
common
build-depends: base-orphans < 1
-- named common stanza which needs to be explicitly included
common cdef1
hs-source-dirs: src
build-depends: text
if flag(small_base)
build-depends: base >=2.1 && <5, array, containers, directory
else
build-depends: base >= 1.0
library
include cdef1
build-depends: parsec
other-modules:
test-suite tests
type: exitcode-stdio-1.0
main-is: test.hs
include cdef1
build-depends: thispkg, tasty
benchmark bench1
type: exitcode-stdio-1.0
main-is: bench1.hs
include cdef1
build-depends: thispkg, criterion
In the example above a single common section named cdef1 is defined, which is included by all 3 real stanzas. include cdef acts as if the respective common stanza's body was inserted in place of include cdef.
Possible extensions
- reserve a few special common stanza ids
all,library,test-suites, andbenchmarkto declare common stanzas that are implicitlyincluded by the respective named real stanza. In the example above we could have usedcommon allinstead ofcommon cdef1and allinclude cdef1simply removed. - allow recursive (but acyclic) includes. I.e. allow common stanzas to
includeother common stanzas.
/cc @dcoutts
@dcoutts suggests to support both,
- named sections and explicit include at uses sites
- unnamed global (implicit include into start of all sections) (would subsume Package global build-depends should apply constraints to all components #3404)
Moreover, we'd want this mechanism not only for .cabal files but also for cabal's config files. For non-.cabal files we want to reuse the infrastructure for file-backed include files (include-file ./some-ast-frament.inc).
refinement: common stanzas ought to be typed so we can catch mistakes early on during parsing already, see #2832 (comment)
Activity
phadej commentedon Jul 25, 2016
As I can see from proposal,
includecommands can occur in any position.Does this imply that they are handled by parser, i.e. not visible in
GenericPackageDescription.From tooling point of view, I'd like to see them in
GenericPackageDescription, but as structure of data type doesn't easily support "includeanywhere" approach:CondTreewould need to be on[Either IncludeField a]. Yet "includeat the beginning of the section" would be simpler:([IncludeField], a):Shortly, which:
phadej commentedon Jul 25, 2016
Another comment,
includecommands will occur incabal.projectfield to, meaning to include other file. Maybe we can think this naming thru a bit better. Probably common stanzas would be nice for project files too.hvr commentedon Jul 25, 2016
@phadej as to the file-including, there's two ideas on the table, either use non-overloaded
include-fileto refer to files, or inferincludereferring to a file by occurence of/s. E.g.include ./foowould refer to a file, whereasinclude foowould refer to a local named include-stanza. One could have optionalfile:/common:prefixes for overriding the detection, and allow for additional types (e.g.http:)Then
include file:foowould refer to a filefoorather than a common stanza namedfoo.phadej commentedon Jul 25, 2016
Ok, I agree, let's keep
GenericPackageDescriptionas something rest ofCabaluses. See #3614phadej commentedon Jul 30, 2016
Question: should stanzas be declared before used?
If yes, then recursive acyclic stanzas are easy to implement (as stanzas overall)
I have no preference on this.
23Skidoo commentedon Jul 30, 2016
I'd say yes, it makes sense to nudge users to put
commonstanzas on top.phadej commentedon Aug 1, 2016
Motivated by possible in-parser implementation. There are two ways to parse common stanza: parse them beforehand or not.
include foois encountered, insert stanza's fields and continue.phadej commentedon Aug 1, 2016
Another comment:
says that
includeis an empty section in outline cabal-like-file view.E.g. it would be possible to write
and it will be kind-of-correct (have to warn that
includeshould be empty section)Alternatively we could have
includelooking like a field:ttuegel commentedon Aug 1, 2016
I don't think this needs to be the case. The common stanzas can be "typed" so that both Cabal (and the reader!) knows where they can go. For example,
I imagine the common build-info stanza would be the most popular by far. Even if we only implemented common build-info stanzas, I think that would be a big improvement.
phadej commentedon Aug 1, 2016
@ttuegel, yes, that's another option. And I do actually like it, except for section names; OTOH I cannot think any better ones.
ttuegel commentedon Aug 1, 2016
Yes, I should have added, those section names are awful and shouldn't be considered for a real implementation!
A serious suggestion: we could add an ellipsis after the name to indicate a common section, i.e.
library... foofor libraries,executable... barfor executables. The ellipsis would indicate that a section may be incomplete and it won't do anything until included in a real section.hvr commentedon Aug 4, 2016
@ttuegel While it's concise, I'm not sure I like using trailing punctuation to denote a difference (and also I don't think that the meaning of
...is obvious enough that you can guess its meaning). It'd be slightly more common to prefix keywords with special characters (e.g.$library,#library,%library) to denote macro-like definitions.However, I'd prefer the more verbose/explicit syntax which doesn't introduce a new style of keywords by via non-alpha-nums.
And I assume
common-libraryw/o an identifier would denote an auto-included global section that's included in alllibrarystanzas?Fwiw, other bikeshed names instead of
common:define(and maybeuseinstead ofinclude) or maybemacro.5 remaining items
hvr commentedon May 12, 2017
@kanishka-azimi Yes, I briefly considered the concept of
hpack, but I've come to the conclusion that it's better to address the problem at the source, i.e. improve the few things lacking in.cabalsyntax so we don't need to resort to external kludges likehpack(which would only introduce a new set of problems, YAML for starters ;-) ) to compensate for.cabalsyntax's shortcomings.BardurArantsson commentedon May 12, 2017
Just while we're speculating, I wonder if people have though the necomer in the "config language" space, Dhall. Seems to have some very nice properties.
hvr commentedon May 12, 2017
@BardurArantsson Dhall is definitely interesting in its own right (and I'm waiting for an occasion to make use of it), but it appears to me that by being actually a programming language (rather than a declarative package specification with enough structure to support automatic refactoring) it's also way too powerful for what we'd want for
.cabalfiles. So we really want something inbetween an overly generic and inexpressive JSON data-model, and mini-programming-languages on the other end of the spectrum featuring too powerful constructs resembling user definable functions (even if not turing-complete). I really think that having a custom designed package specification language tailored to cabal's somewhat unique features and requirements is the most reasonable way to go, even if it means that we can't reuse off-the-shelf parsers.BardurArantsson commentedon May 13, 2017
(I'll stop with the semi-OT after this.)
I keep hearing about automatic refactoring (and perhaps GUI tools?), but how realistic is it to expect any such thing for Cabal? I honestly don't think it's even close to realistic enough to worry about as a goal. Plus we're talking files of (at most) a 100-200 or so lines. Who actually needs automated refactoring for that? (Especially with something like Dhall, you could probably cut down on the size drastically.)
Heck, in JVM-land even Maven had the original goal of having pom.xml files mostly being edited with a GUI tool, but as it turned nobody actually wanted that -- so almost everybody just edits the XML directly.
hvr commentedon May 13, 2017
@BardurArantsson For one, haskell-mode or more generally things like haskell-ide-engine would greatly benefit from the ability to understand the structure of
.cabalfiles, and be able to e.g. manipulate thebuild-depends(IOW, IDE-assisted build-depends/other-extension management).But more importantly, I'm working on tools to assist Hackage curation by Trustees & maintainers, and one super boring, time-consuming and error-prone task is to step in and modify version bounds by hand. But more importantly, we want to make the recommended PVP-workflow more convenient, and for that imagine if we had this process automated to the point where you get presented with all information (changelog, API deltas, test/build-reports, etc) involving a new major version of your dependency, and you just have to click a button on Hackage to confirm that bumping that specific upper version bound is safe (rather than the alternative of flying blind by leaving off upper bounds altogether).
BardurArantsson commentedon May 13, 2017
@hvr Ah, true, I hadn't considered the Hackage version bound thing.
alanz commentedon May 13, 2017
Just a note re
Dhall: It explicitly sets out to limit its power, precisely for use as a configuration language. See the original blog post.Silence new -Wmissing-home-modules warning in +monolithic configuration
Silence new -Wmissing-home-modules warning for `cabal-install`
Silence new -Wmissing-home-modules warning for `cabal-install`
23Skidoo commentedon Jan 23, 2018
@phadej This can be closed as fixed by #4751 now, right?
23Skidoo commentedon Feb 15, 2018
Closing as fixed.