Skip to content

The cabal parser does not see common stanzas #9617

Closed

Description

@Kleidukos

Using parseGenericPackageDescription, on a cabal file, it seems that common stanzas are not "seen" by the parser. By that I mean they are not expanded in the PackageDescription result.

Example:

Cabal file (truncated)
cabal-version:      3.0
name:               libsodium-bindings
version:            0.0.1.1
license:            BSD-3-Clause
build-type:         Simple
tested-with:
  GHC ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.8 || ==9.6.3

extra-source-files:
  LICENSE
  README.md

extra-doc-files:    CHANGELOG.md

flag use-pkg-config
  description: Use pkg-config to find Libsodium. Used by default on macOS.
  default:     False
  manual:      True

common common
  build-depends:    base >=4.14 && <5

  if (os(osx) || flag(use-pkg-config))
    pkgconfig-depends: libsodium ==1.0.18

  extra-libraries: sodium
  default-language: Haskell2010

common common-rts-options
  ghc-options: -rtsopts -threaded -with-rtsopts=-N

library
  import:          common
  hs-source-dirs:  src
Result
PackageDescription
    { specVersion = CabalSpecV3_0
    , package = PackageIdentifier{pkgName = PackageName "libsodium-bindings", pkgVersion = mkVersion [0, 0, 1, 1]}
    , licenseRaw = Left (License (ELicense (ELicenseId BSD_3_Clause) Nothing))
    , licenseFiles = []
    , copyright = ""
    , maintainer = "The Haskell Cryptography contributors"
    , author = "H\233cate Moonlight, Koz Ross"
    , stability = ""
    , testedWith =
        [
            ( GHC
            , UnionVersionRanges
                (ThisVersion (mkVersion [8, 10, 7]))
                ( UnionVersionRanges
                    (ThisVersion (mkVersion [9, 0, 2]))
                    ( UnionVersionRanges
                        (ThisVersion (mkVersion [9, 2, 8]))
                        (UnionVersionRanges (ThisVersion (mkVersion [9, 4, 8])) (ThisVersion (mkVersion [9, 6, 3])))
                    )
                )
            )
        ]
    , homepage = "https://github.com/haskell-cryptography/libsodium-bindings"
    , pkgUrl = ""
    , bugReports = "https://github.com/haskell-cryptography/libsodium-bindings/issues"
    , sourceRepos =
        [ SourceRepo
            { repoKind = RepoHead
            , repoType = Just (KnownRepoType Git)
            , repoLocation = Just "https://github.com/haskell-cryptography/libsodium-bindings"
            , repoModule = Nothing
            , repoBranch = Nothing
            , repoTag = Nothing
            , repoSubdir = Nothing
            }
        ]
    , synopsis = "FFI bindings to libsodium"
    , description =
        "This library embeds FFI bindings to the stable version of libsodium 1.0.18.\nThe interface exposed by this library is kept close to the C library."
    , category = "Cryptography"
    , customFieldsPD = []
    , buildTypeRaw = Just Simple
    , setupBuildInfo = Nothing
    , library = Nothing
    , subLibraries = []
    , executables = []
    , foreignLibs = []
    , testSuites = []
    , benchmarks = []
    , dataFiles = []
    , dataDir = "."
    , extraSrcFiles = ["LICENSE", "README.md"]
    , extraTmpFiles = []
    , extraDocFiles = ["CHANGELOG.md"]
    }

We can see that there is no information whatsoever that is contained in the common stanza.

My question is the following: Which function do I need to call to take common stanzas into account in my PackageDescription?

Activity

  1. added
    Cabal: common stanza
    on Jan 16, 2024
  2. jasagredo commented on Jan 16, 2024

    @jasagredo
    Collaborator

    Could this be a degenerate case because there are no source files at all in the library?

    Have you tried moving the common stanzas before the flags? Does cabal complain in verbose mode about "ignoring section blah"?

  3. Kleidukos commented on Jan 16, 2024

    @Kleidukos
    MemberAuthor

    Could this be a degenerate case because there are no source files at all in the library?

    Apologies, I elided the files to make the example more concise, the actual cabal file has modules: https://github.com/haskell-cryptography/libsodium-bindings/blob/98fa256e355e1037337f1d9a0aa439dca5e48ffd/libsodium-bindings/libsodium-bindings.cabal

    Have you tried moving the common stanzas before the flags? Does cabal complain in verbose mode about "ignoring section blah"?

    I will try this, thank you.

  4. Kleidukos commented on Jan 16, 2024

    @Kleidukos
    MemberAuthor

    Update:

    With the following file:

    libsodium-bindings.cabal
    cabal-version:      3.0
    name:               libsodium-bindings
    version:            0.0.1.1
    category:           Cryptography
    synopsis:           FFI bindings to libsodium
    description:
      This library embeds FFI bindings to the stable version of libsodium 1.0.18.
      The interface exposed by this library is kept close to the C library.
    
    homepage:           https://github.com/haskell-cryptography/libsodium-bindings
    bug-reports:
      https://github.com/haskell-cryptography/libsodium-bindings/issues
    
    author:             Hécate Moonlight, Koz Ross
    maintainer:         The Haskell Cryptography contributors
    license:            BSD-3-Clause
    build-type:         Simple
    tested-with:
      GHC ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.8 || ==9.6.3
    
    extra-source-files:
      LICENSE
      README.md
    
    extra-doc-files:    CHANGELOG.md
    
    common common
      build-depends:    base >=4.14 && <5
      ghc-options:
        -Wall -Wcompat -Widentities -Wincomplete-record-updates
        -Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints
        -fhide-source-paths -Wno-unused-do-bind -haddock
    
      if (os(osx) || flag(use-pkg-config))
        pkgconfig-depends: libsodium ==1.0.18
    
      extra-libraries: sodium
      default-language: Haskell2010
    
    common common-rts-options
      ghc-options: -rtsopts -threaded -with-rtsopts=-N
    
    flag use-pkg-config
      description: Use pkg-config to find Libsodium. Used by default on macOS.
      default:     False
      manual:      True
    
    source-repository head
      type:     git
      location: https://github.com/haskell-cryptography/libsodium-bindings
    
    library
      import:          common
      hs-source-dirs:  src
    
      -- cabal-fmt: expand src/
      exposed-modules:
        LibSodium.Bindings
        LibSodium.Bindings.AEAD
        LibSodium.Bindings.Comparison
        LibSodium.Bindings.CryptoAuth
        LibSodium.Bindings.CryptoBox
        LibSodium.Bindings.CryptoSign
        LibSodium.Bindings.GenericHashing
        LibSodium.Bindings.KeyDerivation
        LibSodium.Bindings.KeyExchange
        LibSodium.Bindings.Main
        LibSodium.Bindings.PasswordHashing
        LibSodium.Bindings.Random
        LibSodium.Bindings.Scrypt
        LibSodium.Bindings.SealedBoxes
        LibSodium.Bindings.Secretbox
        LibSodium.Bindings.SecretStream
        LibSodium.Bindings.SecureMemory
        LibSodium.Bindings.SHA2
        LibSodium.Bindings.ShortHashing
        LibSodium.Bindings.Utils
        LibSodium.Bindings.XChaCha20

    I get the following result

    Package Description
    PackageDescription
        { specVersion = CabalSpecV3_0
        , package = PackageIdentifier{pkgName = PackageName "libsodium-bindings", pkgVersion = mkVersion [0, 0, 1, 1]}
        , licenseRaw = Left (License (ELicense (ELicenseId BSD_3_Clause) Nothing))
        , licenseFiles = []
        , copyright = ""
        , maintainer = "The Haskell Cryptography contributors"
        , author = "H\233cate Moonlight, Koz Ross"
        , stability = ""
        , testedWith =
            [
                ( GHC
                , UnionVersionRanges
                    (ThisVersion (mkVersion [8, 10, 7]))
                    ( UnionVersionRanges
                        (ThisVersion (mkVersion [9, 0, 2]))
                        ( UnionVersionRanges
                            (ThisVersion (mkVersion [9, 2, 8]))
                            (UnionVersionRanges (ThisVersion (mkVersion [9, 4, 8])) (ThisVersion (mkVersion [9, 6, 3])))
                        )
                    )
                )
            ]
        , homepage = "https://github.com/haskell-cryptography/libsodium-bindings"
        , pkgUrl = ""
        , bugReports = "https://github.com/haskell-cryptography/libsodium-bindings/issues"
        , sourceRepos =
            [ SourceRepo
                { repoKind = RepoHead
                , repoType = Just (KnownRepoType Git)
                , repoLocation = Just "https://github.com/haskell-cryptography/libsodium-bindings"
                , repoModule = Nothing
                , repoBranch = Nothing
                , repoTag = Nothing
                , repoSubdir = Nothing
                }
            ]
        , synopsis = "FFI bindings to libsodium"
        , description =
            "This library embeds FFI bindings to the stable version of libsodium 1.0.18.\nThe interface exposed by this library is kept close to the C library."
        , category = "Cryptography"
        , customFieldsPD = []
        , buildTypeRaw = Just Simple
        , setupBuildInfo = Nothing
        , library = Nothing
        , subLibraries = []
        , executables = []
        , foreignLibs = []
        , testSuites = []
        , benchmarks = []
        , dataFiles = []
        , dataDir = "."
        , extraSrcFiles = ["LICENSE", "README.md"]
        , extraTmpFiles = []
        , extraDocFiles = ["CHANGELOG.md"]
        }
  5. jasagredo commented on Jan 16, 2024

    @jasagredo
    Collaborator

    What is the issue you are facing later on? The common stanzas might be expanded later on in the process (I think this is the case), so is there a specific problem you are facing?

  6. fgaz commented on Jan 16, 2024

    @fgaz
    Member

    How did you turn the GenericPackageDescription into a PackageDescription?

  7. Kleidukos commented on Jan 16, 2024

    @Kleidukos
    MemberAuthor

    @jasagredo

    There is no "later on" for me, I use the PackageDescription and I don't know how to get the stanzas (expanded or not).

    @fgaz I'm just accessing the field packageDescription: https://hackage.haskell.org/package/Cabal-syntax-3.10.2.0/docs/Distribution-Types-GenericPackageDescription.html#t:GenericPackageDescription

  8. fgaz commented on Jan 16, 2024

    @fgaz
    Member

    The packageDescription field of GenericPackageDescription is only partially filled. The rest is in the CondTrees, still unresolved. To get a filled PackageDescription you have to use finalizePD or flattenPackageDescription. I think there's a comment about it where PackageDescription or finalizePD is defined.

  9. Kleidukos commented on Jan 16, 2024

    @Kleidukos
    MemberAuthor

    Okay, indeed it was all in the generic package description:

    GenericPackageDescription
    GenericPackageDescription
        { packageDescription =
            PackageDescription
                { specVersion = CabalSpecV3_0
                , package =
                    PackageIdentifier
                        { pkgName = PackageName "libsodium-bindings"
                        , pkgVersion = mkVersion [0, 0, 1, 1]
                        }
                , licenseRaw = Left (License (ELicense (ELicenseId BSD_3_Clause) Nothing))
                , licenseFiles = []
                , copyright = ""
                , maintainer = "The Haskell Cryptography contributors"
                , author = "H\233cate Moonlight, Koz Ross"
                , stability = ""
                , testedWith =
                    [
                        ( GHC
                        , UnionVersionRanges
                            (ThisVersion (mkVersion [8, 10, 7]))
                            ( UnionVersionRanges
                                (ThisVersion (mkVersion [9, 0, 2]))
                                ( UnionVersionRanges
                                    (ThisVersion (mkVersion [9, 2, 8]))
                                    ( UnionVersionRanges
                                        (ThisVersion (mkVersion [9, 4, 8]))
                                        (ThisVersion (mkVersion [9, 6, 3]))
                                    )
                                )
                            )
                        )
                    ]
                , homepage = "https://github.com/haskell-cryptography/libsodium-bindings"
                , pkgUrl = ""
                , bugReports = "https://github.com/haskell-cryptography/libsodium-bindings/issues"
                , sourceRepos =
                    [ SourceRepo
                        { repoKind = RepoHead
                        , repoType = Just (KnownRepoType Git)
                        , repoLocation = Just "https://github.com/haskell-cryptography/libsodium-bindings"
                        , repoModule = Nothing
                        , repoBranch = Nothing
                        , repoTag = Nothing
                        , repoSubdir = Nothing
                        }
                    ]
                , synopsis = "FFI bindings to libsodium"
                , description =
                    "This library embeds FFI bindings to the stable version of libsodium 1.0.18.\nThe interface exposed by this library is kept close to the C library."
                , category = "Cryptography"
                , customFieldsPD = []
                , buildTypeRaw = Just Simple
                , setupBuildInfo = Nothing
                , library = Nothing
                , subLibraries = []
                , executables = []
                , foreignLibs = []
                , testSuites = []
                , benchmarks = []
                , dataFiles = []
                , dataDir = "."
                , extraSrcFiles = ["LICENSE", "README.md"]
                , extraTmpFiles = []
                , extraDocFiles = ["CHANGELOG.md"]
                }
        , gpdScannedVersion = Nothing
        , genPackageFlags =
            [ MkPackageFlag
                { flagName = FlagName "use-pkg-config"
                , flagDescription = "Use pkg-config to find Libsodium. Used by default on macOS."
                , flagDefault = False
                , flagManual = True
                }
            ]
        , condLibrary =
            Just
                ( CondNode
                    { condTreeData =
                        Library
                            { libName = LMainLibName
                            , exposedModules =
                                [ ModuleName "LibSodium.Bindings"
                                , ModuleName "LibSodium.Bindings.AEAD"
                                , ModuleName "LibSodium.Bindings.Comparison"
                                , ModuleName "LibSodium.Bindings.CryptoAuth"
                                , ModuleName "LibSodium.Bindings.CryptoBox"
                                , ModuleName "LibSodium.Bindings.CryptoSign"
                                , ModuleName "LibSodium.Bindings.GenericHashing"
                                , ModuleName "LibSodium.Bindings.KeyDerivation"
                                , ModuleName "LibSodium.Bindings.KeyExchange"
                                , ModuleName "LibSodium.Bindings.Main"
                                , ModuleName "LibSodium.Bindings.PasswordHashing"
                                , ModuleName "LibSodium.Bindings.Random"
                                , ModuleName "LibSodium.Bindings.Scrypt"
                                , ModuleName "LibSodium.Bindings.SealedBoxes"
                                , ModuleName "LibSodium.Bindings.Secretbox"
                                , ModuleName "LibSodium.Bindings.SecretStream"
                                , ModuleName "LibSodium.Bindings.SecureMemory"
                                , ModuleName "LibSodium.Bindings.SHA2"
                                , ModuleName "LibSodium.Bindings.ShortHashing"
                                , ModuleName "LibSodium.Bindings.Utils"
                                , ModuleName "LibSodium.Bindings.XChaCha20"
                                ]
                            , reexportedModules = []
                            , signatures = []
                            , libExposed = True
                            , libVisibility = LibraryVisibilityPublic
                            , libBuildInfo =
                                BuildInfo
                                    { buildable = True
                                    , buildTools = []
                                    , buildToolDepends = []
                                    , cppOptions = []
                                    , asmOptions = []
                                    , cmmOptions = []
                                    , ccOptions = []
                                    , cxxOptions = []
                                    , ldOptions = []
                                    , hsc2hsOptions = []
                                    , pkgconfigDepends = []
                                    , frameworks = []
                                    , extraFrameworkDirs = []
                                    , asmSources = []
                                    , cmmSources = []
                                    , cSources = []
                                    , cxxSources = []
                                    , jsSources = []
                                    , hsSourceDirs = [SymbolicPath "src"]
                                    , otherModules = []
                                    , virtualModules = []
                                    , autogenModules = []
                                    , defaultLanguage = Just Haskell2010
                                    , otherLanguages = []
                                    , defaultExtensions = []
                                    , otherExtensions = []
                                    , oldExtensions = []
                                    , extraLibs = ["sodium"]
                                    , extraLibsStatic = []
                                    , extraGHCiLibs = []
                                    , extraBundledLibs = []
                                    , extraLibFlavours = []
                                    , extraDynLibFlavours = []
                                    , extraLibDirs = []
                                    , extraLibDirsStatic = []
                                    , includeDirs = []
                                    , includes = []
                                    , autogenIncludes = []
                                    , installIncludes = []
                                    , options =
                                        PerCompilerFlavor
                                            [ "-Wall"
                                            , "-Wcompat"
                                            , "-Widentities"
                                            , "-Wincomplete-record-updates"
                                            , "-Wincomplete-uni-patterns"
                                            , "-Wpartial-fields"
                                            , "-Wredundant-constraints"
                                            , "-fhide-source-paths"
                                            , "-Wno-unused-do-bind"
                                            , "-haddock"
                                            ]
                                            []
                                    , profOptions = PerCompilerFlavor [] []
                                    , sharedOptions = PerCompilerFlavor [] []
                                    , staticOptions = PerCompilerFlavor [] []
                                    , customFieldsBI = []
                                    , targetBuildDepends =
                                        [ Dependency
                                            (PackageName "base")
                                            ( IntersectVersionRanges
                                                (OrLaterVersion (mkVersion [4, 14]))
                                                (EarlierVersion (mkVersion [5]))
                                            )
                                            (fromNonEmpty (LMainLibName :| []))
                                        ]
                                    , mixins = []
                                    }
                            }
                    , condTreeConstraints =
                        [ Dependency
                            (PackageName "base")
                            ( IntersectVersionRanges
                                (OrLaterVersion (mkVersion [4, 14]))
                                (EarlierVersion (mkVersion [5]))
                            )
                            (fromNonEmpty (LMainLibName :| []))
                        ]
                    , condTreeComponents =
                        [ CondBranch
                            { condBranchCondition =
                                COr (Var (OS OSX)) (Var (PackageFlag (FlagName "use-pkg-config")))
                            , condBranchIfTrue =
                                CondNode
                                    { condTreeData =
                                        Library
                                            { libName = LMainLibName
                                            , exposedModules = []
                                            , reexportedModules = []
                                            , signatures = []
                                            , libExposed = True
                                            , libVisibility = LibraryVisibilityPublic
                                            , libBuildInfo =
                                                BuildInfo
                                                    { buildable = True
                                                    , buildTools = []
                                                    , buildToolDepends = []
                                                    , cppOptions = []
                                                    , asmOptions = []
                                                    , cmmOptions = []
                                                    , ccOptions = []
                                                    , cxxOptions = []
                                                    , ldOptions = []
                                                    , hsc2hsOptions = []
                                                    , pkgconfigDepends =
                                                        [ PkgconfigDependency
                                                            (PkgconfigName "libsodium")
                                                            (PcThisVersion (PkgconfigVersion "1.0.18"))
                                                        ]
                                                    , frameworks = []
                                                    , extraFrameworkDirs = []
                                                    , asmSources = []
                                                    , cmmSources = []
                                                    , cSources = []
                                                    , cxxSources = []
                                                    , jsSources = []
                                                    , hsSourceDirs = []
                                                    , otherModules = []
                                                    , virtualModules = []
                                                    , autogenModules = []
                                                    , defaultLanguage = Nothing
                                                    , otherLanguages = []
                                                    , defaultExtensions = []
                                                    , otherExtensions = []
                                                    , oldExtensions = []
                                                    , extraLibs = []
                                                    , extraLibsStatic = []
                                                    , extraGHCiLibs = []
                                                    , extraBundledLibs = []
                                                    , extraLibFlavours = []
                                                    , extraDynLibFlavours = []
                                                    , extraLibDirs = []
                                                    , extraLibDirsStatic = []
                                                    , includeDirs = []
                                                    , includes = []
                                                    , autogenIncludes = []
                                                    , installIncludes = []
                                                    , options = PerCompilerFlavor [] []
                                                    , profOptions = PerCompilerFlavor [] []
                                                    , sharedOptions = PerCompilerFlavor [] []
                                                    , staticOptions = PerCompilerFlavor [] []
                                                    , customFieldsBI = []
                                                    , targetBuildDepends = []
                                                    , mixins = []
                                                    }
                                            }
                                    , condTreeConstraints = []
                                    , condTreeComponents = []
                                    }
                            , condBranchIfFalse = Nothing
                            }
                        ]
                    }
                )
        , condSubLibraries = []
        , condForeignLibs = []
        , condExecutables = []
        , condTestSuites = []
        , condBenchmarks = []
        }
  10. fgaz commented on Jan 16, 2024

    @fgaz
    Member

    Great :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Cabal: common stanzaCabal: parsertype: user-question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions