Skip to content

Support resources of arbitrary size in rebar3 #2956

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions apps/rebar/src/rebar_resource_v2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,16 @@ format_error({no_resource, Source}) ->
is_resource_type(Type, Resources) ->
lists:any(fun(#resource{type=T}) -> T =:= Type end, Resources).

-spec get_resource_type(term(), [resource()]) -> {ok, resource()}.
-spec get_resource_type(tuple(), [resource()]) -> {ok, resource()}.
get_resource_type({Type, Location}, Resources) ->
get_resource(Type, Location, Resources);
get_resource_type({Type, Location, _}, Resources) ->
get_resource(Type, Location, Resources);
get_resource_type({Type, _, _, Location}, Resources) ->
get_resource(Type, Location, Resources);
get_resource_type(Location={Type, _, _, _, _, _}, Resources) ->
get_resource(Type, Location, Resources);
get_resource_type(Source, Resources) when tuple_size(Source) > 3 ->
Type = element(1, Source),
get_resource(Type, Source, Resources);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Location and Source aren't the same. In some cases the Location is pulled out of the tuple.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! The reason I originally flattened everything is that a custom resource of size 2-4 can have whatever it likes in its tuple elements, so I thought that being picky about Source and Location is maybe too specific, especially if all this generates is an error message (which may not be the case).

I restored the existing clauses, and merely extended the size 6 case to cover all sizes > 4. The main motivation for the PR is to properly add support a custom resource I am using for some private code, which needs 5 args and previously raised a mere Failed to fetch and copy dep:.

get_resource_type(Source, _) ->
throw(?PRV_ERROR({no_resource, Source})).

Expand Down
Loading