aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Merritt <[email protected]>2013-09-20 15:29:30 -0700
committerEric Merritt <[email protected]>2013-09-20 15:29:30 -0700
commit8da020ccdccc9da37d8accaabe9fab0ab1e825dd (patch)
treef01a4e30515c87cd7e6a8e38c010b83806cda105 /src
parenta23fc9028f1914f7dc680a443e35cf47d347365d (diff)
parent6df9d493655775677400ca0348de747d90305256 (diff)
downloadrelx-8da020ccdccc9da37d8accaabe9fab0ab1e825dd.tar.gz
relx-8da020ccdccc9da37d8accaabe9fab0ab1e825dd.tar.bz2
relx-8da020ccdccc9da37d8accaabe9fab0ab1e825dd.zip
Merge pull request #44 from tsloughter/master
allow template for sys.config and vm.args add lib_dirs config option
Diffstat (limited to 'src')
-rw-r--r--src/relx.erl18
-rw-r--r--src/rlx_cmd_args.erl30
-rw-r--r--src/rlx_prv_assembler.erl41
-rw-r--r--src/rlx_prv_config.erl5
-rw-r--r--src/rlx_state.erl6
5 files changed, 68 insertions, 32 deletions
diff --git a/src/relx.erl b/src/relx.erl
index bc3fbaa..2aac8e4 100644
--- a/src/relx.erl
+++ b/src/relx.erl
@@ -47,11 +47,18 @@ main(Args) ->
OptSpecList = opt_spec_list(),
Result = case getopt:parse(OptSpecList, Args) of
{ok, {Options, NonOptions}} ->
- case lists:member(help, Options) of
+ case lists:member(version, Options) of
true ->
- usage();
+ application:load(relx),
+ {ok, Vsn} = application:get_key(relx, vsn),
+ io:format("~s~n", [Vsn]);
false ->
- do([{caller, command_line} | Options], NonOptions)
+ case lists:member(help, Options) of
+ true ->
+ usage();
+ false ->
+ do([{caller, command_line} | Options], NonOptions)
+ end
end;
{error, Detail} ->
?RLX_ERROR({opt_parse, Detail})
@@ -182,7 +189,9 @@ opt_spec_list() ->
{help, $h, "help", undefined,
"Print usage"},
{lib_dir, $l, "lib-dir", string,
- "Additional dirs that should be searched for OTP Apps"},
+ "Additional dir that should be searched for OTP Apps"},
+ {path, $p, "path", string,
+ "Additional dir to add to the code path"},
{disable_default_libs, undefined, "disable-default-libs",
{boolean, false},
"Disable the default system added lib dirs (means you must add them all manually"},
@@ -191,6 +200,7 @@ opt_spec_list() ->
{override_app, $a, "override_app", string,
"Provide an app name and a directory to override in the form <appname>:<app directory>"},
{config, $c, "config", {string, ""}, "The path to a config file"},
+ {version, $v, "version", undefined, "Print relx version"},
{root_dir, $r, "root", string, "The project root directory"}].
-spec format_error(Reason::term()) -> string().
diff --git a/src/rlx_cmd_args.erl b/src/rlx_cmd_args.erl
index d144953..619163a 100644
--- a/src/rlx_cmd_args.erl
+++ b/src/rlx_cmd_args.erl
@@ -64,7 +64,9 @@ format_error({invalid_option_arg, Arg}) ->
{lib_dir, LibDir} ->
io_lib:format("Invalid Library Directory argument -n ~p~n", [LibDir]);
{log_level, LogLevel} ->
- io_lib:format("Invalid Library Directory argument -n ~p~n", [LogLevel])
+ io_lib:format("Invalid Log Level argument -n ~p~n", [LogLevel]);
+ {path, Path} ->
+ io_lib:format("Invalid code path argument -n ~p~n", [Path])
end;
format_error({invalid_config_file, Config}) ->
io_lib:format("Invalid configuration file specified: ~s", [Config]);
@@ -261,20 +263,34 @@ create_upfrom(Opts, Acc) ->
create_caller(Opts, Acc) ->
case proplists:get_value(caller, Opts, api) of
"command_line" ->
- {ok, [{caller, command_line} | Acc]};
+ create_paths(Opts, [{caller, command_line} | Acc]);
"commandline" ->
- {ok, [{caller, command_line} | Acc]};
+ create_paths(Opts, [{caller, command_line} | Acc]);
"api" ->
- {ok, [{caller, api} | Acc]};
+ create_paths(Opts, [{caller, api} | Acc]);
api ->
- {ok, [{caller, api} | Acc]};
+ create_paths(Opts, [{caller, api} | Acc]);
commandline ->
- {ok, [{caller, command_line} | Acc]};
+ create_paths(Opts, [{caller, command_line} | Acc]);
command_line ->
- {ok, [{caller, command_line} | Acc]};
+ create_paths(Opts, [{caller, command_line} | Acc]);
Caller ->
?RLX_ERROR({invalid_caller, Caller})
end.
+
+-spec create_paths([getopt:option()], rlx_state:cmd_args()) ->
+ {ok, rlx_state:cmd_args()} | relx:error().
+create_paths(Opts, Acc) ->
+ Dirs = proplists:get_all_values(path, Opts) ++
+ proplists:get_value(paths, Opts, []),
+ case check_lib_dirs(Dirs) of
+ Error = {error, _} ->
+ Error;
+ ok ->
+ code:add_pathsa([filename:absname(Path) || Path <- Dirs]),
+ {ok, Acc}
+ end.
+
-spec check_lib_dirs([string()]) -> ok | relx:error().
check_lib_dirs([]) ->
ok;
diff --git a/src/rlx_prv_assembler.erl b/src/rlx_prv_assembler.erl
index d47a850..08d7325 100644
--- a/src/rlx_prv_assembler.erl
+++ b/src/rlx_prv_assembler.erl
@@ -296,10 +296,9 @@ write_bin_file(State, Release, OutputDir, RelDir) ->
copy_or_generate_vmargs_file(State, RelName, RelDir) ->
RelVmargsPath = filename:join([RelDir, "vm.args"]),
-
case rlx_state:vm_args(State) of
undefined ->
- ok = file:write_file(RelVmargsPath, vm_args_file(RelName));
+ unless_exists_write_default(RelVmargsPath, vm_args_file(RelName));
ArgsPath ->
case filelib:is_regular(ArgsPath) of
false ->
@@ -317,7 +316,7 @@ copy_or_generate_sys_config_file(State, Release, OutputDir, RelDir) ->
RelSysConfPath = filename:join([RelDir, "sys.config"]),
case rlx_state:sys_config(State) of
undefined ->
- ok = generate_sys_config_file(RelSysConfPath),
+ unless_exists_write_default(RelSysConfPath, sys_config_file()),
include_erts(State, Release, OutputDir, RelDir);
ConfigPath ->
case filelib:is_regular(ConfigPath) of
@@ -329,22 +328,6 @@ copy_or_generate_sys_config_file(State, Release, OutputDir, RelDir) ->
end
end.
-%% @doc write a generic sys.config to the path RelSysConfPath
--spec generate_sys_config_file(string()) -> ok.
-generate_sys_config_file(RelSysConfPath) ->
- {ok, Fd} = file:open(RelSysConfPath, [write]),
- io:format(Fd,
- "%% Thanks to Ulf Wiger at Ericcson for these comments:~n"
- "%%~n"
- "%% This file is identified via the erl command line option -config File.~n"
- "%% Note that File should have no extension, e.g.~n"
- "%% erl -config .../sys (if this file is called sys.config)~n"
- "%%~n"
- "%% In this file, you can redefine application environment variables.~n"
- "%% This way, you don't have to modify the .app files of e.g. OTP applications.~n"
- "[].~n", []),
- file:close(Fd).
-
%% @doc Optionally add erts directory to release, if defined.
-spec include_erts(rlx_state:t(), rlx_release:t(), file:name(), file:name()) -> {ok, rlx_state:t()} | relx:error().
include_erts(State, Release, OutputDir, RelDir) ->
@@ -529,7 +512,6 @@ strip_rel(Name) ->
rlx_util:to_string(filename:join(filename:dirname(Name),
filename:basename(Name, ".rel"))).
-
get_up_release(State, Release, Vsn) ->
Name = rlx_release:name(Release),
try
@@ -578,6 +560,14 @@ get_code_paths(Release, OutDir) ->
rlx_app_info:vsn_as_string(App), "ebin"]) ||
App <- rlx_release:application_details(Release)].
+unless_exists_write_default(Path, File) ->
+ case ec_file:exists(Path) of
+ true ->
+ ok;
+ false ->
+ ok = file:write_file(Path, File)
+ end.
+
erl_script(ErtsVsn) ->
[<<"#!/bin/sh
set -e
@@ -1124,6 +1114,17 @@ consult(Cont, Str, Acc) ->
consult(Cont1, eof, Acc)
end.">>].
+sys_config_file() ->
+ [<<"%% Thanks to Ulf Wiger at Ericcson for these comments:
+%%
+%% This file is identified via the erl command line option -config File.
+%% Note that File should have no extension, e.g.
+%% erl -config .../sys (if this file is called sys.config)
+%%
+%% In this file, you can redefine application environment variables.
+%% This way, you don't have to modify the .app files of e.g. OTP applications.
+[].">>].
+
vm_args_file(RelName) ->
[<<"## Name of the node
-name ">>, RelName, <<"@127.0.0.1
diff --git a/src/rlx_prv_config.erl b/src/rlx_prv_config.erl
index c6b264a..346b7c8 100644
--- a/src/rlx_prv_config.erl
+++ b/src/rlx_prv_config.erl
@@ -127,6 +127,11 @@ load_terms({default_release, RelName, RelVsn}, {ok, State}) ->
load_terms({paths, Paths}, {ok, State}) ->
code:add_pathsa([filename:absname(Path) || Path <- Paths]),
{ok, State};
+load_terms({lib_dirs, Dirs}, {ok, State}) ->
+ State2 =
+ rlx_state:add_lib_dirs(State,
+ [list_to_binary(filename:absname(Dir)) || Dir <- Dirs]),
+ {ok, State2};
load_terms({providers, Providers0}, {ok, State0}) ->
Providers1 = gen_providers(Providers0, State0),
case Providers1 of
diff --git a/src/rlx_state.erl b/src/rlx_state.erl
index 6d3c4ee..b35baf3 100644
--- a/src/rlx_state.erl
+++ b/src/rlx_state.erl
@@ -28,6 +28,7 @@
actions/1,
output_dir/1,
lib_dirs/1,
+ add_lib_dirs/2,
overrides/1,
overrides/2,
skip_apps/1,
@@ -152,7 +153,6 @@ overrides(#state_t{overrides=Overrides}) ->
overrides(State, Overrides) ->
State#state_t{overrides=Overrides}.
-
-spec skip_apps(t()) -> [AppName::atom()].
skip_apps(#state_t{skip_apps=Apps}) ->
Apps.
@@ -175,6 +175,10 @@ output_dir(#state_t{output_dir=OutDir}) ->
lib_dirs(#state_t{lib_dirs=LibDir}) ->
LibDir.
+-spec add_lib_dirs(t(), [file:name()]) -> t().
+add_lib_dirs(State=#state_t{lib_dirs=LibDir}, Dirs) ->
+ State#state_t{lib_dirs=lists:umerge(lists:sort(LibDir), lists:sort(Dirs))}.
+
-spec goals(t()) -> [rlx_depsolver:constraint()].
goals(#state_t{goals=TS}) ->
TS.