Commit cac6d8ee authored by Camil Staps's avatar Camil Staps 🚀 Committed by GitHub

No commit message

No commit message
parents
module clean_dependencies
/**
* Plot dependencies between Clean libraries as a Dot graph.
* This uses libraries from Cloogle, https://github.com/clean-cloogle/Cloogle.
* This requires the file types.json which is generated by the builddb script of https://github.com/clean-cloogle/Cloogle.
*/
import StdBool
import StdFile
from StdFunc import flip, o
import StdInt
import StdList
import StdOrdList
import StdString
import StdTuple
from Data.Func import mapSt, seqSt
import Data.List
import Data.Maybe
import Data.Tuple
from Text import class Text(concat), instance Text String, <+
from DB import :: Entry{value}
import CloogleDB
STANDARD =
[ "Dynamics"
, "Gast"
, "Generics"
, "GraphCopy"
, "iTasks"
, "Platform"
, "Sapl"
, "StdEnv"
, "TCPIP"
]
DEPRECATED =
[ "ArgEnv"
, "Directory"
, "MersenneTwister"
, "ObjectIO"
, "StdLib"
]
IGNORE_MISCELLANEOUS :== True
Start w
# (io,w) = stdio w
# (_,f,w) = fopen "types.json" FReadText w
# (db,f) = openDB f
# (_,w) = fclose f w
| isNothing db
# io = io <<< "Failed to read database\n"
= snd (fclose io w)
# db = fromJust db
# (es,db) = getEntries db
# mods = [me \\ (ModuleEntry me,_) <- es]
# (deps,db) = appFst (groupDependencies o flatten) (mapSt dependencies mods db)
# io = io
<<< "digraph Dependencies {\n"
<<< "label=\"Dependencies\"\n"
<<< "node[shape=record]\n"
# io = seqSt printLib (removeDup [d.from_lib \\ d <- deps]) io
# io = seqSt (flip (<<<)) deps io
# io = io
<<< "overlap=false\n"
<<< "}\n"
= snd (fclose io w)
where
printLib :: String *File -> *File
printLib lib io
| IGNORE_MISCELLANEOUS && not (isMember lib (STANDARD ++ DEPRECATED)) = io
| otherwise = io
<<< '"' <<< lib
<<< "\"[color=" <<< color <<< " fontcolor=" <<< color <<< "]\n"
where
color
| isMember lib DEPRECATED = "red"
| isMember lib STANDARD = "black"
| otherwise = "gray"
:: Dependency =
{ from_lib :: String
, to_lib :: String
, in_modules :: [String]
}
instance <<< Dependency
where
<<< f d
| IGNORE_MISCELLANEOUS &&
(not (isMember d.from_lib (STANDARD ++ DEPRECATED)) ||
not (isMember d.to_lib (STANDARD ++ DEPRECATED))) = f
| otherwise = f
<<< '"' <<< d.from_lib <<< "\"->\"" <<< d.to_lib <<< '"'
<<< "["
<<< "penwidth=" <<< (1 + toInt (ln (toReal (length d.in_modules)))) <<< " "
<<< "label=\"" <<< label <<< "\" "
<<< "tooltip=\"" <<< tooltip <<< "\" "
<<< "color=" <<< color <<< " fontcolor=" <<< color
<<< "]\n"
where
label = length d.in_modules <+ ": " +++
concat (intersperse ", " (take maxn d.in_modules)) +++
if (length d.in_modules > maxn) ", ..." ""
where maxn = 1
tooltip = concat (intersperse ", " d.in_modules)
color
| isMember d.to_lib DEPRECATED = "red"
| isMember d.to_lib STANDARD = "black"
| otherwise = "gray"
dependencies :: ModuleEntry *CloogleDB -> *([Dependency], *CloogleDB)
dependencies me db
# (usages,db) = getIndices me.me_usages db
= (filter (\x -> x.from_lib <> x.to_lib && hd x.in_modules <> "")
[{ from_lib = fromJust (getLibrary ume.me_loc)
, to_lib = fromJust (getLibrary me.me_loc)
, in_modules = [fromJust (getModule ume.me_loc)]
} \\ {value=ModuleEntry ume} <- usages], db)
groupDependencies :: ([Dependency] -> [Dependency])
groupDependencies =
map (\ds=:[d:_] -> {d & in_modules=sort (removeDup (flatten [d.in_modules \\ d <- ds]))})
o groupBy (\a b -> (a.from_lib, a.to_lib) == (b.from_lib, b.to_lib))
o sortBy (\a b -> (a.from_lib, a.to_lib) < (b.from_lib, b.to_lib))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment