Fix include path not being added if giving explicit options
This commit is contained in:
parent
6a59e455ce
commit
dc5fd74934
@ -9,7 +9,9 @@
|
||||
|
||||
-module(aeso_aci).
|
||||
|
||||
-export([ contract_interface/2
|
||||
-export([ file/2
|
||||
, file/3
|
||||
, contract_interface/2
|
||||
, contract_interface/3
|
||||
|
||||
, render_aci_json/1
|
||||
@ -22,6 +24,18 @@
|
||||
-type json_text() :: binary().
|
||||
|
||||
%% External API
|
||||
-spec file(aci_type(), string()) -> {ok, json() | string()} | {error, term()}.
|
||||
file(Type, File) ->
|
||||
file(Type, File, []).
|
||||
|
||||
file(Type, File, Options0) ->
|
||||
Options = aeso_compiler:add_include_path(File, Options0),
|
||||
case file:read_file(File) of
|
||||
{ok, BinCode} ->
|
||||
do_contract_interface(Type, binary_to_list(BinCode), Options);
|
||||
{error, _} = Err -> Err
|
||||
end.
|
||||
|
||||
-spec contract_interface(aci_type(), string()) ->
|
||||
{ok, json() | string()} | {error, term()}.
|
||||
contract_interface(Type, ContractString) ->
|
||||
|
@ -21,6 +21,7 @@
|
||||
, decode_calldata/3 %% deprecated
|
||||
, decode_calldata/4
|
||||
, parse/2
|
||||
, add_include_path/2
|
||||
]).
|
||||
|
||||
-include_lib("aebytecode/include/aeb_opcodes.hrl").
|
||||
@ -65,12 +66,11 @@ version() ->
|
||||
|
||||
-spec file(string()) -> {ok, map()} | {error, binary()}.
|
||||
file(Filename) ->
|
||||
Dir = filename:dirname(Filename),
|
||||
{ok, Cwd} = file:get_cwd(),
|
||||
file(Filename, [{include, {file_system, [Cwd, Dir]}}]).
|
||||
file(Filename, []).
|
||||
|
||||
-spec file(string(), options()) -> {ok, map()} | {error, binary()}.
|
||||
file(File, Options) ->
|
||||
file(File, Options0) ->
|
||||
Options = add_include_path(File, Options0),
|
||||
case read_contract(File) of
|
||||
{ok, Bin} -> from_string(Bin, [{src_file, File} | Options]);
|
||||
{error, Error} ->
|
||||
@ -78,6 +78,15 @@ file(File, Options) ->
|
||||
{error, join_errors("File errors", [ErrorString], fun(E) -> E end)}
|
||||
end.
|
||||
|
||||
add_include_path(File, Options) ->
|
||||
case lists:keymember(include, 1, Options) of
|
||||
true -> Options;
|
||||
false ->
|
||||
Dir = filename:dirname(File),
|
||||
{ok, Cwd} = file:get_cwd(),
|
||||
[{include, {file_system, [Cwd, Dir]}} | Options]
|
||||
end.
|
||||
|
||||
-spec from_string(binary() | string(), options()) -> {ok, map()} | {error, binary()}.
|
||||
from_string(Contract, Options) ->
|
||||
from_string(proplists:get_value(backend, Options, aevm), Contract, Options).
|
||||
|
Loading…
x
Reference in New Issue
Block a user