2 {-# LANGUAGE DeriveDataTypeable #-}
3 {-# LANGUAGE DeriveGeneric #-}
4 module Distribution
.SPDX
.LicenseExceptionId
(
5 LicenseExceptionId
(..),
9 licenseExceptionIdList
,
12 import Distribution
.Compat
.Prelude
15 import Distribution
.Compat
.Lens
(set
)
16 import Distribution
.Pretty
17 import Distribution
.Parsec
18 import Distribution
.Utils
.Generic
(isAsciiAlphaNum
)
19 import Distribution
.Utils
.Structured
(Structured
(..), nominalStructure
, typeVersion
)
20 import Distribution
.SPDX
.LicenseListVersion
22 import qualified Data
.Binary
.Get
as Binary
23 import qualified Data
.Binary
.Put
as Binary
24 import qualified Data
.Map
.Strict
as Map
25 import qualified Distribution
.Compat
.CharParsing
as P
26 import qualified Text
.PrettyPrint
as Disp
28 -------------------------------------------------------------------------------
30 -------------------------------------------------------------------------------
32 -- | SPDX License Exceptions identifiers list v3.25
33 data LicenseExceptionId
35 deriving (Eq
, Ord
, Enum
, Bounded
, Show, Read, Typeable
, Data
, Generic
)
37 instance Binary LicenseExceptionId
where
38 put
= Binary
.putWord8
. fromIntegral . fromEnum
41 if i
> fromIntegral (fromEnum (maxBound :: LicenseExceptionId
))
42 then fail "Too large LicenseExceptionId tag"
43 else return (toEnum (fromIntegral i
))
45 -- note: remember to bump version each time the definition changes
46 instance Structured LicenseExceptionId
where
47 structure p
= set typeVersion
306 $ nominalStructure p
49 instance Pretty LicenseExceptionId
where
50 pretty
= Disp
.text
. licenseExceptionId
52 instance Parsec LicenseExceptionId
where
54 n
<- some
$ P
.satisfy
$ \c
-> isAsciiAlphaNum c || c
== '-' || c
== '.'
55 v
<- askCabalSpecVersion
56 maybe (fail $ "Unknown SPDX license exception identifier: " ++ n
) return $
57 mkLicenseExceptionId
(cabalSpecVersionToSPDXListVersion v
) n
59 instance NFData LicenseExceptionId
where
62 -------------------------------------------------------------------------------
64 -------------------------------------------------------------------------------
66 -- | License SPDX identifier, e.g. @"BSD-3-Clause"@.
67 licenseExceptionId
:: LicenseExceptionId
-> String
68 {% for l
in licenses
%}
69 licenseExceptionId
{{l
.constructor
}} = {{l
.id}}
72 -- | License name, e.g. @"GNU General Public License v2.0 only"@
73 licenseExceptionName
:: LicenseExceptionId
-> String
74 {% for l
in licenses
%}
75 licenseExceptionName
{{l
.constructor
}} = {{l
.name
}}
78 -------------------------------------------------------------------------------
80 -------------------------------------------------------------------------------
82 licenseExceptionIdList
:: LicenseListVersion
-> [LicenseExceptionId
]
83 licenseExceptionIdList LicenseListVersion_3_0
=
84 {{licenseList_perv
.v_3_0
}}
86 licenseExceptionIdList LicenseListVersion_3_2
=
87 {{licenseList_perv
.v_3_2
}}
89 licenseExceptionIdList LicenseListVersion_3_6
=
90 {{licenseList_perv
.v_3_6
}}
92 licenseExceptionIdList LicenseListVersion_3_9
=
93 {{licenseList_perv
.v_3_9
}}
95 licenseExceptionIdList LicenseListVersion_3_10
=
96 {{licenseList_perv
.v_3_10
}}
98 licenseExceptionIdList LicenseListVersion_3_16
=
99 {{licenseList_perv
.v_3_16
}}
101 licenseExceptionIdList LicenseListVersion_3_23
=
102 {{licenseList_perv
.v_3_23
}}
104 licenseExceptionIdList LicenseListVersion_3_25
=
105 {{licenseList_perv
.v_3_25
}}
108 -- | Create a 'LicenseExceptionId' from a 'String'.
109 mkLicenseExceptionId
:: LicenseListVersion
-> String -> Maybe LicenseExceptionId
110 mkLicenseExceptionId LicenseListVersion_3_0 s
= Map
.lookup s stringLookup_3_0
111 mkLicenseExceptionId LicenseListVersion_3_2 s
= Map
.lookup s stringLookup_3_2
112 mkLicenseExceptionId LicenseListVersion_3_6 s
= Map
.lookup s stringLookup_3_6
113 mkLicenseExceptionId LicenseListVersion_3_9 s
= Map
.lookup s stringLookup_3_9
114 mkLicenseExceptionId LicenseListVersion_3_10 s
= Map
.lookup s stringLookup_3_10
115 mkLicenseExceptionId LicenseListVersion_3_16 s
= Map
.lookup s stringLookup_3_16
116 mkLicenseExceptionId LicenseListVersion_3_23 s
= Map
.lookup s stringLookup_3_23
117 mkLicenseExceptionId LicenseListVersion_3_25 s
= Map
.lookup s stringLookup_3_25
119 stringLookup_3_0
:: Map
String LicenseExceptionId
120 stringLookup_3_0
= Map
.fromList
$ map (\i
-> (licenseExceptionId i
, i
)) $
121 licenseExceptionIdList LicenseListVersion_3_0
123 stringLookup_3_2
:: Map
String LicenseExceptionId
124 stringLookup_3_2
= Map
.fromList
$ map (\i
-> (licenseExceptionId i
, i
)) $
125 licenseExceptionIdList LicenseListVersion_3_2
127 stringLookup_3_6
:: Map
String LicenseExceptionId
128 stringLookup_3_6
= Map
.fromList
$ map (\i
-> (licenseExceptionId i
, i
)) $
129 licenseExceptionIdList LicenseListVersion_3_6
131 stringLookup_3_9
:: Map
String LicenseExceptionId
132 stringLookup_3_9
= Map
.fromList
$ map (\i
-> (licenseExceptionId i
, i
)) $
133 licenseExceptionIdList LicenseListVersion_3_9
135 stringLookup_3_10
:: Map
String LicenseExceptionId
136 stringLookup_3_10
= Map
.fromList
$ map (\i
-> (licenseExceptionId i
, i
)) $
137 licenseExceptionIdList LicenseListVersion_3_10
139 stringLookup_3_16
:: Map
String LicenseExceptionId
140 stringLookup_3_16
= Map
.fromList
$ map (\i
-> (licenseExceptionId i
, i
)) $
141 licenseExceptionIdList LicenseListVersion_3_16
143 stringLookup_3_23
:: Map
String LicenseExceptionId
144 stringLookup_3_23
= Map
.fromList
$ map (\i
-> (licenseExceptionId i
, i
)) $
145 licenseExceptionIdList LicenseListVersion_3_23
147 stringLookup_3_25
:: Map
String LicenseExceptionId
148 stringLookup_3_25
= Map
.fromList
$ map (\i
-> (licenseExceptionId i
, i
)) $
149 licenseExceptionIdList LicenseListVersion_3_25
151 -- | License exceptions in all SPDX License lists
152 bulkOfLicenses
:: [LicenseExceptionId
]