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
f470eacb
Commit
f470eacb
authored
Apr 08, 2020
by
Matt Renaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Default cabal init application-dir to app, and library source-dir to src.
parent
c5d4b7ce
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
88 additions
and
28 deletions
+88
-28
cabal-install/Distribution/Client/Config.hs
cabal-install/Distribution/Client/Config.hs
+2
-2
cabal-install/Distribution/Client/Init/Command.hs
cabal-install/Distribution/Client/Init/Command.hs
+76
-24
cabal-install/Distribution/Client/Init/Defaults.hs
cabal-install/Distribution/Client/Init/Defaults.hs
+9
-1
cabal-install/Distribution/Client/Init/Prompt.hs
cabal-install/Distribution/Client/Init/Prompt.hs
+0
-1
changelog.d/cabal-init
changelog.d/cabal-init
+1
-0
No files found.
cabal-install/Distribution/Client/Config.hs
View file @
f470eacb
...
...
@@ -851,8 +851,8 @@ commentSavedConfig = do
IT
.
cabalVersion
=
toFlag
IT
.
defaultCabalVersion
,
IT
.
language
=
toFlag
Haskell2010
,
IT
.
license
=
NoFlag
,
IT
.
sourceDirs
=
Nothing
,
IT
.
applicationDirs
=
Nothing
IT
.
sourceDirs
=
Just
[
IT
.
defaultSourceDir
]
,
IT
.
applicationDirs
=
Just
[
IT
.
defaultApplicationDir
]
},
savedInstallFlags
=
defaultInstallFlags
,
savedClientInstallFlags
=
defaultClientInstallFlags
,
...
...
cabal-install/Distribution/Client/Init/Command.hs
View file @
f470eacb
...
...
@@ -59,13 +59,13 @@ import Distribution.Types.LibraryName
import
Language.Haskell.Extension
(
Language
(
..
)
)
import
Distribution.Client.Init.Defaults
(
defaultCabalVersion
,
myLibModule
)
(
defaultApplicationDir
,
defaultCabalVersion
,
myLibModule
,
defaultSourceDir
)
import
Distribution.Client.Init.FileCreators
(
writeLicense
,
writeChangeLog
,
createDirectories
,
createLibHs
,
createMainHs
,
createTestSuiteIfEligible
,
writeCabalFile
)
import
Distribution.Client.Init.Prompt
(
prompt
,
promptYesNo
,
promptStr
,
promptList
,
maybePrompt
,
promptListOptional
,
promptListOptional'
)
,
promptListOptional
)
import
Distribution.Client.Init.Utils
(
eligibleForTestSuite
,
message
)
import
Distribution.Client.Init.Types
...
...
@@ -482,56 +482,108 @@ getGenComments flags = do
-- | Ask for the application root directory.
getAppDir
::
InitFlags
->
IO
InitFlags
getAppDir
flags
=
do
appDirs
<-
return
(
applicationDirs
flags
)
-- No application dir if this is a 'Library'.
?>>
if
(
packageType
flags
)
==
Flag
Library
then
return
(
Just
[]
)
else
return
Nothing
?>>
fmap
(
:
[]
)
`
fmap
`
guessAppDir
flags
?>>
fmap
(
>>=
fmap
((
:
[]
)
.
either
id
id
))
(
maybePrompt
flags
(
promptListOptional'
(
"Application "
++
mainFile
++
"directory"
)
[
"src-exe"
,
"app"
]
id
))
appDirs
<-
return
(
applicationDirs
flags
)
?>>
noAppDirIfLibraryOnly
?>>
guessAppDir
flags
?>>
promptUserForApplicationDir
?>>
setDefault
return
$
flags
{
applicationDirs
=
appDirs
}
where
-- If the packageType==Library, then there is no application dir.
noAppDirIfLibraryOnly
::
IO
(
Maybe
[
String
])
noAppDirIfLibraryOnly
=
if
(
packageType
flags
)
==
Flag
Library
then
return
(
Just
[]
)
else
return
Nothing
-- Set the default application directory.
setDefault
::
IO
(
Maybe
[
String
])
setDefault
=
pure
(
Just
[
defaultApplicationDir
])
-- Prompt the user for the application directory (defaulting to "app").
-- Returns 'Nothing' if in non-interactive mode, otherwise will always
-- return a 'Just' value ('Just []' if no separate application directory).
promptUserForApplicationDir
::
IO
(
Maybe
[
String
])
promptUserForApplicationDir
=
fmap
(
either
(
:
[]
)
id
)
<$>
maybePrompt
flags
(
promptList
(
"Application "
++
mainFile
++
"directory"
)
[[
defaultApplicationDir
],
[
"src-exe"
],
[]
]
(
Just
[
defaultApplicationDir
])
showOption
True
)
showOption
::
[
String
]
->
String
showOption
[]
=
"(none)"
showOption
(
x
:
_
)
=
x
-- The name
mainFile
::
String
mainFile
=
case
mainIs
flags
of
Flag
mainPath
->
"("
++
mainPath
++
") "
_
->
""
-- | Try to guess app directory. Could try harder; for the
-- moment just looks to see whether there is a directory called 'app'.
guessAppDir
::
InitFlags
->
IO
(
Maybe
String
)
guessAppDir
::
InitFlags
->
IO
(
Maybe
[
String
]
)
guessAppDir
flags
=
do
dir
<-
maybe
getCurrentDirectory
return
.
flagToMaybe
$
packageDir
flags
appIsDir
<-
doesDirectoryExist
(
dir
</>
"app"
)
return
$
if
appIsDir
then
Just
"app"
then
Just
[
"app"
]
else
Nothing
-- | Ask for the source (library) root directory.
getSrcDir
::
InitFlags
->
IO
InitFlags
getSrcDir
flags
=
do
srcDirs
<-
return
(
sourceDirs
flags
)
-- source dir if this is an 'Executable'.
?>>
if
(
packageType
flags
)
==
Flag
Executable
then
return
(
Just
[]
)
else
return
Nothing
?>>
fmap
(
:
[]
)
`
fmap
`
guessSourceDir
flags
?>>
fmap
(
>>=
fmap
((
:
[]
)
.
either
id
id
))
(
maybePrompt
flags
(
promptListOptional'
"Library source directory"
[
"src"
,
"lib"
,
"src-lib"
]
id
))
srcDirs
<-
return
(
sourceDirs
flags
)
?>>
noSourceDirIfExecutableOnly
?>>
guessSourceDir
flags
?>>
promptUserForSourceDir
?>>
setDefault
return
$
flags
{
sourceDirs
=
srcDirs
}
where
-- If the packageType==Executable, then there is no source dir.
noSourceDirIfExecutableOnly
::
IO
(
Maybe
[
String
])
noSourceDirIfExecutableOnly
=
if
(
packageType
flags
)
==
Flag
Executable
then
return
(
Just
[]
)
else
return
Nothing
-- Set the default source directory.
setDefault
::
IO
(
Maybe
[
String
])
setDefault
=
pure
(
Just
[
defaultSourceDir
])
-- Prompt the user for the source directory (defaulting to "app").
-- Returns 'Nothing' if in non-interactive mode, otherwise will always
-- return a 'Just' value ('Just []' if no separate application directory).
promptUserForSourceDir
::
IO
(
Maybe
[
String
])
promptUserForSourceDir
=
fmap
(
either
(
:
[]
)
id
)
<$>
maybePrompt
flags
(
promptList
(
"Library source directory"
)
[[
defaultSourceDir
],
[
"lib"
],
[
"src-lib"
],
[]
]
(
Just
[
defaultSourceDir
])
showOption
True
)
showOption
::
[
String
]
->
String
showOption
[]
=
"(none)"
showOption
(
x
:
_
)
=
x
-- | Try to guess source directory. Could try harder; for the
-- moment just looks to see whether there is a directory called 'src'.
guessSourceDir
::
InitFlags
->
IO
(
Maybe
String
)
guessSourceDir
::
InitFlags
->
IO
(
Maybe
[
String
]
)
guessSourceDir
flags
=
do
dir
<-
maybe
getCurrentDirectory
return
.
flagToMaybe
$
packageDir
flags
srcIsDir
<-
doesDirectoryExist
(
dir
</>
"src"
)
return
$
if
srcIsDir
then
Just
"src"
then
Just
[
"src"
]
else
Nothing
-- | Check whether a potential source file is located in one of the
...
...
cabal-install/Distribution/Client/Init/Defaults.hs
View file @
f470eacb
...
...
@@ -13,7 +13,9 @@
-----------------------------------------------------------------------------
module
Distribution.Client.Init.Defaults
(
defaultCabalVersion
defaultApplicationDir
,
defaultSourceDir
,
defaultCabalVersion
,
myLibModule
)
where
...
...
@@ -24,6 +26,12 @@ import qualified Distribution.ModuleName as ModuleName
import
Distribution.CabalSpecVersion
(
CabalSpecVersion
(
..
))
defaultApplicationDir
::
String
defaultApplicationDir
=
"app"
defaultSourceDir
::
String
defaultSourceDir
=
"src"
defaultCabalVersion
::
CabalSpecVersion
defaultCabalVersion
=
CabalSpecV2_4
...
...
cabal-install/Distribution/Client/Init/Prompt.hs
View file @
f470eacb
...
...
@@ -20,7 +20,6 @@ module Distribution.Client.Init.Prompt (
,
promptStr
,
promptList
,
promptListOptional
,
promptListOptional'
,
maybePrompt
)
where
...
...
changelog.d/cabal-init
View file @
f470eacb
...
...
@@ -8,6 +8,7 @@ description: {
- Licenses are always asked using SPDX expression
- Fix an infinite loop when invalid license was passed on command line
- `Setup.hs` is not written anymore
- Default to --source-dir=src and --application-dir=app
TODO: complete the description
}
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