@@ -87,32 +87,30 @@ import Stack.Types.PackageFile
87
87
, GetPackageFiles (.. )
88
88
)
89
89
import Stack.PackageFile ( packageDescModulesAndFiles )
90
+
90
91
-- | Read @<package>.buildinfo@ ancillary files produced by some Setup.hs hooks.
91
92
-- The file includes Cabal file syntax to be merged into the package description
92
93
-- derived from the package's Cabal file.
93
94
--
94
95
-- 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
98
97
readDotBuildinfo buildinfofp =
99
98
liftIO $ readHookedBuildInfo silent (toFilePath buildinfofp)
100
99
101
100
-- | Resolve a parsed Cabal file into a 'Package', which contains all of the
102
101
-- info needed for Stack to build the 'Package' given the current configuration.
103
- resolvePackage :: PackageConfig
104
- -> GenericPackageDescription
105
- -> Package
102
+ resolvePackage :: PackageConfig -> GenericPackageDescription -> Package
106
103
resolvePackage packageConfig gpkg =
107
104
packageFromPackageDescription
108
105
packageConfig
109
106
(genPackageFlags gpkg)
110
107
(resolvePackageDescription packageConfig gpkg)
111
108
112
- packageFromPackageDescription :: PackageConfig
113
- -> [PackageFlag ]
114
- -> PackageDescriptionPair
115
- -> Package
109
+ packageFromPackageDescription ::
110
+ PackageConfig
111
+ -> [PackageFlag ]
112
+ -> PackageDescriptionPair
113
+ -> Package
116
114
packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkgNoMod pkg) =
117
115
Package
118
116
{ packageName = name
@@ -125,7 +123,7 @@ packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkg
125
123
, packageCabalConfigOpts = packageConfigCabalConfigOpts packageConfig
126
124
, packageFlags = packageConfigFlags packageConfig
127
125
, packageDefaultFlags = M. fromList
128
- [(flagName flag, flagDefault flag) | flag <- pkgFlags]
126
+ [(flagName flag, flagDefault flag) | flag <- pkgFlags]
129
127
, packageAllDeps = M. keysSet deps
130
128
, packageSubLibDeps = subLibDeps
131
129
, packageLibraries =
@@ -139,38 +137,45 @@ packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkg
139
137
Just _ -> HasLibraries foreignLibNames
140
138
, packageInternalLibraries = subLibNames
141
139
, 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
+ ]
146
144
, 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
+ ]
151
149
-- Same comment about buildable applies here too.
152
150
, packageExes = S. fromList
153
- [ T. pack (Cabal. unUnqualComponentName $ exeName biBuildInfo)
151
+ [ T. pack (Cabal. unUnqualComponentName $ exeName biBuildInfo)
154
152
| biBuildInfo <- executables pkg
155
- , buildable (buildInfo biBuildInfo)]
153
+ , buildable (buildInfo biBuildInfo)
154
+ ]
156
155
-- This is an action used to collect info needed for "stack ghci".
157
156
-- This info isn't usually needed, so computation of it is deferred.
158
157
, 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)
170
175
, packageHasExposedModules = maybe
171
- False
172
- (not . null . exposedModules)
173
- (library pkg)
176
+ False
177
+ (not . null . exposedModules)
178
+ (library pkg)
174
179
, packageBuildType = buildType pkg
175
180
, packageSetupDeps = msetupDeps
176
181
, packageCabalSpec = specVersion pkg
@@ -216,11 +221,13 @@ packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkg
216
221
let setupHsPath = pkgDir </> relFileSetupHs
217
222
setupLhsPath = pkgDir </> relFileSetupLhs
218
223
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
224
231
else pure S. empty
225
232
buildFiles <- fmap (S. insert cabalfp . S. union setupFiles) $ do
226
233
let hpackPath = pkgDir </> relFileHpackPackageConfig
@@ -264,8 +271,8 @@ packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkg
264
271
, dvType = AsLibrary
265
272
}
266
273
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
269
276
isMe name' = name' == name
270
277
|| fromString (packageNameString name') `S.member` extraLibNames
271
278
@@ -478,10 +485,10 @@ generateBuildInfoOpts BioInput {..} =
478
485
-- λ>
479
486
makeObjectFilePathFromC ::
480
487
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.
485
492
-> m (Path Abs File ) -- ^ The path to the .o file for the component.
486
493
makeObjectFilePathFromC cabalDir namedComponent distDir cFilePath = do
487
494
relCFilePath <- stripProperPrefix cabalDir cFilePath
@@ -586,18 +593,18 @@ hardCodedMap = M.fromList
586
593
, (" gtk2hsTypeGen" , Distribution.Package. mkPackageName " gtk2hs-buildtools" )
587
594
]
588
595
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.
593
600
preInstalledPackages :: Set PackageName
594
601
preInstalledPackages = S. fromList
595
602
[ mkPackageName " hsc2hs"
596
603
, mkPackageName " haddock"
597
604
]
598
605
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.
601
608
allBuildInfo' :: PackageDescription -> [BuildInfo ]
602
609
allBuildInfo' pkg_descr = [ bi | lib <- allLibraries pkg_descr
603
610
, let bi = libBuildInfo lib
@@ -615,33 +622,31 @@ allBuildInfo' pkg_descr = [ bi | lib <- allLibraries pkg_descr
615
622
, let bi = benchmarkBuildInfo tst
616
623
, buildable bi ]
617
624
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.
621
628
--
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.
624
630
--
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?"
635
639
data PackageDescriptionPair = PackageDescriptionPair
636
640
{ pdpOrigBuildable :: PackageDescription
637
641
, pdpModifiedBuildable :: PackageDescription
638
642
}
639
643
640
644
-- | Evaluates the conditions of a 'GenericPackageDescription', yielding
641
645
-- a resolved 'PackageDescription'.
642
- resolvePackageDescription :: PackageConfig
643
- -> GenericPackageDescription
644
- -> PackageDescriptionPair
646
+ resolvePackageDescription ::
647
+ PackageConfig
648
+ -> GenericPackageDescription
649
+ -> PackageDescriptionPair
645
650
resolvePackageDescription
646
651
packageConfig
647
652
( GenericPackageDescription
@@ -679,27 +684,24 @@ resolvePackageDescription
679
684
(packageConfigPlatform packageConfig)
680
685
flags
681
686
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.
703
705
updateTestDeps modBuildable test deps =
704
706
let bi = testBuildInfo test
705
707
bi' = bi
@@ -740,10 +742,11 @@ data ResolveConditions = ResolveConditions
740
742
}
741
743
742
744
-- | 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
747
750
mkResolveConditions compilerVersion (Platform arch os) flags = ResolveConditions
748
751
{ rcFlags = flags
749
752
, rcCompilerVersion = compilerVersion
@@ -752,47 +755,46 @@ mkResolveConditions compilerVersion (Platform arch os) flags = ResolveConditions
752
755
}
753
756
754
757
-- | 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
760
764
resolveConditions rc addDeps (CondNode lib deps cs) = basic <> children
761
765
where
762
766
basic = addDeps lib deps
763
767
children = mconcat (map apply cs)
764
768
where
765
769
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
769
773
condSatisfied c =
770
774
case c of
771
775
Var v -> varSatisfied v
772
776
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
779
780
varSatisfied v =
780
781
case v of
781
782
OS os -> os == rcOS rc
782
783
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.
788
787
Impl flavor range ->
789
788
case (flavor, rcCompilerVersion rc) of
790
789
(GHC , ACGhc vghc) -> vghc `withinRange` range
791
790
_ -> False
792
791
793
792
-- | 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 )
796
798
buildLogPath package' msuffix = do
797
799
env <- ask
798
800
let stack = getProjectWorkDir env
@@ -864,5 +866,5 @@ applyForceCustomBuild cabalVersion package
864
866
orLaterVersion $ mkVersion $ cabalSpecToVersionDigits $
865
867
packageCabalSpec package
866
868
forceCustomBuild =
867
- packageBuildType package == Simple &&
868
- not (cabalVersion `withinRange` cabalVersionRange)
869
+ packageBuildType package == Simple
870
+ && not (cabalVersion `withinRange` cabalVersionRange)
0 commit comments