Reputation: 8069
Is there a way to automatically update the build-depends field in the .cabal-file? For example, if we start with the following .cabal
file:
name: HUnit
version: 1.1.1
synopsis: A unit testing framework for Haskell
homepage: http://hunit.sourceforge.net/
category: Testing
author: Dean Herington
license: BSD3
license-file: LICENSE
cabal-version: >= 1.10
build-type: Simple
library
build-depends: base >= 2 && < 4
exposed-modules: Test.HUnit.Base, Test.HUnit.Lang,
Test.HUnit.Terminal, Test.HUnit.Text, Test.HUnit
default-extensions: CPP
Then, install a package:
cabal install warp
Now, I have to add warp >=3.0 && <3.1
to the build-depends
field, to make the file look like this:
name: HUnit
version: 1.1.1
synopsis: A unit testing framework for Haskell
homepage: http://hunit.sourceforge.net/
category: Testing
author: Dean Herington
license: BSD3
license-file: LICENSE
cabal-version: >= 1.10
build-type: Simple
library
build-depends: base >= 2 && < 4, warp >=3.0 && <3.1
exposed-modules: Test.HUnit.Base, Test.HUnit.Lang,
Test.HUnit.Terminal, Test.HUnit.Text, Test.HUnit
default-extensions: CPP
My question is: how do we update this file automatically?
Upvotes: 21
Views: 2605
Reputation: 33861
A possible alternative is to use hpack, yaml, sponge and jq:
You will need hpack package.yaml file.
For example to add aeson
as a dependency:
cp package.yaml package.yaml.backup && (yaml2json package.yaml | jq '.dependencies += ["aeson"]' | json2yaml | sponge package.yaml ) && hpack
Upvotes: 0
Reputation: 38893
There are two tools in modern cabal-install
for aiding with managing bounds of dependencies. First is gen-bounds
which suggests proper version-ranges for packages based on the specifications of versions currently installed. The second is outdated
, which lists dependencies in the cabal
file for which newer versions exist on hackage
. Both are documented in the cabal manual: https://www.haskell.org/cabal/users-guide/developing-packages.html#generating-dependency-version-bounds
Upvotes: 4