Fix include path not being added if giving explicit options

This commit is contained in:
Ulf Norell 2019-06-28 09:33:08 +02:00
parent 6a59e455ce
commit dc5fd74934
2 changed files with 28 additions and 5 deletions

View File

@ -9,7 +9,9 @@
-module(aeso_aci). -module(aeso_aci).
-export([ contract_interface/2 -export([ file/2
, file/3
, contract_interface/2
, contract_interface/3 , contract_interface/3
, render_aci_json/1 , render_aci_json/1
@ -22,6 +24,18 @@
-type json_text() :: binary(). -type json_text() :: binary().
%% External API %% 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()) -> -spec contract_interface(aci_type(), string()) ->
{ok, json() | string()} | {error, term()}. {ok, json() | string()} | {error, term()}.
contract_interface(Type, ContractString) -> contract_interface(Type, ContractString) ->

View File

@ -21,6 +21,7 @@
, decode_calldata/3 %% deprecated , decode_calldata/3 %% deprecated
, decode_calldata/4 , decode_calldata/4
, parse/2 , parse/2
, add_include_path/2
]). ]).
-include_lib("aebytecode/include/aeb_opcodes.hrl"). -include_lib("aebytecode/include/aeb_opcodes.hrl").
@ -65,12 +66,11 @@ version() ->
-spec file(string()) -> {ok, map()} | {error, binary()}. -spec file(string()) -> {ok, map()} | {error, binary()}.
file(Filename) -> file(Filename) ->
Dir = filename:dirname(Filename), file(Filename, []).
{ok, Cwd} = file:get_cwd(),
file(Filename, [{include, {file_system, [Cwd, Dir]}}]).
-spec file(string(), options()) -> {ok, map()} | {error, binary()}. -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 case read_contract(File) of
{ok, Bin} -> from_string(Bin, [{src_file, File} | Options]); {ok, Bin} -> from_string(Bin, [{src_file, File} | Options]);
{error, Error} -> {error, Error} ->
@ -78,6 +78,15 @@ file(File, Options) ->
{error, join_errors("File errors", [ErrorString], fun(E) -> E end)} {error, join_errors("File errors", [ErrorString], fun(E) -> E end)}
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()}. -spec from_string(binary() | string(), options()) -> {ok, map()} | {error, binary()}.
from_string(Contract, Options) -> from_string(Contract, Options) ->
from_string(proplists:get_value(backend, Options, aevm), Contract, Options). from_string(proplists:get_value(backend, Options, aevm), Contract, Options).