From 5abc0e1a738909221a455f440ea002374a6559c6 Mon Sep 17 00:00:00 2001 From: Liang-Ting Chen Date: Mon, 7 Aug 2023 15:51:50 +0800 Subject: [PATCH] Add `licenseFiles` to `InstalledPackageInfo` --- .../src/Distribution/PackageDescription/FieldGrammar.hs | 9 ++++----- .../src/Distribution/Types/InstalledPackageInfo.hs | 2 ++ .../Types/InstalledPackageInfo/FieldGrammar.hs | 1 + .../src/Distribution/Types/InstalledPackageInfo/Lens.hs | 4 ++++ Cabal/src/Distribution/Simple/Register.hs | 4 ++++ 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs b/Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs index c60040f8e34..0c33710028f 100644 --- a/Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs +++ b/Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs @@ -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 diff --git a/Cabal-syntax/src/Distribution/Types/InstalledPackageInfo.hs b/Cabal-syntax/src/Distribution/Types/InstalledPackageInfo.hs index b3e353876eb..c1873d94a7d 100644 --- a/Cabal-syntax/src/Distribution/Types/InstalledPackageInfo.hs +++ b/Cabal-syntax/src/Distribution/Types/InstalledPackageInfo.hs @@ -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 @@ -138,6 +139,7 @@ emptyInstalledPackageInfo = , instantiatedWith = [] , compatPackageKey = "" , license = Left SPDX.NONE + , licenseFiles = [] , copyright = "" , maintainer = "" , author = "" diff --git a/Cabal-syntax/src/Distribution/Types/InstalledPackageInfo/FieldGrammar.hs b/Cabal-syntax/src/Distribution/Types/InstalledPackageInfo/FieldGrammar.hs index 7578907b590..c7cdb7a3df9 100644 --- a/Cabal-syntax/src/Distribution/Types/InstalledPackageInfo/FieldGrammar.hs +++ b/Cabal-syntax/src/Distribution/Types/InstalledPackageInfo/FieldGrammar.hs @@ -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 diff --git a/Cabal-syntax/src/Distribution/Types/InstalledPackageInfo/Lens.hs b/Cabal-syntax/src/Distribution/Types/InstalledPackageInfo/Lens.hs index 47fa1c96f40..20acc56de1d 100644 --- a/Cabal-syntax/src/Distribution/Types/InstalledPackageInfo/Lens.hs +++ b/Cabal-syntax/src/Distribution/Types/InstalledPackageInfo/Lens.hs @@ -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 #-} diff --git a/Cabal/src/Distribution/Simple/Register.hs b/Cabal/src/Distribution/Simple/Register.hs index fc6075dc357..92c9247489c 100644 --- a/Cabal/src/Distribution/Simple/Register.hs +++ b/Cabal/src/Distribution/Simple/Register.hs @@ -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 @@ -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