Skip to content

Commit

Permalink
Compatibility with Cabal >= 3.14
Browse files Browse the repository at this point in the history
readGenericPackageDescription now uses interpretSymbolicPath internally
[1] which allows for passing in a CWD directory explicitly rather than
just inheriting it from the running process.

We want to preserve the old behavior and behave the same as
writeGenericPackageDescription which does not use interpretSymbolicPath,
so we pass Nothing. This amounts to the same behavior as just returning
the underlying path (which is what we had before) [2] [3].

This also seems safer since readGenericPackageDescription seems to
assume that the passed in CWD directory matches the process working
directory [1].

[1]: https://github.com/haskell/cabal/blob/Cabal-v3.14.1.0/Cabal/src/Distribution/Simple/PackageDescription.hs#L83-L84
[2]: https://github.com/haskell/cabal/blob/Cabal-v3.14.1.0/Cabal-syntax/src/Distribution/Utils/Path.hs#L288-L305
[3]: https://github.com/haskell/cabal/blob/Cabal-v3.14.1.0/Cabal-syntax/src/Distribution/Utils/Path.hs#L257-L259
  • Loading branch information
sternenseemann committed Dec 24, 2024
1 parent 5e20d08 commit 17a0ce2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import Distribution.PackageDescription.Parsec
import Distribution.PackageDescription.PrettyPrint
import Distribution.Types.ExeDependency
import Distribution.Types.LegacyExeDependency
#if MIN_VERSION_Cabal(3,14,0)
import Distribution.Utils.Path
#endif
import Distribution.Verbosity
import Distribution.Version
import System.Environment
Expand All @@ -19,7 +22,15 @@ main = getArgs >>= mapM_ jailbreakFile

jailbreakFile :: FilePath -> IO ()
jailbreakFile cabalFile =
readGenericPackageDescription silent cabalFile
readGenericPackageDescription silent
#if MIN_VERSION_Cabal(3,14,0)
-- Do not give a CWD directory, so the working dir of the process is used (like before).
-- Note: Passing a CWD directory is inadvisable since writeGenericPackageDescription
-- does not support it, so we'd get differing behavior.
Nothing (makeSymbolicPath cabalFile)
#else
cabalFile
#endif
>>= writeGenericPackageDescription cabalFile . stripVersionRestrictions

-- We don't relax version restrictions inside conditional statements.
Expand Down

0 comments on commit 17a0ce2

Please sign in to comment.