Skip to content

Commit

Permalink
Add allow-newer config option (closes #922)
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Oct 14, 2015
1 parent 8f3961f commit f359cbe
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 12 deletions.
7 changes: 7 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Unreleased changes

Major changes:

Other enhancements:

* Added an `allow-newer` config option [#922](https://github.com/commercialhaskell/stack/issues/922) [#770](https://github.com/commercialhaskell/stack/issues/770)

Bug fixes:

## v0.1.6.0

Expand Down
13 changes: 13 additions & 0 deletions doc/yaml_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,16 @@ apply-ghc-options: locals # all local packages, the default
```

Note that `everything` is a slightly dangerous value, as it can break invariants about your snapshot database.

### allow-newer

(Since 0.1.7)

Ignore version bounds in .cabal files. Default is false.

```yaml
allow-newer: true
```

Note that this also ignores lower bounds. The name "allow-newer" is chosen to
match the commonly used cabal option.
48 changes: 36 additions & 12 deletions src/Stack/Build/ConstructPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
-- | Construct a @Plan@ for how to build
module Stack.Build.ConstructPlan
Expand All @@ -13,7 +14,7 @@ import Control.Exception.Lifted
import Control.Monad
import Control.Monad.Catch (MonadCatch)
import Control.Monad.IO.Class
import Control.Monad.Logger (MonadLogger)
import Control.Monad.Logger (MonadLogger, logWarn)
import Control.Monad.RWS.Strict
import Control.Monad.Trans.Resource
import qualified Data.ByteString.Char8 as S8
Expand Down Expand Up @@ -82,10 +83,12 @@ data W = W
-- ^ why a local package is considered dirty
, wDeps :: !(Set PackageName)
-- ^ Packages which count as dependencies
, wWarnings :: !([Text] -> [Text])
-- ^ Warnings
}
instance Monoid W where
mempty = W mempty mempty mempty mempty
mappend (W a b c d) (W w x y z) = W (mappend a w) (mappend b x) (mappend c y) (mappend d z)
mempty = W mempty mempty mempty mempty mempty
mappend (W a b c d e) (W w x y z z') = W (mappend a w) (mappend b x) (mappend c y) (mappend d z) (mappend e z')

type M = RWST
Ctx
Expand Down Expand Up @@ -143,7 +146,9 @@ constructPlan mbp0 baseConfigOpts0 locals extraToBuild0 locallyRegistered loadPa
let inner = do
mapM_ onWanted $ filter lpWanted locals
mapM_ (addDep False) $ Set.toList extraToBuild0
((), m, W efinals installExes dirtyReason deps) <- liftIO $ runRWST inner (ctx econfig latest) M.empty
((), m, W efinals installExes dirtyReason deps warnings) <-
liftIO $ runRWST inner (ctx econfig latest) M.empty
mapM_ $logWarn (warnings [])
let toEither (_, Left e) = Left e
toEither (k, Right v) = Right (k, v)
(errlibs, adrs) = partitionEithers $ map toEither $ M.toList m
Expand Down Expand Up @@ -398,14 +403,33 @@ addPackageDeps treatAsDep package = do
UnknownPackage name -> assert (name == depname) NotInBuildPlan
_ -> Couldn'tResolveItsDependencies
in return $ Left (depname, (range, mlatest, bd))
Right adr | not $ adrVersion adr `withinRange` range ->
return $ Left (depname, (range, mlatest, DependencyMismatch $ adrVersion adr))
Right (ADRToInstall task) -> return $ Right
(Set.singleton $ taskProvides task, Map.empty, taskLocation task)
Right (ADRFound loc _ (Executable _)) -> return $ Right
(Set.empty, Map.empty, loc)
Right (ADRFound loc _ (Library ident gid)) -> return $ Right
(Set.empty, Map.singleton ident gid, loc)
Right adr -> do
inRange <- if adrVersion adr `withinRange` range
then return True
else do
allowNewer <- asks $ configAllowNewer . getConfig
if allowNewer
then do
let msg = T.concat
[ "WARNING: Ignoring out of range dependency: "
, T.pack $ packageIdentifierString $ PackageIdentifier depname (adrVersion adr)
, ". "
, T.pack $ packageNameString $ packageName package
, " requires: "
, versionRangeText range
]
tell mempty { wWarnings = (msg:) }
return True
else return False
if inRange
then case adr of
ADRToInstall task -> return $ Right
(Set.singleton $ taskProvides task, Map.empty, taskLocation task)
ADRFound loc _ (Executable _) -> return $ Right
(Set.empty, Map.empty, loc)
ADRFound loc _ (Library ident gid) -> return $ Right
(Set.empty, Map.singleton ident gid, loc)
else return $ Left (depname, (range, mlatest, DependencyMismatch $ adrVersion adr))
case partitionEithers deps of
([], pairs) -> return $ Right $ mconcat pairs
(errs, _) -> return $ Left $ DependencyPlanFailures
Expand Down
1 change: 1 addition & 0 deletions src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ configFromConfigMonoid configStackRoot configUserConfigPath mproject configMonoi
configExplicitSetupDeps = configMonoidExplicitSetupDeps
configRebuildGhcOptions = fromMaybe False configMonoidRebuildGhcOptions
configApplyGhcOptions = fromMaybe AGOLocals configMonoidApplyGhcOptions
configAllowNewer = fromMaybe False configMonoidAllowNewer

return Config {..}

Expand Down
9 changes: 9 additions & 0 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ data Config =
-- ^ Rebuild on GHC options changes
,configApplyGhcOptions :: !ApplyGhcOptions
-- ^ Which packages to ghc-options on the command line apply to?
,configAllowNewer :: !Bool
-- ^ Ignore version ranges in .cabal files. Funny naming chosen to
-- match cabal.
}

-- | Which packages to ghc-options on the command line apply to?
Expand Down Expand Up @@ -605,6 +608,9 @@ data ConfigMonoid =
,configMonoidRebuildGhcOptions :: !(Maybe Bool)
-- ^ See 'configMonoidRebuildGhcOptions'
,configMonoidApplyGhcOptions :: !(Maybe ApplyGhcOptions)
-- ^ See 'configApplyGhcOptions'
,configMonoidAllowNewer :: !(Maybe Bool)
-- ^ See 'configMonoidAllowNewer'
}
deriving Show

Expand Down Expand Up @@ -640,6 +646,7 @@ instance Monoid ConfigMonoid where
, configMonoidExplicitSetupDeps = mempty
, configMonoidRebuildGhcOptions = Nothing
, configMonoidApplyGhcOptions = Nothing
, configMonoidAllowNewer = Nothing
}
mappend l r = ConfigMonoid
{ configMonoidDockerOpts = configMonoidDockerOpts l <> configMonoidDockerOpts r
Expand Down Expand Up @@ -673,6 +680,7 @@ instance Monoid ConfigMonoid where
, configMonoidExplicitSetupDeps = configMonoidExplicitSetupDeps l <> configMonoidExplicitSetupDeps r
, configMonoidRebuildGhcOptions = configMonoidRebuildGhcOptions l <|> configMonoidRebuildGhcOptions r
, configMonoidApplyGhcOptions = configMonoidApplyGhcOptions l <|> configMonoidApplyGhcOptions r
, configMonoidAllowNewer = configMonoidAllowNewer l <|> configMonoidAllowNewer r
}

instance FromJSON (ConfigMonoid, [JSONWarning]) where
Expand Down Expand Up @@ -734,6 +742,7 @@ parseConfigMonoidJSON obj = do
>>= fmap Map.fromList . mapM handleExplicitSetupDep . Map.toList
configMonoidRebuildGhcOptions <- obj ..:? "rebuild-ghc-options"
configMonoidApplyGhcOptions <- obj ..:? "apply-ghc-options"
configMonoidAllowNewer <- obj ..:? "allow-newer"

return ConfigMonoid {..}
where
Expand Down

0 comments on commit f359cbe

Please sign in to comment.