Browse files

Add a depgraph makefile target as well as move sripts to 'misc' folder

  • Loading branch information...
1 parent 5317744 commit 941bd6508213ed38b16b58954b6d92f1251370ca @jaredmorrow jaredmorrow committed Oct 17, 2013
Showing with 128 additions and 3 deletions.
  1. +13 −3 Makefile
  2. +115 −0 misc/mapdeps.erl
  3. 0 { → misc}/orgbatch.el
View
16 Makefile
@@ -102,7 +102,7 @@ perfdev : all
$(foreach dep,$(wildcard deps/*), rm -rf perfdev/lib/$(shell basename $(dep))* && ln -sf $(abspath $(dep)) perfdev/lib;)
perf:
- perfdev/bin/riak stop || :
+ perfdev/bin/riak stop || :
perfdev/bin/riak start
perfdev/bin/riak-admin wait-for-service riak_kv 'perfdev@127.0.0.1'
escript apps/riak/src/riak_perf_smoke || :
@@ -128,10 +128,10 @@ docs:
orgs: orgs-doc orgs-README
orgs-doc:
- @emacs -l orgbatch.el -batch --eval="(riak-export-doc-dir \"doc\" 'html)"
+ @emacs -l misc/orgbatch.el -batch --eval="(riak-export-doc-dir \"doc\" 'html)"
orgs-README:
- @emacs -l orgbatch.el -batch --eval="(riak-export-doc-file \"README.org\" 'ascii)"
+ @emacs -l misc/orgbatch.el -batch --eval="(riak-export-doc-file \"README.org\" 'ascii)"
@mv README.txt README
APPS = kernel stdlib sasl erts ssl tools os_mon runtime_tools crypto inets \
@@ -163,6 +163,16 @@ cleanplt:
sleep 5
rm $(COMBO_PLT)
+
+## Create a dependency graph png
+depgraph: graphviz
+ @echo "Note: If you have nothing in deps/ this might be boring"
+ @echo "Creating dependency graph..."
+ @misc/mapdeps.erl | dot -Tpng -oriak.png
+ @echo "Dependency graph created as riak.png"
+graphviz:
+ $(if $(shell which dot),,$(error "To make the depgraph, you need graphviz installed"))
+
##
## Version and naming variables for distribution and packaging
##
View
115 misc/mapdeps.erl
@@ -0,0 +1,115 @@
+#!/usr/bin/env escript
+
+%% -------------------------------------------------------------------
+%%
+%% Copyright (c) 2013 Basho Technologies, Inc.
+%%
+%% This file is provided to you under the Apache License,
+%% Version 2.0 (the "License"); you may not use this file
+%% except in compliance with the License. You may obtain
+%% a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing,
+%% software distributed under the License is distributed on an
+%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+%% KIND, either express or implied. See the License for the
+%% specific language governing permissions and limitations
+%% under the License.
+%%
+%% -------------------------------------------------------------------
+
+% Map a project by its rebar configs.
+%
+% Usage: mapdeps [directory]
+%
+% Output can be rendered by graphviz:
+% ./mapdeps /Users/basho/riak | dot -Tpng -oriak.png
+%
+% It's fairly simple-minded at the moment:
+% - assumes all deps are in [directory]/deps
+% - assumes all deps definitions are {atom(), _, _}
+% - assumes the name of the toplevel is the basename of the directory
+% - showing the app name, not the repo name
+
+-module(mapdeps).
+
+-export([main/1]).
+
+usage() ->
+ io:format(standard_error,
+ "Map a project by rebar configs~n~n"
+ "Usage: mapdeps [directory]~n~n"
+ "Output can be rendered by graphviz:~n"
+ " ./mapdeps /Users/basho/riak | dot -Tpng -oriak.png",
+ []).
+
+main([]) ->
+ {ok, CWD} = file:get_cwd(),
+ map_dir(CWD);
+main([Dir]) ->
+ map_dir(Dir);
+main(_wat) ->
+ usage(),
+ exit(-1).
+
+map_dir(BaseDir) ->
+ RebarPath = filename:join([BaseDir, "rebar.config"]),
+ case filelib:is_regular(RebarPath) of
+ true ->
+ file_start(),
+ Map = map_rebar(BaseDir, RebarPath, ordsets:new()),
+ [ file_edge(From, To) || {From, To} <- Map ],
+ file_end();
+ false ->
+ io:format(standard_error, "~p not found.", [RebarPath]),
+ usage(),
+ exit(-1)
+ end.
+
+%% Read a rebar file. Find any `deps' option. Accumulate tuples of the
+%% form `{App, Dep}' for each element in this deps list. Recurse and
+%% attempt to read the rebar.config for each dep.
+map_rebar(BaseDir, Path, Acc) ->
+ case file:consult(Path) of
+ {ok, Opts} ->
+ Deps = proplists:get_value(deps, Opts, []),
+ lists:foldl(
+ fun({DepName, _, _}, A) ->
+ From = app_name(Path),
+ To = atom_to_list(DepName),
+ case ordsets:is_element({To, From}, A) of
+ true ->
+ %% we've already seen the other side,
+ %% recursing would just put us in a loop
+ %% TODO: warning color
+ ordsets:add_element({From, To}, A);
+ false ->
+ NA = ordsets:add_element({From, To}, A),
+ DepPath = filename:join(
+ [BaseDir, "deps",
+ atom_to_list(DepName),
+ "rebar.config"]),
+ map_rebar(BaseDir, DepPath, NA)
+ end
+ end,
+ Acc,
+ Deps);
+ _ ->
+ Acc
+ end.
+
+app_name(Path) ->
+ %% assumes Path ends in rebar.config
+ re:replace(filename:basename(filename:dirname(Path)),
+ "-", "_", [global, {return, list}]).
+
+file_start() ->
+ io:format(standard_io, "digraph {~n", []).
+
+file_end() ->
+ io:format(standard_io, "}~n", []).
+
+file_edge(From, To) ->
+ io:format(standard_io, " ~s -> ~s;~n", [From, To]).
View
0 orgbatch.el → misc/orgbatch.el
File renamed without changes.

0 comments on commit 941bd65

Please sign in to comment.