Skip to content

Commit

Permalink
allow extra app dependencies for yaws.app to be configured
Browse files Browse the repository at this point in the history
Yaws can depend on crypto for random numbers and hashes, and on the
compiler for .yaws pages. But the default yaws.app file specifies only
kernel and stdlib as application dependencies, since not all Yaws
deployments use crypto or compiler. Still, if a Yaws system uses crypto and
compiler without including them in the yaws.app file, building and
deploying an Erlang/OTP release for that system will fail.

Add --enable-crypto and --enable-compiler options to the configure script
to allow the user to add either or both of these applications to the
yaws.app file. Specifying the --enable-crypto option also causes the Yaws
startup code to start the crypto application; likewise for
--enable-compiler and the compiler application.

For rebar builds, enhance rebar.config.script to generate the same files
the configure script generates for any extra app dependencies. Setting the
YAWS_APPDEPS environment variable to a space- or comma-separated list of
addition applications to add to yaws.app, e.g.

YAWS_APPDEPS='crypto compiler'

causes rebar to add those apps to the generated yaws.app file and ensure
they're started before Yaws started.
  • Loading branch information
vinoski committed Apr 11, 2014
1 parent 52e7b4c commit cb49390
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -21,6 +21,8 @@ src/mime_types.erl
src/yaws_configure.hrl
src/yaws_generated.erl
src/yaws_charset.hrl
src/yaws_appdeps.hrl
src/yaws.app.src
test/ibrowse
test/ibrowse.tar.gz
test/support/include.mk
Expand Down
22 changes: 17 additions & 5 deletions configure.in
Expand Up @@ -54,6 +54,16 @@ fi
AC_SUBST(EPAM)


APPDEPS=
AC_ARG_ENABLE(crypto, AS_HELP_STRING([--enable-crypto], [adds crypto application to yaws.app file]))
if test "x$enable_crypto" = "xyes"; then
APPDEPS=',crypto'
fi
AC_ARG_ENABLE(compiler, AS_HELP_STRING([--enable-compiler], [adds compiler application to yaws.app file]))
if test "x$enable_compiler" = "xyes"; then
APPDEPS="${APPDEPS},compiler"
fi
AC_SUBST(APPDEPS)

dnl ----------------------------------------------------------------------
dnl
Expand Down Expand Up @@ -359,12 +369,14 @@ AC_SUBST(HAVE_CRYPTO_HASH)

YTOP=`pwd`
AC_SUBST(YTOP)
AC_OUTPUT(include.mk)
AC_OUTPUT(src/yaws_charset.hrl)
AC_OUTPUT(test/support/include.mk)
AC_OUTPUT(test/support/include.sh)

dnl pkg-config support
. ./vsn.mk
AC_SUBST(YAWS_VSN)
AC_OUTPUT(yaws.pc)

AC_CONFIG_FILES([include.mk])
AC_CONFIG_FILES([src/yaws_charset.hrl src/yaws_appdeps.hrl src/yaws.app.src])
AC_CONFIG_FILES([test/support/include.mk test/support/include.sh])
AC_CONFIG_FILES([yaws.pc])

AC_OUTPUT
21 changes: 20 additions & 1 deletion rebar.config.script
Expand Up @@ -16,6 +16,26 @@ ok = file:write_file("src/yaws_charset.hrl",
Charset, <<"\").\n">>]
end),

%% generate src/yaws.app.src file from src/yaws.app.src.in and
%% src/yaws_appdeps.hrl from src/yaws_appdeps.hrl.in
AppDeps = case os:getenv("YAWS_APPDEPS") of
false ->
"";
AppDeps0 ->
case string:tokens(AppDeps0, " ,") of
[] ->
"";
AppDepsList ->
","++string:join(AppDepsList, ",")
end
end,
{ok, AppBin0} = file:read_file("src/yaws.app.src.in"),
AppBin = binary:replace(AppBin0, <<"@APPDEPS@">>, list_to_binary(AppDeps)),
ok = file:write_file("src/yaws.app.src", AppBin),
{ok, AppHrl0} = file:read_file("src/yaws_appdeps.hrl.in"),
AppHrl = binary:replace(AppHrl0, <<"@APPDEPS@">>, list_to_binary(AppDeps)),
ok = file:write_file("src/yaws_appdeps.hrl", AppHrl),

SoapDeps = [{erlsom, ".*", {git, "git://github.com/willemdj/erlsom.git", {branch, "master"}}},
{xmlrpc, ".*", {git, "git://github.com/rwbr/exmlrpc.git", {branch, "master"}}}],

Expand Down Expand Up @@ -80,4 +100,3 @@ Cfg1 = lists:keyreplace(erl_opts, 1, Cfg0, {erl_opts, ErlOpts2}),
Cfg2 = lists:keyreplace(port_env, 1, Cfg1, {port_env, PortEnv1}),
Cfg3 = lists:keyreplace(port_specs, 1, Cfg2, {port_specs, PortSpecs1}),
Cfg3.

2 changes: 1 addition & 1 deletion src/Makefile
Expand Up @@ -76,6 +76,7 @@ dav:
$(EBIN_FILES) : ../include/yaws.hrl ../include/yaws_api.hrl

../ebin/yaws_sendfile.$(EMULATOR): yaws_configure.hrl
../ebin/yaws.$(EMULATOR): yaws_appdeps.hrl

yaws_generated.erl: yaws_generated.template ../vsn.mk
$(MAKE) IS_LOCAL_INSTALL=true gen_yaws_generated
Expand All @@ -91,7 +92,6 @@ mime_types.erl: yaws_charset.hrl ../priv/mime.types \
../ebin/yaws_generated.$(EMULATOR) ../ebin/mime_type_c.$(EMULATOR)
$(ERL) -noshell -pa ../ebin -s mime_type_c generate


debug:
$(MAKE) TYPE=debug

Expand Down
2 changes: 1 addition & 1 deletion src/yaws.app.src → src/yaws.app.src.in
Expand Up @@ -17,4 +17,4 @@
% {pam_use_acct, true}, % true | false
% {pam_use_sess, true} % true | false
]},
{applications,[kernel,stdlib]}]}.
{applications,[kernel,stdlib@APPDEPS@]}]}.
16 changes: 14 additions & 2 deletions src/yaws.erl
Expand Up @@ -10,6 +10,7 @@

-include("../include/yaws.hrl").
-include("../include/yaws_api.hrl").
-include("yaws_appdeps.hrl").
-include("yaws_debug.hrl").

-include_lib("kernel/include/file.hrl").
Expand Down Expand Up @@ -166,6 +167,7 @@
stringdate_to_datetime/1]).

start() ->
ok = start_app_deps(),
application:start(yaws, permanent).

stop() ->
Expand All @@ -185,8 +187,9 @@ start_embedded(DocRoot, SL, GL) when is_list(DocRoot),is_list(SL),is_list(GL) ->
start_embedded(DocRoot, SL, GL, "default").
start_embedded(DocRoot, SL, GL, Id)
when is_list(DocRoot), is_list(SL), is_list(GL) ->
ok = start_app_deps(),
{ok, SCList, GC, _} = yaws_api:embedded_start_conf(DocRoot, SL, GL, Id),
ok = application:start(yaws),
ok = application:start(yaws, permanent),
yaws_config:add_yaws_soap_srv(GC),
yaws_api:setconf(GC, SCList),
ok.
Expand All @@ -209,7 +212,16 @@ create_sconf(DocRoot, SL) when is_list(DocRoot), is_list(SL) ->
SC = yaws_config:make_default_sconf(DocRoot, lkup(port, SL, undefined)),
setup_sconf(SL, SC).


start_app_deps() ->
Deps = split_sep(?YAWS_APPDEPS, $,),
catch lists:foldl(fun(App0, Acc) ->
App = list_to_existing_atom(App0),
case application:start(App, permanent) of
ok -> Acc;
{error,{already_started,App}} -> Acc;
Else -> throw(Else)
end
end, ok, Deps).

%% Access functions for the GCONF and SCONF records.
gconf_yaws_dir (#gconf{yaws_dir = X}) -> X.
Expand Down
1 change: 1 addition & 0 deletions src/yaws_appdeps.hrl.in
@@ -0,0 +1 @@
-define(YAWS_APPDEPS, "@APPDEPS@").

0 comments on commit cb49390

Please sign in to comment.