From 9feffa030c4d1791f76e5b57658945c013df636d Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Thu, 27 Mar 2014 16:53:30 +0100 Subject: Remove syntax_tools and runtime_tools from app file The former is used by the dictionary compiler, the latter by some unfinished code in diameter_dbg. None of the corresponding modules are included in the app file since they typically aren't needed/wanted on a target system. --- lib/diameter/src/diameter.app.src | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/diameter') diff --git a/lib/diameter/src/diameter.app.src b/lib/diameter/src/diameter.app.src index d2290aeccc..4ede488b31 100644 --- a/lib/diameter/src/diameter.app.src +++ b/lib/diameter/src/diameter.app.src @@ -34,6 +34,9 @@ ]}, {env, []}, {mod, {diameter_app, []}}, - {runtime_dependencies, ["syntax_tools-1.6.14","stdlib-2.0","ssl-5.3.4", - "runtime_tools-1.8.14","kernel-3.0","erts-6.0"]} + {runtime_dependencies, ["erts-6.0", + "kernel-3.0", + "stdlib-2.0", + "ssl-5.3.4"]} + %% Note that ssl is only required if configured on TCP transports. ]}. -- cgit v1.2.3 From 1106d1e478f979cd201a66d3180a4511bfa56a93 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Sat, 29 Mar 2014 13:21:11 +0100 Subject: Generate runtime_dependencies in app file To avoid having to specify applications more than once. --- lib/diameter/src/Makefile | 5 +++-- lib/diameter/src/app.sed | 40 +++++++++++++++++++++++++++++++++++++++ lib/diameter/src/diameter.app.src | 22 ++++++++++++--------- 3 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 lib/diameter/src/app.sed (limited to 'lib/diameter') diff --git a/lib/diameter/src/Makefile b/lib/diameter/src/Makefile index 127406ae23..9afccf298c 100644 --- a/lib/diameter/src/Makefile +++ b/lib/diameter/src/Makefile @@ -148,7 +148,7 @@ gen/$(DICT_YRL).erl: compiler/$(DICT_YRL).yrl $(ERLC) -Werror -o $(@D) $< # Generate the app file. -$(APP_TARGET): $(APP_SRC) ../vsn.mk modules.mk +$(APP_TARGET): $(APP_SRC) ../vsn.mk modules.mk app.sed $(gen_verbose) \ M=`echo $(notdir $(APP_MODULES)) | tr ' ' ,`; \ C=`echo $(COMPILER_MODULES) | tr ' ' ,`; \ @@ -159,7 +159,8 @@ $(APP_TARGET): $(APP_SRC) ../vsn.mk modules.mk -e "s;%COMPILER%;$$C;" \ -e "s;%INFO%;$$I;" \ -e "s;%REGISTERED%;$$R;" \ - $< > $@ + $< \ + | sed -f app.sed > $@ $(APPUP_TARGET): $(APPUP_SRC) ../vsn.mk $(vsn_verbose) \ diff --git a/lib/diameter/src/app.sed b/lib/diameter/src/app.sed new file mode 100644 index 0000000000..7916f65002 --- /dev/null +++ b/lib/diameter/src/app.sed @@ -0,0 +1,40 @@ +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 2014. All Rights Reserved. +# +# The contents of this file are subject to the Erlang Public License, +# Version 1.1, (the "License"); you may not use this file except in +# compliance with the License. You should have received a copy of the +# Erlang Public License along with this software. If not, it can be +# retrieved online at http://www.erlang.org/. +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +# the License for the specific language governing rights and limitations +# under the License. +# +# %CopyrightEnd% + +# +# Generate runtime_dependencies from applications to avoid having to +# specify the same application more than once. +# + +/{runtime_dependencies,/b v +/{[-a-z]*, "[0-9.]*"}/!b +/{vsn,/b + +/%%/!H +s/{\([^,]*\)[^}]*}/\1/g +s/%%/%,/ +b + +:v + +p +x +s/\n// +s/%//g +s/\n */ /g +s/{\([^,]*\), "\([^"]*"\)}/"\1-\2/g diff --git a/lib/diameter/src/diameter.app.src b/lib/diameter/src/diameter.app.src index 4ede488b31..ac1d847753 100644 --- a/lib/diameter/src/diameter.app.src +++ b/lib/diameter/src/diameter.app.src @@ -27,16 +27,20 @@ ]}, {registered, [%REGISTERED%]}, {applications, [ - stdlib, kernel - %, syntax_tools - %, runtime_tools - %, ssl + {stdlib, "2.0"}, {kernel, "3.0"}%, {erts, "6.0"} + %% {syntax-tools, "1.6.14"} + %% {runtime-tools, "1.8.14"} + %, {ssl, "5.3.4"} ]}, {env, []}, {mod, {diameter_app, []}}, - {runtime_dependencies, ["erts-6.0", - "kernel-3.0", - "stdlib-2.0", - "ssl-5.3.4"]} - %% Note that ssl is only required if configured on TCP transports. + {runtime_dependencies, [ + ]} + %% + %% Note that ssl is only required if configured on TCP transports, + %% and syntax-tools and runtime-tools are only required if the + %% dictionary compiler and debug modules (respectively) are + %% needed/wanted at runtime, which they typically aren't. These + %% modules are the two commented lines in the 'modules' tuple. + %% ]}. -- cgit v1.2.3 From d360e898d93502d1d27d4552688476a629fdd52e Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Sun, 30 Mar 2014 19:49:52 +0200 Subject: Add app suite test for app file runtime_dependencies In particular, that modules listed in the 'modules' tuple only call modules in other applications listed in the 'runtime_dependencies' tuple. --- lib/diameter/test/diameter_app_SUITE.erl | 54 ++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 10 deletions(-) (limited to 'lib/diameter') diff --git a/lib/diameter/test/diameter_app_SUITE.erl b/lib/diameter/test/diameter_app_SUITE.erl index 1e262895a6..891147b7d1 100644 --- a/lib/diameter/test/diameter_app_SUITE.erl +++ b/lib/diameter/test/diameter_app_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2010-2013. All Rights Reserved. +%% Copyright Ericsson AB 2010-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -158,12 +158,15 @@ appvsn(Name) -> %% # xref/1 %% %% Ensure that no function in our application calls an undefined function -%% or one in an application we haven't specified as a dependency. (Almost.) +%% or one in an application we haven't declared as a dependency. (Almost.) %% =========================================================================== xref(Config) -> App = fetch(app, Config), - Mods = fetch(modules, App), + Mods = fetch(modules, App), %% modules listed in the app file + + %% List of application names extracted from runtime_dependencies. + Deps = lists:map(fun unversion/1, fetch(runtime_dependencies, App)), {ok, XRef} = xref:start(make_name(xref_test_name)), ok = xref:set_default(XRef, [{verbose, false}, {warnings, false}]), @@ -178,7 +181,8 @@ xref(Config) -> [?APP, erts | fetch(applications, App)]), {ok, Undefs} = xref:analyze(XRef, undefined_function_calls), - {ok, Called} = xref:analyze(XRef, {module_call, ?COMPILER_MODULES}), + {ok, CTdeps} = xref:analyze(XRef, {module_call, ?COMPILER_MODULES}), + {ok, RTdeps} = xref:analyze(XRef, {module_call, Mods}), xref:stop(XRef), @@ -193,15 +197,45 @@ xref(Config) -> %% TLS security: it's up to a client who wants TLS it to start %% ssl. - [] = lists:filter(fun is_bad_dependency/1, Called). + %% Ensure that compiler modules don't call runtime modules. + [] = lists:filter(fun nok_compiler_dependency/1, CTdeps), + + %% Ensure that runtime modules only call other runtime modules, or + %% applications declared as in runtime_dependencies in the app + %% file. Note that the declared application versions are ignored + %% since we only know what we can see now. + [] = lists:filter(fun(M) -> not ok_runtime_dependency(M, Mods, Deps) end, + RTdeps). + +unversion(App) -> + T = lists:dropwhile(fun is_vsn_ch/1, lists:reverse(App)), + lists:reverse(case T of [$-|TT] -> TT; _ -> T end). + +is_vsn_ch(C) -> + $0 =< C andalso C =< $9 orelse $. == C. %% It's not strictly necessary that diameter compiler modules not %% depend on other diameter modules but it's a simple source of build -%% errors if not encoded in the makefile (hence the test) so guard -%% against it. -is_bad_dependency(Mod) -> - lists:prefix("diameter", atom_to_list(Mod)) - andalso not lists:member(Mod, ?COMPILER_MODULES). +%% errors if not properly encoded in the makefile so guard against it. +nok_compiler_dependency(Mod) -> + is_diameter(Mod) andalso not lists:member(Mod, ?COMPILER_MODULES). + +ok_runtime_dependency(Mod, Mods, Apps) -> + lists:member(app(Mod), Apps) + orelse (is_diameter(Mod) andalso lists:member(Mod, Mods)). + +is_diameter(Mod) -> + lists:prefix("diameter", atom_to_list(Mod)). + +app('$M_EXPR') -> %% could be anything but assume it's ok + "erts"; +app(Mod) -> + case code:which(Mod) of + preloaded -> + "erts"; + Path -> + unversion(lists:nth(3, lists:reverse(filename:split(Path)))) + end. add_application(XRef, App) -> add_application(XRef, App, code:lib_dir(App)). -- cgit v1.2.3 From 81eefc9958e9bb3e64eebccc87b38acd56cb62df Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Mon, 31 Mar 2014 10:18:24 +0200 Subject: Simplify xref tests in app suite By examining which modules *use* runtime and compiler modules instead of which modules compiler modules call. Note that the semantics are changed somewhat: we will now fail if diameter modules are called from an application which diameter.app lists as a start dependency, which wasn't the case previously. --- lib/diameter/test/diameter_app_SUITE.erl | 40 ++++++++++++++------------------ 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'lib/diameter') diff --git a/lib/diameter/test/diameter_app_SUITE.erl b/lib/diameter/test/diameter_app_SUITE.erl index 891147b7d1..f68a18b5c2 100644 --- a/lib/diameter/test/diameter_app_SUITE.erl +++ b/lib/diameter/test/diameter_app_SUITE.erl @@ -50,7 +50,7 @@ diameter_exprecs, diameter_make]). --define(HELP_MODULES, [diameter_dbg, +-define(INFO_MODULES, [diameter_dbg, diameter_info]). %% =========================================================================== @@ -99,13 +99,13 @@ vsn(Config) -> %% # modules/1 %% %% Ensure that the app file modules and installed modules differ by -%% compiler/help modules. +%% compiler/info modules. %% =========================================================================== modules(Config) -> Mods = fetch(modules, fetch(app, Config)), Installed = code_mods(), - Help = lists:sort(?HELP_MODULES ++ ?COMPILER_MODULES), + Help = lists:sort(?INFO_MODULES ++ ?COMPILER_MODULES), {[], Help} = {Mods -- Installed, lists:sort(Installed -- Mods)}. @@ -181,7 +181,8 @@ xref(Config) -> [?APP, erts | fetch(applications, App)]), {ok, Undefs} = xref:analyze(XRef, undefined_function_calls), - {ok, CTdeps} = xref:analyze(XRef, {module_call, ?COMPILER_MODULES}), + {ok, RTmods} = xref:analyze(XRef, {module_use, Mods}), + {ok, CTmods} = xref:analyze(XRef, {module_use, ?COMPILER_MODULES}), {ok, RTdeps} = xref:analyze(XRef, {module_call, Mods}), xref:stop(XRef), @@ -194,18 +195,24 @@ xref(Config) -> Undefs), %% diameter_tcp does call ssl despite the latter not being listed %% as a dependency in the app file since ssl is only required for - %% TLS security: it's up to a client who wants TLS it to start - %% ssl. + %% TLS security: it's up to a client who wants TLS to start ssl. - %% Ensure that compiler modules don't call runtime modules. - [] = lists:filter(fun nok_compiler_dependency/1, CTdeps), + %% Ensure that only runtime or info modules call runtime modules. + %% It's not strictly necessary that diameter compiler modules not + %% depend on other diameter modules but it's a simple source of + %% build errors if not properly encoded in the makefile so guard + %% against it. + [] = (RTmods -- Mods) -- ?INFO_MODULES, + + %% Ensure that runtime modules don't call compiler modules. + CTmods = CTmods -- Mods, %% Ensure that runtime modules only call other runtime modules, or %% applications declared as in runtime_dependencies in the app %% file. Note that the declared application versions are ignored %% since we only know what we can see now. - [] = lists:filter(fun(M) -> not ok_runtime_dependency(M, Mods, Deps) end, - RTdeps). + [] = lists:filter(fun(M) -> not lists:member(app(M), Deps) end, + RTdeps -- Mods). unversion(App) -> T = lists:dropwhile(fun is_vsn_ch/1, lists:reverse(App)), @@ -214,19 +221,6 @@ unversion(App) -> is_vsn_ch(C) -> $0 =< C andalso C =< $9 orelse $. == C. -%% It's not strictly necessary that diameter compiler modules not -%% depend on other diameter modules but it's a simple source of build -%% errors if not properly encoded in the makefile so guard against it. -nok_compiler_dependency(Mod) -> - is_diameter(Mod) andalso not lists:member(Mod, ?COMPILER_MODULES). - -ok_runtime_dependency(Mod, Mods, Apps) -> - lists:member(app(Mod), Apps) - orelse (is_diameter(Mod) andalso lists:member(Mod, Mods)). - -is_diameter(Mod) -> - lists:prefix("diameter", atom_to_list(Mod)). - app('$M_EXPR') -> %% could be anything but assume it's ok "erts"; app(Mod) -> -- cgit v1.2.3