Created
July 8, 2012 09:57
-
-
Save supki/3070275 to your computer and use it in GitHub Desktop.
Module dependency graph generating scripts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env runhaskell | |
{-# LANGUAGE UnicodeSyntax #-} | |
import Control.Applicative ((<$>)) | |
import Control.Monad ((<=<)) | |
import Data.List (intercalate) | |
import System.Environment (getArgs) | |
import Distribution.ModuleName (components) | |
import Distribution.PackageDescription (condLibrary, condTreeData, libModules) | |
import Distribution.PackageDescription.Parse (readPackageDescription) | |
import Distribution.Verbosity (silent) | |
main ∷ IO () | |
main = getArgs >>= mapM_ (mapM_ putStrLn <=< modules) | |
modules ∷ FilePath → IO [String] | |
modules fp = maybe [] (map normalizeModuleName . libModules . condTreeData) . condLibrary <$> readPackageDescription silent fp | |
where | |
normalizeModuleName = intercalate "." . components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use v5.14; | |
use warnings FATAL => qw(void); | |
sub main (); | |
sub parse (@); | |
sub compile (@); | |
sub main () { | |
my @modules; | |
my %modules; | |
while (<>) { chomp; push @modules, $_ } | |
for my $_ (@modules) { @{$modules{$_}} = parse $_, @modules } | |
compile %modules; | |
} | |
sub parse (@) { | |
(my $module, my @modules) = @_; | |
$module =~ s#\.#/#g; | |
open(my $HANDLE, "<:utf8", "src/$module.hs") or die "Can't open \"src/$module.hs\": $!"; | |
my %dependences; | |
while (<$HANDLE>) { | |
if (/module/) { next } | |
for my $candidate (@modules) { | |
if (/\s$candidate\s/ ) { $dependences{$candidate} = 1 } | |
} | |
} | |
keys %dependences; | |
} | |
sub compile (%) { | |
my %modules = @_; | |
say "digraph sample {"; | |
for my $key (keys %modules) { | |
for my $module (@{$modules{$key}}) { | |
say "\"$key\" -> \"$module\""; | |
} | |
} | |
say "}"; | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To get a dependency graph, run
% ./all-your-modules.hs liblastfm.cabal | ./compile-to-graphviz.pl | dot -Tpng > graph.png