From daeae596b93605265273fd474407865211039204 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Wed, 18 Sep 2013 19:35:38 -0500 Subject: do not write default empty sys.config or vm.args if it exists already --- src/rlx_prv_assembler.erl | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) 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 -- cgit v1.2.3 From 0d1dfed1ac0a1868d943e0174fce9f8bf49e448b Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Wed, 18 Sep 2013 20:15:32 -0500 Subject: add lib_dirs option to for config file, same as -l cli arg --- src/rlx_prv_config.erl | 5 +++++ src/rlx_state.erl | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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..138705c 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:merge(lists:sort(LibDir), lists:sort(Dirs))}. + -spec goals(t()) -> [rlx_depsolver:constraint()]. goals(#state_t{goals=TS}) -> TS. -- cgit v1.2.3 From c0a18117ddaff70e93411df060e1d7c7d1ad1b92 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Wed, 18 Sep 2013 20:49:38 -0500 Subject: add -p for setting code paths --- README.md | 1 + src/relx.erl | 4 +++- src/rlx_cmd_args.erl | 30 +++++++++++++++++++++++------- src/rlx_state.erl | 2 +- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9452f67..3036686 100644 --- a/README.md +++ b/README.md @@ -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..bc311f5 100644 --- a/src/relx.erl +++ b/src/relx.erl @@ -182,7 +182,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"}, 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_state.erl b/src/rlx_state.erl index 138705c..b35baf3 100644 --- a/src/rlx_state.erl +++ b/src/rlx_state.erl @@ -177,7 +177,7 @@ lib_dirs(#state_t{lib_dirs=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:merge(lists:sort(LibDir), lists:sort(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}) -> -- cgit v1.2.3 From 61e6d8bb02149a244d2a3353a78c4543645717ac Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Wed, 18 Sep 2013 22:09:27 -0500 Subject: add rb16b01 and 02 and don't run dialyzer for r15 and below --- .travis.yml | 2 ++ Makefile | 4 ++-- 2 files changed, 4 insertions(+), 2 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 diff --git a/Makefile b/Makefile index bfbaab8..39d0bb0 100644 --- a/Makefile +++ b/Makefile @@ -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 \ -- cgit v1.2.3 From 0b59a913ef3b05a4a72622575a615a5a002cc86a Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Wed, 18 Sep 2013 22:23:18 -0500 Subject: fix deps target for shell target --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 39d0bb0..b8a2657 100644 --- a/Makefile +++ b/Makefile @@ -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 -- cgit v1.2.3 From 6df9d493655775677400ca0348de747d90305256 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Wed, 18 Sep 2013 22:32:42 -0500 Subject: add -v/--version cli option --- src/relx.erl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/relx.erl b/src/relx.erl index bc311f5..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}) @@ -193,6 +200,7 @@ opt_spec_list() -> {override_app, $a, "override_app", string, "Provide an app name and a directory to override in the form :"}, {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(). -- cgit v1.2.3