Skip to content

Commit 3043a80

Browse files
committed
update to work with latest rebar3 and able to run against all project apps
1 parent 6c2e5d6 commit 3043a80

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

src/pc_port_specs.erl

+14-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,20 @@ type(#spec{type = Type}) -> Type.
7777

7878
port_spec_from_legacy(Config) ->
7979
%% Get the target from the so_name variable
80-
AName = rebar_state:get(Config, so_name),
81-
Target = filename:join("priv", AName),
80+
Target = case rebar_state:get(Config, so_name, undefined) of
81+
undefined ->
82+
%% Generate a sensible default from app file
83+
AppName = case rebar_state:current_app(Config) of
84+
undefined ->
85+
throw({error, {pc_prv_compile, no_app}});
86+
CurrentApp ->
87+
rebar_app_info:name(CurrentApp)
88+
end,
89+
filename:join("priv", lists:concat([AppName, "_drv.so"]));
90+
AName ->
91+
filename:join("priv", AName)
92+
end,
93+
8294
%% Get the list of source files from port_sources
8395
Sources = port_sources(rebar_state:dir(Config), rebar_state:get(Config, port_sources, ["c_src/*.c"])),
8496
#spec { type = pc_util:target_type(Target),

src/pc_prv_compile.erl

+16-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,24 @@ init(State) ->
3333

3434
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
3535
do(State) ->
36-
{ok, PortSpecs} = pc_port_specs:construct(State),
37-
ok = pc_compilation:compile_and_link(State, PortSpecs),
36+
Apps = case rebar_state:current_app(State) of
37+
undefined ->
38+
rebar_state:project_apps(State);
39+
AppInfo ->
40+
[AppInfo]
41+
end,
42+
43+
[begin
44+
Opts = rebar_app_info:opts(AppInfo1),
45+
State1 = rebar_state:opts(State, Opts),
46+
{ok, PortSpecs} = pc_port_specs:construct(State1),
47+
ok = pc_compilation:compile_and_link(State1, PortSpecs)
48+
end || AppInfo1 <- Apps],
49+
3850
{ok, State}.
3951

4052
-spec format_error(any()) -> iolist().
53+
format_error(no_app) ->
54+
io_lib:format("No so_name or application defined.", []);
4155
format_error(Reason) ->
4256
io_lib:format("~p", [Reason]).

0 commit comments

Comments
 (0)