1 module Distribution
.Client
.Init
.Simple
2 ( -- * Project creation
12 import qualified Data
.List
.NonEmpty
as NEL
13 import qualified Data
.Set
as Set
14 import Distribution
.Client
.Init
.Defaults
15 import Distribution
.Client
.Init
.FlagExtractors
16 import Distribution
.Client
.Init
.Types
17 import Distribution
.Client
.Init
.Utils
(currentDirPkgName
, fixupDocFiles
, mkPackageNameDep
)
18 import Distribution
.Client
.Types
.SourcePackageDb
(SourcePackageDb
(..))
19 import Distribution
.Simple
.Flag
(Flag
(..), flagElim
, fromFlagOrDefault
)
20 import Distribution
.Simple
.PackageIndex
21 import Distribution
.Types
.Dependency
22 import Distribution
.Types
.PackageName
(unPackageName
)
23 import Distribution
.Verbosity
28 -> InstalledPackageIndex
32 createProject v pkgIx _srcDb initFlags
= do
33 pkgType
<- packageTypePrompt initFlags
34 isMinimal
<- getMinimal initFlags
35 doOverwrite
<- getOverwrite initFlags
36 pkgDir
<- getPackageDir initFlags
37 pkgDesc
<- fixupDocFiles v
=<< genSimplePkgDesc initFlags
39 let pkgName
= _pkgName pkgDesc
40 cabalSpec
= _pkgCabalVersion pkgDesc
51 basedFlags
<- addBaseDepToFlags pkgIx initFlags
55 libTarget
<- genSimpleLibTarget basedFlags
56 testTarget
<- addLibDepToTest pkgName
<$> genSimpleTestTarget basedFlags
59 (mkOpts
False cabalSpec
)
65 exeTarget
<- genSimpleExeTarget basedFlags
68 (mkOpts
False cabalSpec
)
73 LibraryAndExecutable
-> do
74 libTarget
<- genSimpleLibTarget basedFlags
75 testTarget
<- addLibDepToTest pkgName
<$> genSimpleTestTarget basedFlags
76 exeTarget
<- addLibDepToExe pkgName
<$> genSimpleExeTarget basedFlags
79 (mkOpts
False cabalSpec
)
85 testTarget
<- genSimpleTestTarget basedFlags
88 (mkOpts
False cabalSpec
)
94 -- Add package name as dependency of test suite
96 addLibDepToTest _ Nothing
= Nothing
97 addLibDepToTest n
(Just t
) =
100 { _testDependencies
= _testDependencies t
++ [mkPackageNameDep n
]
103 -- Add package name as dependency of executable
105 addLibDepToExe n exe
=
107 { _exeDependencies
= _exeDependencies exe
++ [mkPackageNameDep n
]
110 genSimplePkgDesc
:: Interactive m
=> InitFlags
-> m PkgDescription
111 genSimplePkgDesc flags
= mkPkgDesc
<$> currentDirPkgName
113 defaultExtraDoc
= Just
$ Set
.singleton defaultChangelog
115 extractExtraDoc
[] = defaultExtraDoc
116 extractExtraDoc fs
= Just
$ Set
.fromList fs
120 (fromFlagOrDefault defaultCabalVersion
(cabalVersion flags
))
122 (fromFlagOrDefault defaultVersion
(version flags
))
123 (fromFlagOrDefault
(defaultLicense
$ getCabalVersionNoPrompt flags
) (license flags
))
124 (fromFlagOrDefault
"" (author flags
))
125 (fromFlagOrDefault
"" (email flags
))
126 (fromFlagOrDefault
"" (homepage flags
))
127 (fromFlagOrDefault
"" (synopsis flags
))
128 (fromFlagOrDefault
"" (category flags
))
129 (flagElim mempty Set
.fromList
(extraSrc flags
))
130 (flagElim defaultExtraDoc extractExtraDoc
(extraDoc flags
))
132 genSimpleLibTarget
:: Interactive m
=> InitFlags
-> m LibTarget
133 genSimpleLibTarget flags
= do
134 buildToolDeps
<- getBuildTools flags
137 { _libSourceDirs
= fromFlagOrDefault
[defaultSourceDir
] $ sourceDirs flags
138 , _libLanguage
= fromFlagOrDefault defaultLanguage
$ language flags
139 , _libExposedModules
=
140 flagElim
(myLibModule NEL
.:|
[]) extractMods
$ exposedModules flags
141 , _libOtherModules
= fromFlagOrDefault
[] $ otherModules flags
142 , _libOtherExts
= fromFlagOrDefault
[] $ otherExts flags
143 , _libDependencies
= fromFlagOrDefault
[] $ dependencies flags
144 , _libBuildTools
= buildToolDeps
147 extractMods
[] = myLibModule NEL
.:|
[]
148 extractMods
as = NEL
.fromList
as
150 genSimpleExeTarget
:: Interactive m
=> InitFlags
-> m ExeTarget
151 genSimpleExeTarget flags
= do
152 buildToolDeps
<- getBuildTools flags
155 { _exeMainIs
= flagElim defaultMainIs toHsFilePath
$ mainIs flags
156 , _exeApplicationDirs
=
157 fromFlagOrDefault
[defaultApplicationDir
] $ applicationDirs flags
158 , _exeLanguage
= fromFlagOrDefault defaultLanguage
$ language flags
159 , _exeOtherModules
= fromFlagOrDefault
[] $ otherModules flags
160 , _exeOtherExts
= fromFlagOrDefault
[] $ otherExts flags
161 , _exeDependencies
= fromFlagOrDefault
[] $ dependencies flags
162 , _exeBuildTools
= buildToolDeps
165 genSimpleTestTarget
:: Interactive m
=> InitFlags
-> m
(Maybe TestTarget
)
166 genSimpleTestTarget flags
= go
=<< initializeTestSuitePrompt flags
169 |
not initialized
= return Nothing
171 buildToolDeps
<- getBuildTools flags
175 { _testMainIs
= flagElim defaultMainIs toHsFilePath
$ mainIs flags
176 , _testDirs
= fromFlagOrDefault
[defaultTestDir
] $ testDirs flags
177 , _testLanguage
= fromFlagOrDefault defaultLanguage
$ language flags
178 , _testOtherModules
= fromFlagOrDefault
[] $ otherModules flags
179 , _testOtherExts
= fromFlagOrDefault
[] $ otherExts flags
180 , _testDependencies
= fromFlagOrDefault
[] $ dependencies flags
181 , _testBuildTools
= buildToolDeps
184 -- -------------------------------------------------------------------- --
187 -- | If deps are defined, and base is present, we skip the search for base.
188 -- otherwise, we look up @base@ and add it to the list.
189 addBaseDepToFlags
:: Interactive m
=> InstalledPackageIndex
-> InitFlags
-> m InitFlags
190 addBaseDepToFlags pkgIx initFlags
= case dependencies initFlags
of
192 |
any ((==) "base" . unPackageName
. depPkgName
) as -> return initFlags
194 based
<- dependenciesPrompt pkgIx initFlags
197 { dependencies
= Flag
$ based
++ as
200 based
<- dependenciesPrompt pkgIx initFlags
201 return initFlags
{dependencies
= Flag based
}