Skip to content

Commit

Permalink
cabal-install: incorporate datatype changes
Browse files Browse the repository at this point in the history
This commit leverages the changes to the LocalBuildInfo datatype in
the Cabal library to reduce code duplication. Specifically, we split
off certain fields of ElaboratedConfiguredPackage by re-using the
BuildOptions datatype.

This is purely an internal refactoring with no observable changes
in behaviour.
  • Loading branch information
sheaf committed Nov 24, 2023
1 parent d1dc81b commit df3f7a6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 70 deletions.
113 changes: 62 additions & 51 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ import Distribution.Types.GivenComponent
( GivenComponent (GivenComponent)
)
import Distribution.Types.LibraryName
import qualified Distribution.Types.LocalBuildConfig as LBC
import Distribution.Types.PackageVersionConstraint
import Distribution.Types.PkgconfigDependency
import Distribution.Types.UnqualComponentName
Expand Down Expand Up @@ -2224,14 +2225,28 @@ elaborateInstallPlan

elabPkgDescriptionOverride = descOverride

elabVanillaLib = perPkgOptionFlag pkgid True packageConfigVanillaLib -- TODO: [required feature]: also needs to be handled recursively
elabSharedLib = pkgid `Set.member` pkgsUseSharedLibrary
elabStaticLib = perPkgOptionFlag pkgid False packageConfigStaticLib
elabDynExe = perPkgOptionFlag pkgid False packageConfigDynExe
elabFullyStaticExe = perPkgOptionFlag pkgid False packageConfigFullyStaticExe
elabGHCiLib = perPkgOptionFlag pkgid False packageConfigGHCiLib -- TODO: [required feature] needs to default to enabled on windows still
elabProfExe = perPkgOptionFlag pkgid False packageConfigProf
elabProfLib = pkgid `Set.member` pkgsUseProfilingLibrary
elabBuildOptions =
LBC.BuildOptions
{ withVanillaLib = perPkgOptionFlag pkgid True packageConfigVanillaLib -- TODO: [required feature]: also needs to be handled recursively
, withSharedLib = pkgid `Set.member` pkgsUseSharedLibrary
, withStaticLib = perPkgOptionFlag pkgid False packageConfigStaticLib
, withDynExe = perPkgOptionFlag pkgid False packageConfigDynExe
, withFullyStaticExe = perPkgOptionFlag pkgid False packageConfigFullyStaticExe
, withGHCiLib = perPkgOptionFlag pkgid False packageConfigGHCiLib -- TODO: [required feature] needs to default to enabled on windows still
, withProfExe = perPkgOptionFlag pkgid False packageConfigProf
, withProfLib = pkgid `Set.member` pkgsUseProfilingLibrary
, exeCoverage = perPkgOptionFlag pkgid False packageConfigCoverage
, libCoverage = perPkgOptionFlag pkgid False packageConfigCoverage
, withOptimization = perPkgOptionFlag pkgid NormalOptimisation packageConfigOptimization
, splitObjs = perPkgOptionFlag pkgid False packageConfigSplitObjs
, splitSections = perPkgOptionFlag pkgid False packageConfigSplitSections
, stripLibs = perPkgOptionFlag pkgid False packageConfigStripLibs
, stripExes = perPkgOptionFlag pkgid False packageConfigStripExes
, withDebugInfo = perPkgOptionFlag pkgid NoDebugInfo packageConfigDebugInfo
, relocatable = perPkgOptionFlag pkgid False packageConfigRelocatable
, withProfLibDetail = elabProfExeDetail
, withProfExeDetail = elabProfLibDetail
}

( elabProfExeDetail
, elabProfLibDetail
Expand All @@ -2241,14 +2256,7 @@ elaborateInstallPlan
ProfDetailDefault
packageConfigProfDetail
packageConfigProfLibDetail
elabCoverage = perPkgOptionFlag pkgid False packageConfigCoverage

elabOptimization = perPkgOptionFlag pkgid NormalOptimisation packageConfigOptimization
elabSplitObjs = perPkgOptionFlag pkgid False packageConfigSplitObjs
elabSplitSections = perPkgOptionFlag pkgid False packageConfigSplitSections
elabStripLibs = perPkgOptionFlag pkgid False packageConfigStripLibs
elabStripExes = perPkgOptionFlag pkgid False packageConfigStripExes
elabDebugInfo = perPkgOptionFlag pkgid NoDebugInfo packageConfigDebugInfo

elabDumpBuildInfo = perPkgOptionFlag pkgid NoDumpBuildInfo packageConfigDumpBuildInfo

-- Combine the configured compiler prog settings with the user-supplied
Expand Down Expand Up @@ -4144,31 +4152,34 @@ setupHsConfigureFlags
configHcFlavor = toFlag (compilerFlavor pkgConfigCompiler)
configHcPath = mempty -- we use configProgramPaths instead
configHcPkg = mempty -- we use configProgramPaths instead
configVanillaLib = toFlag elabVanillaLib
configSharedLib = toFlag elabSharedLib
configStaticLib = toFlag elabStaticLib
configVanillaLib = toFlag $ LBC.withVanillaLib elabBuildOptions
configSharedLib = toFlag $ LBC.withSharedLib elabBuildOptions
configStaticLib = toFlag $ LBC.withStaticLib elabBuildOptions

configDynExe = toFlag elabDynExe
configFullyStaticExe = toFlag elabFullyStaticExe
configGHCiLib = toFlag elabGHCiLib
configProfExe = mempty
configProfLib = toFlag elabProfLib
configProf = toFlag elabProfExe
configDynExe = toFlag $ LBC.withDynExe elabBuildOptions
configFullyStaticExe = toFlag $ LBC.withFullyStaticExe elabBuildOptions
configGHCiLib = toFlag $ LBC.withGHCiLib elabBuildOptions
configProfExe = toFlag $ LBC.withProfExe elabBuildOptions
configProfLib = toFlag $ LBC.withProfLib elabBuildOptions
configProf = toFlag $ LBC.withProfExe elabBuildOptions

-- configProfDetail is for exe+lib, but overridden by configProfLibDetail
-- so we specify both so we can specify independently
configProfDetail = toFlag elabProfExeDetail
configProfLibDetail = toFlag elabProfLibDetail
configProfDetail = toFlag $ LBC.withProfExeDetail elabBuildOptions
configProfLibDetail = toFlag $ LBC.withProfLibDetail elabBuildOptions

configCoverage = toFlag elabCoverage
configCoverage = toFlag $ LBC.exeCoverage elabBuildOptions
configLibCoverage = mempty

configOptimization = toFlag elabOptimization
configSplitSections = toFlag elabSplitSections
configSplitObjs = toFlag elabSplitObjs
configStripExes = toFlag elabStripExes
configStripLibs = toFlag elabStripLibs
configDebugInfo = toFlag elabDebugInfo
configRelocatable = toFlag $ LBC.relocatable elabBuildOptions
-- TODO: [research required] ???

configOptimization = toFlag $ LBC.withOptimization elabBuildOptions
configSplitSections = toFlag $ LBC.splitSections elabBuildOptions
configSplitObjs = toFlag $ LBC.splitObjs elabBuildOptions
configStripExes = toFlag $ LBC.stripExes elabBuildOptions
configStripLibs = toFlag $ LBC.stripLibs elabBuildOptions
configDebugInfo = toFlag $ LBC.withDebugInfo elabBuildOptions
configDumpBuildInfo = toFlag elabDumpBuildInfo

configConfigurationsFlags = elabFlagAssignment
Expand Down Expand Up @@ -4224,7 +4235,6 @@ setupHsConfigureFlags

configExactConfiguration = toFlag True
configFlagError = mempty -- TODO: [research required] appears not to be implemented
configRelocatable = mempty -- TODO: [research required] ???
configScratchDir = mempty -- never use
configUserInstall = mempty -- don't rely on defaults
configPrograms_ = mempty -- never use, shouldn't exist
Expand Down Expand Up @@ -4556,22 +4566,22 @@ packageHashConfigInputs shared@ElaboratedSharedConfig{..} pkg =
, pkgHashPlatform = pkgConfigPlatform
, pkgHashFlagAssignment = elabFlagAssignment
, pkgHashConfigureScriptArgs = elabConfigureScriptArgs
, pkgHashVanillaLib = elabVanillaLib
, pkgHashSharedLib = elabSharedLib
, pkgHashDynExe = elabDynExe
, pkgHashFullyStaticExe = elabFullyStaticExe
, pkgHashGHCiLib = elabGHCiLib
, pkgHashProfLib = elabProfLib
, pkgHashProfExe = elabProfExe
, pkgHashProfLibDetail = elabProfLibDetail
, pkgHashProfExeDetail = elabProfExeDetail
, pkgHashCoverage = elabCoverage
, pkgHashOptimization = elabOptimization
, pkgHashSplitSections = elabSplitSections
, pkgHashSplitObjs = elabSplitObjs
, pkgHashStripLibs = elabStripLibs
, pkgHashStripExes = elabStripExes
, pkgHashDebugInfo = elabDebugInfo
, pkgHashVanillaLib = withVanillaLib
, pkgHashSharedLib = withSharedLib
, pkgHashDynExe = withDynExe
, pkgHashFullyStaticExe = withFullyStaticExe
, pkgHashGHCiLib = withGHCiLib
, pkgHashProfLib = withProfLib
, pkgHashProfExe = withProfExe
, pkgHashProfLibDetail = withProfLibDetail
, pkgHashProfExeDetail = withProfExeDetail
, pkgHashCoverage = exeCoverage
, pkgHashOptimization = withOptimization
, pkgHashSplitSections = splitSections
, pkgHashSplitObjs = splitObjs
, pkgHashStripLibs = stripLibs
, pkgHashStripExes = stripExes
, pkgHashDebugInfo = withDebugInfo
, pkgHashProgramArgs = elabProgramArgs
, pkgHashExtraLibDirs = elabExtraLibDirs
, pkgHashExtraLibDirsStatic = elabExtraLibDirsStatic
Expand Down Expand Up @@ -4600,6 +4610,7 @@ packageHashConfigInputs shared@ElaboratedSharedConfig{..} pkg =
}
where
ElaboratedConfiguredPackage{..} = normaliseConfiguredPackage shared pkg
LBC.BuildOptions{..} = elabBuildOptions

-- | Given the 'InstalledPackageIndex' for a nix-style package store, and an
-- 'ElaboratedInstallPlan', replace configured source packages by installed
Expand Down
22 changes: 4 additions & 18 deletions cabal-install/src/Distribution/Client/ProjectPlanning/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}

-- | Types used while planning how to build everything in a project.
Expand Down Expand Up @@ -103,6 +104,7 @@ import Distribution.Simple.Setup
)
import Distribution.System
import Distribution.Types.ComponentRequestedSpec
import qualified Distribution.Types.LocalBuildConfig as LBC
import Distribution.Types.PackageDescription (PackageDescription (..))
import Distribution.Types.PkgconfigVersion
import Distribution.Verbosity (normal)
Expand Down Expand Up @@ -264,23 +266,7 @@ data ElaboratedConfiguredPackage = ElaboratedConfiguredPackage
, elabInplaceRegisterPackageDBStack :: PackageDBStack
, elabPkgDescriptionOverride :: Maybe CabalFileText
, -- TODO: make per-component variants of these flags
elabVanillaLib :: Bool
, elabSharedLib :: Bool
, elabStaticLib :: Bool
, elabDynExe :: Bool
, elabFullyStaticExe :: Bool
, elabGHCiLib :: Bool
, elabProfLib :: Bool
, elabProfExe :: Bool
, elabProfLibDetail :: ProfDetailLevel
, elabProfExeDetail :: ProfDetailLevel
, elabCoverage :: Bool
, elabOptimization :: OptimisationLevel
, elabSplitObjs :: Bool
, elabSplitSections :: Bool
, elabStripLibs :: Bool
, elabStripExes :: Bool
, elabDebugInfo :: DebugInfoLevel
elabBuildOptions :: LBC.BuildOptions
, elabDumpBuildInfo :: DumpBuildInfo
, elabProgramPaths :: Map String FilePath
, elabProgramArgs :: Map String [String]
Expand Down Expand Up @@ -542,7 +528,7 @@ elabDistDirParams shared elab =
ElabPackage _ -> Nothing
, distParamCompilerId = compilerId (pkgConfigCompiler shared)
, distParamPlatform = pkgConfigPlatform shared
, distParamOptimization = elabOptimization elab
, distParamOptimization = LBC.withOptimization $ elabBuildOptions elab
}

-- | The full set of dependencies which dictate what order we
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import Distribution.Simple.Compiler (CompilerFlavor (..), compilerFlavor)
import Distribution.Simple.LocalBuildInfo
( ComponentName (..)
, LocalBuildInfo (..)
, depLibraryPaths
, buildDir
, depLibraryPaths
)
import Distribution.Simple.Utils
( addLibraryPath
Expand Down

0 comments on commit df3f7a6

Please sign in to comment.