Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Glasgow Haskell Compiler
Packages
Cabal
Commits
9e30cb92
Commit
9e30cb92
authored
Nov 28, 2017
by
Chang Yang Jiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial feature add: create both Library and Executable on cabal init
parent
1b1e9086
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
27 deletions
+50
-27
cabal-install/Distribution/Client/Init.hs
cabal-install/Distribution/Client/Init.hs
+40
-25
cabal-install/Distribution/Client/Init/Types.hs
cabal-install/Distribution/Client/Init/Types.hs
+4
-2
cabal-install/Distribution/Client/Setup.hs
cabal-install/Distribution/Client/Setup.hs
+6
-0
No files found.
cabal-install/Distribution/Client/Init.hs
View file @
9e30cb92
...
...
@@ -60,7 +60,7 @@ import qualified Distribution.Package as P
import
Language.Haskell.Extension
(
Language
(
..
)
)
import
Distribution.Client.Init.Types
(
InitFlags
(
..
),
PackageType
(
..
),
Category
(
..
)
)
(
InitFlags
(
..
),
BuildType
(
..
),
PackageType
(
..
),
Category
(
..
)
)
import
Distribution.Client.Init.Licenses
(
bsd2
,
bsd3
,
gplv2
,
gplv3
,
lgpl21
,
lgpl3
,
agplv3
,
apache20
,
mit
,
mpl20
,
isc
)
import
Distribution.Client.Init.Heuristics
...
...
@@ -310,16 +310,16 @@ guessExtraSourceFiles flags = do
-- | Ask whether the project builds a library or executable.
getLibOrExec
::
InitFlags
->
IO
InitFlags
getLibOrExec
flags
=
do
isLib
<-
return
(
flagToMaybe
$
packageType
flags
)
pkgType
<-
return
(
flagToMaybe
$
packageType
flags
)
?>>
maybePrompt
flags
(
either
(
const
Library
)
id
`
fmap
`
promptList
"What does the package build"
[
Library
,
Executable
]
[
Library
,
Executable
,
LibraryAndExecutable
]
Nothing
display
False
)
?>>
return
(
Just
Library
)
mainFile
<-
if
isLib
/=
Just
Executable
then
return
Nothing
else
mainFile
<-
if
pkgType
==
Just
Library
then
return
Nothing
else
getMainFile
flags
return
$
flags
{
packageType
=
maybeToFlag
isLib
return
$
flags
{
packageType
=
maybeToFlag
pkgType
,
mainIs
=
maybeToFlag
mainFile
}
...
...
@@ -742,6 +742,14 @@ createMainHs flags@InitFlags{ sourceDirs = _
,
packageType
=
Flag
Executable
,
mainIs
=
Flag
mainFile
}
=
writeMainHs
flags
mainFile
createMainHs
flags
@
InitFlags
{
sourceDirs
=
Just
(
srcPath
:
_
)
,
packageType
=
Flag
LibraryAndExecutable
,
mainIs
=
Flag
mainFile
}
=
writeMainHs
flags
(
srcPath
</>
mainFile
)
createMainHs
flags
@
InitFlags
{
sourceDirs
=
_
,
packageType
=
Flag
LibraryAndExecutable
,
mainIs
=
Flag
mainFile
}
=
writeMainHs
flags
mainFile
createMainHs
_
=
return
()
-- | Write a main file if it doesn't already exist.
...
...
@@ -870,30 +878,18 @@ generateCabalFile fileName c =
False
,
case
packageType
c
of
Flag
Executable
->
text
"
\n
executable"
<+>
text
(
maybe
""
display
.
flagToMaybe
$
packageName
c
)
$$
nest
2
(
vcat
[
fieldS
"main-is"
(
mainIs
c
)
(
Just
".hs or .lhs file containing the Main module."
)
True
,
generateBuildInfo
Executable
c
])
Flag
Library
->
text
"
\n
library"
$$
nest
2
(
vcat
[
fieldS
"exposed-modules"
(
listField
(
exposedModules
c
))
(
Just
"Modules exported by the library."
)
True
,
generateBuildInfo
Library
c
])
Flag
Executable
->
executableStanza
Flag
Library
->
libraryStanza
Flag
LibraryAndExecutable
->
libraryStanza
$+$
executableStanza
_
->
empty
]
where
generateBuildInfo
::
Package
Type
->
InitFlags
->
Doc
generateBuildInfo
pkgt
ype
c'
=
vcat
generateBuildInfo
::
Build
Type
->
InitFlags
->
Doc
generateBuildInfo
artT
ype
c'
=
vcat
[
fieldS
"other-modules"
(
listField
(
otherModules
c'
))
(
Just
$
case
pkgt
ype
of
Lib
rary
->
"Modules included in this library but not exported."
Exec
utable
->
"Modules included in this executable, other than Main."
)
(
Just
$
case
artT
ype
of
Lib
Build
->
"Modules included in this library but not exported."
Exec
Build
->
"Modules included in this executable, other than Main."
)
True
,
fieldS
"other-extensions"
(
listField
(
otherExts
c'
))
...
...
@@ -964,6 +960,25 @@ generateCabalFile fileName c =
breakLine'
[]
=
[]
breakLine'
cs
=
case
span
(
==
' '
)
cs
of
(
w
,
cs'
)
->
w
:
breakLine
cs'
executableStanza
::
Doc
executableStanza
=
text
"
\n
executable"
<+>
text
(
maybe
""
display
.
flagToMaybe
$
packageName
c
)
$$
nest
2
(
vcat
[
fieldS
"main-is"
(
mainIs
c
)
(
Just
".hs or .lhs file containing the Main module."
)
True
,
generateBuildInfo
ExecBuild
c
])
libraryStanza
::
Doc
libraryStanza
=
text
"
\n
library"
$$
nest
2
(
vcat
[
fieldS
"exposed-modules"
(
listField
(
exposedModules
c
))
(
Just
"Modules exported by the library."
)
True
,
generateBuildInfo
LibBuild
c
])
-- | Generate warnings for missing fields etc.
generateWarnings
::
InitFlags
->
IO
()
generateWarnings
flags
=
do
...
...
cabal-install/Distribution/Client/Init/Types.hs
View file @
9e30cb92
...
...
@@ -78,12 +78,14 @@ data InitFlags =
-- ones, which is why we want Maybe [foo] for collecting foo values,
-- not Flag [foo].
data
PackageType
=
Library
|
Executable
data
BuildType
=
LibBuild
|
ExecBuild
data
PackageType
=
Library
|
Executable
|
LibraryAndExecutable
deriving
(
Show
,
Read
,
Eq
)
instance
Text
PackageType
where
disp
=
Disp
.
text
.
show
parse
=
Parse
.
choice
$
map
(
fmap
read
.
Parse
.
string
.
show
)
[
Library
,
Executable
]
-- TODO: eradicateNoParse
parse
=
Parse
.
choice
$
map
(
fmap
read
.
Parse
.
string
.
show
)
[
Library
,
Executable
,
LibraryAndExecutable
]
-- TODO: eradicateNoParse
instance
Monoid
InitFlags
where
mempty
=
gmempty
...
...
cabal-install/Distribution/Client/Setup.hs
View file @
9e30cb92
...
...
@@ -2012,6 +2012,12 @@ initCommand = CommandUI {
(
\
v
flags
->
flags
{
IT
.
packageType
=
v
})
(
noArg
(
Flag
IT
.
Executable
))
,
option
[]
[
"is-libandexec"
]
"Build a library and an executable."
IT
.
packageType
(
\
v
flags
->
flags
{
IT
.
packageType
=
v
})
(
noArg
(
Flag
IT
.
LibraryAndExecutable
))
,
option
[]
[
"main-is"
]
"Specify the main module."
IT
.
mainIs
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment