Permalink
Browse files

Merge branch 'rebarify-15688'

  • Loading branch information...
David Reid
David Reid committed Nov 12, 2010
2 parents 80571b9 + cbc93be commit b39bd09eb0a7c066949246d7237263f5c778c668
View
@@ -1,4 +1,5 @@
/ebin
/doc
/_test
+/.eunit
/docs
View
@@ -1,20 +1,29 @@
-all: ebin/
- (cd src;$(MAKE) all)
+
+PREFIX:=../
+DEST:=$(PREFIX)$(PROJECT)
+
+REBAR=./rebar
+
+all:
+ @$(REBAR) get-deps compile
edoc:
- (cd src;$(MAKE) edoc)
+ @$(REBAR) doc
-test: ebin/
- (cd src;$(MAKE) test)
+test:
+ @rm -rf .eunit
+ @mkdir -p .eunit
+ @$(REBAR) skip_deps=true eunit
clean:
- rm -rf ebin
+ @$(REBAR) clean
-clean_plt:
- (cd src;$(MAKE) clean_plt)
+build_plt:
+ @$(REBAR) build_plt
dialyzer:
- (cd src;$(MAKE) dialyzer)
+ @$(REBAR) analyze
+
+app:
+ @$(REBAR) create template=mochiwebapp dest=$(DEST) appid=$(PROJECT)
-ebin/:
- @mkdir -p ebin
View
6 README
@@ -7,3 +7,9 @@ The master of MochiWeb is tested with R13B04 and later. A branch compatible
with R12B is maintained separately at http://github.com/lemenkov/mochiweb
The R12B branch of that repository is mirrored in the official repository
occasionally for convenience.
+
+To create a new mochiweb using project:
+ make app PROJECT=project_name
+
+To create a new mochiweb using project in a specific directory:
+ make app PROJECT=project_name PREFIX=$HOME/projects/
View
@@ -1,20 +0,0 @@
-all: ebin/
- (cd src;$(MAKE) all)
-
-edoc:
- (cd src;$(MAKE) edoc)
-
-test:
- (cd src;$(MAKE) test)
-
-clean:
- (cd src;$(MAKE) clean)
-
-clean_plt:
- (cd src;$(MAKE) clean_plt)
-
-dialyzer:
- (cd src;$(MAKE) dialyzer)
-
-ebin/:
- @mkdir -p ebin
View
@@ -1,33 +0,0 @@
-include ../support/include.mk
-
-APPLICATION=skel
-DOC_OPTS={dir,\"../doc\"}
-TEST_PLT=$(TEST_DIR)/dialyzer_plt
-
-all: $(EBIN_FILES)
-
-debug:
- $(MAKE) DEBUG=-DDEBUG
-
-clean:
- rm -rf $(EBIN_FILES)
-
-edoc:
- $(ERL) -noshell -pa ../ebin \
- -eval "edoc:application($(APPLICATION), \".\", [$(DOC_OPTS)])" \
- -s init stop
-
-test: $(EBIN_FILES)
- mkdir -p $(TEST_DIR);
- @../support/run_tests.escript $(EBIN_DIR) | tee $(TEST_DIR)/test.log
-
-$(TEST_PLT):
- mkdir -p $(TEST_DIR)
- cp $(DIALYZER_PLT) $(TEST_PLT)
- dialyzer --plt $(TEST_PLT) --add_to_plt -r ../deps/*/ebin
-
-clean_plt:
- rm $(TEST_PLT)
-
-dialyzer: $(TEST_PLT)
- dialyzer --src --plt $(TEST_PLT) -DNOTEST -DDIALYZER -c ../src | tee $(TEST_DIR)/dialyzer.log
View
@@ -1,14 +0,0 @@
-{application, skel,
- [{description, "skel"},
- {vsn, "0.01"},
- {modules, [
- skel,
- skel_app,
- skel_sup,
- skel_web,
- skel_deps
- ]},
- {registered, []},
- {mod, {skel_app, []}},
- {env, []},
- {applications, [kernel, stdlib, crypto]}]}.
View
@@ -1,30 +0,0 @@
-%% @author author <author@example.com>
-%% @copyright YYYY author.
-
-%% @doc TEMPLATE.
-
--module(skel).
--author('author <author@example.com>').
--export([start/0, stop/0]).
-
-ensure_started(App) ->
- case application:start(App) of
- ok ->
- ok;
- {error, {already_started, App}} ->
- ok
- end.
-
-%% @spec start() -> ok
-%% @doc Start the skel server.
-start() ->
- skel_deps:ensure(),
- ensure_started(crypto),
- application:start(skel).
-
-%% @spec stop() -> ok
-%% @doc Stop the skel server.
-stop() ->
- Res = application:stop(skel),
- application:stop(crypto),
- Res.
View
@@ -1 +0,0 @@
-
View
@@ -1,30 +0,0 @@
-%% @author author <author@example.com>
-%% @copyright YYYY author.
-
-%% @doc Callbacks for the skel application.
-
--module(skel_app).
--author('author <author@example.com>').
-
--behaviour(application).
--export([start/2, stop/1]).
-
-
-%% @spec start(_Type, _StartArgs) -> ServerRet
-%% @doc application start callback for skel.
-start(_Type, _StartArgs) ->
- skel_deps:ensure(),
- skel_sup:start_link().
-
-%% @spec stop(_State) -> ServerRet
-%% @doc application stop callback for skel.
-stop(_State) ->
- ok.
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.
View
@@ -1,51 +0,0 @@
-%% @author author <author@example.com>
-%% @copyright YYYY author.
-
-%% @doc Web server for skel.
-
--module(skel_web).
--author('author <author@example.com>').
-
--export([start/1, stop/0, loop/2]).
-
-%% External API
-
-start(Options) ->
- {DocRoot, Options1} = get_option(docroot, Options),
- Loop = fun (Req) ->
- ?MODULE:loop(Req, DocRoot)
- end,
- mochiweb_http:start([{name, ?MODULE}, {loop, Loop} | Options1]).
-
-stop() ->
- mochiweb_http:stop(?MODULE).
-
-loop(Req, DocRoot) ->
- "/" ++ Path = Req:get(path),
- case Req:get(method) of
- Method when Method =:= 'GET'; Method =:= 'HEAD' ->
- case Path of
- _ ->
- Req:serve_file(Path, DocRoot)
- end;
- 'POST' ->
- case Path of
- _ ->
- Req:not_found()
- end;
- _ ->
- Req:respond({501, [], []})
- end.
-
-%% Internal API
-
-get_option(Option, Options) ->
- {proplists:get_value(Option, Options), proplists:delete(Option, Options)}.
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.
View
@@ -1,12 +0,0 @@
-#!/bin/sh
-cd `dirname $0`
-
-MAKE=make
-case `uname` in
-*BSD)
- MAKE=gmake
- ;;
-esac
-
-"${MAKE}"
-exec erl -pa $PWD/ebin $PWD/deps/*/ebin -boot start_sasl -s reloader -s skel
View
@@ -1,3 +0,0 @@
-#!/bin/sh
-cd `dirname $0`
-exec erl -pa $PWD/ebin $PWD/deps/*/ebin -boot start_sasl -s skel
@@ -1,40 +0,0 @@
-## -*- makefile -*-
-
-######################################################################
-## Erlang
-
-ERL := erl
-ERLC := $(ERL)c
-
-INCLUDE_DIRS := ../include $(wildcard ../deps/*/include)
-EBIN_DIRS := $(wildcard ../deps/*/ebin)
-ERLC_FLAGS := -W $(INCLUDE_DIRS:../%=-I ../%) $(EBIN_DIRS:%=-pa %)
-
-ifndef no_debug_info
- ERLC_FLAGS += +debug_info
-endif
-
-ifdef debug
- ERLC_FLAGS += -Ddebug
-endif
-
-EBIN_DIR := ../ebin
-TEST_DIR := ../_test
-EMULATOR := beam
-
-ERL_SOURCES := $(wildcard *.erl)
-ERL_HEADERS := $(wildcard *.hrl) $(wildcard ../include/*.hrl)
-ERL_OBJECTS := $(ERL_SOURCES:%.erl=$(EBIN_DIR)/%.$(EMULATOR))
-ERL_OBJECTS_LOCAL := $(ERL_SOURCES:%.erl=./%.$(EMULATOR))
-APP_FILES := $(wildcard *.app)
-EBIN_FILES = $(ERL_OBJECTS) $(APP_FILES:%.app=../ebin/%.app)
-MODULES = $(ERL_SOURCES:%.erl=%)
-
-../ebin/%.app: %.app
- cp $< $@
-
-$(EBIN_DIR)/%.$(EMULATOR): %.erl
- $(ERLC) $(ERLC_FLAGS) -o $(EBIN_DIR) $<
-
-./%.$(EMULATOR): %.erl
- $(ERLC) $(ERLC_FLAGS) -o . $<
@@ -1,94 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-%%! -name mochiweb__test@127.0.0.1
-main([Ebin]) ->
- code:add_path(Ebin),
- code:add_paths(filelib:wildcard("../deps/*/ebin", Ebin)),
- code:add_paths(filelib:wildcard("../deps/*/deps/*/ebin", Ebin)),
-
- ModuleNames = [hd(string:tokens(M, "."))
- || "../src/" ++ M <- filelib:wildcard("../src/*.erl")],
-
- {ok, NonTestRe} = re:compile("_tests$"),
- Modules = [list_to_atom(M) ||
- M <- lists:filter(
- fun(M) ->
- nomatch == re:run(M, NonTestRe)
- end,
- ModuleNames)],
-
-
- crypto:start(),
- start_cover(Modules),
- eunit:test(Modules, [verbose,{report,{eunit_surefire,[{dir,"../_test"}]}}]),
- analyze_cover(Modules);
-main(_) ->
- io:format("usage: run_tests.escript EBIN_DIR~n"),
- halt(1).
-
-start_cover(Modules) ->
- {ok, _Cover} = cover:start(),
- io:format("Cover compiling...~n"),
- Compiled = [ M || {ok, M} <- [ cover:compile(
- M,
- [{i, "include"}
- ])
- || M <- Modules ] ],
- case length(Modules) == length(Compiled) of
- true -> ok;
- false ->
- io:format("Warning: the following modules were not"
- " cover-compiled:~n ~p~n", [Compiled])
- end.
-
-analyze_cover(Modules) ->
- io:format("Analyzing cover...~n"),
- CoverBase = filename:join(["..", "_test", "cover"]),
- ok = filelib:ensure_dir(filename:join([CoverBase, "fake"])),
- Coverages = lists:foldl(
- fun(M, Acc) ->
- [analyze_module(CoverBase, M)|Acc]
- end,
- [], Modules),
- IndexFilename = filename:join([CoverBase, "index.html"]),
- {ok, Index} = file:open(IndexFilename, [write]),
- {LineTotal, CoverTotal} =
- lists:foldl(fun({_,_,Lines,Covered}, {LineAcc, CovAcc}) ->
- {LineAcc+Lines, CovAcc+Covered}
- end, {0,0}, Coverages),
- file:write(Index,
- "<html><head><title>Coverage</title></head>\n"
- "<body><h1>Coverage</h1><ul>\n"),
- file:write(Index,
- io_lib:format("<h2>Total: ~.2f%</h2>\n",
- [percentage(CoverTotal, LineTotal)])),
- [ file:write(Index,
- io_lib:format(
- "<li><a href=\"~s\">~p</a>: ~.2f%</li>~n",
- [Filename, Module, percentage(Covered, Lines)]))
- || {Filename, Module, Lines, Covered} <- Coverages ],
- file:write(Index,"</ul></body></html>"),
- file:close(Index),
- io:format("Cover analysis in ~s~n", [IndexFilename]).
-
-analyze_module(CoverBase, Module) ->
- {ok, Filename} =
- cover:analyze_to_file(
- Module,
- filename:join(CoverBase, atom_to_list(Module)++".COVER.html"),
- [html]),
- Lines = count_lines(Filename, "[[:digit:]]\.\.|"),
- Covered = count_lines(Filename, "[[:space:]]0\.\.|"),
- {filename:basename(Filename), Module, Lines, Lines-Covered}.
-
-count_lines(Filename, Pattern) ->
- {ok, [Lines],_} = io_lib:fread(
- "~d",
- os:cmd(io_lib:format("grep -e \"~s\" ~s | wc -l",
- [Pattern, Filename]))),
- Lines.
-
-percentage(_, 0) -> 1000.0;
-percentage(Part, Total) ->
- (Part/Total)*100.
-
View
BIN rebar
Binary file not shown.
Oops, something went wrong.

0 comments on commit b39bd09

Please sign in to comment.