Skip to content

Instantly share code, notes, and snippets.

@aerosol
Created October 17, 2011 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aerosol/1293679 to your computer and use it in GitHub Desktop.
Save aerosol/1293679 to your computer and use it in GitHub Desktop.
Dynamic compilation
validate_rules() ->
?SYS_INFO("Validating common rules configuration..."),
case compile:file(?PRIV("common_rules.erl"), [strong_validation, report, return, {i, ?PRIV("../include")}]) of
{ok, _, _} ->
?SYS_DEBUG("File common_rules.erl validated successfully"),
ok;
{ok, _, _, Warnings} ->
ok;
{ok, _, _, Warnings} ->
case Warnings of
[] ->
?SYS_DEBUG("File common_rules.erl validated successfully");
_Any ->
?SYS_WARN("File common_rules.erl warnings:~n~p", [Warnings])
end,
?SYS_DEBUG("File common_rules.erl validated successfully"),
ok;
{ok, _, _, Warnings} ->
case Warnings of
[] ->
?SYS_DEBUG("File common_rules.erl validated successfully");
_Any ->
?SYS_WARN("File common_rules.erl warnings:~n~p", [Warnings])
end,
ok;
{error, Errors, Warnings} ->
?SYS_ERROR("Configuration file common_rules.erl validation failed:~nErrors: ~p~nWarnings: ~p", [Errors, Warnings]),
{error, "Validation of configuration file failed. See log for details"}
end.
reload_rules() ->
reload_rules(true).
reload_rules(Dump) ->
?SYS_INFO("Loading common rules configuration..."),
case compile:file(?PRIV("common_rules.erl"), [binary, report, return, {i, ?PRIV("../include")}]) of
{ok, ModuleName, Binary} ->
?SYS_DEBUG("File common_rules.erl validated successfully"),
self_reload(ModuleName, Binary, Dump);
{ok, ModuleName, Binary, Warnings} ->
case Warnings of
[] ->
?SYS_DEBUG("File common_rules.erl validated successfully");
_Any ->
?SYS_WARN("File common_rules.erl warnings:~n~p", [Warnings])
end,
self_reload(ModuleName, Binary, Dump);
{error, Errors, Warnings} ->
?SYS_ERROR("Configuration file common_rules.erl validation failed:~nErrors: ~p~nWarnings: ~p",
[Errors, Warnings]),
{error, "Validation of configuration file failed. See log for details"}
end.
self_reload(ModuleName, Binary, Dump) ->
code:purge(ModuleName),
{module, _} = code:load_binary(ModuleName, "common_rules.beam", Binary),
case Dump of
true ->
profile_store:dump_common_rules();
_Else ->
ok
end,
profile_store:store_common_rules(),
?SYS_INFO("Common rules configuration successfully loaded"),
ok.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment