Maxim Sokhatsky 11 лет назад
Родитель
Сommit
28b9ffc59a
6 измененных файлов с 47 добавлено и 60 удалено
  1. 0 7
      Makefile
  2. 0 29
      depman.erl
  3. BIN
      mad
  4. 20 0
      orderapps.erl
  5. 26 23
      otp.mk
  6. 1 1
      rebar.config

+ 0 - 7
Makefile

@@ -1,13 +1,6 @@
 RELEASE := kakaranet
 COOKIE  := node_runner
-APPS    := kernel avz stdlib sasl gproc cowboy cowlib ranch erlydtl n2o db sync server web
 VER     := 1.0.0
-VM      := rels/web/files/vm.args
-SYS     := rels/web/files/sys.config
-PLT_NAME := ~/.n2o_dialyzer.plt
-ERL_ARGS := -args_file $(VM) -config $(SYS)
-RUN_DIR ?= rels/web/devbox
-LOG_DIR ?= rels/web/devbox/logs
 APP     := apps/web/priv/static/nitrogen
 
 default: get-deps compile static-link

+ 0 - 29
depman.erl

@@ -1,29 +0,0 @@
-#!/usr/bin/env escript
-
--module(depman).
--compile([export_all]).
--define(ABORT(Str, Args), io:format(Str, Args), throw(abort)).
-
-app_exists(App,Srv) when is_tuple(App) -> app_exists(element(1,App), Srv);
-app_exists(App,Srv) when is_atom(App) -> case reltool_server:get_app(Srv,App) of {ok, _} -> true; _ -> false end.
-
-validate_rel_apps(ReltoolServer, {sys, ReltoolConfig}) ->
-    case lists:keyfind(rel, 1, ReltoolConfig) of
-        false -> ok;
-        {rel, _Name, _Vsn, Apps} ->
-            Missing = lists:sort([App || App <- Apps, app_exists(App, ReltoolServer) == false]),
-            case Missing of [] -> ok; _ -> ?ABORT("Missing Apps: ~p\n", [Missing]) end;
-        Rel -> ?ABORT("Invalid {rel, ...} section in reltool.config: ~p\n", [Rel]) end.
-
-relconfig(Apps) ->
-    LibDirs = [Dir || Dir <- ["apps", "deps"], case file:read_file_info(Dir) of {ok, _} -> true; _ -> false end],
-    {sys, [ {lib_dirs,LibDirs}, {rel,"node","1",Apps}, {boot_rel,"node"}, {app,observer,[{incl_cond,exclude}]} ]}.
-
-main([]) -> ?ABORT("usage: ./depman.erl apps", []);
-main(MainApps) ->
-    Relconfig = relconfig([list_to_atom(A) || A <- MainApps]),
-    {ok, Server} = reltool:start_server([{config, Relconfig}]),
-    validate_rel_apps(Server, Relconfig),
-    {ok, {release, _Node, _Erts, Apps}} = reltool_server:get_rel(Server, "node"),
-    Alist = [element(1, A) || A <- Apps],
-    io:format("~w~n", [Alist]).


+ 20 - 0
orderapps.erl

@@ -0,0 +1,20 @@
+#!/usr/bin/env escript
+
+% This script boots up the Reltool Server for apps ordering
+% It also could generate reltool.config
+
+-module(orderapps).
+-compile([export_all]).
+
+relconfig(Apps) ->
+    LibDirs = [Dir || Dir <- ["apps", "deps"], case file:read_file_info(Dir) of {ok, _} -> true; _ -> false end],
+    {sys, [{lib_dirs,LibDirs}, {rel,"node","1",Apps}, {profile, embedded},
+           {boot_rel,"node"}, {app,observer,[{incl_cond,exclude}]} ]}.
+
+main([]) -> io:format("usage: ./orderapps.erl apps~n", []);
+main(MainApps) ->
+    Relconfig = relconfig([list_to_atom(A) || A <- MainApps]),
+    {ok, Server} = reltool:start_server([{config, Relconfig}]),
+    {ok, {release, _Node, _Erts, Apps}} = reltool_server:get_rel(Server, "node"),
+    Ordered = [element(1, A) || A <- Apps],
+    io:format("~w~n", [Ordered]).

+ 26 - 23
otp.mk

@@ -1,48 +1,51 @@
-empty :=
-ROOTS := apps deps
-space := $(empty) $(empty)
-comma := $(empty),$(empty)
-VSN   := $(shell git rev-parse HEAD | cut -c 1-6)
-DATE  := $(shell git show -s --format="%ci" HEAD | sed -e 's/\+/Z/g' -e 's/-/./g' -e 's/ /-/g' -e 's/:/./g')
+VM       := rels/web/files/vm.args
+SYS      := rels/web/files/sys.config
+PLT_NAME := ~/.n2o_dialyzer.plt
+ERL_ARGS := -args_file $(VM) -config $(SYS)
+RUN_DIR  ?= rels/web/devbox
+LOG_DIR  ?= rels/web/devbox/logs
+empty    :=
+ROOTS    := apps deps
+space    := $(empty) $(empty)
+comma    := $(empty),$(empty)
+VSN      := $(shell git rev-parse HEAD | head -c 6)
+DATE     := $(shell date "+%Y%m%d-%H%M%S")
 ERL_LIBS := $(subst $(space),:,$(ROOTS))
-relx  := "{release,{$(RELEASE),\"$(VER)\"},[$(subst $(space),$(comma),$(APPS))]}.\\n{include_erts,true}.\
+relx     := "{release,{$(RELEASE),\"$(VER)\"},[$(RELEASE)]}.\\n{include_erts,true}.\
 \\n{extended_start_script,true}.\\n{generate_start_script,true}.\\n{sys_config,\"$(SYS)\"}.\
 \\n{vm_args,\"$(VM)\"}.\\n{overlay,[{mkdir,\"log/sasl\"}]}."
 
-ifeq "$(NODEPS)" "1"
-rebar_skip_deps=skip_deps=true
-endif
-
-test: ct
+test: eunit ct
 compile: get-deps static-link
 delete-deps get-deps compile clean update-deps:
-	rebar $(rebar_skip_deps) $(REBAR_D) $@
+	./mad $@
 .applist:
-	./depman.erl $(APPS) > $@
+	$(eval APPS := $(subst deps/,,$(subst apps/,,$(shell find apps deps -maxdepth 1 -mindepth 1 -type d))))
+	./orderapps.erl $(APPS) > $@
 $(RUN_DIR) $(LOG_DIR):
 	mkdir -p $(RUN_DIR) & mkdir -p $(LOG_DIR)
 console: .applist
-	echo $(APPS)
-	ERL_LIBS=$(ERL_LIBS) erl $(ERL_ARGS) -eval \
-		'[ok = application:ensure_started(A, permanent) || A <- $(shell cat .applist)]'
+	ERL_LIBS=$(ERL_LIBS) erl $(ERL_ARGS) -eval '[application:start(A) || A <- $(shell cat .applist)]'
 start: $(RUN_DIR) $(LOG_DIR) .applist
 	RUN_ERL_LOG_GENERATIONS=1000 RUN_ERL_LOG_MAXSIZE=20000000 \
 	ERL_LIBS=$(ERL_LIBS) run_erl -daemon $(RUN_DIR)/ $(LOG_DIR)/ "exec $(MAKE) console"
 attach:
 	to_erl $(RUN_DIR)/
 release:
-	echo $(shell echo $(relx) > relx.config) & relx
+	echo $(relx) > relx.config && relx
 stop:
-	kill -9 `ps ax -o pid= -o command=|grep $(RELEASE)|grep $(COOKIE)|awk '{print $$1}'`
+	@kill -9 $(shell ps ax -o pid= -o command=|grep $(RELEASE)|grep $(COOKIE)|awk '{print $$1}')
 $(PLT_NAME):
-	ERL_LIBS=deps dialyzer --build_plt --output_plt $(PLT_NAME) --apps $(APPS) || true
+	$(eval APPS := $(subst deps/,,$(subst apps/,,$(shell find apps deps -maxdepth 1 -mindepth 1 -type d))))
+	ERL_LIBS=$(ERL_LIBS) dialyzer --build_plt --output_plt $(PLT_NAME) --apps $(APPS) || true
 dialyze: $(PLT_NAME) compile
-	dialyzer deps/*/ebin --plt $(PLT_NAME) --no_native -Werror_handling -Wunderspecs -Wrace_conditions
-tar:
+	$(eval APPS := $(shell find apps deps -maxdepth 1 -mindepth 1 -type d))
+	@$(foreach var,$(APPS),(echo "Process $(var)"; dialyzer -q $(var)/ebin --plt $(PLT_NAME) --no_native -Werror_handling -Wunderspecs -Wrace_conditions -Wno_undefined_callbacks);)
+tar: release
 	tar zcvf $(RELEASE)-$(VSN)-$(DATE).tar.gz _rel/lib/*/ebin _rel/lib/*/priv _rel/bin _rel/releases
 eunit:
 	rebar eunit skip_deps=true
 ct:
 	rebar ct skip_deps=true verbose=1
 
-.PHONY: delete-deps get-deps clean compile console start attach release update-deps dialyze ct eunit tar
+.PHONY: delete-deps get-deps compile clean console start attach release update-deps dialyze ct eunit tar

+ 1 - 1
rebar.config

@@ -1,4 +1,4 @@
-{sub_dirs,["deps","apps"]}.
+{sub_dirs,["apps"]}.
 {lib_dirs,["apps"]}.
 {deps_dir,"deps"}.
 {deps, [