diff options
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | src/relx.erl | 18 | ||||
-rw-r--r-- | src/rlx_cmd_args.erl | 30 | ||||
-rw-r--r-- | src/rlx_prv_assembler.erl | 41 | ||||
-rw-r--r-- | src/rlx_prv_config.erl | 5 | ||||
-rw-r--r-- | src/rlx_state.erl | 6 |
8 files changed, 74 insertions, 35 deletions
diff --git a/.travis.yml b/.travis.yml index adf0a04..9b12a1c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ language: erlang otp_release: + - R16B02 + - R16B01 - R16B - R15B03 - R15B02 @@ -45,12 +45,12 @@ endif # problem that travis times out. The code below lets us not run # dialyzer on R14 OTP_VSN=$(shell erl -noshell -eval 'io:format("~p", [erlang:system_info(otp_release)]), erlang:halt(0).' | perl -lne 'print for /R(\d+).*/g') -TRAVIS_SLOW=$(shell expr $(OTP_VSN) \<= 14 ) +TRAVIS_SLOW=$(shell expr $(OTP_VSN) \<= 15 ) ifeq ($(TRAVIS_SLOW), 0) DIALYZER=$(shell which dialyzer) else -DIALYZER=: not running dialyzer on R14 +DIALYZER=: not running dialyzer on R14 or R15 endif .PHONY: all compile doc clean test dialyzer typer shell distclean pdf \ @@ -105,7 +105,7 @@ dialyzer: $(DEPS_PLT) typer: typer --plt $(DEPS_PLT) -r ./src -shell: get-deps compile +shell: deps compile # You often want *rebuilt* rebar tests to be available to the # shell you have to call eunit (to get the tests # rebuilt). However, eunit runs the tests, which probably @@ -55,6 +55,7 @@ Options | -u | --upfrom | string | | The release to upgrade from. Only valid with relup target | | -o | --output-dir | string | ./ | The output directory for the release | | -l | --lib-dir | string | | Additional dirs to search for OTP apps | +| -p | --path | string | | Additional dirs to add to Erlang code path | | | --disable-default-libs | boolean | false | Disable use of the default system added lib dirs | | -V | --verbose | integer | 0 | The verbosity level between 0 and 2 | | -a | --override_app | string | | An app name and a directory to override in the form appname:dir | 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. |