8000 Honor app switch when used in umbrella for build task by starbelly · Pull Request #349 · erlef/rebar3_hex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Honor app switch when used in umbrella for build task #349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/rebar3_hex_build.erl
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ format_error(repo_required_for_docs) ->
" rebar3 hex build package if you only need to build a package.",
io_lib:format(Str, []);

format_error({app_not_found, AppName}) ->
io_lib:format("App ~s specified with --app switch not found in project", [AppName]);

format_error(app_switch_required) ->
"--app switch is required when building packages or docs in a umbrella with multiple apps";

Expand All @@ -230,6 +233,14 @@ doc_missing_index_message() ->
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 := [_,_|_] = Apps, args := #{app := AppName}} = T) ->
case rebar3_hex_app:find(Apps, AppName) of
{ok, App} ->
handle_task(T#{apps := [App]});
_Error ->
?RAISE({app_not_found, AppName})
end;

handle_task(#{apps := [_,_|_]}) ->
?RAISE(app_switch_required);

Expand Down
64 changes: 63 additions & 1 deletion test/rebar3_hex_integration_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ all() ->
, org_list_test
, org_bad_command_test
, build_package_test
, build_umbrella_package_test
, build_umbrella_package_bad_name_test
, build_docs_test
, build_umbrella_docs_test
, build_umbrella_docs_bad_name_test
, build_test
, publish_test
, publish_no_prompt_test
Expand Down Expand Up @@ -525,17 +529,75 @@ build_package_test(Config) ->
expects_repo_config(Setup),
?assertMatch({ok, _}, rebar3_hex_build:do(State)).

build_umbrella_package_test(Config) ->
P = #{
command => #{provider => rebar3_hex_build, args => ["--app", "foo"]},
umbrella => #{
name => "umbrella",
apps => [#{name => "foo", selected => true}, #{name => "bar"}, #{name => "baz"}]
},
mocks => []
},

#{rebar_state := State} = Setup = setup_state(P, Config),
expects_repo_config(Setup),
?assertMatch({ok, _}, rebar3_hex_build:do(State)).

build_umbrella_package_bad_name_test(Config) ->
P = #{
command => #{provider => rebar3_hex_build, args => ["--app", "eh"]},
umbrella => #{
name => "umbrella",
apps => [#{name => "foo", selected => true}, #{name => "bar"}, #{name => "baz"}]
},
mocks => []
},

#{rebar_state := State} = Setup = setup_state(P, Config),
expects_repo_config(Setup),
Exp = {error,{rebar3_hex_build,{app_not_found,"eh"}}},
?assertError(Exp, 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_umbrella_docs_test(Config) ->
P = #{
command => #{provider => rebar3_hex_build, args => ["docs", "--app", "foo"]},
umbrella => #{
name => "umbrella",
apps => [#{name => "foo", selected => true}, #{name => "bar"}, #{name => "baz"}]
},
mocks => []
},

#{rebar_state := State} = Setup = setup_state(P, Config),
expects_repo_config(Setup),
?assertMatch({ok, _}, rebar3_hex_build:do(State)).

build_umbrella_docs_bad_name_test(Config) ->
P = #{
command => #{provider => rebar3_hex_build, args => ["docs", "--app", "eh"]},
umbrella => #{
name => "umbrella",
apps => [#{name => "foo", selected => true}, #{name => "bar"}, #{name => "baz"}]
},
mocks => []
},

#{rebar_state := State} = Setup = setup_state(P, Config),
expects_repo_config(Setup),
Exp = {error,{rebar3_hex_build,{app_not_found,"eh"}}},
?assertError(Exp, rebar3_hex_build:do(State)).


build_test(Config) ->
P = #{
Expand Down
0