Skip to content

Commit 8ca47e2

Browse files
committed
Promote packages to local database by ghc-options #849
1 parent 9ae8070 commit 8ca47e2

File tree

5 files changed

+32
-31
lines changed

5 files changed

+32
-31
lines changed

src/Stack/Build/Source.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ loadSourceMapFull needTargets boptsCli = do
9292
[ Map.fromList $ map (\lp' -> (packageName $ lpPackage lp', PSLocal lp')) locals
9393
, flip Map.mapWithKey localDeps $ \n lpi ->
9494
let configOpts = getGhcOptions bconfig boptsCli n False False
95-
in PSUpstream (lpiVersion lpi) Local (lpiFlags lpi) (lpiGhcOptions lpi ++ configOpts) (lpiLocation lpi)
95+
-- NOTE: configOpts includes lpiGhcOptions for now, this may get refactored soon
96+
in PSUpstream (lpiVersion lpi) Local (lpiFlags lpi) configOpts (lpiLocation lpi)
9697
, flip Map.mapWithKey (lsPackages ls) $ \n lpi ->
9798
let configOpts = getGhcOptions bconfig boptsCli n False False
98-
in PSUpstream (lpiVersion lpi) Snap (lpiFlags lpi) (lpiGhcOptions lpi ++ configOpts) (lpiLocation lpi)
99+
-- NOTE: configOpts includes lpiGhcOptions for now, this may get refactored soon
100+
in PSUpstream (lpiVersion lpi) Snap (lpiFlags lpi) configOpts (lpiLocation lpi)
99101
]
100102
`Map.difference` Map.fromList (map (, ()) (HashSet.toList wiredInPackages))
101103

@@ -125,7 +127,8 @@ getLocalFlags bconfig boptsCli name = Map.unions
125127
-- configuration and commandline.
126128
getGhcOptions :: BuildConfig -> BuildOptsCLI -> PackageName -> Bool -> Bool -> [Text]
127129
getGhcOptions bconfig boptsCli name isTarget isLocal = concat
128-
[ ghcOptionsFor name (configGhcOptions config)
130+
[ Map.findWithDefault [] name (configGhcOptionsByName config)
131+
, configGhcOptionsAll config
129132
, concat [["-fhpc"] | isLocal && toCoverage (boptsTestOpts bopts)]
130133
, if boptsLibProfile bopts || boptsExeProfile bopts
131134
then ["-auto-all","-caf-all"]

src/Stack/Build/Target.hs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -522,16 +522,12 @@ parseTargets needTargets boptscli = do
522522
(bcFlags bconfig)
523523
hides = Map.empty -- not supported to add hidden packages
524524

525-
-- We set this to empty here, which will prevent the call to
526-
-- calculatePackagePromotion from promoting packages based on
527-
-- changed GHC options. This is probably not ideal behavior,
528-
-- but is consistent with pre-extensible-snapshots behavior of
529-
-- Stack. We can consider modifying this instead.
525+
-- We promote packages to the local database if the GHC options
526+
-- are added to them by name. See:
527+
-- https://github.com/commercialhaskell/stack/issues/849#issuecomment-320892095.
530528
--
531-
-- Nonetheless, GHC options will be calculated later based on
532-
-- config file and command line parameters, so we're not
533-
-- actually losing them.
534-
options = Map.empty
529+
-- GHC options applied to all packages are handled by getGhcOptions.
530+
options = configGhcOptionsByName (bcConfig bconfig)
535531

536532
drops = Set.empty -- not supported to add drops
537533

src/Stack/Config.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ configFromConfigMonoid
358358

359359
let configTemplateParams = configMonoidTemplateParameters
360360
configScmInit = getFirst configMonoidScmInit
361-
configGhcOptions = configMonoidGhcOptions
361+
configGhcOptionsByName = configMonoidGhcOptionsByName
362+
configGhcOptionsAll = configMonoidGhcOptionsAll
362363
configSetupInfoLocations = configMonoidSetupInfoLocations
363364
configPvpBounds = fromFirst (PvpBounds PvpBoundsNone False) configMonoidPvpBounds
364365
configModifyCodePage = fromFirst True configMonoidModifyCodePage

src/Stack/Ghci.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,8 @@ runGhci GhciOpts{..} targets mainIsTargets pkgs extraFiles = do
301301
genOpts = nubOrd (concatMap (concatMap (oneWordOpts . snd) . ghciPkgOpts) pkgs)
302302
(omittedOpts, ghcOpts) = partition badForGhci $
303303
concatMap (concatMap (bioOpts . snd) . ghciPkgOpts) pkgs ++
304-
getUserOptions Nothing ++
305-
concatMap (getUserOptions . Just . ghciPkgName) pkgs
306-
getUserOptions mpkg =
307-
map T.unpack (M.findWithDefault [] mpkg (unGhcOptions (configGhcOptions config)))
304+
map T.unpack (configGhcOptionsAll config ++ concatMap (getUserOptions . ghciPkgName) pkgs)
305+
getUserOptions pkg = M.findWithDefault [] pkg (configGhcOptionsByName config)
308306
badForGhci x =
309307
isPrefixOf "-O" x || elem x (words "-debug -threaded -ticky -static -Werror")
310308
unless (null omittedOpts) $

src/Stack/Types/Config.hs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ module Stack.Types.Config
104104
,readColorWhen
105105
-- ** SCM
106106
,SCM(..)
107-
-- ** GhcOptions
108-
,GhcOptions(..)
109-
,ghcOptionsFor
110107
-- * Paths
111108
,bindirSuffix
112109
,configInstalledCache
@@ -314,9 +311,10 @@ data Config =
314311
-- ^ Parameters for templates.
315312
,configScmInit :: !(Maybe SCM)
316313
-- ^ Initialize SCM (e.g. git) when creating new projects.
317-
,configGhcOptions :: !GhcOptions
318-
-- ^ Additional GHC options to apply to either all packages (Nothing)
319-
-- or a specific package (Just).
314+
,configGhcOptionsByName :: !(Map PackageName [Text])
315+
-- ^ Additional GHC options to apply to specific packages.
316+
,configGhcOptionsAll :: ![Text]
317+
-- ^ Additional GHC options to apply to all packages
320318
,configSetupInfoLocations :: ![SetupInfoLocation]
321319
-- ^ Additional SetupInfo (inline or remote) to use to find tools.
322320
,configPvpBounds :: !PvpBounds
@@ -709,8 +707,10 @@ data ConfigMonoid =
709707
-- ^ Template parameters.
710708
,configMonoidScmInit :: !(First SCM)
711709
-- ^ Initialize SCM (e.g. git init) when making new projects?
712-
,configMonoidGhcOptions :: !GhcOptions
713-
-- ^ See 'configGhcOptions'
710+
,configMonoidGhcOptionsByName :: !(Map PackageName [Text])
711+
-- ^ See 'configGhcOptionsByName'
712+
,configMonoidGhcOptionsAll :: ![Text]
713+
-- ^ See 'configGhcOptionsAll'
714714
,configMonoidExtraPath :: ![Path Abs Dir]
715715
-- ^ Additional paths to search for executables in
716716
,configMonoidSetupInfoLocations :: ![SetupInfoLocation]
@@ -794,7 +794,15 @@ parseConfigMonoidObject rootDir obj = do
794794
return (First scmInit,fromMaybe M.empty params)
795795
configMonoidCompilerCheck <- First <$> obj ..:? configMonoidCompilerCheckName
796796

797-
configMonoidGhcOptions <- obj ..:? configMonoidGhcOptionsName ..!= mempty
797+
GhcOptions configMonoidGhcOptions <- obj ..:? configMonoidGhcOptionsName ..!= mempty
798+
let configMonoidGhcOptionsByName = Map.unions (map
799+
(\(mname, opts) ->
800+
case mname of
801+
Nothing -> Map.empty
802+
Just name -> Map.singleton name opts)
803+
(Map.toList configMonoidGhcOptions))
804+
configMonoidGhcOptionsAll = fromMaybe [] (Map.lookup Nothing configMonoidGhcOptions)
805+
798806
configMonoidExtraPath <- obj ..:? configMonoidExtraPathName ..!= []
799807
configMonoidSetupInfoLocations <-
800808
maybeToList <$> jsonSubWarningsT (obj ..:? configMonoidSetupInfoLocationsName)
@@ -1746,11 +1754,6 @@ instance Monoid GhcOptions where
17461754
mappend (GhcOptions l) (GhcOptions r) =
17471755
GhcOptions (Map.unionWith (++) l r)
17481756

1749-
ghcOptionsFor :: PackageName -> GhcOptions -> [Text]
1750-
ghcOptionsFor name (GhcOptions mp) =
1751-
M.findWithDefault [] Nothing mp ++
1752-
M.findWithDefault [] (Just name) mp
1753-
17541757
-----------------------------------
17551758
-- Lens classes
17561759
-----------------------------------

0 commit comments

Comments
 (0)