Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Cabal
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Haskell
Cabal
Commits
b339b31f
Commit
b339b31f
authored
17 years ago
by
Duncan Coutts
Browse files
Options
Downloads
Patches
Plain Diff
Add PackageIndex.dependencyGraph that builds a Graph
Useful for some more tricky queries.
parent
6bcd6cc0
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Distribution/Simple/PackageIndex.hs
+34
-0
34 additions, 0 deletions
Distribution/Simple/PackageIndex.hs
with
34 additions
and
0 deletions
Distribution/Simple/PackageIndex.hs
+
34
−
0
View file @
b339b31f
...
...
@@ -44,6 +44,7 @@ module Distribution.Simple.PackageIndex (
dependencyClosure
,
dependencyInconsistencies
,
dependencyCycles
,
dependencyGraph
,
)
where
import
Prelude
hiding
(
lookup
)
...
...
@@ -51,6 +52,8 @@ import Control.Exception (assert)
import
qualified
Data.Map
as
Map
import
Data.Map
(
Map
)
import
qualified
Data.Graph
as
Graph
import
qualified
Data.Array
as
Array
import
Data.Array
((
!
))
import
Data.List
(
nubBy
,
group
,
sort
,
groupBy
,
sortBy
,
find
)
import
Data.Monoid
(
Monoid
(
..
))
import
Data.Maybe
(
isNothing
)
...
...
@@ -329,3 +332,34 @@ dependencyCycles index =
where
adjacencyList
=
[
(
pkg
,
packageId
pkg
,
depends
pkg
)
|
pkg
<-
allPackages
index
]
-- | Builds a graph of the package dependencies.
--
-- Dependencies on other packages that are in the index are discarded.
-- You can check if there are any such dependencies with 'brokenPackages'.
--
dependencyGraph
::
PackageFixedDeps
pkg
=>
PackageIndex
pkg
->
(
Graph
.
Graph
,
Graph
.
Vertex
->
PackageIdentifier
,
PackageIdentifier
->
Maybe
Graph
.
Vertex
)
dependencyGraph
index
=
(
graph
,
vertexToPkgId
,
pkgIdToVertex
)
where
graph
=
Array
.
listArray
bounds
[
[
v
|
Just
v
<-
map
pkgIdToVertex
(
depends
pkg
)
]
|
pkg
<-
pkgs
]
vertexToPkgId
vertex
=
pkgIdTable
!
vertex
pkgIdToVertex
=
binarySearch
0
topBound
pkgIdTable
=
Array
.
listArray
bounds
(
map
packageId
pkgs
)
pkgs
=
sortBy
(
comparing
packageId
)
(
allPackages
index
)
topBound
=
length
pkgs
-
1
bounds
=
(
0
,
topBound
)
binarySearch
a
b
key
|
a
>
b
=
Nothing
|
otherwise
=
case
compare
key
(
pkgIdTable
!
mid
)
of
LT
->
binarySearch
a
(
mid
-
1
)
key
EQ
->
Just
mid
GT
->
binarySearch
(
mid
+
1
)
b
key
where
mid
=
(
a
+
b
)
`
div
`
2
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment