Skip to content

Fix #701: Add licenseFiles to InstalledPackageInfo #9172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions Cabal-tests/tests/ParserTests/ipi/Includes2.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package-name: Includes2
lib-name: mylib
key: Includes2-0.1.0.0-inplace-mylib+3gY9SyjX86dBypHcOaev1n
license: BSD3
license-files: LICENSE
maintainer: [email protected]
author: Edward Z. Yang
exposed: False
Expand Down
1 change: 1 addition & 0 deletions Cabal-tests/tests/ParserTests/ipi/Includes2.expr
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ InstalledPackageInfo {
compatPackageKey =
"Includes2-0.1.0.0-inplace-mylib+3gY9SyjX86dBypHcOaev1n",
license = Right BSD3,
licenseFiles = ["LICENSE"],
copyright = "",
maintainer =
"[email protected]",
Expand Down
1 change: 1 addition & 0 deletions Cabal-tests/tests/ParserTests/ipi/Includes2.format
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ id: Includes2-0.1.0.0-inplace-mylib+3gY9SyjX86dBypHcOaev1n
instantiated-with: Database=Includes2-0.1.0.0-inplace-mysql:Database.MySQL
key: Includes2-0.1.0.0-inplace-mylib+3gY9SyjX86dBypHcOaev1n
license: BSD3
license-files: LICENSE
maintainer: [email protected]
author: Edward Z. Yang
abi: inplace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: 0.1.0.0
id: internal-preprocessor-test-0.1.0.0
key: internal-preprocessor-test-0.1.0.0
license: GPL-3
license-files: LICENSE
maintainer: [email protected]
synopsis: Internal custom preprocessor example.
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ InstalledPackageInfo {
"internal-preprocessor-test-0.1.0.0",
license = Right
(GPL (Just (mkVersion [3]))),
licenseFiles = ["LICENSE"],
copyright = "",
maintainer =
"[email protected]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ visibility: public
id: internal-preprocessor-test-0.1.0.0
key: internal-preprocessor-test-0.1.0.0
license: GPL-3
license-files: LICENSE
maintainer: [email protected]
author: Mikhail Glushenkov
synopsis: Internal custom preprocessor example.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: 0.5.2.0
id: transformers-0.5.2.0
key: transformers-0.5.2.0
license: BSD3
license-files: LICENSE
maintainer: Ross Paterson <[email protected]>
synopsis: Concrete functor and monad transformers
description:
Expand Down
1 change: 1 addition & 0 deletions Cabal-tests/tests/ParserTests/ipi/issue-2276-ghc-9885.expr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ InstalledPackageInfo {
compatPackageKey =
"transformers-0.5.2.0",
license = Right BSD3,
licenseFiles = ["LICENSE"],
copyright = "",
maintainer =
"Ross Paterson <[email protected]>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ visibility: public
id: transformers-0.5.2.0
key: transformers-0.5.2.0
license: BSD3
license-files: LICENSE
maintainer: Ross Paterson <[email protected]>
author: Andy Gill, Ross Paterson
synopsis: Concrete functor and monad transformers
Expand Down
1 change: 1 addition & 0 deletions Cabal-tests/tests/ParserTests/ipi/transformers.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: 0.5.2.0
id: transformers-0.5.2.0
key: transformers-0.5.2.0
license: BSD3
license-files: LICENSE
maintainer: Ross Paterson <[email protected]>
synopsis: Concrete functor and monad transformers
description:
Expand Down
1 change: 1 addition & 0 deletions Cabal-tests/tests/ParserTests/ipi/transformers.expr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ InstalledPackageInfo {
compatPackageKey =
"transformers-0.5.2.0",
license = Right BSD3,
licenseFiles = ["LICENSE"],
copyright = "",
maintainer =
"Ross Paterson <[email protected]>",
Expand Down
1 change: 1 addition & 0 deletions Cabal-tests/tests/ParserTests/ipi/transformers.format
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ visibility: public
id: transformers-0.5.2.0
key: transformers-0.5.2.0
license: BSD3
license-files: LICENSE
maintainer: Ross Paterson <[email protected]>
author: Andy Gill, Ross Paterson
synopsis: Concrete functor and monad transformers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cabal-version: >=1.8
name: Octree
version: 0.5
license: BSD3
license-file: LICENSE
license-files: LICENSE
copyright: Copyright by Michal J. Gajda '2012
maintainer: [email protected]
author: Michal J. Gajda
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cabal-version: >=1.10
name: generics-sop
version: 0.3.1.0
license: BSD3
license-file: LICENSE
license-files: LICENSE
maintainer: [email protected]
author:
Edsko de Vries <[email protected]>, Andres Löh <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cabal-version: 2.2
name: jaeger-flamegraph
version: 1.0.0
license: BSD-3-Clause
license-file: LICENSE
license-files: LICENSE
copyright: (c) 2018 Symbiont.io
maintainer: Sam Halliday
author: Sam Halliday
Expand Down
2 changes: 1 addition & 1 deletion Cabal-tests/tests/ParserTests/regressions/libpq1.format
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cabal-version: >=1.8
name: postgresql-libpq
version: 0.9.4.2
license: BSD3
license-file: LICENSE
license-files: LICENSE
copyright:
(c) 2010 Grant Monroe
(c) 2011 Leon P Smith
Expand Down
2 changes: 1 addition & 1 deletion Cabal-tests/tests/ParserTests/regressions/libpq2.format
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cabal-version: 3.0
name: postgresql-libpq
version: 0.9.4.2
license: BSD-3-Clause
license-file: LICENSE
license-files: LICENSE
copyright:
(c) 2010 Grant Monroe
(c) 2011 Leon P Smith
Expand Down
22 changes: 11 additions & 11 deletions Cabal-tests/tests/ParserTests/regressions/monad-param.format
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
monad-param.cabal:19:1: Tabs used as indentation at 19:1, 20:1
name: monad-param
version: 0.0.1
license: BSD3
license-file: LICENSE
copyright: Copyright (C) 2006-2007, Edward Kmett
maintainer: Edward Kmett <[email protected]>
author: Edward Kmett <[email protected]>
stability: alpha
name: monad-param
version: 0.0.1
license: BSD3
license-files: LICENSE
copyright: Copyright (C) 2006-2007, Edward Kmett
maintainer: Edward Kmett <[email protected]>
author: Edward Kmett <[email protected]>
stability: alpha
homepage:
http://comonad.com/haskell/monad-param/dist/doc/html/Control-Monad-Parameterized.html

package-url: http://comonad.com/haskell/monad-param
synopsis: Parameterized monads
package-url: http://comonad.com/haskell/monad-param
synopsis: Parameterized monads
description:
Implements parameterized monads by overloading the monad sugar with more liberal types.

category: Control
category: Control

library
exposed-modules: Control.Monad.Parameterized
Expand Down
2 changes: 1 addition & 1 deletion Cabal-tests/tests/ParserTests/regressions/shake.format
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cabal-version: 1.18
name: shake
version: 0.15.11
license: BSD3
license-file: LICENSE
license-files: LICENSE
copyright: Neil Mitchell 2011-2017
maintainer: Neil Mitchell <[email protected]>
author: Neil Mitchell <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cabal-version: >=1.10
name: th-lift-instances
version: 0.1.4
license: BSD3
license-file: LICENSE
license-files: LICENSE
copyright: Copyright (C) 2013-2014 Benno Fünfstück
maintainer: Benno Fünfstück <[email protected]>
author: Benno Fünfstück
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: >=1.6
name: wl-pprint-indef
version: 1.2
license: BSD3
license-file: LICENSE
license-files: LICENSE
maintainer: Noam Lewis <[email protected]>
author: Daan Leijen
synopsis: The Wadler/Leijen Pretty Printer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tests = testGroup "Distribution.Utils.Structured"
, testCase "GenericPackageDescription" $
md5Check (Proxy :: Proxy GenericPackageDescription) 0xedd391339de1201511636bbb563fa5db
, testCase "LocalBuildInfo" $
md5Check (Proxy :: Proxy LocalBuildInfo) 0x40253e3699453643336bdc7911717af0
md5Check (Proxy :: Proxy LocalBuildInfo) 0x70da7ec48f751a73d4958e5fc0bbd25e
#endif
]

Expand Down
4 changes: 4 additions & 0 deletions Cabal/src/Distribution/Simple/BuildPaths.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Distribution.Simple.BuildPaths
, haddockDirName
, hscolourPref
, haddockPref
, licenseFilePref
, autogenPackageModulesDir
, autogenComponentModulesDir
, autogenPathsModuleName
Expand Down Expand Up @@ -90,6 +91,9 @@ haddockPref :: HaddockTarget -> FilePath -> PackageDescription -> FilePath
haddockPref haddockTarget distPref pkg_descr =
distPref </> "doc" </> "html" </> haddockDirName haddockTarget pkg_descr

licenseFilePref :: FilePath -> FilePath -> FilePath
licenseFilePref docPref = (docPref </>)

-- | The directory in which we put auto-generated modules for EVERY
-- component in the package.
autogenPackageModulesDir :: LocalBuildInfo -> String
Expand Down
9 changes: 6 additions & 3 deletions Cabal/src/Distribution/Simple/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ import Distribution.Types.UnqualComponentName

import Distribution.Package
import Distribution.PackageDescription
import Distribution.Simple.BuildPaths (haddockName, haddockPref)
import Distribution.Simple.BuildPaths
( haddockName
, haddockPref
, licenseFilePref
)
import Distribution.Simple.BuildTarget
import Distribution.Simple.Compiler
( CompilerFlavor (..)
Expand Down Expand Up @@ -74,7 +78,6 @@ import System.Directory
import System.FilePath
( isRelative
, takeDirectory
, takeFileName
, (</>)
)

Expand Down Expand Up @@ -182,7 +185,7 @@ copyPackage verbosity pkg_descr lbi distPref copydest = do
for_ lfiles $ \lfile' -> do
let lfile :: FilePath
lfile = getSymbolicPath lfile'
installOrdinaryFile verbosity lfile (docPref </> takeFileName lfile)
installOrdinaryFile verbosity lfile (licenseFilePref docPref lfile)

-- | Copy files associated with a component.
copyComponent
Expand Down
2 changes: 2 additions & 0 deletions Cabal/src/Distribution/Simple/Register.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,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
import System.Directory
Expand Down Expand Up @@ -497,6 +498,7 @@ 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 = licenseFilePref (docdir installDirs) . getSymbolicPath <$> licenseFiles pkg
, IPI.copyright = copyright pkg
, IPI.maintainer = maintainer pkg
, IPI.author = author pkg
Expand Down
11 changes: 11 additions & 0 deletions changelog.d/pr-9172
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
synopsis: Add `licenseFiles` to `InstalledPackageInfo`
packages: Cabal-syntax Cabal
prs: #9172
issues: #701 #9184

description: {

- A new field `licenseFiles` is added to `InstalledPackageInfo` to track their locations.
- The field `licenseFiles` is pretty printed as `license-files` canonically.

}