Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cabal Init Omnibus #7344

Merged
merged 37 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1068755
Rewrite `cabal init` command
emilypi May 4, 2021
5892f42
Add changelog.d entry for #7344
emilypi May 4, 2021
186d448
Changing to canonicalizePathNoThrow to prevent exceptions
ptkato May 4, 2021
6a7621c
Preppending the package dir to the app dir
ptkato May 4, 2021
7c82d28
Using the compiler version from Distribution.Simple.Compiler
ptkato May 4, 2021
299db9a
Adding tests for base version bounds
ptkato May 4, 2021
b5b1865
revert compiler argument in createProject
emilypi May 5, 2021
c92b2ad
explicit fix for 6864
emilypi May 5, 2021
d2242f3
Add flag for extra doc file
emilypi May 5, 2021
e398baa
add adaptive fix for #6864
emilypi May 5, 2021
d32ec70
output warning for doc files specified with cabal spec < 1.18
emilypi May 5, 2021
977de79
add formatters + fix text for extra doc + extra src files
emilypi May 5, 2021
6bb2df8
remove little version parser, fix up some hanging cruft
emilypi May 5, 2021
bb3afee
fix formatter extra-doc-files
emilypi May 5, 2021
6fff94d
Adjusting module name detection to ignore comments
ptkato May 6, 2021
06c9595
Adding boundaries for the other-extensions parser
ptkato May 6, 2021
a9daeff
fix build-tool vs build-tool-depends problem
emilypi May 7, 2021
035a6bc
fix build-tool-depends inferrance
emilypi May 7, 2021
79f69b9
fix build-tool-depends inferrance
emilypi May 7, 2021
9042b79
TODO for patrick
emilypi May 7, 2021
0e9de06
Adding checks for module name correctness and file existence
ptkato May 8, 2021
e2806fa
Adapting tests for the new dependency checks
ptkato May 8, 2021
fcce141
Adding more checks for the existence of paths
ptkato May 11, 2021
a63fe9b
Adjusting tests for the remaining checks
ptkato May 12, 2021
836d6b6
Pinpointing in which modules the packages couldn't be found
ptkato May 12, 2021
7d91d3c
remove golden file cruft
emilypi May 14, 2021
0d20866
Parametrizing verbosity for dependencies function
ptkato May 14, 2021
a0f1ef2
undo reversion
emilypi May 14, 2021
5995ada
respect minimal flag
emilypi May 14, 2021
03dbdd7
regen golden tests with better names
emilypi May 14, 2021
509a2dd
fix warnings
emilypi May 15, 2021
9118940
fix some prompt bugs, last minute file creation bugs
emilypi May 16, 2021
6ffee75
fix some prompt bugs, last minute file creation bugs
emilypi May 16, 2021
0e20b01
Remove redundant imports
emilypi May 16, 2021
f2c8bb7
improve filecreation consistency and safety checks
emilypi May 17, 2021
76468fb
remove tem dir
emilypi May 17, 2021
1ae7433
remove stale test directory
emilypi May 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/Init.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ initCmd v packageDBs repoCtxt comp progdb initFlags = do
installedPkgIndex <- getInstalledPackages v comp packageDBs progdb
sourcePkgDb <- getSourcePackages v repoCtxt
hSetBuffering stdout NoBuffering
settings <- createProject v installedPkgIndex sourcePkgDb initFlags
settings <- createProject v comp installedPkgIndex sourcePkgDb initFlags
writeProject settings
where
-- When no flag is set, default to interactive.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import Distribution.Client.Types (SourcePackageDb(..))
import Distribution.Solver.Types.PackageIndex (elemByPackageName)

import Language.Haskell.Extension (Language(..))
import Distribution.Simple.Compiler



Expand All @@ -69,11 +70,12 @@ import Language.Haskell.Extension (Language(..))
createProject
:: Interactive m
=> Verbosity
-> Compiler
-> InstalledPackageIndex
-> SourcePackageDb
-> InitFlags
-> m ProjectSettings
createProject v pkgIx srcDb initFlags = do
createProject v _comp pkgIx srcDb initFlags = do
Copy link
Member Author

@emilypi emilypi May 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ptkato This is unused in a bunch of cases (interactive + simple, including thier tests). I'd just configure NonInteractive.createProject to take the compiler arg first and then return NonInteractive.createProject comp as the function returned in the where clause. Otherwise it just introduces cruft into more places than we want.


-- The workflow is as follows:
--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,20 @@ import Distribution.Utils.Generic (safeHead)
import Language.Haskell.Extension (Language(..), Extension(..))

import System.FilePath (splitDirectories, (</>))
import Distribution.Simple.Compiler


-- | Main driver for interactive prompt code.
--
createProject
:: Interactive m
=> Verbosity
-> Compiler
-> InstalledPackageIndex
-> SourcePackageDb
-> InitFlags
-> m ProjectSettings
createProject v pkgIx srcDb initFlags = do
createProject v comp pkgIx srcDb initFlags = do

-- The workflow is as follows:
--
Expand Down Expand Up @@ -109,24 +111,24 @@ createProject v pkgIx srcDb initFlags = do

case pkgType of
Library -> do
libTarget <- genLibTarget initFlags pkgIx
testTarget <- genTestTarget initFlags pkgIx
libTarget <- genLibTarget initFlags comp pkgIx
testTarget <- genTestTarget initFlags comp pkgIx

return $ ProjectSettings
(mkOpts comments) pkgDesc
(Just libTarget) Nothing testTarget

Executable -> do
exeTarget <- genExeTarget initFlags pkgIx
exeTarget <- genExeTarget initFlags comp pkgIx

return $ ProjectSettings
(mkOpts comments) pkgDesc Nothing
(Just exeTarget) Nothing

LibraryAndExecutable -> do
libTarget <- genLibTarget initFlags pkgIx
exeTarget <- genExeTarget initFlags pkgIx
testTarget <- genTestTarget initFlags pkgIx
libTarget <- genLibTarget initFlags comp pkgIx
exeTarget <- genExeTarget initFlags comp pkgIx
testTarget <- genTestTarget initFlags comp pkgIx

return $ ProjectSettings
(mkOpts comments) pkgDesc (Just libTarget)
Expand All @@ -152,13 +154,14 @@ genPkgDescription flags srcDb = PkgDescription
genLibTarget
:: Interactive m
=> InitFlags
-> Compiler
-> InstalledPackageIndex
-> m LibTarget
genLibTarget flags pkgs = do
genLibTarget flags comp pkgs = do
srcDirs <- srcDirsHeuristics flags
let srcDir = fromMaybe defaultSourceDir $ safeHead srcDirs
LibTarget srcDirs
<$> languageHeuristics flags
<$> languageHeuristics flags comp
<*> exposedModulesHeuristics flags
<*> libOtherModulesHeuristics flags
<*> otherExtsHeuristics flags srcDir
Expand All @@ -168,15 +171,16 @@ genLibTarget flags pkgs = do
genExeTarget
:: Interactive m
=> InitFlags
-> Compiler
-> InstalledPackageIndex
-> m ExeTarget
genExeTarget flags pkgs = do
genExeTarget flags comp pkgs = do
appDirs <- appDirsHeuristics flags
let appDir = fromMaybe defaultApplicationDir $ safeHead appDirs
ExeTarget
<$> mainFileHeuristics flags
<*> pure appDirs
<*> languageHeuristics flags
<*> languageHeuristics flags comp
<*> exeOtherModulesHeuristics flags
<*> otherExtsHeuristics flags appDir
<*> dependenciesHeuristics flags appDir pkgs
Expand All @@ -185,9 +189,10 @@ genExeTarget flags pkgs = do
genTestTarget
:: Interactive m
=> InitFlags
-> Compiler
-> InstalledPackageIndex
-> m (Maybe TestTarget)
genTestTarget flags pkgs = do
genTestTarget flags comp pkgs = do
initialized <- initializeTestSuiteHeuristics flags
testDirs' <- testDirsHeuristics flags
let testDir = fromMaybe defaultTestDir $ safeHead testDirs'
Expand All @@ -196,7 +201,7 @@ genTestTarget flags pkgs = do
else fmap Just $ TestTarget
<$> testMainHeuristics flags
<*> pure testDirs'
<*> languageHeuristics flags
<*> languageHeuristics flags comp
<*> testOtherModulesHeuristics flags
<*> otherExtsHeuristics flags testDir
<*> dependenciesHeuristics flags testDir pkgs
Expand Down Expand Up @@ -304,8 +309,8 @@ testDirsHeuristics :: Interactive m => InitFlags -> m [String]
testDirsHeuristics flags = getTestDirs flags $ return [defaultTestDir]

-- | Ask for the Haskell base language of the package.
languageHeuristics :: Interactive m => InitFlags -> m Language
languageHeuristics flags = getLanguage flags guessLanguage
languageHeuristics :: Interactive m => InitFlags -> Compiler -> m Language
languageHeuristics flags comp = getLanguage flags $ guessLanguage comp

-- | Ask whether to generate explanatory comments.
noCommentsHeuristics :: Interactive m => InitFlags -> m Bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import Distribution.CabalSpecVersion
import Language.Haskell.Extension
import Distribution.Version
import Distribution.Types.PackageName (PackageName, mkPackageName)
import Distribution.Simple.Compiler



Expand Down Expand Up @@ -72,15 +73,12 @@ guessCabalSpecVersion = do
format' (x:xs) = x : format' xs

-- | Guess the language specification based on the GHC version
guessLanguage :: Interactive m => m Language
guessLanguage = do
(_, verString, _) <- readProcessWithExitCode "ghc" ["--version"] ""
case simpleParsec <$> runParser versionParser () "" verString of
Right (Just ver) -> return $
if ver < mkVersion [7,0,1]
then Haskell98
else Haskell2010
_ -> return defaultLanguage
guessLanguage :: Interactive m => Compiler -> m Language
guessLanguage Compiler {compilerId = CompilerId GHC ver} =
return $ if ver < mkVersion [7,0,1]
then Haskell98
else Haskell2010
guessLanguage _ = return defaultLanguage

-- | Guess the package name based on the given root directory.
guessPackageName :: Interactive m => FilePath -> m PackageName
Expand Down
4 changes: 3 additions & 1 deletion cabal-install/src/Distribution/Client/Init/Simple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ import Distribution.Client.Init.Utils (currentDirPkgName, mkPackageNameDep)
import Distribution.Client.Init.Defaults
import Distribution.Simple.Flag (fromFlagOrDefault, flagElim)
import Distribution.Client.Init.FlagExtractors
import Distribution.Simple.Compiler


createProject
:: Interactive m
=> Verbosity
-> Compiler
-> InstalledPackageIndex
-> SourcePackageDb
-> InitFlags
-> m ProjectSettings
createProject v _pkgIx _srcDb initFlags = do
createProject v _comp _pkgIx _srcDb initFlags = do
pkgType <- packageTypePrompt initFlags
isMinimal <- getMinimal initFlags
doOverwrite <- getOverwrite initFlags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ tests
-> InstalledPackageIndex
-> SourcePackageDb
-> TestTree
tests v initFlags _comp pkgIx srcDb = testGroup "golden"
tests v initFlags comp pkgIx srcDb = testGroup "golden"
[ goldenLibTests v pkgIx pkgDir pkgName
, goldenExeTests v pkgIx pkgDir pkgName
, goldenTestTests v pkgIx pkgDir pkgName
, goldenPkgDescTests v srcDb pkgDir pkgName
, goldenCabalTests v pkgIx srcDb
, goldenCabalTests v comp pkgIx srcDb
]
where
pkgDir = evalPrompt (getPackageDir initFlags)
Expand Down Expand Up @@ -232,10 +232,11 @@ goldenTestTests v pkgIx pkgDir pkgName = testGroup "test golden tests"
-- | Full cabal file golden tests
goldenCabalTests
:: Verbosity
-> Compiler
-> InstalledPackageIndex
-> SourcePackageDb
-> TestTree
goldenCabalTests v pkgIx srcDb = testGroup ".cabal file golden tests"
goldenCabalTests v comp pkgIx srcDb = testGroup ".cabal file golden tests"
[ goldenVsString "Library and executable, empty flags, not simple, with comments + no minimal"
(goldenCabal "cabal-lib-and-exe-with-comments.golden") $
runGoldenTest (fullProjArgs "Y") emptyFlags
Expand All @@ -254,7 +255,7 @@ goldenCabalTests v pkgIx srcDb = testGroup ".cabal file golden tests"
]
where
runGoldenTest args flags =
case _runPrompt (createProject v pkgIx srcDb flags) args of
case _runPrompt (createProject v comp pkgIx srcDb flags) args of
Left e -> assertFailure $ show e

(Right (ProjectSettings opts pkgDesc (Just libTarget) (Just exeTarget) (Just testTarget), _)) -> do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ tests
-> InstalledPackageIndex
-> SourcePackageDb
-> TestTree
tests _v initFlags _comp pkgIx srcDb =
tests _v initFlags comp pkgIx srcDb =
testGroup "Distribution.Client.Init.Interactive.Command.hs"
[ createProjectTest pkgIx srcDb
[ createProjectTest comp pkgIx srcDb
, fileCreatorTests pkgIx srcDb pkgName
, interactiveTests srcDb
]
Expand All @@ -52,10 +52,11 @@ tests _v initFlags _comp pkgIx srcDb =
-- pkgNm = evalPrompt (getPackageName srcDb initFlags) $ fromList ["test-package", "y"]

createProjectTest
:: InstalledPackageIndex
:: Compiler
-> InstalledPackageIndex
-> SourcePackageDb
-> TestTree
createProjectTest pkgIx srcDb = testGroup "createProject tests"
createProjectTest comp pkgIx srcDb = testGroup "createProject tests"
[ testGroup "with flags"
[ testCase "Check the non-interactive workflow" $ do
let dummyFlags' = dummyFlags
Expand All @@ -72,7 +73,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
, dependencies = Flag []
}

case (_runPrompt $ createProject silent pkgIx srcDb dummyFlags') (fromList ["3", "quxTest/Main.hs"]) of
case (_runPrompt $ createProject silent comp pkgIx srcDb dummyFlags') (fromList ["3", "quxTest/Main.hs"]) of
Right (ProjectSettings opts desc (Just lib) (Just exe) (Just test), _) -> do
_optOverwrite opts @?= False
_optMinimal opts @?= False
Expand Down Expand Up @@ -174,7 +175,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
, "y"
]

case (_runPrompt $ createProject silent pkgIx srcDb (emptyFlags {initializeTestSuite = Flag True})) inputs of
case (_runPrompt $ createProject silent comp pkgIx srcDb (emptyFlags {initializeTestSuite = Flag True})) inputs of
Right (ProjectSettings opts desc (Just lib) (Just exe) (Just test), _) -> do
_optOverwrite opts @?= False
_optMinimal opts @?= False
Expand Down Expand Up @@ -267,7 +268,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
, "y"
]

case (_runPrompt $ createProject silent pkgIx srcDb (emptyFlags {initializeTestSuite = Flag True})) inputs of
case (_runPrompt $ createProject silent comp pkgIx srcDb (emptyFlags {initializeTestSuite = Flag True})) inputs of
Right (ProjectSettings opts desc (Just lib) Nothing (Just test), _) -> do
_optOverwrite opts @?= False
_optMinimal opts @?= False
Expand Down Expand Up @@ -355,7 +356,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
, "y"
]

case (_runPrompt $ createProject silent pkgIx srcDb emptyFlags) inputs of
case (_runPrompt $ createProject silent comp pkgIx srcDb emptyFlags) inputs of
Right (ProjectSettings opts desc (Just lib) (Just exe) Nothing, _) -> do
_optOverwrite opts @?= False
_optMinimal opts @?= False
Expand Down Expand Up @@ -435,7 +436,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
, "y"
]

case (_runPrompt $ createProject silent pkgIx srcDb emptyFlags) inputs of
case (_runPrompt $ createProject silent comp pkgIx srcDb emptyFlags) inputs of
Right (ProjectSettings opts desc (Just lib) Nothing Nothing, _) -> do
_optOverwrite opts @?= False
_optMinimal opts @?= False
Expand Down Expand Up @@ -507,7 +508,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
, "y"
]

case (_runPrompt $ createProject silent pkgIx srcDb emptyFlags) inputs of
case (_runPrompt $ createProject silent comp pkgIx srcDb emptyFlags) inputs of
Right (ProjectSettings opts desc Nothing (Just exe) Nothing, _) -> do
_optOverwrite opts @?= False
_optMinimal opts @?= False
Expand Down
Loading