From 22b88bd393a9e82ad3ff74956f39c63791f96586 Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Mon, 11 Nov 2019 11:05:07 +0100 Subject: [PATCH] Add stdlib include handling when inside an escript --- src/aeso_parser.erl | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/aeso_parser.erl b/src/aeso_parser.erl index 3bb789a..06a3c43 100644 --- a/src/aeso_parser.erl +++ b/src/aeso_parser.erl @@ -619,11 +619,28 @@ read_file(File, Opts) -> case maps:get(binary_to_list(File), Files, not_found) of not_found -> {error, not_found}; Src -> {ok, Src} + end; + escript -> + try + Escript = escript:script_name(), + {ok, Sections} = escript:extract(Escript, []), + Archive = proplists:get_value(archive, Sections), + FileName = binary_to_list(filename:join([aesophia, priv, stdlib, File])), + case zip:extract(Archive, [{file_list, [FileName]}, memory]) of + {ok, [{_, Src}]} -> {ok, Src}; + _ -> {error, not_found} + end + catch _:_ -> + {error, not_found} end end. stdlib_options() -> - [{include, {file_system, [aeso_stdlib:stdlib_include_path()]}}]. + StdLibDir = aeso_stdlib:stdlib_include_path(), + case filelib:is_dir(StdLibDir) of + true -> [{include, {file_system, [StdLibDir]}}]; + false -> [{include, escript}] + end. get_include_code(File, Ann, Opts) -> case {read_file(File, Opts), read_file(File, stdlib_options())} of