Legacy.hs 59.2 KB
Newer Older
1
{-# LANGUAGE RecordWildCards, NamedFieldPuns, DeriveGeneric #-}
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

-- | Project configuration, implementation in terms of legacy types.
--
module Distribution.Client.ProjectConfig.Legacy (

    -- * Project config in terms of legacy types
    LegacyProjectConfig,
    parseLegacyProjectConfig,
    showLegacyProjectConfig,

    -- * Conversion to and from legacy config types
    commandLineFlagsToProjectConfig,
    convertLegacyProjectConfig,
    convertLegacyGlobalConfig,
    convertToLegacyProjectConfig,

    -- * Internals, just for tests
    parsePackageLocationTokenQ,
20
    renderPackageLocationToken,
21 22
  ) where

23 24 25
import Prelude ()
import Distribution.Client.Compat.Prelude

26 27
import Distribution.Deprecated.ParseUtils (parseFlagAssignment)

28
import Distribution.Client.ProjectConfig.Types
Oleg Grenrus's avatar
Oleg Grenrus committed
29 30 31 32
import Distribution.Client.Types.RepoName (RepoName (..), unRepoName)
import Distribution.Client.Types.Repo (RemoteRepo(..), LocalRepo (..), emptyRemoteRepo)
import Distribution.Client.Types.AllowNewer (AllowNewer(..), AllowOlder(..))
import Distribution.Client.Types.SourceRepo (sourceRepositoryPackageGrammar, SourceRepoList)
33

34
import Distribution.Client.Config
35
         ( SavedConfig(..), remoteRepoFields, postProcessRepo )
36

37 38 39 40
import Distribution.Client.CmdInstall.ClientInstallFlags
         ( ClientInstallFlags(..), defaultClientInstallFlags
         , clientInstallOptions )

41 42
import Distribution.Solver.Types.ConstraintSource

43 44
import Distribution.Package
import Distribution.PackageDescription
45
         ( dispFlagAssignment )
46 47
import Distribution.Simple.Compiler
         ( OptimisationLevel(..), DebugInfoLevel(..) )
Moritz Angermann's avatar
Moritz Angermann committed
48
import Distribution.Simple.InstallDirs ( CopyDest (NoCopyDest) )
49 50 51 52
import Distribution.Simple.Setup
         ( Flag(Flag), toFlag, fromFlagOrDefault
         , ConfigFlags(..), configureOptions
         , HaddockFlags(..), haddockOptions, defaultHaddockFlags
53
         , TestFlags(..), testOptions', defaultTestFlags
54
         , BenchmarkFlags(..), benchmarkOptions', defaultBenchmarkFlags
55
         , programDbPaths', splitArgs
56
         )
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
import Distribution.Client.Setup
         ( GlobalFlags(..), globalCommand
         , ConfigExFlags(..), configureExOptions, defaultConfigExFlags
         , InstallFlags(..), installOptions, defaultInstallFlags )
import Distribution.Simple.Program
         ( programName, knownPrograms )
import Distribution.Simple.Program.Db
         ( ProgramDb, defaultProgramDb )
import Distribution.Simple.Utils
         ( lowercase )
import Distribution.Utils.NubList
         ( toNubList, fromNubList, overNubList )
import Distribution.Simple.LocalBuildInfo
         ( toPathTemplate, fromPathTemplate )

72 73 74
import Distribution.Deprecated.Text
import qualified Distribution.Deprecated.ReadP as Parse
import Distribution.Deprecated.ReadP
75
         ( ReadP, (+++) )
76 77 78
import qualified Text.PrettyPrint as Disp
import Text.PrettyPrint
         ( Doc, ($+$) )
79 80
import qualified Distribution.Deprecated.ParseUtils as ParseUtils (field)
import Distribution.Deprecated.ParseUtils
81
         ( ParseResult(..), PError(..), syntaxError, PWarning(..)
82 83
         , simpleField, commaNewLineListField, newLineListField, parseTokenQ
         , parseHaskellString, showToken )
84 85 86 87
import Distribution.Client.ParseUtils
import Distribution.Simple.Command
         ( CommandUI(commandOptions), ShowOrParseArgs(..)
         , OptionField, option, reqArg' )
88 89
import Distribution.Types.PackageVersionConstraint
         ( PackageVersionConstraint )
90 91

import qualified Data.Map as Map
92

93 94
import Network.URI (URI (..))

95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
------------------------------------------------------------------
-- Representing the project config file in terms of legacy types
--

-- | We already have parsers\/pretty-printers for almost all the fields in the
-- project config file, but they're in terms of the types used for the command
-- line flags for Setup.hs or cabal commands. We don't want to redefine them
-- all, at least not yet so for the moment we use the parsers at the old types
-- and use conversion functions.
--
-- Ultimately if\/when this project-based approach becomes the default then we
-- can redefine the parsers directly for the new types.
--
data LegacyProjectConfig = LegacyProjectConfig {
       legacyPackages          :: [String],
       legacyPackagesOptional  :: [String],
111
       legacyPackagesRepo      :: [SourceRepoList],
112
       legacyPackagesNamed     :: [PackageVersionConstraint],
113 114

       legacySharedConfig      :: LegacySharedConfig,
115
       legacyAllConfig         :: LegacyPackageConfig,
116
       legacyLocalConfig       :: LegacyPackageConfig,
117
       legacySpecificConfig    :: MapMappend PackageName LegacyPackageConfig
118 119 120 121 122 123 124 125 126 127 128 129
     } deriving Generic

instance Monoid LegacyProjectConfig where
  mempty  = gmempty
  mappend = (<>)

instance Semigroup LegacyProjectConfig where
  (<>) = gmappend

data LegacyPackageConfig = LegacyPackageConfig {
       legacyConfigureFlags    :: ConfigFlags,
       legacyInstallPkgFlags   :: InstallFlags,
130
       legacyHaddockFlags      :: HaddockFlags,
131 132
       legacyTestFlags         :: TestFlags,
       legacyBenchmarkFlags    :: BenchmarkFlags
133 134 135 136 137 138 139 140 141 142 143 144 145
     } deriving Generic

instance Monoid LegacyPackageConfig where
  mempty  = gmempty
  mappend = (<>)

instance Semigroup LegacyPackageConfig where
  (<>) = gmappend

data LegacySharedConfig = LegacySharedConfig {
       legacyGlobalFlags       :: GlobalFlags,
       legacyConfigureShFlags  :: ConfigFlags,
       legacyConfigureExFlags  :: ConfigExFlags,
146 147
       legacyInstallFlags      :: InstallFlags,
       legacyClientInstallFlags:: ClientInstallFlags
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
     } deriving Generic

instance Monoid LegacySharedConfig where
  mempty  = gmempty
  mappend = (<>)

instance Semigroup LegacySharedConfig where
  (<>) = gmappend


------------------------------------------------------------------
-- Converting from and to the legacy types
--

-- | Convert configuration from the @cabal configure@ or @cabal build@ command
-- line into a 'ProjectConfig' value that can combined with configuration from
-- other sources.
--
-- At the moment this uses the legacy command line flag types. See
-- 'LegacyProjectConfig' for an explanation.
--
commandLineFlagsToProjectConfig :: GlobalFlags
                                -> ConfigFlags  -> ConfigExFlags
171 172
                                -> InstallFlags -> ClientInstallFlags
                                -> HaddockFlags
173
                                -> TestFlags
174
                                -> BenchmarkFlags
175 176
                                -> ProjectConfig
commandLineFlagsToProjectConfig globalFlags configFlags configExFlags
177
                                installFlags clientInstallFlags
178
                                haddockFlags testFlags benchmarkFlags =
179 180 181
    mempty {
      projectConfigBuildOnly     = convertLegacyBuildOnlyFlags
                                     globalFlags configFlags
182
                                     installFlags clientInstallFlags
183
                                     haddockFlags testFlags benchmarkFlags,
184 185 186
      projectConfigShared        = convertLegacyAllPackageFlags
                                     globalFlags configFlags
                                     configExFlags installFlags,
187 188
      projectConfigLocalPackages = localConfig,
      projectConfigAllPackages   = allConfig
189
    }
190 191
  where (localConfig, allConfig) = splitConfig
                                 (convertLegacyPerPackageFlags
192 193
                                    configFlags installFlags
                                    haddockFlags testFlags benchmarkFlags)
194 195 196 197 198 199
        -- split the package config (from command line arguments) into
        -- those applied to all packages and those to local only.
        --
        -- for now we will just copy over the ProgramPaths/Args/Extra into
        -- the AllPackages.  The LocalPackages do not inherit them from
        -- AllPackages, and as such need to retain them.
Moritz Angermann's avatar
Moritz Angermann committed
200 201 202 203 204 205 206 207 208 209 210
        --
        -- The general decision rule for what to put into allConfig
        -- into localConfig is the following:
        --
        -- - anything that is host/toolchain/env specific should be applied
        --   to all packages, as packagesets have to be host/toolchain/env
        --   consistent.
        -- - anything else should be in the local config and could potentially
        --   be lifted into all-packages vial the `package *` cabal.project
        --   section.
        --
211 212 213 214
        splitConfig :: PackageConfig -> (PackageConfig, PackageConfig)
        splitConfig pc = (pc
                         , mempty { packageConfigProgramPaths = packageConfigProgramPaths pc
                                  , packageConfigProgramArgs  = packageConfigProgramArgs  pc
215 216
                                  , packageConfigProgramPathExtra = packageConfigProgramPathExtra pc
                                  , packageConfigDocumentation = packageConfigDocumentation pc })
217 218 219 220 221 222 223 224 225 226 227 228 229 230

-- | Convert from the types currently used for the user-wide @~/.cabal/config@
-- file into the 'ProjectConfig' type.
--
-- Only a subset of the 'ProjectConfig' can be represented in the user-wide
-- config. In particular it does not include packages that are in the project,
-- and it also doesn't support package-specific configuration (only
-- configuration that applies to all packages).
--
convertLegacyGlobalConfig :: SavedConfig -> ProjectConfig
convertLegacyGlobalConfig
    SavedConfig {
      savedGlobalFlags       = globalFlags,
      savedInstallFlags      = installFlags,
231
      savedClientInstallFlags= clientInstallFlags,
232 233 234 235 236 237
      savedConfigureFlags    = configFlags,
      savedConfigureExFlags  = configExFlags,
      savedUserInstallDirs   = _,
      savedGlobalInstallDirs = _,
      savedUploadFlags       = _,
      savedReportFlags       = _,
238
      savedHaddockFlags      = haddockFlags,
239 240
      savedTestFlags         = testFlags,
      savedBenchmarkFlags    = benchmarkFlags
241 242
    } =
    mempty {
243 244 245
      projectConfigBuildOnly   = configBuildOnly,
      projectConfigShared      = configShared,
      projectConfigAllPackages = configAllPackages
246 247 248 249
    }
  where
    --TODO: [code cleanup] eliminate use of default*Flags here and specify the
    -- defaults in the various resolve functions in terms of the new types.
Mikhail Glushenkov's avatar
Mikhail Glushenkov committed
250 251 252 253 254
    configExFlags'      = defaultConfigExFlags      <> configExFlags
    installFlags'       = defaultInstallFlags       <> installFlags
    clientInstallFlags' = defaultClientInstallFlags <> clientInstallFlags
    haddockFlags'       = defaultHaddockFlags       <> haddockFlags
    testFlags'          = defaultTestFlags          <> testFlags
255
    benchmarkFlags'     = defaultBenchmarkFlags     <> benchmarkFlags
256

257
    configAllPackages   = convertLegacyPerPackageFlags
258 259
                            configFlags installFlags'
                            haddockFlags' testFlags' benchmarkFlags'
260
    configShared        = convertLegacyAllPackageFlags
261 262 263 264
                            globalFlags configFlags
                            configExFlags' installFlags'
    configBuildOnly     = convertLegacyBuildOnlyFlags
                            globalFlags configFlags
265
                            installFlags' clientInstallFlags'
266
                            haddockFlags' testFlags' benchmarkFlags'
267 268 269 270 271 272 273 274 275 276 277 278 279 280


-- | Convert the project config from the legacy types to the 'ProjectConfig'
-- and associated types. See 'LegacyProjectConfig' for an explanation of the
-- approach.
--
convertLegacyProjectConfig :: LegacyProjectConfig -> ProjectConfig
convertLegacyProjectConfig
  LegacyProjectConfig {
    legacyPackages,
    legacyPackagesOptional,
    legacyPackagesRepo,
    legacyPackagesNamed,
    legacySharedConfig = LegacySharedConfig globalFlags configShFlags
281 282
                                            configExFlags installSharedFlags
                                            clientInstallFlags,
283
    legacyAllConfig,
284
    legacyLocalConfig  = LegacyPackageConfig configFlags installPerPkgFlags
285
                                             haddockFlags testFlags benchmarkFlags,
286 287 288 289 290 291 292 293 294 295
    legacySpecificConfig
  } =

    ProjectConfig {
      projectPackages              = legacyPackages,
      projectPackagesOptional      = legacyPackagesOptional,
      projectPackagesRepo          = legacyPackagesRepo,
      projectPackagesNamed         = legacyPackagesNamed,

      projectConfigBuildOnly       = configBuildOnly,
296
      projectConfigShared          = configPackagesShared,
297
      projectConfigProvenance      = mempty,
298
      projectConfigAllPackages     = configAllPackages,
299 300 301 302
      projectConfigLocalPackages   = configLocalPackages,
      projectConfigSpecificPackage = fmap perPackage legacySpecificConfig
    }
  where
303 304
    configAllPackages   = convertLegacyPerPackageFlags g i h t b
                            where LegacyPackageConfig g i h t b = legacyAllConfig
305 306
    configLocalPackages = convertLegacyPerPackageFlags
                            configFlags installPerPkgFlags haddockFlags
307
                            testFlags benchmarkFlags
308
    configPackagesShared= convertLegacyAllPackageFlags
309 310 311 312
                            globalFlags (configFlags <> configShFlags)
                            configExFlags installSharedFlags
    configBuildOnly     = convertLegacyBuildOnlyFlags
                            globalFlags configShFlags
313
                            installSharedFlags clientInstallFlags
314
                            haddockFlags testFlags benchmarkFlags
315 316

    perPackage (LegacyPackageConfig perPkgConfigFlags perPkgInstallFlags
317 318
                                    perPkgHaddockFlags perPkgTestFlags
                                    perPkgBenchmarkFlags) =
319
      convertLegacyPerPackageFlags
320 321
        perPkgConfigFlags perPkgInstallFlags perPkgHaddockFlags
                          perPkgTestFlags perPkgBenchmarkFlags
322 323 324 325 326 327 328 329 330 331 332 333 334


-- | Helper used by other conversion functions that returns the
-- 'ProjectConfigShared' subset of the 'ProjectConfig'.
--
convertLegacyAllPackageFlags :: GlobalFlags -> ConfigFlags
                             -> ConfigExFlags -> InstallFlags
                             -> ProjectConfigShared
convertLegacyAllPackageFlags globalFlags configFlags
                             configExFlags installFlags =
    ProjectConfigShared{..}
  where
    GlobalFlags {
335
      globalConfigFile        = projectConfigConfigFile,
336 337
      globalSandboxConfigFile = _, -- ??
      globalRemoteRepos       = projectConfigRemoteRepos,
338
      globalLocalRepos        = projectConfigLocalRepos,
339
      globalLocalNoIndexRepos = projectConfigLocalNoIndexRepos,
340 341
      globalProgPathExtra     = projectConfigProgPathExtra,
      globalStoreDir          = projectConfigStoreDir
342 343 344
    } = globalFlags

    ConfigFlags {
345
      configDistPref            = projectConfigDistDir,
346 347
      configHcFlavor            = projectConfigHcFlavor,
      configHcPath              = projectConfigHcPath,
348 349
      configHcPkg               = projectConfigHcPkg
    --configProgramPathExtra    = projectConfigProgPathExtra DELETE ME
350 351 352 353 354 355 356 357 358
    --configInstallDirs         = projectConfigInstallDirs,
    --configUserInstall         = projectConfigUserInstall,
    --configPackageDBs          = projectConfigPackageDBs,
    } = configFlags

    ConfigExFlags {
      configCabalVersion        = projectConfigCabalVersion,
      configExConstraints       = projectConfigConstraints,
      configPreferences         = projectConfigPreferences,
359 360
      configSolver              = projectConfigSolver,
      configAllowOlder          = projectConfigAllowOlder,
361 362 363
      configAllowNewer          = projectConfigAllowNewer,
      configWriteGhcEnvironmentFilesPolicy
                                = projectConfigWriteGhcEnvironmentFilesPolicy
364 365 366
    } = configExFlags

    InstallFlags {
367
      installProjectFileName    = projectConfigProjectFile,
368 369 370 371
      installHaddockIndex       = projectConfigHaddockIndex,
    --installReinstall          = projectConfigReinstall,
    --installAvoidReinstalls    = projectConfigAvoidReinstalls,
    --installOverrideReinstall  = projectConfigOverrideReinstall,
372
      installIndexState         = projectConfigIndexState,
373 374 375
      installMaxBackjumps       = projectConfigMaxBackjumps,
    --installUpgradeDeps        = projectConfigUpgradeDeps,
      installReorderGoals       = projectConfigReorderGoals,
376
      installCountConflicts     = projectConfigCountConflicts,
377
      installFineGrainedConflicts = projectConfigFineGrainedConflicts,
378
      installMinimizeConflictSet = projectConfigMinimizeConflictSet,
379
      installPerComponent       = projectConfigPerComponent,
kristenk's avatar
kristenk committed
380
      installIndependentGoals   = projectConfigIndependentGoals,
381
    --installShadowPkgs         = projectConfigShadowPkgs,
382
      installStrongFlags        = projectConfigStrongFlags,
383 384
      installAllowBootLibInstalls = projectConfigAllowBootLibInstalls,
      installOnlyConstrained    = projectConfigOnlyConstrained
385 386 387 388 389 390 391 392
    } = installFlags



-- | Helper used by other conversion functions that returns the
-- 'PackageConfig' subset of the 'ProjectConfig'.
--
convertLegacyPerPackageFlags :: ConfigFlags -> InstallFlags -> HaddockFlags
393 394 395
                             -> TestFlags -> BenchmarkFlags -> PackageConfig
convertLegacyPerPackageFlags configFlags installFlags
                             haddockFlags testFlags benchmarkFlags =
396 397 398
    PackageConfig{..}
  where
    ConfigFlags {
399 400 401
      configProgramPaths,
      configProgramArgs,
      configProgramPathExtra    = packageConfigProgramPathExtra,
402 403 404
      configVanillaLib          = packageConfigVanillaLib,
      configProfLib             = packageConfigProfLib,
      configSharedLib           = packageConfigSharedLib,
Moritz Angermann's avatar
Moritz Angermann committed
405
      configStaticLib           = packageConfigStaticLib,
406
      configDynExe              = packageConfigDynExe,
407
      configFullyStaticExe      = packageConfigFullyStaticExe,
408 409 410 411 412 413 414 415 416
      configProfExe             = packageConfigProfExe,
      configProf                = packageConfigProf,
      configProfDetail          = packageConfigProfDetail,
      configProfLibDetail       = packageConfigProfLibDetail,
      configConfigureArgs       = packageConfigConfigureArgs,
      configOptimization        = packageConfigOptimization,
      configProgPrefix          = packageConfigProgPrefix,
      configProgSuffix          = packageConfigProgSuffix,
      configGHCiLib             = packageConfigGHCiLib,
Ben Gamari's avatar
Ben Gamari committed
417
      configSplitSections       = packageConfigSplitSections,
418 419 420 421 422 423
      configSplitObjs           = packageConfigSplitObjs,
      configStripExes           = packageConfigStripExes,
      configStripLibs           = packageConfigStripLibs,
      configExtraLibDirs        = packageConfigExtraLibDirs,
      configExtraFrameworkDirs  = packageConfigExtraFrameworkDirs,
      configExtraIncludeDirs    = packageConfigExtraIncludeDirs,
424
      configConfigurationsFlags = packageConfigFlagAssignment,
425 426 427 428 429 430 431
      configTests               = packageConfigTests,
      configBenchmarks          = packageConfigBenchmarks,
      configCoverage            = coverage,
      configLibCoverage         = libcoverage, --deprecated
      configDebugInfo           = packageConfigDebugInfo,
      configRelocatable         = packageConfigRelocatable
    } = configFlags
432
    packageConfigProgramPaths   = MapLast    (Map.fromList configProgramPaths)
433
    packageConfigProgramArgs    = MapMappend (Map.fromListWith (++) configProgramArgs)
434 435 436 437 438 439 440 441 442 443 444 445 446

    packageConfigCoverage       = coverage <> libcoverage
    --TODO: defer this merging to the resolve phase

    InstallFlags {
      installDocumentation      = packageConfigDocumentation,
      installRunTests           = packageConfigRunTests
    } = installFlags

    HaddockFlags {
      haddockHoogle             = packageConfigHaddockHoogle,
      haddockHtml               = packageConfigHaddockHtml,
      haddockHtmlLocation       = packageConfigHaddockHtmlLocation,
447
      haddockForeignLibs        = packageConfigHaddockForeignLibs,
448
      haddockForHackage         = packageConfigHaddockForHackage,
449 450 451 452 453
      haddockExecutables        = packageConfigHaddockExecutables,
      haddockTestSuites         = packageConfigHaddockTestSuites,
      haddockBenchmarks         = packageConfigHaddockBenchmarks,
      haddockInternal           = packageConfigHaddockInternal,
      haddockCss                = packageConfigHaddockCss,
454
      haddockLinkedSource       = packageConfigHaddockLinkedSource,
455
      haddockQuickJump          = packageConfigHaddockQuickJump,
456 457 458 459
      haddockHscolourCss        = packageConfigHaddockHscolourCss,
      haddockContents           = packageConfigHaddockContents
    } = haddockFlags

460 461 462 463 464
    TestFlags {
      testHumanLog              = packageConfigTestHumanLog,
      testMachineLog            = packageConfigTestMachineLog,
      testShowDetails           = packageConfigTestShowDetails,
      testKeepTix               = packageConfigTestKeepTix,
Moritz Angermann's avatar
Moritz Angermann committed
465
      testWrapper               = packageConfigTestWrapper,
466
      testFailWhenNoTestSuites  = packageConfigTestFailWhenNoTestSuites,
467 468 469
      testOptions               = packageConfigTestTestOptions
    } = testFlags

470 471 472
    BenchmarkFlags {
      benchmarkOptions          = packageConfigBenchmarkOptions
    } = benchmarkFlags
473 474 475 476 477 478


-- | Helper used by other conversion functions that returns the
-- 'ProjectConfigBuildOnly' subset of the 'ProjectConfig'.
--
convertLegacyBuildOnlyFlags :: GlobalFlags -> ConfigFlags
479 480
                            -> InstallFlags -> ClientInstallFlags
                            -> HaddockFlags -> TestFlags
481
                            -> BenchmarkFlags
482 483
                            -> ProjectConfigBuildOnly
convertLegacyBuildOnlyFlags globalFlags configFlags
484
                              installFlags clientInstallFlags
485
                              haddockFlags _ _ =
486 487
    ProjectConfigBuildOnly{..}
  where
488
    projectConfigClientInstallFlags = clientInstallFlags
489 490 491
    GlobalFlags {
      globalCacheDir          = projectConfigCacheDir,
      globalLogsDir           = projectConfigLogsDir,
492
      globalWorldFile         = _,
493
      globalHttpTransport     = projectConfigHttpTransport,
494
      globalIgnoreExpiry      = projectConfigIgnoreExpiry
495 496 497 498 499 500 501 502 503 504
    } = globalFlags

    ConfigFlags {
      configVerbosity           = projectConfigVerbosity
    } = configFlags

    InstallFlags {
      installDryRun             = projectConfigDryRun,
      installOnly               = _,
      installOnlyDeps           = projectConfigOnlyDeps,
505
      installRootCmd            = _,
506 507 508 509 510 511 512
      installSummaryFile        = projectConfigSummaryFile,
      installLogFile            = projectConfigLogFile,
      installBuildReports       = projectConfigBuildReports,
      installReportPlanningFailure = projectConfigReportPlanningFailure,
      installSymlinkBinDir      = projectConfigSymlinkBinDir,
      installOneShot            = projectConfigOneShot,
      installNumJobs            = projectConfigNumJobs,
513
      installKeepGoing          = projectConfigKeepGoing,
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
      installOfflineMode        = projectConfigOfflineMode
    } = installFlags

    HaddockFlags {
      haddockKeepTempFiles      = projectConfigKeepTempFiles --TODO: this ought to live elsewhere
    } = haddockFlags


convertToLegacyProjectConfig :: ProjectConfig -> LegacyProjectConfig
convertToLegacyProjectConfig
    projectConfig@ProjectConfig {
      projectPackages,
      projectPackagesOptional,
      projectPackagesRepo,
      projectPackagesNamed,
529
      projectConfigAllPackages,
530 531 532 533 534 535 536 537 538
      projectConfigLocalPackages,
      projectConfigSpecificPackage
    } =
    LegacyProjectConfig {
      legacyPackages         = projectPackages,
      legacyPackagesOptional = projectPackagesOptional,
      legacyPackagesRepo     = projectPackagesRepo,
      legacyPackagesNamed    = projectPackagesNamed,
      legacySharedConfig     = convertToLegacySharedConfig projectConfig,
539 540
      legacyAllConfig        = convertToLegacyPerPackageConfig
                                 projectConfigAllPackages,
541 542 543 544 545 546 547 548 549 550 551
      legacyLocalConfig      = convertToLegacyAllPackageConfig projectConfig
                            <> convertToLegacyPerPackageConfig
                                 projectConfigLocalPackages,
      legacySpecificConfig   = fmap convertToLegacyPerPackageConfig
                                    projectConfigSpecificPackage
    }

convertToLegacySharedConfig :: ProjectConfig -> LegacySharedConfig
convertToLegacySharedConfig
    ProjectConfig {
      projectConfigBuildOnly     = ProjectConfigBuildOnly {..},
552 553 554 555
      projectConfigShared        = ProjectConfigShared {..},
      projectConfigAllPackages   = PackageConfig {
        packageConfigDocumentation
      }
556 557 558 559 560 561
    } =

    LegacySharedConfig {
      legacyGlobalFlags      = globalFlags,
      legacyConfigureShFlags = configFlags,
      legacyConfigureExFlags = configExFlags,
562 563
      legacyInstallFlags     = installFlags,
      legacyClientInstallFlags = projectConfigClientInstallFlags
564 565 566 567 568
    }
  where
    globalFlags = GlobalFlags {
      globalVersion           = mempty,
      globalNumericVersion    = mempty,
569
      globalConfigFile        = projectConfigConfigFile,
570 571 572 573 574
      globalSandboxConfigFile = mempty,
      globalConstraintsFile   = mempty,
      globalRemoteRepos       = projectConfigRemoteRepos,
      globalCacheDir          = projectConfigCacheDir,
      globalLocalRepos        = projectConfigLocalRepos,
575
      globalLocalNoIndexRepos = projectConfigLocalNoIndexRepos,
576
      globalLogsDir           = projectConfigLogsDir,
577
      globalWorldFile         = mempty,
578 579 580
      globalRequireSandbox    = mempty,
      globalIgnoreSandbox     = mempty,
      globalIgnoreExpiry      = projectConfigIgnoreExpiry,
ttuegel's avatar
ttuegel committed
581
      globalHttpTransport     = projectConfigHttpTransport,
582
      globalNix               = mempty,
583 584
      globalStoreDir          = projectConfigStoreDir,
      globalProgPathExtra     = projectConfigProgPathExtra
585 586 587 588
    }

    configFlags = mempty {
      configVerbosity     = projectConfigVerbosity,
589
      configDistPref      = projectConfigDistDir
590 591 592 593 594 595
    }

    configExFlags = ConfigExFlags {
      configCabalVersion  = projectConfigCabalVersion,
      configExConstraints = projectConfigConstraints,
      configPreferences   = projectConfigPreferences,
596 597
      configSolver        = projectConfigSolver,
      configAllowOlder    = projectConfigAllowOlder,
598 599 600
      configAllowNewer    = projectConfigAllowNewer,
      configWriteGhcEnvironmentFilesPolicy
                          = projectConfigWriteGhcEnvironmentFilesPolicy
601 602 603
    }

    installFlags = InstallFlags {
604
      installDocumentation     = packageConfigDocumentation,
605
      installHaddockIndex      = projectConfigHaddockIndex,
Moritz Angermann's avatar
Moritz Angermann committed
606
      installDest              = Flag NoCopyDest,
607 608 609 610 611 612 613
      installDryRun            = projectConfigDryRun,
      installReinstall         = mempty, --projectConfigReinstall,
      installAvoidReinstalls   = mempty, --projectConfigAvoidReinstalls,
      installOverrideReinstall = mempty, --projectConfigOverrideReinstall,
      installMaxBackjumps      = projectConfigMaxBackjumps,
      installUpgradeDeps       = mempty, --projectConfigUpgradeDeps,
      installReorderGoals      = projectConfigReorderGoals,
614
      installCountConflicts    = projectConfigCountConflicts,
615
      installFineGrainedConflicts = projectConfigFineGrainedConflicts,
616
      installMinimizeConflictSet = projectConfigMinimizeConflictSet,
kristenk's avatar
kristenk committed
617
      installIndependentGoals  = projectConfigIndependentGoals,
618 619
      installShadowPkgs        = mempty, --projectConfigShadowPkgs,
      installStrongFlags       = projectConfigStrongFlags,
620
      installAllowBootLibInstalls = projectConfigAllowBootLibInstalls,
621
      installOnlyConstrained   = projectConfigOnlyConstrained,
622 623
      installOnly              = mempty,
      installOnlyDeps          = projectConfigOnlyDeps,
624
      installIndexState        = projectConfigIndexState,
625
      installRootCmd           = mempty, --no longer supported
626 627 628 629 630
      installSummaryFile       = projectConfigSummaryFile,
      installLogFile           = projectConfigLogFile,
      installBuildReports      = projectConfigBuildReports,
      installReportPlanningFailure = projectConfigReportPlanningFailure,
      installSymlinkBinDir     = projectConfigSymlinkBinDir,
631
      installPerComponent      = projectConfigPerComponent,
632 633
      installOneShot           = projectConfigOneShot,
      installNumJobs           = projectConfigNumJobs,
634
      installKeepGoing         = projectConfigKeepGoing,
635
      installRunTests          = mempty,
636
      installOfflineMode       = projectConfigOfflineMode,
637
      installProjectFileName   = projectConfigProjectFile
638 639 640 641 642 643 644 645 646 647 648 649 650
    }


convertToLegacyAllPackageConfig :: ProjectConfig -> LegacyPackageConfig
convertToLegacyAllPackageConfig
    ProjectConfig {
      projectConfigBuildOnly = ProjectConfigBuildOnly {..},
      projectConfigShared    = ProjectConfigShared {..}
    } =

    LegacyPackageConfig {
      legacyConfigureFlags = configFlags,
      legacyInstallPkgFlags= mempty,
651
      legacyHaddockFlags   = haddockFlags,
652 653
      legacyTestFlags      = mempty,
      legacyBenchmarkFlags = mempty
654 655 656
    }
  where
    configFlags = ConfigFlags {
657
      configArgs                = mempty,
658
      configPrograms_           = mempty,
659 660 661
      configProgramPaths        = mempty,
      configProgramArgs         = mempty,
      configProgramPathExtra    = mempty,
662 663 664
      configHcFlavor            = projectConfigHcFlavor,
      configHcPath              = projectConfigHcPath,
      configHcPkg               = projectConfigHcPkg,
665
      configInstantiateWith     = mempty,
666 667 668
      configVanillaLib          = mempty,
      configProfLib             = mempty,
      configSharedLib           = mempty,
Moritz Angermann's avatar
Moritz Angermann committed
669
      configStaticLib           = mempty,
670
      configDynExe              = mempty,
671
      configFullyStaticExe      = mempty,
672 673 674 675 676 677 678 679 680 681 682
      configProfExe             = mempty,
      configProf                = mempty,
      configProfDetail          = mempty,
      configProfLibDetail       = mempty,
      configConfigureArgs       = mempty,
      configOptimization        = mempty,
      configProgPrefix          = mempty,
      configProgSuffix          = mempty,
      configInstallDirs         = mempty,
      configScratchDir          = mempty,
      configDistPref            = mempty,
683
      configCabalFilePath       = mempty,
684 685 686 687
      configVerbosity           = mempty,
      configUserInstall         = mempty, --projectConfigUserInstall,
      configPackageDBs          = mempty, --projectConfigPackageDBs,
      configGHCiLib             = mempty,
Ben Gamari's avatar
Ben Gamari committed
688
      configSplitSections       = mempty,
689 690 691 692 693 694 695 696
      configSplitObjs           = mempty,
      configStripExes           = mempty,
      configStripLibs           = mempty,
      configExtraLibDirs        = mempty,
      configExtraFrameworkDirs  = mempty,
      configConstraints         = mempty,
      configDependencies        = mempty,
      configExtraIncludeDirs    = mempty,
697
      configDeterministic       = mempty,
698
      configIPID                = mempty,
699
      configCID                 = mempty,
700
      configConfigurationsFlags = mempty,
701 702 703 704 705 706 707
      configTests               = mempty,
      configCoverage            = mempty, --TODO: don't merge
      configLibCoverage         = mempty, --TODO: don't merge
      configExactConfiguration  = mempty,
      configBenchmarks          = mempty,
      configFlagError           = mempty,                --TODO: ???
      configRelocatable         = mempty,
708
      configDebugInfo           = mempty,
709 710
      configUseResponseFiles    = mempty,
      configAllowDependingOnPrivateLibs = mempty
711 712 713 714 715 716 717 718 719 720 721 722
    }

    haddockFlags = mempty {
      haddockKeepTempFiles = projectConfigKeepTempFiles
    }


convertToLegacyPerPackageConfig :: PackageConfig -> LegacyPackageConfig
convertToLegacyPerPackageConfig PackageConfig {..} =
    LegacyPackageConfig {
      legacyConfigureFlags  = configFlags,
      legacyInstallPkgFlags = installFlags,
723
      legacyHaddockFlags    = haddockFlags,
724 725
      legacyTestFlags       = testFlags,
      legacyBenchmarkFlags  = benchmarkFlags
726 727 728
    }
  where
    configFlags = ConfigFlags {
729
      configArgs                = mempty,
730
      configPrograms_           = configPrograms_ mempty,
731 732 733
      configProgramPaths        = Map.toList (getMapLast packageConfigProgramPaths),
      configProgramArgs         = Map.toList (getMapMappend packageConfigProgramArgs),
      configProgramPathExtra    = packageConfigProgramPathExtra,
734 735 736
      configHcFlavor            = mempty,
      configHcPath              = mempty,
      configHcPkg               = mempty,
737
      configInstantiateWith     = mempty,
738 739 740
      configVanillaLib          = packageConfigVanillaLib,
      configProfLib             = packageConfigProfLib,
      configSharedLib           = packageConfigSharedLib,
Moritz Angermann's avatar
Moritz Angermann committed
741
      configStaticLib           = packageConfigStaticLib,
742
      configDynExe              = packageConfigDynExe,
743
      configFullyStaticExe      = packageConfigFullyStaticExe,
744 745 746 747 748 749 750 751 752 753 754
      configProfExe             = packageConfigProfExe,
      configProf                = packageConfigProf,
      configProfDetail          = packageConfigProfDetail,
      configProfLibDetail       = packageConfigProfLibDetail,
      configConfigureArgs       = packageConfigConfigureArgs,
      configOptimization        = packageConfigOptimization,
      configProgPrefix          = packageConfigProgPrefix,
      configProgSuffix          = packageConfigProgSuffix,
      configInstallDirs         = mempty,
      configScratchDir          = mempty,
      configDistPref            = mempty,
755
      configCabalFilePath       = mempty,
756 757 758 759
      configVerbosity           = mempty,
      configUserInstall         = mempty,
      configPackageDBs          = mempty,
      configGHCiLib             = packageConfigGHCiLib,
Ben Gamari's avatar
Ben Gamari committed
760
      configSplitSections       = packageConfigSplitSections,
761 762 763 764 765 766 767 768 769
      configSplitObjs           = packageConfigSplitObjs,
      configStripExes           = packageConfigStripExes,
      configStripLibs           = packageConfigStripLibs,
      configExtraLibDirs        = packageConfigExtraLibDirs,
      configExtraFrameworkDirs  = packageConfigExtraFrameworkDirs,
      configConstraints         = mempty,
      configDependencies        = mempty,
      configExtraIncludeDirs    = packageConfigExtraIncludeDirs,
      configIPID                = mempty,
770
      configCID                 = mempty,
771
      configDeterministic       = mempty,
772
      configConfigurationsFlags = packageConfigFlagAssignment,
773 774 775 776 777 778 779
      configTests               = packageConfigTests,
      configCoverage            = packageConfigCoverage, --TODO: don't merge
      configLibCoverage         = packageConfigCoverage, --TODO: don't merge
      configExactConfiguration  = mempty,
      configBenchmarks          = packageConfigBenchmarks,
      configFlagError           = mempty,                --TODO: ???
      configRelocatable         = packageConfigRelocatable,
780
      configDebugInfo           = packageConfigDebugInfo,
781 782
      configUseResponseFiles    = mempty,
      configAllowDependingOnPrivateLibs = mempty
783 784 785 786 787 788 789 790 791 792 793 794 795
    }

    installFlags = mempty {
      installDocumentation      = packageConfigDocumentation,
      installRunTests           = packageConfigRunTests
    }

    haddockFlags = HaddockFlags {
      haddockProgramPaths  = mempty,
      haddockProgramArgs   = mempty,
      haddockHoogle        = packageConfigHaddockHoogle,
      haddockHtml          = packageConfigHaddockHtml,
      haddockHtmlLocation  = packageConfigHaddockHtmlLocation,
796
      haddockForHackage    = packageConfigHaddockForHackage,
797
      haddockForeignLibs   = packageConfigHaddockForeignLibs,
798 799 800 801 802
      haddockExecutables   = packageConfigHaddockExecutables,
      haddockTestSuites    = packageConfigHaddockTestSuites,
      haddockBenchmarks    = packageConfigHaddockBenchmarks,
      haddockInternal      = packageConfigHaddockInternal,
      haddockCss           = packageConfigHaddockCss,
803
      haddockLinkedSource  = packageConfigHaddockLinkedSource,
804
      haddockQuickJump     = packageConfigHaddockQuickJump,
805 806 807 808
      haddockHscolourCss   = packageConfigHaddockHscolourCss,
      haddockContents      = packageConfigHaddockContents,
      haddockDistPref      = mempty,
      haddockKeepTempFiles = mempty,
809
      haddockVerbosity     = mempty,
810 811
      haddockCabalFilePath = mempty,
      haddockArgs          = mempty
812 813
    }

814 815 816 817 818 819 820
    testFlags = TestFlags {
      testDistPref    = mempty,
      testVerbosity   = mempty,
      testHumanLog    = packageConfigTestHumanLog,
      testMachineLog  = packageConfigTestMachineLog,
      testShowDetails = packageConfigTestShowDetails,
      testKeepTix     = packageConfigTestKeepTix,
Moritz Angermann's avatar
Moritz Angermann committed
821
      testWrapper     = packageConfigTestWrapper,
822
      testFailWhenNoTestSuites = packageConfigTestFailWhenNoTestSuites,
823 824 825
      testOptions     = packageConfigTestTestOptions
    }

826 827 828 829 830
    benchmarkFlags = BenchmarkFlags {
      benchmarkDistPref  = mempty,
      benchmarkVerbosity = mempty,
      benchmarkOptions   = packageConfigBenchmarkOptions
    }
831 832 833 834 835 836 837 838 839

------------------------------------------------
-- Parsing and showing the project config file
--

parseLegacyProjectConfig :: String -> ParseResult LegacyProjectConfig
parseLegacyProjectConfig =
    parseConfig legacyProjectConfigFieldDescrs
                legacyPackageConfigSectionDescrs
840
                legacyPackageConfigFGSectionDescrs
841 842 843 844 845 846 847
                mempty

showLegacyProjectConfig :: LegacyProjectConfig -> String
showLegacyProjectConfig config =
    Disp.render $
    showConfig  legacyProjectConfigFieldDescrs
                legacyPackageConfigSectionDescrs
848
                legacyPackageConfigFGSectionDescrs
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927
                config
  $+$
    Disp.text ""


legacyProjectConfigFieldDescrs :: [FieldDescr LegacyProjectConfig]
legacyProjectConfigFieldDescrs =

    [ newLineListField "packages"
        (Disp.text . renderPackageLocationToken) parsePackageLocationTokenQ
        legacyPackages
        (\v flags -> flags { legacyPackages = v })
    , newLineListField "optional-packages"
        (Disp.text . renderPackageLocationToken) parsePackageLocationTokenQ
        legacyPackagesOptional
        (\v flags -> flags { legacyPackagesOptional = v })
    , commaNewLineListField "extra-packages"
        disp parse
        legacyPackagesNamed
        (\v flags -> flags { legacyPackagesNamed = v })
    ]

 ++ map (liftField
           legacySharedConfig
           (\flags conf -> conf { legacySharedConfig = flags }))
        legacySharedConfigFieldDescrs

 ++ map (liftField
           legacyLocalConfig
           (\flags conf -> conf { legacyLocalConfig = flags }))
        legacyPackageConfigFieldDescrs

-- | This is a bit tricky since it has to cover globs which have embedded @,@
-- chars. But we don't just want to parse strictly as a glob since we want to
-- allow http urls which don't parse as globs, and possibly some
-- system-dependent file paths. So we parse fairly liberally as a token, but
-- we allow @,@ inside matched @{}@ braces.
--
parsePackageLocationTokenQ :: ReadP r String
parsePackageLocationTokenQ = parseHaskellString
                   Parse.<++ parsePackageLocationToken
  where
    parsePackageLocationToken :: ReadP r String
    parsePackageLocationToken = fmap fst (Parse.gather outerTerm)
      where
        outerTerm   = alternateEither1 outerToken (braces innerTerm)
        innerTerm   = alternateEither  innerToken (braces innerTerm)
        outerToken  = Parse.munch1 outerChar >> return ()
        innerToken  = Parse.munch1 innerChar >> return ()
        outerChar c = not (isSpace c || c == '{' || c == '}' || c == ',')
        innerChar c = not (isSpace c || c == '{' || c == '}')
        braces      = Parse.between (Parse.char '{') (Parse.char '}')

    alternateEither, alternateEither1,
      alternatePQs, alternate1PQs, alternateQsP, alternate1QsP
      :: ReadP r () -> ReadP r () -> ReadP r ()

    alternateEither1 p q = alternate1PQs p q +++ alternate1QsP q p
    alternateEither  p q = alternateEither1 p q +++ return ()
    alternate1PQs    p q = p >> alternateQsP q p
    alternatePQs     p q = alternate1PQs p q +++ return ()
    alternate1QsP    q p = Parse.many1 q >> alternatePQs p q
    alternateQsP     q p = alternate1QsP q p +++ return ()

renderPackageLocationToken :: String -> String
renderPackageLocationToken s | needsQuoting = show s
                             | otherwise    = s
  where
    needsQuoting  = not (ok 0 s)
                 || s == "." -- . on its own on a line has special meaning
                 || take 2 s == "--" -- on its own line is comment syntax
                 --TODO: [code cleanup] these "." and "--" escaping issues
                 -- ought to be dealt with systematically in ParseUtils.
    ok :: Int -> String -> Bool
    ok n []       = n == 0
    ok _ ('"':_)  = False
    ok n ('{':cs) = ok (n+1) cs
    ok n ('}':cs) = ok (n-1) cs
    ok n (',':cs) = (n > 0) && ok n cs
928 929
    ok _ (c:_)
      | isSpace c = False
930 931 932 933 934 935 936 937 938 939 940 941 942
    ok n (_  :cs) = ok n cs


legacySharedConfigFieldDescrs :: [FieldDescr LegacySharedConfig]
legacySharedConfigFieldDescrs =

  ( liftFields
      legacyGlobalFlags
      (\flags conf -> conf { legacyGlobalFlags = flags })
  . addFields
      [ newLineListField "local-repo"
          showTokenQ parseTokenQ
          (fromNubList . globalLocalRepos)
gershomb's avatar
gershomb committed
943 944 945 946 947
          (\v conf -> conf { globalLocalRepos = toNubList v }),
         newLineListField "extra-prog-path-shared-only"
          showTokenQ parseTokenQ
          (fromNubList . globalProgPathExtra)
          (\v conf -> conf { globalProgPathExtra = toNubList v })
948 949 950
      ]
  . filterFields
      [ "remote-repo-cache"
951
      , "logs-dir", "store-dir", "ignore-expiry", "http-transport"
952 953 954 955 956 957 958
      ]
  . commandOptionsToFields
  ) (commandOptions (globalCommand []) ParseArgs)
 ++
  ( liftFields
      legacyConfigureShFlags
      (\flags conf -> conf { legacyConfigureShFlags = flags })
959
  . filterFields ["verbose", "builddir" ]
960 961 962 963 964 965 966 967 968 969 970 971 972 973
  . commandOptionsToFields
  ) (configureOptions ParseArgs)
 ++
  ( liftFields
      legacyConfigureExFlags
      (\flags conf -> conf { legacyConfigureExFlags = flags })
  . addFields
      [ commaNewLineListField "constraints"
        (disp . fst) (fmap (\constraint -> (constraint, constraintSrc)) parse)
        configExConstraints (\v conf -> conf { configExConstraints = v })

      , commaNewLineListField "preferences"
        disp parse
        configPreferences (\v conf -> conf { configPreferences = v })
974

975
      , monoidField "allow-older"
976
        (maybe mempty disp) (fmap Just parse)
977 978 979
        (fmap unAllowOlder . configAllowOlder)
        (\v conf -> conf { configAllowOlder = fmap AllowOlder v })

980
      , monoidField "allow-newer"
981
        (maybe mempty disp) (fmap Just parse)
982 983
        (fmap unAllowNewer . configAllowNewer)
        (\v conf -> conf { configAllowNewer = fmap AllowNewer v })
984 985
      ]
  . filterFields
986
      [ "cabal-lib-version", "solver", "write-ghc-environment-files"
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
        -- not "constraint" or "preference", we use our own plural ones above
      ]
  . commandOptionsToFields
  ) (configureExOptions ParseArgs constraintSrc)
 ++
  ( liftFields
      legacyInstallFlags
      (\flags conf -> conf { legacyInstallFlags = flags })
  . addFields
      [ newLineListField "build-summary"
          (showTokenQ . fromPathTemplate) (fmap toPathTemplate parseTokenQ)
          (fromNubList . installSummaryFile)
          (\v conf -> conf { installSummaryFile = toNubList v })
      ]
  . filterFields
      [ "doc-index-file"
      , "root-cmd", "symlink-bindir"
      , "build-log"
      , "remote-build-reporting", "report-planning-failure"
1006
      , "one-shot", "jobs", "keep-going", "offline", "per-component"
1007
        -- solver flags:
1008
      , "max-backjumps", "reorder-goals", "count-conflicts"
1009 1010 1011
      , "fine-grained-conflicts" , "minimize-conflict-set", "independent-goals"
      , "strong-flags" , "allow-boot-library-installs"
      , "reject-unconstrained-dependencies", "index-state"
1012 1013 1014
      ]
  . commandOptionsToFields
  ) (installOptions ParseArgs)
1015 1016 1017 1018 1019 1020
 ++
  ( liftFields
      legacyClientInstallFlags
      (\flags conf -> conf { legacyClientInstallFlags = flags })
  . commandOptionsToFields
  ) (clientInstallOptions ParseArgs)
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
  where
    constraintSrc = ConstraintSourceProjectConfig "TODO"


legacyPackageConfigFieldDescrs :: [FieldDescr LegacyPackageConfig]
legacyPackageConfigFieldDescrs =
  ( liftFields
      legacyConfigureFlags
      (\flags conf -> conf { legacyConfigureFlags = flags })
  . addFields
      [ newLineListField "extra-include-dirs"
          showTokenQ parseTokenQ
          configExtraIncludeDirs
          (\v conf -> conf { configExtraIncludeDirs = v })
      , newLineListField "extra-lib-dirs"
          showTokenQ parseTokenQ
          configExtraLibDirs
          (\v conf -> conf { configExtraLibDirs = v })
      , newLineListField "extra-framework-dirs"
          showTokenQ parseTokenQ
          configExtraFrameworkDirs
          (\v conf -> conf { configExtraFrameworkDirs = v })
      , newLineListField "extra-prog-path"
          showTokenQ parseTokenQ
          (fromNubList . configProgramPathExtra)
          (\v conf -> conf { configProgramPathExtra = toNubList v })
      , newLineListField "configure-options"
          showTokenQ parseTokenQ
          configConfigureArgs
          (\v conf -> conf { configConfigureArgs = v })
      , simpleField "flags"
          dispFlagAssignment parseFlagAssignment
          configConfigurationsFlags
          (\v conf -> conf { configConfigurationsFlags = v })
      ]
  . filterFields
1057
      [ "with-compiler", "with-hc-pkg"
1058 1059
      , "program-prefix", "program-suffix"
      , "library-vanilla", "library-profiling"
1060
      , "shared", "static", "executable-dynamic", "executable-static"
1061 1062
      , "profiling", "executable-profiling"
      , "profiling-detail", "library-profiling-detail"
Ben Gamari's avatar
Ben Gamari committed
1063
      , "library-for-ghci", "split-objs", "split-sections"
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079