Skip to content

Commit

Permalink
apply-ghc-options config (#1089)
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Oct 8, 2015
1 parent ddf002c commit 7c89751
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 5 deletions.
3 changes: 2 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Other enhancements:
* Use Haddock's `--hyperlinked-source` (crosslinked source), if available [#1070](https://github.com/commercialhaskell/stack/pull/1070)
* Use Stack-installed GHCs for `stack init --solver` [#1072](https://github.com/commercialhaskell/stack/issues/1072)
* New experimental `stack query` command [#1087](https://github.com/commercialhaskell/stack/issues/1087)
* By default, stack no longer rebuilds a package due to GHC options changes. This behavior can be tweaked with the `rebuild-ghc-options` settings. [#1089](https://github.com/commercialhaskell/stack/issues/1089)
* By default, stack no longer rebuilds a package due to GHC options changes. This behavior can be tweaked with the `rebuild-ghc-options` setting. [#1089](https://github.com/commercialhaskell/stack/issues/1089)
* By default, ghc-options are applied to all local packages, not just targets. This behavior can be tweaked with the `apply-ghc-options` setting. [#1089](https://github.com/commercialhaskell/stack/issues/1089)

Bug fixes:

Expand Down
14 changes: 14 additions & 0 deletions doc/yaml_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,17 @@ Should we rebuild a package when its GHC options change? Before 0.1.6, this was
```yaml
rebuild-ghc-options: true
```

### apply-ghc-options

(Since 0.1.6)

Which packages do ghc-options on the command line get applied to? Before 0.1.6, the default value was `targets`

```yaml
apply-ghc-options: locals # all local packages, the default
# apply-ghc-options: targets # all local packages that are targets
# apply-ghc-options: everything # applied even to snapshot and extra-deps
```

Note that `everything` is a slightly dangerous value, as it can break invariants about your snapshot database.
7 changes: 7 additions & 0 deletions src/Stack/Build/ConstructPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ addFinal lp lptb = do
(baseConfigOpts ctx)
allDeps
True -- wanted
True -- local
Local
package
, taskPresent = present
Expand Down Expand Up @@ -350,6 +351,7 @@ installPackage treatAsDep name ps = do
(baseConfigOpts ctx)
allDeps
(psWanted ps)
(psLocal ps)
-- An assertion to check for a recurrence of
-- https://github.com/commercialhaskell/stack/issues/345
(assert (destLoc == piiLocation ps) destLoc)
Expand Down Expand Up @@ -427,6 +429,7 @@ checkDirtiness ps installed package present wanted = do
(baseConfigOpts ctx)
present
(psWanted ps)
(psLocal ps)
(piiLocation ps) -- should be Local always
package
buildOpts = bcoBuildOpts (baseConfigOpts ctx)
Expand Down Expand Up @@ -526,6 +529,10 @@ psWanted :: PackageSource -> Bool
psWanted (PSLocal lp) = lpWanted lp
psWanted (PSUpstream _ _ _) = False

psLocal :: PackageSource -> Bool
psLocal (PSLocal _) = True
psLocal (PSUpstream _ _ _) = False

psPackage :: PackageName -> PackageSource -> M Package
psPackage _ (PSLocal lp) = return $ lpPackage lp
psPackage name (PSUpstream version _ flags) = do
Expand Down
1 change: 1 addition & 0 deletions src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ configFromConfigMonoid configStackRoot configUserConfigPath mproject configMonoi
configModifyCodePage = fromMaybe True configMonoidModifyCodePage
configExplicitSetupDeps = configMonoidExplicitSetupDeps
configRebuildGhcOptions = fromMaybe False configMonoidRebuildGhcOptions
configApplyGhcOptions = fromMaybe AGOLocals configMonoidApplyGhcOptions

return Config {..}

Expand Down
16 changes: 12 additions & 4 deletions src/Stack/Types/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,13 @@ configureOpts :: EnvConfig
-> BaseConfigOpts
-> Map PackageIdentifier GhcPkgId -- ^ dependencies
-> Bool -- ^ wanted?
-> Bool -- ^ local non-extra-dep?
-> InstallLocation
-> Package
-> ConfigureOpts
configureOpts econfig bco deps wanted loc package = ConfigureOpts
configureOpts econfig bco deps wanted isLocal loc package = ConfigureOpts
{ coDirs = configureOptsDirs bco loc package
, coNoDirs = configureOptsNoDir econfig bco deps wanted package
, coNoDirs = configureOptsNoDir econfig bco deps wanted isLocal package
}

configureOptsDirs :: BaseConfigOpts
Expand Down Expand Up @@ -660,9 +661,10 @@ configureOptsNoDir :: EnvConfig
-> BaseConfigOpts
-> Map PackageIdentifier GhcPkgId -- ^ dependencies
-> Bool -- ^ wanted?
-> Bool -- ^ is this a local, non-extra-dep?
-> Package
-> [String]
configureOptsNoDir econfig bco deps wanted package = concat
configureOptsNoDir econfig bco deps wanted isLocal package = concat
[ depOptions
, ["--enable-library-profiling" | boptsLibProfile bopts || boptsExeProfile bopts]
, ["--enable-executable-profiling" | boptsExeProfile bopts]
Expand Down Expand Up @@ -711,11 +713,17 @@ configureOptsNoDir econfig bco deps wanted package = concat
allGhcOptions = concat
[ fromMaybe [] $ Map.lookup Nothing ghcOptionsMap
, fromMaybe [] $ Map.lookup (Just $ packageName package) ghcOptionsMap
, if wanted
, if includeExtraOptions
then boptsGhcOptions bopts
else []
]

includeExtraOptions =
case configApplyGhcOptions config of
AGOTargets -> wanted
AGOLocals -> isLocal
AGOEverything -> True

-- | Get set of wanted package names from locals.
wantedLocalPackages :: [LocalPackage] -> Set PackageName
wantedLocalPackages = Set.fromList . map (packageName . lpPackage) . filter lpWanted
Expand Down
20 changes: 20 additions & 0 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,24 @@ data Config =
-- ^ See 'explicitSetupDeps'. 'Nothing' provides the default value.
,configRebuildGhcOptions :: !Bool
-- ^ Rebuild on GHC options changes
,configApplyGhcOptions :: !ApplyGhcOptions
-- ^ Which packages to ghc-options on the command line apply to?
}

-- | Which packages to ghc-options on the command line apply to?
data ApplyGhcOptions = AGOTargets -- ^ all local targets
| AGOLocals -- ^ all local packages, even non-targets
| AGOEverything -- ^ every package
deriving (Show, Read, Eq, Ord, Enum, Bounded)

instance FromJSON ApplyGhcOptions where
parseJSON = withText "ApplyGhcOptions" $ \t ->
case t of
"targets" -> return AGOTargets
"locals" -> return AGOLocals
"everything" -> return AGOEverything
_ -> fail $ "Invalid ApplyGhcOptions: " ++ show t

-- | Information on a single package index
data PackageIndex = PackageIndex
{ indexName :: !IndexName
Expand Down Expand Up @@ -586,6 +602,7 @@ data ConfigMonoid =
-- ^ See 'configExplicitSetupDeps'
,configMonoidRebuildGhcOptions :: !(Maybe Bool)
-- ^ See 'configMonoidRebuildGhcOptions'
,configMonoidApplyGhcOptions :: !(Maybe ApplyGhcOptions)
}
deriving Show

Expand Down Expand Up @@ -620,6 +637,7 @@ instance Monoid ConfigMonoid where
, configMonoidModifyCodePage = Nothing
, configMonoidExplicitSetupDeps = mempty
, configMonoidRebuildGhcOptions = Nothing
, configMonoidApplyGhcOptions = Nothing
}
mappend l r = ConfigMonoid
{ configMonoidDockerOpts = configMonoidDockerOpts l <> configMonoidDockerOpts r
Expand Down Expand Up @@ -652,6 +670,7 @@ instance Monoid ConfigMonoid where
, configMonoidModifyCodePage = configMonoidModifyCodePage l <|> configMonoidModifyCodePage r
, configMonoidExplicitSetupDeps = configMonoidExplicitSetupDeps l <> configMonoidExplicitSetupDeps r
, configMonoidRebuildGhcOptions = configMonoidRebuildGhcOptions l <|> configMonoidRebuildGhcOptions r
, configMonoidApplyGhcOptions = configMonoidApplyGhcOptions l <|> configMonoidApplyGhcOptions r
}

instance FromJSON (ConfigMonoid, [JSONWarning]) where
Expand Down Expand Up @@ -712,6 +731,7 @@ parseConfigMonoidJSON obj = do
(obj ..:? "explicit-setup-deps" ..!= mempty)
>>= fmap Map.fromList . mapM handleExplicitSetupDep . Map.toList
configMonoidRebuildGhcOptions <- obj ..:? "rebuild-ghc-options"
configMonoidApplyGhcOptions <- obj ..:? "apply-ghc-options"

return ConfigMonoid {..}
where
Expand Down

0 comments on commit 7c89751

Please sign in to comment.