diff options
Diffstat (limited to 'src/relcool.erl')
-rw-r--r-- | src/relcool.erl | 92 |
1 files changed, 69 insertions, 23 deletions
diff --git a/src/relcool.erl b/src/relcool.erl index 0d75c62..c8c0cde 100644 --- a/src/relcool.erl +++ b/src/relcool.erl @@ -1,4 +1,4 @@ -%%% -*- mode: Erlang; fill-column: 80; comment-column: 75; -*- +%% -*- 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, @@ -23,6 +23,7 @@ -export([main/1, do/7, do/8, + do/9, format_error/1, opt_spec_list/0]). @@ -35,6 +36,7 @@ %%============================================================================ -type error() :: {error, {Module::module(), Reason::term()}}. +-type goal() :: string() | binary() | rcl_depsolver:constraint(). %%============================================================================ %% API @@ -42,12 +44,20 @@ -spec main([string()]) -> ok | error() | {ok, rcl_state:t()}. main(Args) -> OptSpecList = opt_spec_list(), - case rcl_cmd_args:args2state(getopt:parse(OptSpecList, Args)) of - {ok, {State, _Target}} -> - run_relcool_process(rcl_state:caller(State, command_line)); - Error={error, _} -> - report_error(rcl_state:caller(rcl_state:new([], []), - command_line), Error) + Result = + case rcl_cmd_args:args2state(getopt:parse(OptSpecList, Args)) of + {ok, State} -> + run_relcool_process(rcl_state:caller(State, command_line)); + Error={error, _} -> + Error + end, + case Result of + {error, _} -> + report_error(rcl_state:caller(rcl_state:new([], undefined), + command_line), + Result); + _ -> + Result end. %% @doc provides an API to run the Relcool process from erlang applications @@ -59,11 +69,32 @@ main(Args) -> %% @param LibDirs - The library dirs that should be used for the system %% @param OutputDir - The directory where the release should be built to %% @param Configs - The list of config files for the system -do(RelName, RelVsn, Goals, LibDirs, LogLevel, OutputDir, Configs) -> - do(RelName, RelVsn, Goals, LibDirs, LogLevel, OutputDir, [], Configs). +-spec do(atom(), string(), [goal()], [file:name()], rcl_log:log_level(), + [file:name()], file:name()) -> + ok | error() | {ok, rcl_state:t()}. +do(RelName, RelVsn, Goals, LibDirs, LogLevel, OutputDir, Config) -> + {ok, Cwd} = file:get_cwd(), + do(Cwd, RelName, RelVsn, Goals, LibDirs, LogLevel, OutputDir, [], Config). + +%% @doc provides an API to run the Relcool process from erlang applications +%% +%% @param RootDir - The root directory for the project +%% @param RelName - The release name to build (maybe `undefined`) +%% @param RelVsn - The release version to build (maybe `undefined`) +%% @param Goals - The release goals for the system in depsolver or Relcool goal +%% format +%% @param LibDirs - The library dirs that should be used for the system +%% @param OutputDir - The directory where the release should be built to +%% @param Configs - The list of config files for the system +-spec do(file:name(), atom(), string(), [goal()], [file:name()], + rcl_log:log_level(), [file:name()], file:name()) -> + ok | error() | {ok, rcl_state:t()}. +do(RootDir, RelName, RelVsn, Goals, LibDirs, LogLevel, OutputDir, Configs) -> + do(RootDir, RelName, RelVsn, Goals, LibDirs, LogLevel, OutputDir, [], Configs). %% @doc provides an API to run the Relcool process from erlang applications %% +%% @param RootDir - The root directory for the system %% @param RelName - The release name to build (maybe `undefined`) %% @param RelVsn - The release version to build (maybe `undefined`) %% @param Goals - The release goals for the system in depsolver or Relcool goal @@ -72,29 +103,41 @@ 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) -> +-spec do(file:name(), atom(), string(), [goal()], [file:name()], + rcl_log:log_level(), [file:name()], [{atom(), file:name()}], file:name()) -> + ok | error() | {ok, rcl_state:t()}. +do(RootDir, RelName, RelVsn, Goals, LibDirs, LogLevel, OutputDir, Overrides, Config) -> State = rcl_state:new([{relname, RelName}, {relvsn, RelVsn}, {goals, Goals}, {overrides, Overrides}, {output_dir, OutputDir}, {lib_dirs, LibDirs}, - {log, rcl_log:new(LogLevel)}], - Configs), + {root_dir, RootDir}, + {log, rcl_log:new(LogLevel)}, + {config, Config}], + release), run_relcool_process(rcl_state:caller(State, api)). -spec opt_spec_list() -> [getopt:option_spec()]. opt_spec_list() -> - [ - {relname, $n, "relname", string, "Specify the name for the release that will be generated"}, + [{relname, $n, "relname", string, + "Specify the name for the release that will be generated"}, {relvsn, $v, "relvsn", string, "Specify the version for the release"}, - {goals, $g, "goal", string, "Specify a target constraint on the system. These are " - "usually the OTP"}, - {output_dir, $o, "output-dir", string, "The output directory for the release. This is `./` by default."}, - {lib_dir, $l, "lib-dir", string, "Additional dirs that should be searched for OTP Apps"}, - {log_level, $V, "verbose", {integer, 2}, "Verbosity level, maybe between 0 and 2"} - ]. + {goals, $g, "goal", string, + "Specify a target constraint on the system. These are usually the OTP"}, + {output_dir, $o, "output-dir", string, + "The output directory for the release. This is `./` by default."}, + {lib_dir, $l, "lib-dir", string, + "Additional dirs that should be searched for OTP Apps"}, + {disable_default_libs, undefined, "disable-default-libs", + {boolean, false}, + "Disable the default system added lib dirs (means you must add them all manually"}, + {log_level, $V, "verbose", {integer, 1}, + "Verbosity level, maybe between 0 and 2"}, + {config, $c, "config", {string, ""}, "The path to a config file"}, + {root_dir, $r, "root", string, "The project root directory"}]. -spec format_error(Reason::term()) -> iolist(). format_error({invalid_return_value, Provider, Value}) -> @@ -103,7 +146,6 @@ format_error({invalid_return_value, Provider, Value}) -> format_error({error, {Module, Reason}}) -> io_lib:format("~s~n", [Module:format_error(Reason)]). - %%============================================================================ %% internal api %%============================================================================ @@ -126,6 +168,8 @@ run_providers(State0) -> Err = {error, _} -> Err; {ok, State1} -> + RootDir = rcl_state:root_dir(State1), + ok = file:set_cwd(RootDir), Providers = rcl_state:providers(State1), Result = run_providers(ConfigProvider, Providers, State1), handle_output(State1, rcl_state:caller(State1), Result) @@ -158,9 +202,12 @@ run_provider(Provider, {ok, State0}) -> [rcl_provider:impl(Provider)]), case rcl_provider:do(Provider, State0) of {ok, State1} -> + rcl_log:debug(rcl_state:log(State0), "Provider successfully run: ~p~n", + [rcl_provider:impl(Provider)]), {ok, State1}; E={error, _} -> - + rcl_log:debug(rcl_state:log(State0), "Provider (~p) failed with: ~p~n", + [rcl_provider:impl(Provider), E]), E end. @@ -168,7 +215,6 @@ run_provider(Provider, {ok, State0}) -> usage() -> getopt:usage(opt_spec_list(), "relcool", "[*release-specification-file*]"). - -spec report_error(rcl_state:t(), error()) -> none() | error(). report_error(State, Error) -> io:format(format_error(Error)), |