Skip to content

Commit 1916fca

Browse files
authored
Add -w/--with-compiler flag to cabal init (#5658)
`cabal init` needs a haskell compiler to operate but is missing the `-w` flag other commands have (see also #4956). This patch addresses this inconsistency. Fixes #5654 Fixes #4936
1 parent f8fe5d2 commit 1916fca

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

cabal-install/Distribution/Client/Init/Types.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ data InitFlags =
6969
, sourceDirs :: Maybe [String]
7070
, buildTools :: Maybe [String]
7171

72+
, initHcPath :: Flag FilePath
73+
7274
, initVerbosity :: Flag Verbosity
7375
, overwrite :: Flag Bool
7476
}

cabal-install/Distribution/Client/Setup.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,6 +2319,14 @@ initCommand = CommandUI {
23192319
(reqArg' "TOOL" (Just . (:[]))
23202320
(fromMaybe []))
23212321

2322+
-- NB: this is a bit of a transitional hack and will likely be
2323+
-- removed again if `cabal init` is migrated to the v2-* command
2324+
-- framework
2325+
, option "w" ["with-compiler"]
2326+
"give the path to a particular compiler"
2327+
IT.initHcPath (\v flags -> flags { IT.initHcPath = v })
2328+
(reqArgFlag "PATH")
2329+
23222330
, optionVerbosity IT.initVerbosity (\v flags -> flags { IT.initVerbosity = v })
23232331
]
23242332
}

cabal-install/main/Main.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import Distribution.Client.Setup
3838
, UploadFlags(..), uploadCommand
3939
, ReportFlags(..), reportCommand
4040
, runCommand
41-
, InitFlags(initVerbosity), initCommand
41+
, InitFlags(initVerbosity, initHcPath), initCommand
4242
, SDistFlags(..), SDistExFlags(..), sdistCommand
4343
, Win32SelfUpgradeFlags(..), win32SelfUpgradeCommand
4444
, ActAsSetupFlags(..), actAsSetupCommand
@@ -1143,7 +1143,9 @@ initAction initFlags extraArgs globalFlags = do
11431143
die' verbosity $ "'init' doesn't take any extra arguments: " ++ unwords extraArgs
11441144
(_useSandbox, config) <- loadConfigOrSandboxConfig verbosity
11451145
(globalFlags { globalRequireSandbox = Flag False })
1146-
let configFlags = savedConfigureFlags config
1146+
let configFlags = savedConfigureFlags config `mappend`
1147+
-- override with `--with-compiler` from CLI if available
1148+
mempty { configHcPath = initHcPath initFlags }
11471149
let globalFlags' = savedGlobalFlags config `mappend` globalFlags
11481150
(comp, _, progdb) <- configCompilerAux' configFlags
11491151
withRepoContext verbosity globalFlags' $ \repoContext ->

0 commit comments

Comments
 (0)