Dependency version bounds are a lie

Ok, here is a a first prototype, showing what I think is a good way to approach the problem:

$ cabal build -w ghc-9.2.4 --builddir dist-9.2
Build profile: -w ghc-9.2.4 -O1
…
$ cabal build -w ghc-9.0.2 --builddir dist-9.0
Build profile: -w ghc-9.0.2 -O1
…
$ cabal run -v0  cabal-plan-bounds -- -i dist-9.0/cache/plan.json -i dist-9.2/cache/plan.json  -c cabal-plan-bounds.cabal 

Now the tool has updated its own .cabal file (how meta), with the following diff:

$ git diff
diff --git a/cabal-plan-bounds.cabal b/cabal-plan-bounds.cabal
index 8e5dce8..bee19b1 100644
--- a/cabal-plan-bounds.cabal
+++ b/cabal-plan-bounds.cabal
@@ -21,11 +21,14 @@ executable cabal-plan-bounds
     main-is:          Main.hs
     other-modules:    ReplaceDependencies
     -- other-extensions:
-    build-depends:    base, Cabal-syntax, cabal-plan,
+    build-depends:    base ^>=4.15.1.0 || ^>=4.16.3.0,
+                      Cabal-syntax ^>=3.8.1.0,
+                      cabal-plan ^>=0.7.2.3,
+                      optparse-applicative ^>=0.17.0.0,
+                      containers ^>=0.6.4.1,
+                      text ^>=1.2.5.0
       -- a comment in the middle of te build depends
-      optparse-applicative
-      , containers, text
-    build-depends:   bytestring
+    build-depends:   bytestring ^>=0.10.12.1 || ^>=0.11.3.1
     build-depends:
     hs-source-dirs:   src/
     default-language: Haskell2010

You can see that

  • It left indentation and comments in place (but comments within a field are moved to the end of the field)
  • It left the build-depends as they were – one field or multiple fields, including the order of the build depends.
  • Every build depends now has the version range indicated by a disjunction of ^>= constraints, corresponding to the passed build files (and I could pass more, of course)
  • The build-depends field value is pretty-printed as Cabal would do it, commas at the end, one per line. (I’d leave it to a separate cabal file formatter to clean this up if you don’t like it).

That’s it, I’d say, the rest is “just” polishing of the tool itself (error handling, tests, the usual stuff). But not today. I dumped the current state of affairs here if someone (@tcard) wants to play around with it:

4 Likes