diff --git a/src/rebar3_hex.erl b/src/rebar3_hex.erl
index 9452c976..3f7712b2 100644
--- a/src/rebar3_hex.erl
+++ b/src/rebar3_hex.erl
@@ -7,6 +7,7 @@
, get_required/2
, task_args/1
, task_state/1
+ , task_state/2
, repo_opt/0
, help_opt/0
]).
@@ -15,10 +16,10 @@
-type task() :: #{raw_opts := proplists:proplist(),
raw_args := list(),
- args := map(),
- repo := map(),
- apps := [rebar_app_info:t()],
- state := rebar_state:t(),
+ args := map(),
+ repo := map(),
+ apps := [rebar_app_info:t()],
+ state := rebar_state:t(),
multi_app := boolean()
}.
@@ -71,26 +72,30 @@ task_args(State) ->
%% as returned from rebar_state:command_parsed_args/1 as raw_args and raw_opts.
-spec task_state(rebar_state:t()) -> {ok, task()} | {error, term()}.
task_state(State) ->
- {Opts0, Args0} = rebar_state:command_parsed_args(State),
case rebar3_hex_config:repo(State) of
- {ok, Repo} ->
- Opts = get_args(State),
- CurrentTask = maps:get(task, Opts, undefined),
- Opts1 = Opts#{task => CurrentTask},
- case rebar_state:project_apps(State) of
- [] ->
- {ok, #{raw_opts => Opts0, raw_args => Args0, args => Opts1, repo => Repo, state => State, multi_app => false, apps => []}};
- [_App] = Apps ->
- {ok, #{raw_opts => Opts0, raw_args => Args0, args => Opts1, repo => Repo, state => State, multi_app => false, apps => Apps}};
- [_|_] = Apps ->
- {ok, #{raw_opts => Opts0, raw_args => Args0, args => Opts1, repo => Repo, state => State, multi_app => true, apps => Apps}}
- end;
- Err ->
+ {ok, Repo} ->
+ {ok, task_state(State, Repo)};
+ Err ->
Err
end.
+-spec task_state(rebar_state:t(), map()) -> task().
+task_state(State, Repo) ->
+ {Opts0, Args0} = rebar_state:command_parsed_args(State),
+ Opts = get_args(State),
+ CurrentTask = maps:get(task, Opts, undefined),
+ Opts1 = Opts#{task => CurrentTask},
+ case rebar_state:project_apps(State) of
+ [] ->
+ #{raw_opts => Opts0, raw_args => Args0, args => Opts1, repo => Repo, state => State, multi_app => false, apps => []};
+ [_App] = Apps ->
+ #{raw_opts => Opts0, raw_args => Args0, args => Opts1, repo => Repo, state => State, multi_app => false, apps => Apps};
+ [_|_] = Apps ->
+ #{raw_opts => Opts0, raw_args => Args0, args => Opts1, repo => Repo, state => State, multi_app => true, apps => Apps}
+ end.
+
-spec get_args(rebar_state:t()) -> map().
-get_args(State) ->
+get_args(State) ->
{Opts, Args} = rebar_state:command_parsed_args(State),
Opts1 = lists:foldl(fun (Arg, Acc) ->
case is_atom(Arg) of
@@ -100,14 +105,14 @@ get_args(State) ->
case Arg of
{task, Task} ->
[{task, list_to_atom(Task)} | Acc];
- _ ->
+ _ ->
[Arg | Acc]
end
end
end,
[],
Opts),
-
+
Opts2 = lists:foldl(fun (Arg, Acc) ->
case is_atom(Arg) of
true ->
diff --git a/src/rebar3_hex_build.erl b/src/rebar3_hex_build.erl
index 8f1467f7..e8c9b17e 100644
--- a/src/rebar3_hex_build.erl
+++ b/src/rebar3_hex_build.erl
@@ -1,34 +1,34 @@
-% @doc `rebar3 hex build' - Build packages and docs
+% @doc `rebar3 hex build' - Build packages and docs
%
%% Builds a new local version of your package.
%%
-%% By default this provider will build both a package tarball and docs tarball.
-%%
-%% The package and docs .tar files are created in the current directory, but is not pushed to the repository. An app
-%% named foo at version 1.2.3 will be built as foo-1.2.3.tar. Likewise the docs .tar would be built as
-%% foo-1.2.4-docs.tar.
+%% By default this provider will build both a package tarball and docs tarball.
+%%
+%% The package and docs .tar files are created in the current directory, but is not pushed to the repository. An app
+%% named foo at version 1.2.3 will be built as foo-1.2.3.tar. Likewise the docs .tar would be built as
+%% foo-1.2.4-docs.tar.
%%
%% ```
-%% $ rebar3 hex build
+%% $ rebar3 hex build
%% '''
-%%
-%% You may also build only a package or docs tarball utilizing the same available command line options.
%%
-%% ```
-%% $ rebar3 hex build package
+%% You may also build only a package or docs tarball utilizing the same available command line options.
+%%
+%% ```
+%% $ rebar3 hex build package
%% '''
%%
%% ```
-%% $ rebar3 hex build docs
+%% $ rebar3 hex build docs
%% '''
-%%
-%%
Configuration
+%%
+%% Configuration
%% Packages are configured via `src/.app.src' attributes.
-%%
-%% == Required configuration ==
-%%
+%%
+%% == Required configuration ==
+%%
%%
-%% -
+%%
-
%% `application' - application name. This is required per Erlang/OTP thus it should always be present anyway.
%%
% -
@@ -40,44 +40,44 @@
%%
%%
%%
-%%
-%% == Optional configuration ==
-%% In addition, the following meta attributes are supported and highly recommended :
+%%
+%% == Optional configuration ==
+%% In addition, the following meta attributes are supported and highly recommended :
%%
%%
-%% -
+%%
-
%% `description' - a brief description about your application.
%%
-%%
+%%
%% -
%% `pkg_name' - The name of the package in case you want to publish the package with a different name than the
%% application name.
%%
-%%
+%%
%% -
%% `links' - A map where the key is a link name and the value is the link URL. Optional but highly
%% recommended.
%%
-%%
-%% - `files' - A list of files and directories to include in the package. Defaults to standard project directories,
-%% so you usually don't need to set this property.
+%%
+%%
- `files' - A list of files and directories to include in the package. Defaults to standard project directories,
+%% so you usually don't need to set this property.
%%
-%% -
-%% `include_paths' - A list of paths containing files you wish to include in a release.
+%%
-
+%% `include_paths' - A list of paths containing files you wish to include in a release.
%%
-%% -
-%% `exclude_paths' - A list of paths containing files you wish to exclude in a release.
+%%
-
+%% `exclude_paths' - A list of paths containing files you wish to exclude in a release.
%%
-%% -
+%%
-
%% `exclude_patterns' - A list of regular expressions used to exclude files that may have been accumulated via
%% `files' and `include_paths' and standard project paths.
-%%
-%% -
-%% `build_tools' - List of build tools that can build the package. It's very rare that you need to set this.
+%%
+%% -
+%% `build_tools' - List of build tools that can build the package. It's very rare that you need to set this.
%%
%%
%%
-%% Below is an example :
+%% Below is an example :
%%
%% ```
%% {application, myapp,
@@ -95,15 +95,15 @@
%% Command line options
%%
%%
-%% - `-r', `--repo' - Specify the repository to work with. This option is required when
-%% you have multiple repositories configured, including organizations. The argument must
-%% be a fully qualified repository name (e.g, `hexpm', `hexpm:my_org', `my_own_hexpm').
-%% Defaults to `hexpm'.
+%%
- `-r', `--repo' - Specify the repository to work with. This option is required when
+%% you have multiple repositories configured, including organizations. The argument must
+%% be a fully qualified repository name (e.g, `hexpm', `hexpm:my_org', `my_own_hexpm').
+%% Defaults to `hexpm'.
%%
-%% - `-u', `--unpack' - Builds the tarball and unpacks contents into a directory. Useful for making sure the tarball
+%%
- `-u', `--unpack' - Builds the tarball and unpacks contents into a directory. Useful for making sure the tarball
%% contains all needed files before publishing. See --output below for setting the output path.
%%
-%% - `-o', `--output' - Sets output path. When used with --unpack it means the directory
+%%
- `-o', `--output' - Sets output path. When used with --unpack it means the directory
%% (Default: `-'). Otherwise, it specifies tarball path (Default: `-.tar').
%% Artifacts will be written to `_build//lib//' by default.
%%
@@ -111,7 +111,7 @@
-module(rebar3_hex_build).
--export([create_package/3, create_docs/3, create_docs/4]).
+-export([create_package/2, create_docs/3, create_docs/4]).
-include("rebar3_hex.hrl").
@@ -171,49 +171,60 @@ init(State) ->
%% @private
-spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
do(State) ->
- case rebar3_hex:task_state(State) of
- {ok, Task} ->
- handle_task(Task);
- {error, Reason} ->
- ?RAISE(Reason)
- end.
+ Task = rebar3_hex:task_state(State, get_repo(State)),
+ handle_task(Task).
+
+get_repo(State) ->
+ {Args, _} = rebar_state:command_parsed_args(State),
+ case proplists:get_value(repo, Args, undefined) of
+ undefined ->
+ rebar3_hex_config:default_repo(State);
+ RepoName ->
+ rebar3_hex_config:repo(State, RepoName)
+ end.
%% @private
-spec format_error(any()) -> iolist().
-format_error({build_package, Error}) when is_list(Error) ->
+format_error({build_package, Error}) when is_list(Error) ->
io_lib:format("Error building package : ~ts", [Error]);
-format_error({build_docs, {error, no_doc_config}}) ->
+format_error({build_docs, {error, no_doc_config}}) ->
no_doc_config_messsage();
-format_error({build_docs, {error, {doc_provider_not_found, PrvName}}}) ->
+format_error({build_docs, {error, {doc_provider_not_found, PrvName}}}) ->
doc_provider_not_found(PrvName);
-format_error({build_docs, {error, missing_doc_index}}) ->
+format_error({build_docs, {error, missing_doc_index}}) ->
doc_missing_index_message();
-format_error({build_docs, Error}) when is_list(Error) ->
+format_error({build_docs, Error}) when is_list(Error) ->
io_lib:format("Error building docs : ~ts", [Error]);
-format_error(app_switch_required) ->
+format_error(repo_required_for_docs) ->
+ Str = "Error :~n\tA repo argument is required when building docs if multiple repos exist"
+ " and at least one has doc configuration.~n\tSpecify a repo argument or run"
+ " rebar3 hex build package if you only need to build a package.",
+ io_lib:format(Str, []);
+
+format_error(app_switch_required) ->
"--app switch is required when building packages or docs in a umbrella with multiple apps";
format_error(Reason) ->
rebar3_hex_error:format_error(Reason).
-no_doc_config_messsage() ->
+no_doc_config_messsage() ->
"No doc provider has been specified in your hex config.\n"
"Be sure to add a doc provider to the hex config you rebar configuration file.\n\n"
"Example : {hex, [{doc, ex_doc}]\n".
-doc_missing_index_message() ->
+doc_missing_index_message() ->
"An index.html file was not found in docs after running docs provider.\n"
"Be sure the docs provider is configured correctly and double check it by running it on its own\n".
doc_provider_not_found(Provider) ->
io_lib:format("The doc provider ~ts specified in your hex config could not be found", [Provider]).
-handle_task(#{apps := [_,_|_]}) ->
+handle_task(#{apps := [_,_|_]}) ->
?RAISE(app_switch_required);
handle_task(#{state := State, repo := Repo, apps := [App], args := #{task := docs} = Args}) ->
@@ -226,8 +237,8 @@ handle_task(#{state := State, repo := Repo, apps := [App], args := #{task := doc
?RAISE({build_docs, Error})
end;
-handle_task(#{state := State, repo := Repo, apps := [App], args := #{task := package} = Args}) ->
- case create_package(State, Repo, App) of
+handle_task(#{state := State, apps := [App], args := #{task := package} = Args}) ->
+ case create_package(State, App) of
{ok, Pkg} ->
AbsDir = write_or_unpack(App, Pkg, Args),
rebar3_hex_io:say("Your package contents can be inspected at ~ts", [AbsDir]),
@@ -237,7 +248,7 @@ handle_task(#{state := State, repo := Repo, apps := [App], args := #{task := pac
end;
handle_task(#{state := State, repo := Repo, apps := [App], args := Args}) ->
- case create_package(State, Repo, App) of
+ case create_package(State, App) of
{ok, Pkg} ->
AbsOutput = write_or_unpack(App, Pkg, Args),
rebar3_hex_io:say("Your package tarball is available at ~ts", [AbsOutput]),
@@ -246,13 +257,13 @@ handle_task(#{state := State, repo := Repo, apps := [App], args := Args}) ->
AbsFile = write_or_unpack(App, Docs, Args),
rebar3_hex_io:say("Your docs tarball is available at ~ts", [AbsFile]),
{ok, State};
- {error, no_doc_config} ->
+ {error, no_doc_config} ->
rebar_api:warn(no_doc_config_messsage(), []),
{ok, State};
- {error, {doc_provider_not_found, PrvName}} ->
+ {error, {doc_provider_not_found, PrvName}} ->
rebar_api:warn(doc_provider_not_found(PrvName), []),
{ok, State};
- {error, missing_doc_index} ->
+ {error, missing_doc_index} ->
rebar_api:warn(doc_missing_index_message(), []),
{ok, State};
Error ->
@@ -271,24 +282,24 @@ output_path(package, Name, Version, #{unpack := true}) ->
output_path(package, Name, Version, _Args) ->
io_lib:format("~ts-~ts.tar", [Name, Version]).
-write_or_unpack(App, #{type := Type, tarball := Tarball, name := Name, version := Version}, Args) ->
+write_or_unpack(App, #{type := Type, tarball := Tarball, name := Name, version := Version}, Args) ->
OutputDir = output_dir(App, Args),
Out = output_path(Type, Name, Version, Args),
AbsOut = filename:join(OutputDir, Out),
- case Args of
- #{unpack := true} ->
+ case Args of
+ #{unpack := true} ->
file:make_dir(AbsOut),
- case Type of
- docs ->
+ case Type of
+ docs ->
hex_tarball:unpack_docs(Tarball, AbsOut);
- package ->
+ package ->
hex_tarball:unpack(Tarball, AbsOut)
end;
- _ ->
+ _ ->
file:write_file(AbsOut, Tarball)
end,
AbsOut.
-
+
%% We are exploiting a feature of ensuredir that that creates all
%% directories up to the last element in the filename, then ignores
%% that last element. This way we ensure that the dir is created
@@ -307,7 +318,7 @@ output_dir(App, _) ->
Dir.
%% @private
-create_package(State, #{name := RepoName} = _Repo, App) ->
+create_package(State, App) ->
Name = rebar_app_info:name(App),
Version = rebar3_hex_app:vcs_vsn(State, App),
{application, _, AppDetails} = rebar3_hex_file:update_app_src(App, Version),
@@ -354,7 +365,6 @@ create_package(State, #{name := RepoName} = _Repo, App) ->
Package = #{
type => package,
name => PkgName,
- repo_name => RepoName,
deps => Deps1,
version => Version,
metadata => Metadata,
@@ -392,7 +402,7 @@ include_files(Name, AppDir, AppDetails) ->
AppSrc = {application, to_atom(Name), AppDetails},
FilePaths = proplists:get_value(files, AppDetails, ?DEFAULT_FILES),
%% In versions prior to v7 the name of the for including paths and excluding paths was include_files and
- %% exclude_files. We don't document this anymore, but we do support it to avoid breaking changes. However,
+ %% exclude_files. We don't document this anymore, but we do support it to avoid breaking changes. However,
%% users should be instructed to use *_paths. Likewise for exclude_regexps which is now documented as
%% exclude_patterns.
IncludePaths = proplists:get_value(include_paths, AppDetails, proplists:get_value(include_files, AppDetails, [])),
@@ -521,6 +531,10 @@ docs_detected(DocDir) ->
doc_opts(State, Repo) ->
case Repo of
#{doc := #{provider := PrvName}} when is_atom(PrvName) ->
+ Deprecation = "Setting doc options in repo configuration has been deprecated."
+ " You should configure a docmentation provider in top level hex "
+ " configuration now.",
+ rebar_api:warn(Deprecation, []),
{ok, PrvName};
_ ->
Opts = rebar_state:opts(State),
diff --git a/src/rebar3_hex_config.erl b/src/rebar3_hex_config.erl
index 5cdc12af..f586aade 100644
--- a/src/rebar3_hex_config.erl
+++ b/src/rebar3_hex_config.erl
@@ -3,12 +3,14 @@
-export([ api_key_name/1
, api_key_name/2
+ , all_repos/1
, encrypt_write_key/3
, decrypt_write_key/3
, repos_key_name/0
, org_key_name/2
, parent_repos/1
, get_hex_config/3
+ , default_repo/1
, repo/1
, repo/2
, update_auth_config/2
@@ -95,11 +97,15 @@ key_name_prefix(Key) -> Key.
update_auth_config(Config, State) ->
rebar_hex_repos:update_auth_config(Config, State).
+all_repos(State) ->
+ Resources = rebar_state:resources(State),
+ #{repos := Repos} = rebar_resource_v2:find_resource_state(pkg, Resources),
+ Repos.
+
-spec repo(rebar_state:t()) -> {ok, map()} | {error, repo_error()}.
repo(State) ->
{Args, _} = rebar_state:command_parsed_args(State),
- Resources = rebar_state:resources(State),
- #{repos := Repos} = rebar_resource_v2:find_resource_state(pkg, Resources),
+ Repos = all_repos(State),
case proplists:get_value(repo, Args, undefined) of
undefined ->
Res = [R || R <- Repos, maps:get(name, R) =/= ?DEFAULT_HEX_REPO],
@@ -119,10 +125,9 @@ repo(State) ->
end.
repo(State, RepoName) ->
- Resources = rebar_state:resources(State),
- #{repos := Repos} = rebar_resource_v2:find_resource_state(pkg, Resources),
BinName = rebar_utils:to_binary(RepoName),
- MaybeFound1 = get_repo(BinName, Repos),
+ Repos = all_repos(State),
+ MaybeFound1 = get_repo(BinName, all_repos(State)),
MaybeParentRepo = <<"hexpm:">>,
MaybeFound2 = get_repo(<>, Repos),
case {MaybeFound1, MaybeFound2} of
@@ -181,8 +186,6 @@ to_bool("false") -> false;
to_bool(_) -> true.
parent_repos(State) ->
- Resources = rebar_state:resources(State),
- #{repos := Repos} = rebar_resource_v2:find_resource_state(pkg, Resources),
Fun = fun(#{name := Name} = Repo, Acc) ->
[Parent|_] = rebar3_hex_io:str_split(Name, <<":">>),
case maps:is_key(Parent, Acc) of
@@ -192,9 +195,12 @@ parent_repos(State) ->
maps:put(name, Repo, Acc)
end
end,
- Map = lists:foldl(Fun, #{}, Repos),
+ Map = lists:foldl(Fun, #{}, all_repos(State)),
maps:values(Map).
+default_repo(State) ->
+ rebar_hex_repos:get_repo_config(?DEFAULT_HEX_REPO, all_repos(State)).
+
get_repo(BinaryName, Repos) ->
try rebar_hex_repos:get_repo_config(BinaryName, Repos) of
Name ->
@@ -232,10 +238,10 @@ hex_config_read(#{read_key := ReadKey} = HexConfig) ->
hex_config_read(_Config) ->
{error, no_read_key}.
-maybe_set_api_organization(#{name := Name} = Repo) ->
+maybe_set_api_organization(#{name := Name} = Repo) ->
case binary:split(Name, <<":">>) of
- [_] ->
+ [_] ->
Repo;
- [_,Org] ->
+ [_,Org] ->
Repo#{api_organization => Org}
end.
diff --git a/src/rebar3_hex_publish.erl b/src/rebar3_hex_publish.erl
index 42343be5..197194ab 100644
--- a/src/rebar3_hex_publish.erl
+++ b/src/rebar3_hex_publish.erl
@@ -401,9 +401,9 @@ publish(State, Repo, App, Args) ->
-dialyzer({nowarn_function, publish_package/4}).
publish_package(State, Repo, App, Args) ->
assert_valid_app(State, App),
- Package = create_package(State, Repo, App),
+ Package = create_package(State, App),
maybe_print_checkouts_warnings(App, Package),
- print_package_info(Package),
+ print_package_info(Package, Repo),
maybe_say_coc(Repo),
MaybeCheckoutWarnings = maybe_checkout_warnings(Package),
case maybe_prompt(Args, "Proceed" ++ MaybeCheckoutWarnings ++ "?") of
@@ -430,16 +430,16 @@ publish_package(State, Repo, App, Args) ->
abort
end.
-create_package(State, Repo, App) ->
- case rebar3_hex_build:create_package(State, Repo, App) of
+create_package(State, App) ->
+ case rebar3_hex_build:create_package(State, App) of
{ok, Package} ->
Package;
Err ->
?RAISE({create_package, Err})
end.
-print_package_info(Package) ->
- #{metadata := Meta, files := Files, deps := Deps, name := Name, repo_name := RepoName, version := Version} = Package,
+print_package_info(Package, #{name := RepoName} = _Repo) ->
+ #{metadata := Meta, files := Files, deps := Deps, name := Name, version := Version} = Package,
rebar3_hex_io:say("Publishing ~ts ~ts to ~ts", [Name, Version, RepoName]),
rebar3_hex_io:say(" Description: ~ts", [rebar_utils:to_list(maps:get(<<"description">>, Meta, <<"">>))]),
rebar3_hex_io:say(" Dependencies:~n ~ts", [format_deps(Deps)]),
diff --git a/test/rebar3_hex_build_SUITE.erl b/test/rebar3_hex_build_SUITE.erl
index 926fcc7d..aae97691 100644
--- a/test/rebar3_hex_build_SUITE.erl
+++ b/test/rebar3_hex_build_SUITE.erl
@@ -10,6 +10,7 @@ all() ->
create_package_with_git_deps_test,
create_package_with_alias_deps,
create_package_with_binary_versions,
+ create_docs_with_no_repo_set,
create_docs_test,
create_docs_unknown_provider_test,
create_docs_no_provider_test,
@@ -20,10 +21,9 @@ all() ->
create_package_test(Config) ->
StubConfig = #{type => app, dir => data_dir(Config), name => "valid"},
- {State, Repo, App} = test_utils:make_stub(StubConfig),
- {ok, #{tarball := Tarball} = Package} = rebar3_hex_build:create_package(State, Repo, App),
+ {State, _Repo, App} = test_utils:make_stub(StubConfig),
+ {ok, #{tarball := Tarball} = Package} = rebar3_hex_build:create_package(State, App),
?assert(maps:is_key(tarball, Package)),
- ?assert(maps:is_key(repo_name, Package)),
?assert(maps:is_key(version, Package)),
?assert(maps:is_key(files, Package)),
?assert(maps:is_key(has_checkouts, Package)),
@@ -38,9 +38,9 @@ create_package_test(Config) ->
[{N, P}|Acc];
_ ->
case file:read_file(P) of
- {ok, Bin} ->
+ {ok, Bin} ->
[{N, Bin}|Acc];
- _ ->
+ _ ->
Acc
end
end
@@ -51,18 +51,18 @@ create_package_test(Config) ->
create_package_with_git_deps_test(Config) ->
StubConfig = #{type => app, dir => data_dir(Config), name => "valid", profile => with_git_deps},
- {State, Repo, App} = test_utils:make_stub(StubConfig),
- {error, _} = rebar3_hex_build:create_package(State, Repo, App).
+ {State, _Repo, App} = test_utils:make_stub(StubConfig),
+ {error, _} = rebar3_hex_build:create_package(State, App).
create_package_with_binary_versions(Config) ->
StubConfig = #{type => app, dir => data_dir(Config), name => "valid", profile => with_binary_versions},
- {State, Repo, App} = test_utils:make_stub(StubConfig),
- {ok, _} = rebar3_hex_build:create_package(State, Repo, App).
+ {State, _Repo, App} = test_utils:make_stub(StubConfig),
+ {ok, _} = rebar3_hex_build:create_package(State, App).
create_package_with_alias_deps(Config) ->
StubConfig = #{type => app, dir => data_dir(Config), name => "valid", profile => with_alias_deps},
- {State, Repo, App} = test_utils:make_stub(StubConfig),
- {ok, _} = rebar3_hex_build:create_package(State, Repo, App).
+ {State, _Repo, App} = test_utils:make_stub(StubConfig),
+ {ok, _} = rebar3_hex_build:create_package(State, App).
create_docs_test(Config) ->
StubConfig = #{type => app, dir => data_dir(Config), name => "valid"},
@@ -90,7 +90,14 @@ create_docs_no_provider_test(Config) ->
StubConfig = #{type => app, dir => data_dir(Config), name => "no_doc_config"},
{State, Repo, App} = test_utils:make_stub(StubConfig),
Repo1 = maps:remove(doc, Repo),
- ?assertMatch({error, no_doc_config}, rebar3_hex_build:create_docs(State, Repo1, App)).
+ State1 = rebar_state:set(State, hex, [{repos, [Repo]}]),
+ ?assertMatch({error, no_doc_config}, rebar3_hex_build:create_docs(State1, Repo1, App)).
+
+create_docs_with_no_repo_set(Config) ->
+ StubConfig = #{type => app, dir => data_dir(Config), name => "no_repo_set"},
+ {State, _Repo, App} = test_utils:make_stub(StubConfig),
+ State1 = rebar_state:set(State, hex, [{doc, edoc}]),
+ ?assertMatch({ok, _}, rebar3_hex_build:create_docs(State1, #{name => <<"some_repo">>}, App)).
create_docs_doc_dir_test(Config) ->
#{dir := RootDir} = StubConfig = #{type => app, dir => data_dir(Config), name => "doc_attr"},
diff --git a/test/rebar3_hex_integration_SUITE.erl b/test/rebar3_hex_integration_SUITE.erl
index 5c0e4dee..302224d5 100644
--- a/test/rebar3_hex_integration_SUITE.erl
+++ b/test/rebar3_hex_integration_SUITE.erl
@@ -42,6 +42,9 @@ all() ->
, org_key_list_test
, org_list_test
, org_bad_command_test
+ , build_package_test
+ , build_docs_test
+ , build_test
, publish_test
, publish_no_prompt_test
, publish_package_with_pointless_app_arg_test
@@ -512,6 +515,38 @@ deauth_test(Config) ->
expects_repo_config(Setup),
?assertMatch({ok, State}, rebar3_hex_user:do(State)).
+build_package_test(Config) ->
+ P = #{
+ command => #{provider => rebar3_hex_build, args => ["package"]},
+ app => #{name => "valid"},
+ mocks => []
+ },
+ #{rebar_state := State} = Setup = setup_state(P, Config),
+ expects_repo_config(Setup),
+ ?assertMatch({ok, _}, rebar3_hex_build:do(State)).
+
+build_docs_test(Config) ->
+ P = #{
+ command => #{provider => rebar3_hex_build, args => ["docs"]},
+ app => #{name => "valid_docs"},
+ mocks => []
+ },
+ #{rebar_state := State, repo := _Repo} = Setup = setup_state(P, Config),
+ %State1 = rebar_state:set(State, hex, [{repos, [Repo]}, {doc, edoc}]),
+ expects_repo_config(Setup),
+ ?assertMatch({ok, _}, rebar3_hex_build:do(State)).
+
+
+build_test(Config) ->
+ P = #{
+ command => #{provider => rebar3_hex_build, args => []},
+ app => #{name => "valid"},
+ mocks => []
+ },
+ #{rebar_state := State} = Setup = setup_state(P, Config),
+ expects_repo_config(Setup),
+ ?assertMatch({ok, _}, rebar3_hex_build:do(State)).
+
publish_test(Config) ->
P = #{
command => #{provider => rebar3_hex_publish, args => []},
@@ -1100,7 +1135,7 @@ setup_state(P, Config) ->
lists:foreach(fun(W) -> setup_mocks_for(W, Setup) end, Mocks),
#{command := #{provider := Provider, args := Args}} = Setup,
- {ok, State1} = test_utils:mock_command(Provider, Args, [{repos, [Repo]}], State),
+ {ok, State1} = test_utils:mock_command(Provider, Args, [{repos, [Repo]}, {doc, edoc}], State),
Setup#{rebar_state => State1}.
@@ -1307,6 +1342,7 @@ expects_registration_confirmation_output(RepoName, Email) ->
expects_output([{TokenInfo, [RepoName]}, {ReqInfo, [Email]}]).
expects_repo_config(#{repo := Repo}) ->
+ meck:expect(rebar3_hex_config, all_repos, fun(_) -> [Repo] end),
meck:expect(rebar3_hex_config, repo, fun(_) -> {ok, Repo} end),
meck:expect(rebar3_hex_config, repo, fun(_, <<"hexpm">>) -> {ok, test_utils:default_config()} end).
@@ -1325,11 +1361,11 @@ expects_update_auth_config( #{username := Username, repo := Repo}) ->
expects_update_auth_config_for(RepoName) ->
Fun = fun(Cfg, State) ->
- case Cfg of
- #{RepoName := _Repo} ->
+ case Cfg of
+ #{RepoName := _Repo} ->
{ok, State};
- Got ->
- meck:exception(error, {expected, RepoName, got, Got})
+ Got ->
+ meck:exception(error, {expected, RepoName, got, Got})
end
end,
meck:expect(rebar3_hex_config, update_auth_config, Fun).
@@ -1438,7 +1474,7 @@ expect_local_password_prompt(#{password := Password, password_confirmation := Pa
Password;
<<"Local Password (confirm): ">> ->
PasswordConfirm;
- <<"New local Password: ">> ->
+ <<"New local Password: ">> ->
Password;
<<"New local Password (confirm): ">> ->
PasswordConfirm
diff --git a/test/support/test_utils.erl b/test/support/test_utils.erl
index fe25bada..20524e1d 100644
--- a/test/support/test_utils.erl
+++ b/test/support/test_utils.erl
@@ -66,7 +66,7 @@ make_stub(#{type := umbrella, dir := Dir, name := Name, apps := Apps} = StubConf
#{repo := Repo} = StubConfig1,
RootDir = filename:join(Dir, [Name]),
make_stub(StubConfig#{type => app, dir => Dir}),
- lists:foreach(fun(#{name := _AppName} = App) ->
+ lists:foreach(fun(#{name := _AppName} = App) ->
AppDir = filename:join(RootDir, ["apps/"]),
make_stub(App#{type => app, dir => AppDir})
end, Apps),
@@ -80,7 +80,7 @@ init_state(Dir, Repo, #{profile := Profile}) ->
LibDirs = rebar_dir:lib_dirs(State),
rebar_app_discover:do(State, LibDirs).
-put_defaults(Cfg) ->
+put_defaults(Cfg) ->
Cfg1 = maybe_put_default_repo(Cfg),
Cfg2 = maybe_put_default_profile(Cfg1),
maybe_put_default_app_src_spec(Cfg2).
@@ -128,18 +128,28 @@ write_lock_file(Dir, #{profile := Profile}) ->
write_config_file(Dir, #{profile := Profile}) ->
Filename = filename:join([Dir, "rebar.config"]),
ok = filelib:ensure_dir(Filename),
- ok = ec_file:write_term(Filename, config(Profile)).
+ ok = write_terms(Filename, config(Profile)).
+
+write_terms(FileName, Terms) ->
+ TermsStrs = [ format_term(T) || T <- Terms],
+ file:write_file(FileName, string:join(TermsStrs, " ")).
+
+format_term(Term) ->
+ lists:flatten(io_lib:fwrite("~p. ", [Term])).
config(default) ->
- {deps, [{hex_core, "0.8.2"}, {verl, "1.1.1"}]};
+ [
+ {hex, [{doc, edoc}]},
+ {deps, [{hex_core, "0.8.2"}, {verl, "1.1.1"}]}
+ ];
config(with_git_deps) ->
- {deps, [
+ [{deps, [
{hex_core, "0.8.2"}, {verl, "1.1.1"}, {rebar, {git, "git://github.com/erlang/rebar3.git"}}
- ]};
+ ]}];
config(with_binary_versions) ->
- {deps, [{hex_core, <<"0.8.2">>}, {verl, <<"1.1.1">>}]};
+ [{deps, [{hex_core, <<"0.8.2">>}, {verl, <<"1.1.1">>}]}];
config(with_alias_deps) ->
- {deps, [{hex_core}, {verl}]}.
+ [{deps, [{hex_core}, {verl}]}].
locks(with_binary_versions) ->
locks(default);
@@ -198,7 +208,7 @@ rebar_state(AppsDir, Repo, Deps) ->
{base_dir, filename:join([AppsDir, "_build"])},
{command_parsed_args, []},
{resources, []},
- {hex, [{repos, [Repo]}]}
+ {hex, [{repos, [Repo]}, {doc, edoc}]}
],
Config1 = rebar_config:merge_locks(Config, Deps),
State = rebar_state:new(Config1),