Cabal: Add support for (some) `cabal.project`-fields to cabal script-metadata

Created on 19 Nov 2018  路  10Comments  路  Source: haskell/cabal

The basic script feature (see #3843) implemented has support for including package-description/buildinfo fields but didn't yet implement support for project metadata.

At the very least fields such as index-state, with-compiler, allow-{newer,older} and constraints shall be supported as exemplified in the example below

#! /usr/bin/env cabal
{- cabal:
index-state: 2016-09-15T12:00:00Z
with-compiler: ghc-8.0.2
allow-newer: shelly:base
constraints: filepath==1.4.1.1, containers==0.5.7.1, Cabal installed, cryptonite -none

build-depends: base ^>= 4.9
             , shelly ^>= 1.6.8
-}

main :: IO ()
main = do
   ...

/cc @typedrat

enhancement

Most helpful comment

allow-newer

All 10 comments

allow-newer

We should also think about the backwards compat story for {- cabal: blocks while we're at it.

@phadej good catch!

@23Skidoo cabal: afaik is versioned; i.e. it's actually {- cabal:[<script-spec-version>] (and the spec ver is optional)

@hvr

cabal: afaik is versioned; i.e. it's actually {- cabal:[<script-spec-version>] (and the spec ver is optional)

Is it documented somewhere which script-spec-version is the implicit one?

Not against this proposal, but wouldn't something like

#! /usr/bin/env cabal --allow-newer=foo,bar,baz

work too?

@23Skidoo Unfortunately, what is allowed under POSIX for portable shebang scripts is very limited; see https://en.wikipedia.org/wiki/Shebang_(Unix)#Portability for the sad story

TLDR: the answer is "no" :-)

okay.jpg

does this require the file be named Main.hs or have a module main? (i'm kinda interested in just making sure its easy to check / validate them?)

+1 to this feature. I also would like to be able to set verbose: 0 to suppress build messages.

@23Skidoo

Is it documented somewhere which script-spec-version is the implicit one?

According to the code:
https://github.com/haskell/cabal/blob/master/cabal-install/Distribution/Client/CmdRun.hs#L473
It looks like 2.2

And according to the parsing of the script-block: https://github.com/haskell/cabal/blob/master/cabal-install/Distribution/Client/CmdRun.hs#L379
It uses the latest cabal-spec-version for parsing. Not sure if this means that it actually cant be overriden.
It seems the current parser for meta-data allows anything that can be written in an executable stanza (it is actually possible to provide a main-is field, but it is overriden later on without warning).

Using the parser for cabal.project and automatically writing it to the same fake-package seems rather easy to me! Are there more complex interactions that I should be aware of?


EDIT: the syntax cabal:[<cabal-spec-version>] does not seem to parse.

Was this page helpful?
0 / 5 - 0 ratings