Skip to content

Commit f8b3ccb

Browse files
committed
Minor reformatting of Stack.Package
1 parent 11a1586 commit f8b3ccb

File tree

1 file changed

+120
-118
lines changed

1 file changed

+120
-118
lines changed

src/Stack/Package.hs

Lines changed: 120 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -87,32 +87,30 @@ import Stack.Types.PackageFile
8787
, GetPackageFiles (..)
8888
)
8989
import Stack.PackageFile ( packageDescModulesAndFiles )
90+
9091
-- | Read @<package>.buildinfo@ ancillary files produced by some Setup.hs hooks.
9192
-- The file includes Cabal file syntax to be merged into the package description
9293
-- derived from the package's Cabal file.
9394
--
9495
-- NOTE: not to be confused with BuildInfo, an Stack-internal datatype.
95-
readDotBuildinfo :: MonadIO m
96-
=> Path Abs File
97-
-> m HookedBuildInfo
96+
readDotBuildinfo :: MonadIO m => Path Abs File -> m HookedBuildInfo
9897
readDotBuildinfo buildinfofp =
9998
liftIO $ readHookedBuildInfo silent (toFilePath buildinfofp)
10099

101100
-- | Resolve a parsed Cabal file into a 'Package', which contains all of the
102101
-- info needed for Stack to build the 'Package' given the current configuration.
103-
resolvePackage :: PackageConfig
104-
-> GenericPackageDescription
105-
-> Package
102+
resolvePackage :: PackageConfig -> GenericPackageDescription -> Package
106103
resolvePackage packageConfig gpkg =
107104
packageFromPackageDescription
108105
packageConfig
109106
(genPackageFlags gpkg)
110107
(resolvePackageDescription packageConfig gpkg)
111108

112-
packageFromPackageDescription :: PackageConfig
113-
-> [PackageFlag]
114-
-> PackageDescriptionPair
115-
-> Package
109+
packageFromPackageDescription ::
110+
PackageConfig
111+
-> [PackageFlag]
112+
-> PackageDescriptionPair
113+
-> Package
116114
packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkgNoMod pkg) =
117115
Package
118116
{ packageName = name
@@ -125,7 +123,7 @@ packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkg
125123
, packageCabalConfigOpts = packageConfigCabalConfigOpts packageConfig
126124
, packageFlags = packageConfigFlags packageConfig
127125
, packageDefaultFlags = M.fromList
128-
[(flagName flag, flagDefault flag) | flag <- pkgFlags]
126+
[(flagName flag, flagDefault flag) | flag <- pkgFlags]
129127
, packageAllDeps = M.keysSet deps
130128
, packageSubLibDeps = subLibDeps
131129
, packageLibraries =
@@ -139,38 +137,45 @@ packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkg
139137
Just _ -> HasLibraries foreignLibNames
140138
, packageInternalLibraries = subLibNames
141139
, packageTests = M.fromList
142-
[(T.pack (Cabal.unUnqualComponentName $ testName t), testInterface t)
143-
| t <- testSuites pkgNoMod
144-
, buildable (testBuildInfo t)
145-
]
140+
[ (T.pack (Cabal.unUnqualComponentName $ testName t), testInterface t)
141+
| t <- testSuites pkgNoMod
142+
, buildable (testBuildInfo t)
143+
]
146144
, packageBenchmarks = S.fromList
147-
[T.pack (Cabal.unUnqualComponentName $ benchmarkName b)
148-
| b <- benchmarks pkgNoMod
149-
, buildable (benchmarkBuildInfo b)
150-
]
145+
[ T.pack (Cabal.unUnqualComponentName $ benchmarkName b)
146+
| b <- benchmarks pkgNoMod
147+
, buildable (benchmarkBuildInfo b)
148+
]
151149
-- Same comment about buildable applies here too.
152150
, packageExes = S.fromList
153-
[T.pack (Cabal.unUnqualComponentName $ exeName biBuildInfo)
151+
[ T.pack (Cabal.unUnqualComponentName $ exeName biBuildInfo)
154152
| biBuildInfo <- executables pkg
155-
, buildable (buildInfo biBuildInfo)]
153+
, buildable (buildInfo biBuildInfo)
154+
]
156155
-- This is an action used to collect info needed for "stack ghci".
157156
-- This info isn't usually needed, so computation of it is deferred.
158157
, packageOpts = GetPackageOpts $
159-
\installMap installedMap omitPkgs addPkgs cabalfp ->
160-
do (componentsModules,componentFiles,_,_) <- getPackageFiles pkgFiles cabalfp
161-
let internals = S.toList $ internalLibComponents $ M.keysSet componentsModules
162-
excludedInternals <- mapM (parsePackageNameThrowing . T.unpack) internals
163-
mungedInternals <- mapM (parsePackageNameThrowing . T.unpack .
164-
toInternalPackageMungedName) internals
165-
componentsOpts <-
166-
generatePkgDescOpts installMap installedMap
167-
(excludedInternals ++ omitPkgs) (mungedInternals ++ addPkgs)
168-
cabalfp pkg componentFiles
169-
pure (componentsModules,componentFiles,componentsOpts)
158+
\installMap installedMap omitPkgs addPkgs cabalfp -> do
159+
(componentsModules,componentFiles, _, _) <- getPackageFiles pkgFiles cabalfp
160+
let internals =
161+
S.toList $ internalLibComponents $ M.keysSet componentsModules
162+
excludedInternals <- mapM (parsePackageNameThrowing . T.unpack) internals
163+
mungedInternals <- mapM
164+
(parsePackageNameThrowing . T.unpack . toInternalPackageMungedName)
165+
internals
166+
componentsOpts <- generatePkgDescOpts
167+
installMap
168+
installedMap
169+
(excludedInternals ++ omitPkgs)
170+
(mungedInternals ++ addPkgs)
171+
cabalfp
172+
pkg
173+
componentFiles
174+
pure (componentsModules, componentFiles, componentsOpts)
170175
, packageHasExposedModules = maybe
171-
False
172-
(not . null . exposedModules)
173-
(library pkg)
176+
False
177+
(not . null . exposedModules)
178+
(library pkg)
174179
, packageBuildType = buildType pkg
175180
, packageSetupDeps = msetupDeps
176181
, packageCabalSpec = specVersion pkg
@@ -216,11 +221,13 @@ packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkg
216221
let setupHsPath = pkgDir </> relFileSetupHs
217222
setupLhsPath = pkgDir </> relFileSetupLhs
218223
setupHsExists <- doesFileExist setupHsPath
219-
if setupHsExists then pure (S.singleton setupHsPath) else do
220-
setupLhsExists <- doesFileExist setupLhsPath
221-
if setupLhsExists
222-
then pure (S.singleton setupLhsPath)
223-
else pure S.empty
224+
if setupHsExists
225+
then pure (S.singleton setupHsPath)
226+
else do
227+
setupLhsExists <- doesFileExist setupLhsPath
228+
if setupLhsExists
229+
then pure (S.singleton setupLhsPath)
230+
else pure S.empty
224231
else pure S.empty
225232
buildFiles <- fmap (S.insert cabalfp . S.union setupFiles) $ do
226233
let hpackPath = pkgDir </> relFileHpackPackageConfig
@@ -264,8 +271,8 @@ packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkg
264271
, dvType = AsLibrary
265272
}
266273

267-
-- Is the package dependency mentioned here me: either the package
268-
-- name itself, or the name of one of the sub libraries
274+
-- Is the package dependency mentioned here me: either the package name
275+
-- itself, or the name of one of the sub libraries
269276
isMe name' = name' == name
270277
|| fromString (packageNameString name') `S.member` extraLibNames
271278

@@ -478,10 +485,10 @@ generateBuildInfoOpts BioInput {..} =
478485
-- λ>
479486
makeObjectFilePathFromC ::
480487
MonadThrow m
481-
=> Path Abs Dir -- ^ The cabal directory.
482-
-> NamedComponent -- ^ The name of the component.
483-
-> Path Abs Dir -- ^ Dist directory.
484-
-> Path Abs File -- ^ The path to the .c file.
488+
=> Path Abs Dir -- ^ The cabal directory.
489+
-> NamedComponent -- ^ The name of the component.
490+
-> Path Abs Dir -- ^ Dist directory.
491+
-> Path Abs File -- ^ The path to the .c file.
485492
-> m (Path Abs File) -- ^ The path to the .o file for the component.
486493
makeObjectFilePathFromC cabalDir namedComponent distDir cFilePath = do
487494
relCFilePath <- stripProperPrefix cabalDir cFilePath
@@ -586,18 +593,18 @@ hardCodedMap = M.fromList
586593
, ("gtk2hsTypeGen", Distribution.Package.mkPackageName "gtk2hs-buildtools")
587594
]
588595

589-
-- | Executable-only packages which come pre-installed with GHC and do
590-
-- not need to be built. Without this exception, we would either end
591-
-- up unnecessarily rebuilding these packages, or failing because the
592-
-- packages do not appear in the Stackage snapshot.
596+
-- | Executable-only packages which come pre-installed with GHC and do not need
597+
-- to be built. Without this exception, we would either end up unnecessarily
598+
-- rebuilding these packages, or failing because the packages do not appear in
599+
-- the Stackage snapshot.
593600
preInstalledPackages :: Set PackageName
594601
preInstalledPackages = S.fromList
595602
[ mkPackageName "hsc2hs"
596603
, mkPackageName "haddock"
597604
]
598605

599-
-- | Variant of 'allBuildInfo' from Cabal that, like versions before
600-
-- 2.2, only includes buildable components.
606+
-- | Variant of 'allBuildInfo' from Cabal that, like versions before Cabal 2.2
607+
-- only includes buildable components.
601608
allBuildInfo' :: PackageDescription -> [BuildInfo]
602609
allBuildInfo' pkg_descr = [ bi | lib <- allLibraries pkg_descr
603610
, let bi = libBuildInfo lib
@@ -615,33 +622,31 @@ allBuildInfo' pkg_descr = [ bi | lib <- allLibraries pkg_descr
615622
, let bi = benchmarkBuildInfo tst
616623
, buildable bi ]
617624

618-
-- | A pair of package descriptions: one which modified the buildable
619-
-- values of test suites and benchmarks depending on whether they are
620-
-- enabled, and one which does not.
625+
-- | A pair of package descriptions: one which modified the buildable values of
626+
-- test suites and benchmarks depending on whether they are enabled, and one
627+
-- which does not.
621628
--
622-
-- Fields are intentionally lazy, we may only need one or the other
623-
-- value.
629+
-- Fields are intentionally lazy, we may only need one or the other value.
624630
--
625-
-- MSS 2017-08-29: The very presence of this data type is terribly
626-
-- ugly, it represents the fact that the Cabal 2.0 upgrade did _not_
627-
-- go well. Specifically, we used to have a field to indicate whether
628-
-- a component was enabled in addition to buildable, but that's gone
629-
-- now, and this is an ugly proxy. We should at some point clean up
630-
-- the mess of Package, LocalPackage, etc, and probably pull in the
631-
-- definition of PackageDescription from Cabal with our additionally
632-
-- needed metadata. But this is a good enough hack for the
633-
-- moment. Odds are, you're reading this in the year 2024 and thinking
634-
-- "wtf?"
631+
-- Michael S Snoyman 2017-08-29: The very presence of this data type is terribly
632+
-- ugly, it represents the fact that the Cabal 2.0 upgrade did _not_ go well.
633+
-- Specifically, we used to have a field to indicate whether a component was
634+
-- enabled in addition to buildable, but that's gone now, and this is an ugly
635+
-- proxy. We should at some point clean up the mess of Package, LocalPackage,
636+
-- etc, and probably pull in the definition of PackageDescription from Cabal
637+
-- with our additionally needed metadata. But this is a good enough hack for the
638+
-- moment. Odds are, you're reading this in the year 2024 and thinking "wtf?"
635639
data PackageDescriptionPair = PackageDescriptionPair
636640
{ pdpOrigBuildable :: PackageDescription
637641
, pdpModifiedBuildable :: PackageDescription
638642
}
639643

640644
-- | Evaluates the conditions of a 'GenericPackageDescription', yielding
641645
-- a resolved 'PackageDescription'.
642-
resolvePackageDescription :: PackageConfig
643-
-> GenericPackageDescription
644-
-> PackageDescriptionPair
646+
resolvePackageDescription ::
647+
PackageConfig
648+
-> GenericPackageDescription
649+
-> PackageDescriptionPair
645650
resolvePackageDescription
646651
packageConfig
647652
( GenericPackageDescription
@@ -679,27 +684,24 @@ resolvePackageDescription
679684
(packageConfigPlatform packageConfig)
680685
flags
681686

682-
updateLibDeps lib deps =
683-
lib {libBuildInfo =
684-
(libBuildInfo lib) {targetBuildDepends = deps}}
685-
updateForeignLibDeps lib deps =
686-
lib {foreignLibBuildInfo =
687-
(foreignLibBuildInfo lib) {targetBuildDepends = deps}}
688-
updateExeDeps exe deps =
689-
exe {buildInfo =
690-
(buildInfo exe) {targetBuildDepends = deps}}
691-
692-
-- Note that, prior to moving to Cabal 2.0, we would set
693-
-- testEnabled/benchmarkEnabled here. These fields no longer
694-
-- exist, so we modify buildable instead here. The only
695-
-- wrinkle in the Cabal 2.0 story is
696-
-- https://github.com/haskell/cabal/issues/1725, where older
697-
-- versions of Cabal (which may be used for actually building
698-
-- code) don't properly exclude build-depends for
699-
-- non-buildable components. Testing indicates that everything
700-
-- is working fine, and that this comment can be completely
701-
-- ignored. I'm leaving the comment anyway in case something
702-
-- breaks and you, poor reader, are investigating.
687+
updateLibDeps lib deps = lib
688+
{ libBuildInfo = (libBuildInfo lib) {targetBuildDepends = deps} }
689+
updateForeignLibDeps lib deps = lib
690+
{ foreignLibBuildInfo =
691+
(foreignLibBuildInfo lib) {targetBuildDepends = deps}
692+
}
693+
updateExeDeps exe deps = exe
694+
{ buildInfo = (buildInfo exe) {targetBuildDepends = deps} }
695+
696+
-- Note that, prior to moving to Cabal 2.0, we would set testEnabled or
697+
-- benchmarkEnabled here. These fields no longer exist, so we modify buildable
698+
-- instead here. The only wrinkle in the Cabal 2.0 story is
699+
-- https://github.com/haskell/cabal/issues/1725, where older versions of Cabal
700+
-- (which may be used for actually building code) don't properly exclude
701+
-- build-depends for non-buildable components. Testing indicates that
702+
-- everything is working fine, and that this comment can be completely
703+
-- ignored. I'm leaving the comment anyway in case something breaks and you,
704+
-- poor reader, are investigating.
703705
updateTestDeps modBuildable test deps =
704706
let bi = testBuildInfo test
705707
bi' = bi
@@ -740,10 +742,11 @@ data ResolveConditions = ResolveConditions
740742
}
741743

742744
-- | Generic a @ResolveConditions@ using sensible defaults.
743-
mkResolveConditions :: ActualCompiler -- ^ Compiler version
744-
-> Platform -- ^ installation target platform
745-
-> Map FlagName Bool -- ^ enabled flags
746-
-> ResolveConditions
745+
mkResolveConditions ::
746+
ActualCompiler -- ^ Compiler version
747+
-> Platform -- ^ installation target platform
748+
-> Map FlagName Bool -- ^ enabled flags
749+
-> ResolveConditions
747750
mkResolveConditions compilerVersion (Platform arch os) flags = ResolveConditions
748751
{ rcFlags = flags
749752
, rcCompilerVersion = compilerVersion
@@ -752,47 +755,46 @@ mkResolveConditions compilerVersion (Platform arch os) flags = ResolveConditions
752755
}
753756

754757
-- | Resolve the condition tree for the library.
755-
resolveConditions :: (Semigroup target,Monoid target,Show target)
756-
=> ResolveConditions
757-
-> (target -> cs -> target)
758-
-> CondTree ConfVar cs target
759-
-> target
758+
resolveConditions ::
759+
(Semigroup target, Monoid target, Show target)
760+
=> ResolveConditions
761+
-> (target -> cs -> target)
762+
-> CondTree ConfVar cs target
763+
-> target
760764
resolveConditions rc addDeps (CondNode lib deps cs) = basic <> children
761765
where
762766
basic = addDeps lib deps
763767
children = mconcat (map apply cs)
764768
where
765769
apply (Cabal.CondBranch cond node mcs) =
766-
if condSatisfied cond
767-
then resolveConditions rc addDeps node
768-
else maybe mempty (resolveConditions rc addDeps) mcs
770+
if condSatisfied cond
771+
then resolveConditions rc addDeps node
772+
else maybe mempty (resolveConditions rc addDeps) mcs
769773
condSatisfied c =
770774
case c of
771775
Var v -> varSatisfied v
772776
Lit b -> b
773-
CNot c' ->
774-
not (condSatisfied c')
775-
COr cx cy ->
776-
condSatisfied cx || condSatisfied cy
777-
CAnd cx cy ->
778-
condSatisfied cx && condSatisfied cy
777+
CNot c' -> not (condSatisfied c')
778+
COr cx cy -> condSatisfied cx || condSatisfied cy
779+
CAnd cx cy -> condSatisfied cx && condSatisfied cy
779780
varSatisfied v =
780781
case v of
781782
OS os -> os == rcOS rc
782783
Arch arch -> arch == rcArch rc
783-
PackageFlag flag ->
784-
fromMaybe False $ M.lookup flag (rcFlags rc)
785-
-- NOTE: ^^^^^ This should never happen, as all flags
786-
-- which are used must be declared. Defaulting to
787-
-- False.
784+
PackageFlag flag -> fromMaybe False $ M.lookup flag (rcFlags rc)
785+
-- NOTE: ^^^^^ This should never happen, as all flags which are used
786+
-- must be declared. Defaulting to False.
788787
Impl flavor range ->
789788
case (flavor, rcCompilerVersion rc) of
790789
(GHC, ACGhc vghc) -> vghc `withinRange` range
791790
_ -> False
792791

793792
-- | Path for the package's build log.
794-
buildLogPath :: (MonadReader env m, HasBuildConfig env, MonadThrow m)
795-
=> Package -> Maybe String -> m (Path Abs File)
793+
buildLogPath ::
794+
(MonadReader env m, HasBuildConfig env, MonadThrow m)
795+
=> Package
796+
-> Maybe String
797+
-> m (Path Abs File)
796798
buildLogPath package' msuffix = do
797799
env <- ask
798800
let stack = getProjectWorkDir env
@@ -864,5 +866,5 @@ applyForceCustomBuild cabalVersion package
864866
orLaterVersion $ mkVersion $ cabalSpecToVersionDigits $
865867
packageCabalSpec package
866868
forceCustomBuild =
867-
packageBuildType package == Simple &&
868-
not (cabalVersion `withinRange` cabalVersionRange)
869+
packageBuildType package == Simple
870+
&& not (cabalVersion `withinRange` cabalVersionRange)

0 commit comments

Comments
 (0)