Skip to content

Commit

Permalink
When a Hackage revision invalidates a build plan in a snapshot, trust…
Browse files Browse the repository at this point in the history
… the snapshot #770
  • Loading branch information
snoyberg committed Oct 15, 2015
1 parent 701f250 commit df54339
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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)
* When a Hackage revision invalidates a build plan in a snapshot, trust the snapshot [#770](https://github.com/commercialhaskell/stack/issues/770)

Bug fixes:

Expand Down
40 changes: 30 additions & 10 deletions src/Stack/Build/ConstructPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -407,20 +407,32 @@ addPackageDeps treatAsDep package = do
inRange <- if adrVersion adr `withinRange` range
then return True
else do
let warn reason = do
tell mempty { wWarnings = (msg:) }
where
msg = T.concat
[ "WARNING: Ignoring out of range dependency"
, reason
, ": "
, T.pack $ packageIdentifierString $ PackageIdentifier depname (adrVersion adr)
, ". "
, T.pack $ packageNameString $ packageName package
, " requires: "
, versionRangeText range
]
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:) }
warn " (allow-newer enabled)"
return True
else return False
else do
x <- inSnapshot (packageName package) (packageVersion package)
y <- inSnapshot depname (adrVersion adr)
if x && y
then do
warn " (trusting snapshot over Hackage revisions)"
return True
else return False
if inRange
then case adr of
ADRToInstall task -> return $ Right
Expand Down Expand Up @@ -601,3 +613,11 @@ stripNonDeps deps plan = plan

markAsDep :: PackageName -> M ()
markAsDep name = tell mempty { wDeps = Set.singleton name }

-- | Is the given package/version combo defined in the snapshot?
inSnapshot :: PackageName -> Version -> M Bool
inSnapshot name version = do
p <- asks mbp
return $ fromMaybe False $ do
mpi <- Map.lookup name (mbpPackages p)
return $ mpiVersion mpi == version

0 comments on commit df54339

Please sign in to comment.