221V 1 год назад
Родитель
Сommit
094d92121a
5 измененных файлов с 286 добавлено и 121 удалено
  1. 16 16
      build.config
  2. 1 1
      doc/src/guide/getting_started.asciidoc
  3. 265 104
      plugins/bootstrap.mk
  4. 2 0
      test/core_deps.mk
  5. 2 0
      test/plugin_bootstrap.mk

+ 16 - 16
build.config

@@ -5,40 +5,40 @@
 
 # Core modules.
 core/core
-index/*
-core/index
+#index/*
+#core/index
 core/deps
 
 # Plugins that must run before Erlang code gets compiled.
 plugins/erlydtl
-plugins/protobuffs
+#plugins/protobuffs
 
 # Core modules, continued.
 core/erlc
-core/docs
-core/rel
+#core/docs
+#core/rel
 core/test
-core/compat
+#core/compat
 
 # Plugins.
-plugins/asciidoc
+#plugins/asciidoc
 plugins/bootstrap
 plugins/c_src
-plugins/ci
+#plugins/ci
 plugins/ct
-plugins/dialyzer
-plugins/edoc
+#plugins/dialyzer
+#plugins/edoc
 plugins/escript
 plugins/eunit
-plugins/relx
-plugins/shell
-plugins/syntastic
-plugins/triq
-plugins/xref
+#plugins/relx
+#plugins/shell
+#plugins/syntastic
+#plugins/triq
+#plugins/xref
 
 # Plugins enhancing the functionality of other plugins.
 plugins/cover
-plugins/sfx
+#plugins/sfx
 
 # Core modules which can use variables from plugins.
 core/deps-tools

+ 1 - 1
doc/src/guide/getting_started.asciidoc

@@ -242,7 +242,7 @@ target:
 
 [source,bash]
 $ make list-templates
-Available templates: cowboy_http cowboy_loop cowboy_rest cowboy_ws gen_fsm gen_server ranch_protocol supervisor
+Available templates: cowboy_http cowboy_loop cowboy_rest cowboy_ws gen_fsm gen_statem gen_server ranch_protocol supervisor
 
 To generate a module, let's say a `gen_server`, all you need to
 do is to call `make new` with the appropriate arguments:

+ 265 - 104
plugins/bootstrap.mk

@@ -21,32 +21,34 @@ help::
 
 define bs_appsrc
 {application, $p, [
-	{description, ""},
-	{vsn, "0.1.0"},
-	{id, "git"},
-	{modules, []},
-	{registered, []},
-	{applications, [
-		kernel,
-		stdlib
-	]},
-	{mod, {$p_app, []}},
-	{env, []}
+  {description, ""},
+  {vsn, "0.1.0"},
+  {modules, []},
+  {registered, []},
+  {applications, [
+    kernel,
+    stdlib
+  ]},
+  {mod, {$p_app, []}},
+  {env, []}
 ]}.
+
+
 endef
 
 define bs_appsrc_lib
 {application, $p, [
-	{description, ""},
-	{vsn, "0.1.0"},
-	{id, "git"},
-	{modules, []},
-	{registered, []},
-	{applications, [
-		kernel,
-		stdlib
-	]}
+  {description, ""},
+  {vsn, "0.1.0"},
+  {modules, []},
+  {registered, []},
+  {applications, [
+    kernel,
+    stdlib
+  ]}
 ]}.
+
+
 endef
 
 # To prevent autocompletion issues with ZSH, we add "include erlang.mk"
@@ -60,6 +62,7 @@ PROJECT_VERSION = 0.1.0
 # Whitespace to be used when creating files from templates.
 SP = $(SP)
 
+
 endef
 else
 define bs_Makefile
@@ -67,6 +70,7 @@ PROJECT = $p
 PROJECT_DESCRIPTION = New project
 PROJECT_VERSION = 0.1.0
 
+
 endef
 endif
 
@@ -76,20 +80,28 @@ PROJECT_DESCRIPTION = New project
 PROJECT_VERSION = 0.1.0
 
 include $(call core_relpath,$(dir $(ERLANG_MK_FILENAME)),$(APPS_DIR)/app)/erlang.mk
+
+
 endef
 
 define bs_app
 -module($p_app).
+
 -behaviour(application).
 
--export([start/2]).
--export([stop/1]).
+
+-export([
+  start/2,
+  stop/1
+]).
+
 
 start(_Type, _Args) ->
-	$p_sup:start_link().
+  $p_sup:start_link().
 
 stop(_State) ->
-	ok.
+  ok.
+
 endef
 
 define bs_relx_config
@@ -97,261 +109,410 @@ define bs_relx_config
 {extended_start_script, true}.
 {sys_config, "rel/sys.config"}.
 {vm_args, "rel/vm.args"}.
+
+
 endef
 
 define bs_sys_config
 [
+  
 ].
+
+
 endef
 
 define bs_vm_args
 -name $p@127.0.0.1
 -setcookie $p
 -heart
++pc unicode
++K true
++A 5
+-env ERL_MAX_PORTS 4096
+-env ERL_FULLSWEEP_AFTER 10
 endef
 
 # Normal templates.
 
 define tpl_supervisor
 -module($(n)).
+
 -behaviour(supervisor).
 
--export([start_link/0]).
--export([init/1]).
+
+-export([
+  start_link/0,
+  init/1
+]).
+
 
 start_link() ->
-	supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+  supervisor:start_link({local, ?MODULE}, ?MODULE, []).
 
 init([]) ->
-	Procs = [],
-	{ok, {{one_for_one, 1, 5}, Procs}}.
+  Procs = [],
+  {ok, {{one_for_one, 1, 5}, Procs}}.
+
+
 endef
 
 define tpl_gen_server
 -module($(n)).
+
 -behaviour(gen_server).
 
+
 %% API.
--export([start_link/0]).
+-export([
+  start_link/0
+]).
+
 
 %% gen_server.
--export([init/1]).
--export([handle_call/3]).
--export([handle_cast/2]).
--export([handle_info/2]).
--export([terminate/2]).
--export([code_change/3]).
+-export([
+  init/1,
+  handle_call/3,
+  handle_cast/2,
+  handle_info/2,
+  terminate/2,
+  code_change/3
+]).
+
 
 -record(state, {
+  
 }).
 
+
 %% API.
 
 -spec start_link() -> {ok, pid()}.
 start_link() ->
-	gen_server:start_link(?MODULE, [], []).
+  gen_server:start_link(?MODULE, [], []).
+
 
 %% gen_server.
 
 init([]) ->
-	{ok, #state{}}.
+  {ok, #state{}}.
 
 handle_call(_Request, _From, State) ->
-	{reply, ignored, State}.
+  {reply, ignored, State}.
 
 handle_cast(_Msg, State) ->
-	{noreply, State}.
+  {noreply, State}.
 
 handle_info(_Info, State) ->
-	{noreply, State}.
+  {noreply, State}.
 
 terminate(_Reason, _State) ->
-	ok.
+  ok.
 
 code_change(_OldVsn, State, _Extra) ->
-	{ok, State}.
+  {ok, State}.
+
+
 endef
 
 define tpl_module
 -module($(n)).
--export([]).
+
+
+-export([
+  
+]).
+
+
 endef
 
 define tpl_cowboy_http
 -module($(n)).
+
 -behaviour(cowboy_http_handler).
 
--export([init/3]).
--export([handle/2]).
--export([terminate/3]).
+
+-export([
+  init/3,
+  handle/2,
+  terminate/3
+]).
+
 
 -record(state, {
+  
 }).
 
+
 init(_, Req, _Opts) ->
-	{ok, Req, #state{}}.
+  {ok, Req, #state{}}.
 
-handle(Req, State=#state{}) ->
-	{ok, Req2} = cowboy_req:reply(200, Req),
-	{ok, Req2, State}.
+handle(Req, State = #state{}) ->
+  {ok, Req2} = cowboy_req:reply(200, Req),
+  {ok, Req2, State}.
 
 terminate(_Reason, _Req, _State) ->
-	ok.
+  ok.
+
+
 endef
 
 define tpl_gen_fsm
 -module($(n)).
+
 -behaviour(gen_fsm).
 
+
 %% API.
--export([start_link/0]).
+-export([
+  start_link/0
+]).
+
 
 %% gen_fsm.
--export([init/1]).
--export([state_name/2]).
--export([handle_event/3]).
--export([state_name/3]).
--export([handle_sync_event/4]).
--export([handle_info/3]).
--export([terminate/3]).
--export([code_change/4]).
+-export([
+  init/1,
+  state_name/2,
+  handle_event/3,
+  state_name/3,
+  handle_sync_event/4,
+  handle_info/3,
+  terminate/3,
+  code_change/4
+]).
+
 
 -record(state, {
+  
 }).
 
+
 %% API.
 
 -spec start_link() -> {ok, pid()}.
 start_link() ->
-	gen_fsm:start_link(?MODULE, [], []).
+  gen_fsm:start_link(?MODULE, [], []).
+
 
 %% gen_fsm.
 
 init([]) ->
-	{ok, state_name, #state{}}.
+  {ok, state_name, #state{}}.
 
 state_name(_Event, StateData) ->
-	{next_state, state_name, StateData}.
+  {next_state, state_name, StateData}.
 
 handle_event(_Event, StateName, StateData) ->
-	{next_state, StateName, StateData}.
+  {next_state, StateName, StateData}.
 
 state_name(_Event, _From, StateData) ->
-	{reply, ignored, state_name, StateData}.
+  {reply, ignored, state_name, StateData}.
 
 handle_sync_event(_Event, _From, StateName, StateData) ->
-	{reply, ignored, StateName, StateData}.
+  {reply, ignored, StateName, StateData}.
 
 handle_info(_Info, StateName, StateData) ->
-	{next_state, StateName, StateData}.
+  {next_state, StateName, StateData}.
+
+terminate(_Reason, _StateName, _StateData) ->
+  ok.
+
+code_change(_OldVsn, StateName, StateData, _Extra) ->
+  {ok, StateName, StateData}.
+
+
+endef
+
+define tpl_gen_statem
+-module($(n)).
+
+-behaviour(gen_statem).
+
+
+%% API.
+-export([
+  start_link/0
+]).
+
+
+%% gen_statem.
+-export([
+  callback_mode/0,
+  init/1,
+  state_name/3,
+  handle_event/4,
+  terminate/3,
+  code_change/4
+]).
+
+
+-record(state, {
+  
+}).
+
+
+%% API.
+
+-spec start_link() -> {ok, pid()}.
+start_link() ->
+  gen_statem:start_link(?MODULE, [], []).
+
+
+%% gen_statem.
+
+callback_mode() ->
+  state_functions.
+
+init([]) ->
+  {ok, state_name, #state{}}.
+
+state_name(_EventType, _EventData, StateData) ->
+  {next_state, state_name, StateData}.
+
+handle_event(_EventType, _EventData, StateName, StateData) ->
+  {next_state, StateName, StateData}.
 
 terminate(_Reason, _StateName, _StateData) ->
-	ok.
+  ok.
 
 code_change(_OldVsn, StateName, StateData, _Extra) ->
-	{ok, StateName, StateData}.
+  {ok, StateName, StateData}.
+
+
 endef
 
 define tpl_cowboy_loop
 -module($(n)).
+
 -behaviour(cowboy_loop_handler).
 
--export([init/3]).
--export([info/3]).
--export([terminate/3]).
+
+-export([
+  init/3,
+  info/3,
+  terminate/3
+]).
+
 
 -record(state, {
+  
 }).
 
+
 init(_, Req, _Opts) ->
-	{loop, Req, #state{}, 5000, hibernate}.
+  {loop, Req, #state{}, 5000, hibernate}.
 
 info(_Info, Req, State) ->
-	{loop, Req, State, hibernate}.
+  {loop, Req, State, hibernate}.
 
 terminate(_Reason, _Req, _State) ->
-	ok.
+  ok.
+
+
 endef
 
 define tpl_cowboy_rest
 -module($(n)).
 
--export([init/3]).
--export([content_types_provided/2]).
--export([get_html/2]).
+-export([
+  init/3,
+  content_types_provided/2,
+  get_html/2
+]).
+
 
 init(_, _Req, _Opts) ->
-	{upgrade, protocol, cowboy_rest}.
+  {upgrade, protocol, cowboy_rest}.
 
 content_types_provided(Req, State) ->
-	{[{{<<"text">>, <<"html">>, '*'}, get_html}], Req, State}.
+  {[{{<<"text">>, <<"html">>, '*'}, get_html}], Req, State}.
 
 get_html(Req, State) ->
-	{<<"<html><body>This is REST!</body></html>">>, Req, State}.
+  {<<"<html><body>This is REST!</body></html>">>, Req, State}.
+
+
 endef
 
 define tpl_cowboy_ws
 -module($(n)).
+
 -behaviour(cowboy_websocket_handler).
 
--export([init/3]).
--export([websocket_init/3]).
--export([websocket_handle/3]).
--export([websocket_info/3]).
--export([websocket_terminate/3]).
+
+-export([
+  init/3,
+  websocket_init/3,
+  websocket_handle/3,
+  websocket_info/3,
+  websocket_terminate/3
+]).
+
 
 -record(state, {
+  
 }).
 
+
 init(_, _, _) ->
-	{upgrade, protocol, cowboy_websocket}.
+  {upgrade, protocol, cowboy_websocket}.
 
 websocket_init(_, Req, _Opts) ->
-	Req2 = cowboy_req:compact(Req),
-	{ok, Req2, #state{}}.
+  Req2 = cowboy_req:compact(Req),
+  {ok, Req2, #state{}}.
 
 websocket_handle({text, Data}, Req, State) ->
-	{reply, {text, Data}, Req, State};
+  {reply, {text, Data}, Req, State};
 websocket_handle({binary, Data}, Req, State) ->
-	{reply, {binary, Data}, Req, State};
+  {reply, {binary, Data}, Req, State};
 websocket_handle(_Frame, Req, State) ->
-	{ok, Req, State}.
+  {ok, Req, State}.
 
 websocket_info(_Info, Req, State) ->
-	{ok, Req, State}.
+  {ok, Req, State}.
 
 websocket_terminate(_Reason, _Req, _State) ->
-	ok.
+  ok.
+
+
 endef
 
 define tpl_ranch_protocol
 -module($(n)).
+
 -behaviour(ranch_protocol).
 
--export([start_link/4]).
--export([init/4]).
+
+-export([
+  start_link/4,
+  init/4
+]).
+
 
 -type opts() :: [].
 -export_type([opts/0]).
 
+
 -record(state, {
-	socket :: inet:socket(),
-	transport :: module()
+  socket :: inet:socket(),
+  transport :: module()
 }).
 
+
 start_link(Ref, Socket, Transport, Opts) ->
-	Pid = spawn_link(?MODULE, init, [Ref, Socket, Transport, Opts]),
-	{ok, Pid}.
+  Pid = spawn_link(?MODULE, init, [Ref, Socket, Transport, Opts]),
+  {ok, Pid}.
 
 -spec init(ranch:ref(), inet:socket(), module(), opts()) -> ok.
 init(Ref, Socket, Transport, _Opts) ->
-	ok = ranch:accept_ack(Ref),
-	loop(#state{socket=Socket, transport=Transport}).
+  ok = ranch:accept_ack(Ref),
+  loop(#state{socket=Socket, transport=Transport}).
 
 loop(State) ->
-	loop(State).
+  loop(State).
+
+
 endef
 
+
 # Plugin-specific targets.
 
 define render_template

+ 2 - 0
test/core_deps.mk

@@ -382,7 +382,9 @@ core-deps-apps-new-tpl: build clean
 
 	$i "Generate one of each template"
 	$t $(MAKE) -C $(APP) --no-print-directory new in=my_app t=gen_fsm n=my_fsm
+	$t $(MAKE) -C $(APP) --no-print-directory new in=cowboy_rest t=gen_fsm n=my_cowboy_rest
 	$t $(MAKE) -C $(APP) --no-print-directory new in=my_app t=gen_server n=my_server
+	$t $(MAKE) -C $(APP) --no-print-directory new in=my_app t=gen_statem n=my_statem
 	$t $(MAKE) -C $(APP) --no-print-directory new in=my_app t=supervisor n=my_sup
 
 # Here we disable warnings because templates contain missing behaviors.

+ 2 - 0
test/plugin_bootstrap.mk

@@ -185,6 +185,8 @@ bootstrap-templates: build clean
 
 	$i "Generate one of each template"
 	$t $(MAKE) -C $(APP) --no-print-directory new t=gen_fsm n=my_fsm
+	$t $(MAKE) -C $(APP) --no-print-directory new t=gen_statem n=my_statem
+	$t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_rest n=my_cowboy_rest
 	$t $(MAKE) -C $(APP) --no-print-directory new t=gen_server n=my_server
 	$t $(MAKE) -C $(APP) --no-print-directory new t=supervisor n=my_sup
 	$t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_http n=my_http