Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Glasgow Haskell Compiler
Packages
Cabal
Commits
526bec73
Unverified
Commit
526bec73
authored
Dec 04, 2017
by
Mikhail Glushenkov
Committed by
GitHub
Dec 04, 2017
Browse files
Merge pull request #4916 from cj285/extendedCabalBranch
Initial feature add: create both Library and Executable on cabal init
parents
6e1871a5
d5bc75f1
Changes
3
Hide whitespace changes
Inline
Side-by-side
cabal-install/Distribution/Client/Init.hs
View file @
526bec73
...
...
@@ -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
}
...
...
@@ -734,17 +734,16 @@ createSourceDirectories flags = case sourceDirs flags of
-- | Create Main.hs, but only if we are init'ing an executable and
-- the mainIs flag has been provided.
createMainHs
::
InitFlags
->
IO
()
createMainHs
flags
@
InitFlags
{
sourceDirs
=
Just
(
srcPath
:
_
)
,
packageType
=
Flag
Executable
,
mainIs
=
Flag
mainFile
}
=
writeMainHs
flags
(
srcPath
</>
mainFile
)
createMainHs
flags
@
InitFlags
{
sourceDirs
=
_
,
packageType
=
Flag
Executable
,
mainIs
=
Flag
mainFile
}
=
writeMainHs
flags
mainFile
createMainHs
_
=
return
()
-- | Write a main file if it doesn't already exist.
createMainHs
flags
=
if
hasMainHs
flags
then
case
sourceDirs
flags
of
Just
(
srcPath
:
_
)
->
writeMainHs
flags
(
srcPath
</>
mainFile
)
_
->
writeMainHs
flags
mainFile
else
return
()
where
Flag
mainFile
=
mainIs
flags
--- | Write a main file if it doesn't already exist.
writeMainHs
::
InitFlags
->
FilePath
->
IO
()
writeMainHs
flags
mainPath
=
do
dir
<-
maybe
getCurrentDirectory
return
(
flagToMaybe
$
packageDir
flags
)
...
...
@@ -754,6 +753,12 @@ writeMainHs flags mainPath = do
message
flags
$
"Generating "
++
mainPath
++
"..."
writeFileSafe
flags
mainFullPath
mainHs
-- | Checks to see if a main file shoulcd exist
hasMainHs
::
InitFlags
->
Bool
hasMainHs
flags
=
case
mainIs
flags
of
Flag
_
->
(
packageType
flags
==
Flag
Executable
||
packageType
flags
==
Flag
LibraryAndExecutable
)
_
->
False
-- | Default Main.hs file. Used when no Main.hs exists.
mainHs
::
String
mainHs
=
unlines
...
...
@@ -870,30 +875,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
buildT
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
buildT
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 +957,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 @
526bec73
...
...
@@ -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 @
526bec73
...
...
@@ -2012,6 +2012,12 @@ initCommand = CommandUI {
(
\
v
flags
->
flags
{
IT
.
packageType
=
v
})
(
noArg
(
Flag
IT
.
Executable
))
,
option
[]
[
"is-libandexe"
]
"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
Supports
Markdown
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