@@ -31,8 +31,6 @@ import System.Directory
31
31
import System.FilePath
32
32
( (</>) , takeBaseName , equalFilePath )
33
33
34
- import Data.List
35
- ( (\\) )
36
34
import qualified Data.List.NonEmpty as NE
37
35
import Data.Function
38
36
( on )
@@ -43,8 +41,10 @@ import Control.Monad
43
41
import Control.Arrow
44
42
( (&&&) , (***) )
45
43
44
+ import Distribution.CabalSpecVersion
45
+ ( CabalSpecVersion (.. ), showCabalSpecVersion )
46
46
import Distribution.Version
47
- ( Version , mkVersion , alterVersion , versionNumbers , majorBoundVersion
47
+ ( Version , mkVersion , alterVersion , majorBoundVersion
48
48
, orLaterVersion , earlierVersion , intersectVersionRanges , VersionRange )
49
49
import Distribution.Verbosity
50
50
( Verbosity )
@@ -53,6 +53,7 @@ import Distribution.ModuleName
53
53
import Distribution.InstalledPackageInfo
54
54
( InstalledPackageInfo , exposed )
55
55
import qualified Distribution.Package as P
56
+ import qualified Distribution.SPDX as SPDX
56
57
import Distribution.Types.LibraryName
57
58
( LibraryName (.. ) )
58
59
import Language.Haskell.Extension ( Language (.. ) )
@@ -75,10 +76,6 @@ import Distribution.Client.Init.Heuristics
75
76
SourceFileEntry (.. ),
76
77
scanForModules , neededBuildPrograms )
77
78
78
- import Distribution.License
79
- ( License (.. ), knownLicenses , licenseToSPDX )
80
- import qualified Distribution.SPDX as SPDX
81
-
82
79
import Distribution.Simple.Setup
83
80
( Flag (.. ), flagToMaybe )
84
81
import Distribution.Simple.Configure
@@ -123,8 +120,8 @@ initCabal verbosity packageDBs repoCtxt comp progdb initFlags = do
123
120
initFlags' <- extendFlags installedPkgIndex sourcePkgDb initFlags
124
121
125
122
case license initFlags' of
126
- Flag PublicDomain -> return ()
127
- _ -> writeLicense initFlags'
123
+ Flag SPDX. NONE -> return ()
124
+ _ -> writeLicense initFlags'
128
125
writeChangeLog initFlags'
129
126
createDirectories (sourceDirs initFlags')
130
127
createLibHs initFlags'
@@ -189,7 +186,7 @@ getSimpleProject flags = do
189
186
flags { interactive = Flag False
190
187
, simpleProject = Flag True
191
188
, packageType = Flag LibraryAndExecutable
192
- , cabalVersion = Flag (mkVersion [ 2 , 4 ])
189
+ , cabalVersion = Flag defaultCabalVersion
193
190
}
194
191
simpleProjFlag@ _ ->
195
192
flags { simpleProject = simpleProjFlag }
@@ -205,20 +202,21 @@ getCabalVersion flags = do
205
202
cabVer <- return (flagToMaybe $ cabalVersion flags)
206
203
?>> maybePrompt flags (either (const defaultCabalVersion) id `fmap`
207
204
promptList " Please choose version of the Cabal specification to use"
208
- [mkVersion [ 1 , 10 ], mkVersion [ 2 , 0 ], mkVersion [ 2 , 2 ], mkVersion [ 2 , 4 ] ]
205
+ [CabalSpecV1_10 , CabalSpecV2_0 , CabalSpecV2_2 , CabalSpecV2_4 , CabalSpecV3_0 ]
209
206
(Just defaultCabalVersion) displayCabalVersion False )
210
207
?>> return (Just defaultCabalVersion)
211
208
212
209
return $ flags { cabalVersion = maybeToFlag cabVer }
213
210
214
211
where
215
- displayCabalVersion :: Version -> String
216
- displayCabalVersion v = case versionNumbers v of
217
- [1 ,10 ] -> " 1.10 (legacy)"
218
- [2 ,0 ] -> " 2.0 (+ support for Backpack, internal sub-libs, '^>=' operator)"
219
- [2 ,2 ] -> " 2.2 (+ support for 'common', 'elif', redundant commas, SPDX)"
220
- [2 ,4 ] -> " 2.4 (+ support for '**' globbing)"
221
- _ -> display v
212
+ displayCabalVersion :: CabalSpecVersion -> String
213
+ displayCabalVersion v = case v of
214
+ CabalSpecV1_10 -> " 1.10 (legacy)"
215
+ CabalSpecV2_0 -> " 2.0 (+ support for Backpack, internal sub-libs, '^>=' operator)"
216
+ CabalSpecV2_2 -> " 2.2 (+ support for 'common', 'elif', redundant commas, SPDX)"
217
+ CabalSpecV2_4 -> " 2.4 (+ support for '**' globbing)"
218
+ CabalSpecV3_0 -> " 3.0 (+ set notation for ==, common stanzas in ifs, more redundant commas, better pkgconfig-depends)"
219
+ _ -> showCabalSpecVersion v
222
220
223
221
224
222
@@ -269,39 +267,44 @@ getVersion flags = do
269
267
-- then prompt the user from a predefined list of licenses.
270
268
getLicense :: InitFlags -> IO InitFlags
271
269
getLicense flags = do
272
- lic <- return (flagToMaybe $ license flags)
273
- ?>> fmap (fmap (either UnknownLicense id ))
274
- (maybePrompt flags
275
- (promptList " Please choose a license" listedLicenses
276
- (Just BSD3 ) displayLicense True ))
277
-
278
- case checkLicenseInvalid lic of
279
- Just msg -> putStrLn msg >> getLicense flags
280
- Nothing -> return $ flags { license = maybeToFlag lic }
281
-
270
+ elic <- return (fmap Right $ flagToMaybe $ license flags)
271
+ ?>> maybePrompt flags (promptList " Please choose a license" listedLicenses Nothing prettyShow True )
272
+
273
+ case elic of
274
+ Nothing -> return flags { license = NoFlag }
275
+ Just (Right lic) -> return flags { license = Flag lic }
276
+ Just (Left str) -> case eitherParsec str of
277
+ Right lic -> return flags { license = Flag lic }
278
+ -- on error, loop
279
+ Left err -> do
280
+ putStrLn " The license must be a valid SPDX expression."
281
+ putStrLn err
282
+ getLicense flags
282
283
where
283
- displayLicense l | needSpdx = prettyShow (licenseToSPDX l)
284
- | otherwise = display l
285
-
286
- checkLicenseInvalid (Just (UnknownLicense t))
287
- | needSpdx = case eitherParsec t :: Either String SPDX. License of
288
- Right _ -> Nothing
289
- Left _ -> Just " \n The license must be a valid SPDX expression."
290
- | otherwise = if any (not . isAlphaNum) t
291
- then Just promptInvalidOtherLicenseMsg
292
- else Nothing
293
- checkLicenseInvalid _ = Nothing
294
-
295
- promptInvalidOtherLicenseMsg = " \n The license must be alphanumeric. " ++
296
- " If your license name has many words, " ++
297
- " the convention is to use camel case (e.g. PublicDomain). " ++
298
- " Please choose a different license."
299
-
284
+ -- perfectly we'll have this and writeLicense (in FileCreators)
285
+ -- in a single file
300
286
listedLicenses =
301
- knownLicenses \\ [GPL Nothing , LGPL Nothing , AGPL Nothing
302
- , Apache Nothing , OtherLicense ]
303
-
304
- needSpdx = maybe False (>= mkVersion [2 ,2 ]) $ flagToMaybe (cabalVersion flags)
287
+ SPDX. NONE :
288
+ map (\ lid -> SPDX. License (SPDX. ELicense (SPDX. ELicenseId lid) Nothing ))
289
+ [ SPDX. BSD_2_Clause
290
+ , SPDX. BSD_3_Clause
291
+ , SPDX. Apache_2_0
292
+ , SPDX. MIT
293
+ , SPDX. MPL_2_0
294
+ , SPDX. ISC
295
+
296
+ , SPDX. GPL_2_0_only
297
+ , SPDX. GPL_3_0_only
298
+ , SPDX. LGPL_2_1_only
299
+ , SPDX. LGPL_3_0_only
300
+ , SPDX. AGPL_3_0_only
301
+
302
+ , SPDX. GPL_2_0_or_later
303
+ , SPDX. GPL_3_0_or_later
304
+ , SPDX. LGPL_2_1_or_later
305
+ , SPDX. LGPL_3_0_or_later
306
+ , SPDX. AGPL_3_0_or_later
307
+ ]
305
308
306
309
-- | The author's name and email. Prompt, or try to guess from an existing
307
310
-- darcs repo.
@@ -641,7 +644,7 @@ chooseDep flags (m, Just ps)
641
644
where
642
645
pkgGroups = NE. groupBy ((==) `on` P. pkgName) (map P. packageId ps)
643
646
644
- desugar = maybe True (< mkVersion [ 2 ] ) $ flagToMaybe (cabalVersion flags)
647
+ desugar = maybe True (< CabalSpecV2_0 ) $ flagToMaybe (cabalVersion flags)
645
648
646
649
-- Given a list of available versions of the same package, pick a dependency.
647
650
toDep :: NonEmpty P. PackageIdentifier -> IO P. Dependency
0 commit comments