aboutsummaryrefslogtreecommitdiffstats
path: root/src/rlx_prv_rel_discover.erl
diff options
context:
space:
mode:
authorJordan Wilberding <[email protected]>2014-11-06 09:21:41 -0800
committerJordan Wilberding <[email protected]>2014-11-06 09:21:41 -0800
commit75b44fa44ef70e078dd450bf68bfaea4d48bf4e3 (patch)
treec91e2cb7d92232a7f216e1c8b19eadba3aacd17b /src/rlx_prv_rel_discover.erl
parent655b54a45c5d1a2e319841408c0b5431ea0cd9e2 (diff)
parent79bbf33cbd46c9a1beeae00424e14969608385ba (diff)
downloadrelx-75b44fa44ef70e078dd450bf68bfaea4d48bf4e3.tar.gz
relx-75b44fa44ef70e078dd450bf68bfaea4d48bf4e3.tar.bz2
relx-75b44fa44ef70e078dd450bf68bfaea4d48bf4e3.zip
Merge pull request #252 from tsloughter/master
Split app and release discovery and format_error fix
Diffstat (limited to 'src/rlx_prv_rel_discover.erl')
-rw-r--r--src/rlx_prv_rel_discover.erl97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/rlx_prv_rel_discover.erl b/src/rlx_prv_rel_discover.erl
new file mode 100644
index 0000000..8b6fd88
--- /dev/null
+++ b/src/rlx_prv_rel_discover.erl
@@ -0,0 +1,97 @@
+%% -*- erlang-indent-level: 4; indent-tabs-mode: nil; fill-column: 80 -*-
+%%% Copyright 2012 Erlware, LLC. All Rights Reserved.
+%%%
+%%% This file is provided to you under the Apache License,
+%%% Version 2.0 (the "License"); you may not use this file
+%%% except in compliance with the License. You may obtain
+%%% a copy of the License at
+%%%
+%%% http://www.apache.org/licenses/LICENSE-2.0
+%%%
+%%% Unless required by applicable law or agreed to in writing,
+%%% software distributed under the License is distributed on an
+%%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+%%% KIND, either express or implied. See the License for the
+%%% specific language governing permissions and limitations
+%%% under the License.
+%%%---------------------------------------------------------------------------
+%%% @author Eric Merritt <[email protected]>
+%%% @copyright (C) 2012 Erlware, LLC.
+%%%
+-module(rlx_prv_rel_discover).
+-behaviour(provider).
+
+-export([init/1,
+ do/1,
+ format_error/2]).
+
+-include("relx.hrl").
+
+-define(PROVIDER, rel_discover).
+-define(DEPS, [app_discover]).
+
+%%============================================================================
+%% API
+%%============================================================================
+
+-spec init(rlx_state:t()) -> {ok, rlx_state:t()}.
+init(State) ->
+ State1 = rlx_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, false},
+ {deps, ?DEPS},
+ {example, "build"},
+ {short_desc, ""},
+ {desc, ""},
+ {opts, []}])),
+ {ok, State1}.
+
+-spec do(rlx_state:t()) -> {ok, rlx_state:t()} | relx:error().
+do(State0) ->
+ LibDirs = get_lib_dirs(State0),
+ AppMeta = rlx_state:available_apps(State0),
+ case rlx_rel_discovery:do(State0, LibDirs, AppMeta) of
+ {ok, Releases} ->
+ {ok, rlx_state:realized_releases(State0, lists:foldl(fun add/2,
+ ec_dictionary:new(ec_dict),
+ Releases))};
+ Error ->
+ Error
+ end.
+
+-spec format_error(any(), rlx_state:t()) -> iolist().
+format_error(_, _) ->
+ "".
+
+%%%===================================================================
+%%% Internal Functions
+%%%===================================================================
+%% @doc only add the release if its not documented in the system
+add(Rel, Dict) ->
+ RelName = rlx_release:name(Rel),
+ RelVsn = rlx_release:vsn(Rel),
+ ec_dictionary:add({RelName, RelVsn}, Rel, Dict).
+
+get_lib_dirs(State) ->
+ LibDirs0 = rlx_state:lib_dirs(State),
+ case rlx_state:get(State, default_libs, true) of
+ false ->
+ LibDirs0;
+ true ->
+ lists:flatten([LibDirs0,
+ add_release_output_dir(State)])
+ end.
+
+add_release_output_dir(State) ->
+ case rlx_state:get(State, disable_discover_release_output, false) of
+ true ->
+ [];
+ false ->
+ Output = erlang:iolist_to_binary(rlx_state:base_output_dir(State)),
+ case ec_file:exists(erlang:binary_to_list(Output)) of
+ true ->
+ Output;
+ false ->
+ []
+ end
+ end.