Skip to content

Commit 8006f38

Browse files
committed
Merge branch 'janus/fix-dependency-branching'
2 parents b9aca89 + abe2127 commit 8006f38

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

src/Distribution/Server/Features/UserNotify.hs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,14 @@ dependencyReleaseEmails userSetIdForPackage index (ReverseIndex revs nodemap dep
494494
(userId, Just NotifyPref{..}) <- zip ids mPrefs
495495
guard $ not notifyOptOut
496496
guard notifyDependencyForMaintained
497-
Just depList <- [mDepList]
497+
498+
Just depListWithCollisions <- [mDepList]
499+
-- Remove collisions on the same PackageName, amassed e.g. across
500+
-- multiple conditional branches. The branches could be from either
501+
-- side of an 'if' block conditioned on a flag. If either of them
502+
-- permits the newly released version, avoid sending the notification.
503+
let depList = unionSamePackageName depListWithCollisions
504+
498505
case notifyDependencyTriggerBounds of
499506
NewIncompatibility -> do
500507
let allNewUploadPkgInfos = PackageIndex.lookupPackageName index (pkgName pkgId)
@@ -532,6 +539,23 @@ dependencyReleaseEmails userSetIdForPackage index (ReverseIndex revs nodemap dep
532539
| otherwise = True
533540
newestVersion = pkgVersion pkgId
534541

542+
-- | Boolean OR on ranges across dependencies on the same PackageName
543+
unionSamePackageName :: [Dependency] -> [Dependency]
544+
unionSamePackageName collisions =
545+
let
546+
maps = [Map.singleton depName dep | dep@(Dependency depName _ _) <- collisions]
547+
disjunct :: Dependency -> Dependency -> Dependency
548+
disjunct
549+
(Dependency fName fRange fLibraries)
550+
(Dependency _ gRange gLibraries) =
551+
mkDependency
552+
fName
553+
(unionVersionRanges fRange gRange)
554+
(fLibraries <> gLibraries)
555+
disjunctions = Map.unionsWith disjunct maps
556+
in
557+
Map.elems disjunctions
558+
535559
pkgInfoToPkgId :: PkgInfo -> PackageIdentifier
536560
pkgInfoToPkgId pkgInfo =
537561
PackageIdentifier (packageName pkgInfo) (packageVersion pkgInfo)

tests/RevDepCommon.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ packToPkgInfo Package {pName, pVersion, pDeps} =
3131

3232
mkPackage :: PackageName -> [Int] -> [BSL.ByteString] -> PkgInfo
3333
mkPackage name intVersion depends =
34+
mkPackageWithCabalFileSuffix name intVersion $
35+
if depends /= []
36+
then "library\n build-depends: " <> BSL.intercalate "," depends
37+
else ""
38+
39+
mkPackageWithCabalFileSuffix :: PackageName -> [Int] -> BSL.ByteString -> PkgInfo
40+
mkPackageWithCabalFileSuffix name intVersion cabalFileSuffix =
3441
let
3542
version = mkVersion intVersion
3643
-- e.g. "2.3" for [2,3]
@@ -41,7 +48,7 @@ mkPackage name intVersion depends =
4148
\name: " <> BSL.fromStrict (Char8.pack $ unPackageName name) <> "\n\
4249
\version: " <> dotVersion <> "\n"
4350
cabalFile :: CabalFileText
44-
cabalFile = CabalFileText $ cabalFilePrefix <> if depends /= [] then "library\n build-depends: " <> BSL.intercalate "," depends else ""
51+
cabalFile = CabalFileText $ cabalFilePrefix <> cabalFileSuffix
4552
in
4653
PkgInfo
4754
(PackageIdentifier name version)

tests/ReverseDependenciesTest.hs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import qualified Hedgehog.Range as Range
3131
import qualified Hedgehog.Gen as Gen
3232
import Hedgehog ((===), Group(Group), MonadGen, Property, PropertyT, checkSequential, forAll, property)
3333

34-
import RevDepCommon (Package(..), TestPackage(..), mkPackage, packToPkgInfo)
34+
import RevDepCommon (Package(..), TestPackage(..), mkPackage, mkPackageWithCabalFileSuffix, packToPkgInfo)
3535

3636
mtlBeelineLens :: [PkgInfo]
3737
mtlBeelineLens =
@@ -214,6 +214,22 @@ allTests = testGroup "ReverseDependenciesTest"
214214
"dependencyReleaseEmails(trigger=BoundsOutOfRange) shouldn't generate a notification when the new package is for an old release series"
215215
mempty
216216
(runWithPref (pref BoundsOutOfRange) (PackageIndex.fromList newVersionOfOldBase) base4_14_1)
217+
assertEqual
218+
"dependencyReleaseEmails(trigger=BoundsOutOfRange) should only generate a notification when the new version is forbidden across all branches"
219+
mempty -- The two branches below should get OR'd and therefore the dependency is not out of bounds
220+
(runWithPref
221+
(pref BoundsOutOfRange)
222+
(PackageIndex.fromList
223+
[ mkPackage "base" [4,14] []
224+
, mkPackage "base" [4,15] []
225+
, mkPackageWithCabalFileSuffix "mtl" [2,3]
226+
"library\n\
227+
\ if arch(arm)\n\
228+
\ build-depends: base >= 4.14 && < 4.15\n\
229+
\ else\n\
230+
\ build-depends: base >= 4.15 && < 4.16"
231+
])
232+
base4_15)
217233
, testCase "hedgehogTests" $ do
218234
res <- hedgehogTests
219235
assertEqual "hedgehog test pass" True res

0 commit comments

Comments
 (0)