Skip to content

Commit

Permalink
Add licenseFiles to InstalledPackageInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
L-TChen committed Aug 15, 2023
1 parent 0ab5571 commit 5abc0e1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,11 @@ packageDescriptionFieldGrammar =

licenseFilesGrammar =
(++)
-- TODO: neither field is deprecated
-- should we pretty print license-file if there's single license file
-- and license-files when more
<$> monoidalFieldAla "license-file" CompatLicenseFile L.licenseFiles
-- Always pretty print license-files
<$> ( monoidalFieldAla "license-file" CompatLicenseFile L.licenseFiles
^^^ hiddenField
)
<*> monoidalFieldAla "license-files" (alaList FSep) L.licenseFiles
^^^ hiddenField

-------------------------------------------------------------------------------
-- Library
Expand Down
2 changes: 2 additions & 0 deletions Cabal-syntax/src/Distribution/Types/InstalledPackageInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ data InstalledPackageInfo = InstalledPackageInfo
instantiatedWith :: [(ModuleName, OpenModule)]
, compatPackageKey :: String
, license :: Either SPDX.License License
, licenseFiles :: [FilePath]
, copyright :: !ShortText
, maintainer :: !ShortText
, author :: !ShortText
Expand Down Expand Up @@ -138,6 +139,7 @@ emptyInstalledPackageInfo =
, instantiatedWith = []
, compatPackageKey = ""
, license = Left SPDX.NONE
, licenseFiles = []
, copyright = ""
, maintainer = ""
, author = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ ipiFieldGrammar =
<@> optionalFieldDefAla "instantiated-with" InstWith L.instantiatedWith []
<@> optionalFieldDefAla "key" CompatPackageKey L.compatPackageKey ""
<@> optionalFieldDefAla "license" SpecLicenseLenient L.license (Left SPDX.NONE)
<@> monoidalFieldAla "license-files" (alaList' FSep FilePathNT) L.licenseFiles
<@> freeTextFieldDefST "copyright" L.copyright
<@> freeTextFieldDefST "maintainer" L.maintainer
<@> freeTextFieldDefST "author" L.author
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ license :: Lens' InstalledPackageInfo (Either SPDX.License License)
license f s = fmap (\x -> s{T.license = x}) (f (T.license s))
{-# INLINE license #-}

licenseFiles :: Lens' InstalledPackageInfo [FilePath]
licenseFiles f s = fmap (\x -> s{T.licenseFiles = x}) (f (T.licenseFiles s))
{-# INLINE licenseFiles #-}

copyright :: Lens' InstalledPackageInfo ShortText
copyright f s = fmap (\x -> s{T.copyright = x}) (f (T.copyright s))
{-# INLINE copyright #-}
Expand Down
4 changes: 4 additions & 0 deletions Cabal/src/Distribution/Simple/Register.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import Distribution.Simple.Setup.Register
import Distribution.Simple.Utils
import Distribution.System
import Distribution.Utils.MapAccum
import Distribution.Utils.Path
import Distribution.Verbosity as Verbosity
import Distribution.Version

Expand Down Expand Up @@ -511,6 +512,9 @@ generalInstalledPackageInfo adjustRelIncDirs pkg abi_hash lib lbi clbi installDi
if ghc84
then Left $ either id licenseToSPDX $ licenseRaw pkg
else Right $ either licenseFromSPDX id $ licenseRaw pkg
, IPI.licenseFiles =
let doc = docdir installDirs
in map ((doc </>) . getSymbolicPath) $ licenseFiles pkg
, IPI.copyright = copyright pkg
, IPI.maintainer = maintainer pkg
, IPI.author = author pkg
Expand Down

0 comments on commit 5abc0e1

Please sign in to comment.