@@ -37,6 +37,7 @@ module Distribution.Client.ProjectConfig (
37
37
resolveSolverSettings ,
38
38
BuildTimeSettings (.. ),
39
39
resolveBuildTimeSettings ,
40
+ getProjectFileName ,
40
41
41
42
-- * Checking configuration
42
43
checkBadPerPackageCompilerPaths ,
@@ -46,6 +47,7 @@ module Distribution.Client.ProjectConfig (
46
47
import Prelude ()
47
48
import Distribution.Client.Compat.Prelude
48
49
50
+ import Distribution.Client.GlobalFlags
49
51
import Distribution.Client.ProjectConfig.Types
50
52
import Distribution.Client.ProjectConfig.Legacy
51
53
import Distribution.Client.RebuildMonad
@@ -55,8 +57,6 @@ import Distribution.Client.Glob
55
57
import Distribution.Client.Types
56
58
import Distribution.Client.DistDirLayout
57
59
( CabalDirLayout (.. ) )
58
- import Distribution.Client.GlobalFlags
59
- ( RepoContext (.. ), withRepoContext' )
60
60
import Distribution.Client.BuildReports.Types
61
61
( ReportLevel (.. ) )
62
62
import Distribution.Client.Config
@@ -338,14 +338,20 @@ resolveBuildTimeSettings verbosity
338
338
-- Reading and writing project config files
339
339
--
340
340
341
+ getProjectFileName :: GlobalFlags -> FilePath
342
+ getProjectFileName globalFlags =
343
+ fromFlagOrDefault " cabal.project" (globalProjectFileName globalFlags)
344
+
341
345
-- | Find the root of this project.
342
346
--
343
347
-- Searches for an explicit @cabal.project@ file, in the current directory or
344
348
-- parent directories. If no project file is found then the current dir is the
345
349
-- project root (and the project will use an implicit config).
346
350
--
347
- findProjectRoot :: IO FilePath
348
- findProjectRoot = do
351
+ findProjectRoot :: GlobalFlags -> IO FilePath
352
+ findProjectRoot globalFlags = do
353
+
354
+ let projectFileName = getProjectFileName globalFlags
349
355
350
356
curdir <- getCurrentDirectory
351
357
homedir <- getHomeDirectory
@@ -355,7 +361,7 @@ findProjectRoot = do
355
361
let probe dir | isDrive dir || dir == homedir
356
362
= return curdir -- implicit project root
357
363
probe dir = do
358
- exists <- doesFileExist (dir </> " cabal.project " )
364
+ exists <- doesFileExist (dir </> projectFileName )
359
365
if exists
360
366
then return dir -- explicit project root
361
367
else probe (takeDirectory dir)
@@ -367,20 +373,20 @@ findProjectRoot = do
367
373
-- | Read all the config relevant for a project. This includes the project
368
374
-- file if any, plus other global config.
369
375
--
370
- readProjectConfig :: Verbosity -> FilePath -> Rebuild ProjectConfig
371
- readProjectConfig verbosity projectRootDir = do
372
- global <- readGlobalConfig verbosity
373
- local <- readProjectLocalConfig verbosity projectRootDir
374
- freeze <- readProjectLocalFreezeConfig verbosity projectRootDir
375
- extra <- readProjectLocalExtraConfig verbosity projectRootDir
376
+ readProjectConfig :: Verbosity -> GlobalFlags -> FilePath -> Rebuild ProjectConfig
377
+ readProjectConfig verbosity globalFlags projectRootDir = do
378
+ global <- readGlobalConfig verbosity
379
+ local <- readProjectLocalConfig verbosity globalFlags projectRootDir
380
+ freeze <- readProjectLocalFreezeConfig verbosity globalFlags projectRootDir
381
+ extra <- readProjectLocalExtraConfig verbosity globalFlags projectRootDir
376
382
return (global <> local <> freeze <> extra)
377
383
378
384
379
385
-- | Reads an explicit @cabal.project@ file in the given project root dir,
380
386
-- or returns the default project config for an implicitly defined project.
381
387
--
382
- readProjectLocalConfig :: Verbosity -> FilePath -> Rebuild ProjectConfig
383
- readProjectLocalConfig verbosity projectRootDir = do
388
+ readProjectLocalConfig :: Verbosity -> GlobalFlags -> FilePath -> Rebuild ProjectConfig
389
+ readProjectLocalConfig verbosity globalFlags projectRootDir = do
384
390
usesExplicitProjectRoot <- liftIO $ doesFileExist projectFile
385
391
if usesExplicitProjectRoot
386
392
then do
@@ -391,7 +397,7 @@ readProjectLocalConfig verbosity projectRootDir = do
391
397
return defaultImplicitProjectConfig
392
398
393
399
where
394
- projectFile = projectRootDir </> " cabal.project "
400
+ projectFile = projectRootDir </> getProjectFileName globalFlags
395
401
readProjectFile =
396
402
reportParseResult verbosity " project file" projectFile
397
403
. parseProjectConfig
@@ -419,25 +425,25 @@ readProjectLocalConfig verbosity projectRootDir = do
419
425
-- or returns empty. This file gets written by @cabal configure@, or in
420
426
-- principle can be edited manually or by other tools.
421
427
--
422
- readProjectLocalExtraConfig :: Verbosity -> FilePath -> Rebuild ProjectConfig
423
- readProjectLocalExtraConfig verbosity =
424
- readProjectExtensionFile verbosity " local"
428
+ readProjectLocalExtraConfig :: Verbosity -> GlobalFlags -> FilePath -> Rebuild ProjectConfig
429
+ readProjectLocalExtraConfig verbosity globalFlags =
430
+ readProjectExtensionFile verbosity globalFlags " local"
425
431
" project local configuration file"
426
432
427
433
-- | Reads a @cabal.project.freeze@ file in the given project root dir,
428
434
-- or returns empty. This file gets written by @cabal freeze@, or in
429
435
-- principle can be edited manually or by other tools.
430
436
--
431
- readProjectLocalFreezeConfig :: Verbosity -> FilePath -> Rebuild ProjectConfig
432
- readProjectLocalFreezeConfig verbosity =
433
- readProjectExtensionFile verbosity " freeze"
437
+ readProjectLocalFreezeConfig :: Verbosity -> GlobalFlags -> FilePath -> Rebuild ProjectConfig
438
+ readProjectLocalFreezeConfig verbosity globalFlags =
439
+ readProjectExtensionFile verbosity globalFlags " freeze"
434
440
" project freeze file"
435
441
436
442
-- | Reads a named config file in the given project root dir, or returns empty.
437
443
--
438
- readProjectExtensionFile :: Verbosity -> String -> FilePath
444
+ readProjectExtensionFile :: Verbosity -> GlobalFlags -> String -> FilePath
439
445
-> FilePath -> Rebuild ProjectConfig
440
- readProjectExtensionFile verbosity extensionName extensionDescription
446
+ readProjectExtensionFile verbosity globalFlags extensionName extensionDescription
441
447
projectRootDir = do
442
448
exists <- liftIO $ doesFileExist extensionFile
443
449
if exists
@@ -446,7 +452,9 @@ readProjectExtensionFile verbosity extensionName extensionDescription
446
452
else do monitorFiles [monitorNonExistentFile extensionFile]
447
453
return mempty
448
454
where
449
- extensionFile = projectRootDir </> " cabal.project" <.> extensionName
455
+ extensionFile = projectRootDir </> projectFileName <.> extensionName
456
+
457
+ projectFileName = getProjectFileName globalFlags
450
458
451
459
readExtensionFile =
452
460
reportParseResult verbosity extensionDescription extensionFile
@@ -477,20 +485,20 @@ showProjectConfig =
477
485
478
486
-- | Write a @cabal.project.local@ file in the given project root dir.
479
487
--
480
- writeProjectLocalExtraConfig :: FilePath -> ProjectConfig -> IO ()
481
- writeProjectLocalExtraConfig projectRootDir =
488
+ writeProjectLocalExtraConfig :: GlobalFlags -> FilePath -> ProjectConfig -> IO ()
489
+ writeProjectLocalExtraConfig globalFlags projectRootDir =
482
490
writeProjectConfigFile projectExtraConfigFile
483
491
where
484
- projectExtraConfigFile = projectRootDir </> " cabal.project. local"
492
+ projectExtraConfigFile = projectRootDir </> getProjectFileName globalFlags <.> " local"
485
493
486
494
487
495
-- | Write a @cabal.project.freeze@ file in the given project root dir.
488
496
--
489
- writeProjectLocalFreezeConfig :: FilePath -> ProjectConfig -> IO ()
490
- writeProjectLocalFreezeConfig projectRootDir =
497
+ writeProjectLocalFreezeConfig :: GlobalFlags -> FilePath -> ProjectConfig -> IO ()
498
+ writeProjectLocalFreezeConfig globalFlags projectRootDir =
491
499
writeProjectConfigFile projectFreezeConfigFile
492
500
where
493
- projectFreezeConfigFile = projectRootDir </> " cabal.project. freeze"
501
+ projectFreezeConfigFile = projectRootDir </> getProjectFileName globalFlags <.> " freeze"
494
502
495
503
496
504
-- | Write in the @cabal.project@ format to the given file.
0 commit comments