You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Expose cabal.project.freeze parsing in the Cabal library #7224
Currently it seems impossible to get at contents of cabal.project.freeze file without re-implementing a bunch of the Distribution.Client.Config that's only in the cabal-install binary and not available to be used.
Our specific use-case is that we generate stack.yaml file as a shim from our cabal files and the freeze file contains the set of flags that we should be using.
In general, it seems that parsing this file should be inside Cabal.
Asking to add cabal.project.freeze parsing to Cabal library is the same as adding parsing support for stack.yaml there.
In the current state of configuration code, splitting out the parser of cabal-install files (cabal.config, cabal.project), and having even some degree of compatibility is unfortunately impossible.
Asking to add cabal.project.freeze parsing to Cabal library is the same as adding parsing support for stack.yaml there.
I'm not sure how this would be. We already do the parsing in cabal-install using the Cabal package, it seems like some of the code should just migrate back into Cabal...
In the current state of configuration code, splitting out the parser of cabal-install files (cabal.config, cabal.project), and having even some degree of compatibility is unfortunately impossible.
We already parse .cabal files, isn't it exactly the same issue? Is Cabal only meant to parse the .cabal file and offer tools to parse other things in the cabal format, but nothing specific to cabal-install? Hence the stack comment. If yes, feel free to close. It is very unfortunate though. Maybe cabal-install should expose modules so we could just invoke an already written piece of code from there...
In the meantime, if anyone is interested, I am parsing out the bits I'm interested in (package flags in constraints) with following code:
parseCabalFlags::ActionCabalFlags
parseCabalFlags =do
need [cabalProjectFreezeFile]
fields <-do
freezeFileBs <- liftIO $BS.readFile cabalProjectFreezeFile
caseCabal.readFields freezeFileBs ofLeft e ->fail$show e
Right fields ->pure fields
constraints <-case listToMaybe $ mapMaybe getConstraints fields ofNothing->fail"No constraints section in cabal freeze file."Just constraints ->pure constraints
let cabalFlags =let f m t =caseCabal.simpleParse (T.unpack t) ofNothing-> m
Just (CabalPkgFlags pkg flags) ->HashMap.insertWith (<>) pkg flags m
in foldl' f mempty constraints
pure$!CabalFlags cabalFlags
where
getConstraints (Cabal.Field (Cabal.Name _ n) ls)
| n == fromString "constraints"=pure$ ls <&>\caseCabal.FieldLine _ t ->T.decodeUtf8 t
getConstraints _ =NothingdataCabalPkgFlags=CabalPkgFlags!T.Text!Cabal.FlagAssignmentinstanceCabal.ParsecCabalPkgFlagswhere
parsec =do-- We don't check the package name: if there are no flags on this-- line, parsecFlagAssignment will fail or be empty and we won't-- include this anyway.
pkg <-Cabal.munch1 (not. isSpace)
()<-Cabal.skipSpaces1
flags <-Cabal.parsecFlagAssignment
guard .not$Cabal.nullFlagAssignment flags
-- Consume any trailing spaces and trailing comma if it's not the last-- item.Cabal.spaces <*Cabal.optional (Cabal.char ',')
pure$!CabalPkgFlags (fromString pkg) flags
Honestly, i don't think #7358 really closes this. Figuring out how to parse cabal.project(.freeze) using current cabal-install is beyond human. It's in theory possible, in practice it isn't.
Activity
phadej commentedon Jan 5, 2021
Asking to add
cabal.project.freezeparsing toCaballibrary is the same as adding parsing support forstack.yamlthere.In the current state of configuration code, splitting out the parser of cabal-install files (
cabal.config,cabal.project), and having even some degree of compatibility is unfortunately impossible.Fuuzetsu commentedon Jan 5, 2021
I'm not sure how this would be. We already do the parsing in
cabal-installusing theCabalpackage, it seems like some of the code should just migrate back intoCabal...We already parse
.cabalfiles, isn't it exactly the same issue? IsCabalonly meant to parse the.cabalfile and offer tools to parse other things in the cabal format, but nothing specific to cabal-install? Hence thestackcomment. If yes, feel free to close. It is very unfortunate though. Maybecabal-installshould expose modules so we could just invoke an already written piece of code from there...In the meantime, if anyone is interested, I am parsing out the bits I'm interested in (package flags in constraints) with following code:
phadej commentedon May 3, 2021
Honestly, i don't think #7358 really closes this. Figuring out how to parse
cabal.project(.freeze)using currentcabal-installis beyond human. It's in theory possible, in practice it isn't.emilypi commentedon May 3, 2021
Was this closed by linking? I didn't physically close this issue. Thanks for reopening @phadej
fgaz commentedon May 3, 2021
Yes, I thought I'd do good by linking the merge of that pr with the closure of the issues listed in "fixes", my bad
emilypi commentedon May 3, 2021
No worries. I went through and this is the only one that is partially fixed but not fully.
andreabedini commentedon Jan 12, 2023
This is now easy with the
cabal-installlibrary. We have readProjectConfig and even a readProjectLocalFreezeConfigAPI could be improved but these functions do exactly what the OP asked.
Fuuzetsu commentedon Jan 13, 2023
Fine with me. FWIW we no longer have need for this so feel free to close at own discretion.
Mikolaj commentedon Jan 13, 2023
Thank you, everybody. Closing.