diff options
-rw-r--r-- | src/rcl_prv_config.erl | 14 | ||||
-rw-r--r-- | src/rcl_prv_overlay.erl | 3 | ||||
-rw-r--r-- | src/rcl_state.erl | 48 | ||||
-rw-r--r-- | src/relcool.erl | 4 | ||||
-rw-r--r-- | test/rclt_release_SUITE.erl | 6 |
5 files changed, 26 insertions, 49 deletions
diff --git a/src/rcl_prv_config.erl b/src/rcl_prv_config.erl index 7ea9a77..f87c467 100644 --- a/src/rcl_prv_config.erl +++ b/src/rcl_prv_config.erl @@ -29,11 +29,11 @@ init(State) -> %% populating the state as a result. -spec do(rcl_state:t()) ->{ok, rcl_state:t()} | relcool:error(). do(State) -> - case rcl_state:config_files(State) of + case rcl_state:config_file(State) of [] -> search_for_dominating_config(State); - ConfigFiles -> - lists:foldl(fun load_config/2, {ok, State}, ConfigFiles) + ConfigFile -> + load_config(ConfigFile, State) end. -spec format_error(Reason::term()) -> iolist(). @@ -63,7 +63,7 @@ search_for_dominating_config(State0) -> %% we need to set the root dir on state as well {ok, RootDir} = parent_dir(Config), State1 = rcl_state:root_dir(State0, RootDir), - load_config(Config, {ok, rcl_state:config_files(State1, [Config])}); + load_config(Config, rcl_state:config_file(State1, Config)); no_config -> {ok, State0} end. @@ -88,11 +88,9 @@ parent_dir([H | T], Acc) -> parent_dir(T, [H | Acc]). --spec load_config(file:filename(), {ok, rcl_state:t()} | relcool:error()) -> +-spec load_config(file:filename(), rcl_state:t()) -> {ok, rcl_state:t()} | relcool:error(). -load_config(_, Err = {error, _}) -> - Err; -load_config(ConfigFile, {ok, State}) -> +load_config(ConfigFile, State) -> {ok, CurrentCwd} = file:get_cwd(), ok = file:set_cwd(filename:dirname(ConfigFile)), Result = case file:consult(ConfigFile) of diff --git a/src/rcl_prv_overlay.erl b/src/rcl_prv_overlay.erl index 0e9781b..866ace5 100644 --- a/src/rcl_prv_overlay.erl +++ b/src/rcl_prv_overlay.erl @@ -196,7 +196,7 @@ generate_state_vars(State) -> {goals, [rcl_depsolver:format_constraint(Constraint) || Constraint <- rcl_state:goals(State)]}, {lib_dirs, rcl_state:lib_dirs(State)}, - {config_files, rcl_state:config_files(State)}, + {config_file, rcl_state:config_file(State)}, {providers, rcl_state:providers(State)}, {sys_config, rcl_state:sys_config(State)}, {root_dir, rcl_state:root_dir(State)}, @@ -295,6 +295,7 @@ do_individual_overlay(State, OverlayVars, {template, From, To}) -> copy_to(State, FromFile0, ToFile0) -> ToFile1 = absolutize(State, filename:join(rcl_state:output_dir(State), erlang:iolist_to_binary(ToFile0))), + FromFile1 = absolutize(State, FromFile0), ToFile2 = case is_directory(ToFile0, ToFile1) of false -> diff --git a/src/rcl_state.erl b/src/rcl_state.erl index eb70ecc..28effbd 100644 --- a/src/rcl_state.erl +++ b/src/rcl_state.erl @@ -30,8 +30,8 @@ overrides/1, overrides/2, goals/1, - config_files/1, - config_files/2, + config_file/1, + config_file/2, providers/1, providers/2, sys_config/1, @@ -64,7 +64,7 @@ caller :: caller(), output_dir :: file:name(), lib_dirs=[] :: [file:name()], - config_files=[] :: [file:filename()], + config_file=[] :: file:filename(), goals=[] :: [rcl_depsolver:constraint()], providers = [] :: [rcl_provider:t()], available_apps = [] :: [rcl_app_info:t()], @@ -93,13 +93,13 @@ %%============================================================================ %% @doc Create a new 'log level' for the system -spec new(proplists:proplist(), [file:filename()] | file:filename()) -> t(). -new(PropList, Targets) when erlang:is_list(PropList) -> +new(PropList, Target) when erlang:is_list(PropList) -> {ok, Root} = file:get_cwd(), State0 = #state_t{log = proplists:get_value(log, PropList, rcl_log:new(error)), output_dir=proplists:get_value(output_dir, PropList, ""), - lib_dirs=get_lib_dirs(proplists:get_value(lib_dirs, PropList, [])), - config_files=process_config_files(Targets), + lib_dirs=proplists:get_value(lib_dirs, PropList, ""), + config_file=Target, goals=proplists:get_value(goals, PropList, []), providers = [], releases=ec_dictionary:new(ec_dict), @@ -137,13 +137,13 @@ lib_dirs(#state_t{lib_dirs=LibDir}) -> goals(#state_t{goals=TS}) -> TS. --spec config_files(t()) -> [file:filename()]. -config_files(#state_t{config_files=ConfigFiles}) -> +-spec config_file(t()) -> file:filename(). +config_file(#state_t{config_file=ConfigFiles}) -> ConfigFiles. --spec config_files(t(), [file:filename()]) -> t(). -config_files(State, ConfigFiles) -> - State#state_t{config_files=ConfigFiles}. +-spec config_file(t(), file:filename()) -> t(). +config_file(State, ConfigFiles) -> + State#state_t{config_file=ConfigFiles}. -spec providers(t()) -> [rcl_provider:t()]. providers(#state_t{providers=Providers}) -> @@ -243,15 +243,14 @@ format(Mod) -> -spec format(t(), non_neg_integer()) -> iolist(). format(#state_t{log=LogState, output_dir=OutDir, lib_dirs=LibDirs, caller=Caller, config_values=Values0, - goals=Goals, config_files=ConfigFiles, + goals=Goals, config_file=ConfigFile, providers=Providers}, Indent) -> Values1 = ec_dictionary:to_list(Values0), [rcl_util:indent(Indent), <<"state(">>, erlang:atom_to_list(Caller), <<"):\n">>, rcl_util:indent(Indent + 1), <<"log: ">>, rcl_log:format(LogState), <<",\n">>, - rcl_util:indent(Indent + 1), "config files: \n", - [[rcl_util:indent(Indent + 2), ConfigFile, ",\n"] || ConfigFile <- ConfigFiles], + rcl_util:indent(Indent + 1), "config file: ", ConfigFile, "\n", rcl_util:indent(Indent + 1), "goals: \n", [[rcl_util:indent(Indent + 2), rcl_depsolver:format_constraint(Goal), ",\n"] || Goal <- Goals], rcl_util:indent(Indent + 1), "output_dir: ", OutDir, "\n", @@ -265,15 +264,6 @@ format(#state_t{log=LogState, output_dir=OutDir, lib_dirs=LibDirs, %%%=================================================================== %%% Internal Functions %%%=================================================================== --spec get_lib_dirs([file:name()]) -> [file:name()]. -get_lib_dirs(CmdDirs) -> - case os:getenv("ERL_LIBS") of - false -> - CmdDirs; - EnvString -> - [Lib || Lib <- re:split(EnvString, ":|;"), - filelib:is_dir(Lib)] ++ CmdDirs - end. -spec create_logic_providers(t()) -> t(). create_logic_providers(State0) -> @@ -285,18 +275,6 @@ create_logic_providers(State0) -> State5#state_t{providers=[ConfigProvider, DiscoveryProvider, ReleaseProvider, OverlayProvider, AssemblerProvider]}. - -%% @doc config files can come in as either a single file name or as a list of -%% files. We what to support both where possible. -process_config_files(File = [Char | _]) - when erlang:is_integer(Char) -> - [File]; -process_config_files(Files = [File | _]) - when erlang:is_list(File) -> - Files; -process_config_files([]) -> - []. - %%%=================================================================== %%% Test Functions %%%=================================================================== diff --git a/src/relcool.erl b/src/relcool.erl index fb17711..9babdb2 100644 --- a/src/relcool.erl +++ b/src/relcool.erl @@ -72,7 +72,7 @@ do(RelName, RelVsn, Goals, LibDirs, LogLevel, OutputDir, Configs) -> %% @param OutputDir - The directory where the release should be built to %% @param Overrides - A list of overrides for the system %% @param Configs - The list of config files for the system -do(RelName, RelVsn, Goals, LibDirs, LogLevel, OutputDir, Overrides, Configs) -> +do(RelName, RelVsn, Goals, LibDirs, LogLevel, OutputDir, Overrides, Config) -> State = rcl_state:new([{relname, RelName}, {relvsn, RelVsn}, {goals, Goals}, @@ -80,7 +80,7 @@ do(RelName, RelVsn, Goals, LibDirs, LogLevel, OutputDir, Overrides, Configs) -> {output_dir, OutputDir}, {lib_dirs, LibDirs}, {log, rcl_log:new(LogLevel)}], - Configs), + Config), run_relcool_process(rcl_state:caller(State, api)). diff --git a/test/rclt_release_SUITE.erl b/test/rclt_release_SUITE.erl index 593944e..bcdf354 100644 --- a/test/rclt_release_SUITE.erl +++ b/test/rclt_release_SUITE.erl @@ -391,7 +391,7 @@ overlay_release(Config) -> ?assertEqual([""], proplists:get_value(goals, TemplateData)), ?assert(proplists:is_defined(lib_dirs, TemplateData)), - ?assert(proplists:is_defined(config_files, TemplateData)), + ?assert(proplists:is_defined(config_file, TemplateData)), ?assertEqual([""], proplists:get_value(goals, TemplateData)), ?assertEqual("undefined", @@ -457,7 +457,7 @@ write_config(Filename, Values) -> test_template_contents() -> "{erts_vsn, \"{{erts_vsn}}\"}.\n" - "{release_erts_version, \"{{release_erts_version}}\"}.\n" + "{release_erts_version, \"{{release_erts_version}}\"}.\n" "{release_name, {{release_name}}}.\n" "{rel_vsn, \"{{release_version}}\"}.\n" "{release_version, \"{{release_version}}\"}.\n" @@ -479,7 +479,7 @@ test_template_contents() -> "{overridden, [{{ overridden|join:\", \" }}]}.\n" "{goals, [\"{{ goals|join:\", \" }}\"]}.\n" "{lib_dirs, [\"{{ lib_dirs|join:\", \" }}\"]}.\n" - "{config_files, [\"{{ config_files|join:\", \" }}\"]}.\n" + "{config_file, \"{{ config_file }}\"}.\n" "{providers, [{{ providers|join:\", \" }}]}.\n" "{sys_config, \"{{sys_config}}\"}.\n" "{root_dir, \"{{root_dir}}\"}.\n" |