Improve resolution of relative includes #980

Merged
zxq9 merged 6 commits from fix_relative_includes into master 2023-09-14 22:00:30 +09:00
2 changed files with 14 additions and 2 deletions
Showing only changes of commit f94a37b02a - Show all commits

View File

@ -99,7 +99,7 @@ add_include_path(File, Options) ->
false -> false ->
Dir = filename:dirname(File), Dir = filename:dirname(File),
{ok, Cwd} = file:get_cwd(), {ok, Cwd} = file:get_cwd(),
[{include, {file_system, [Cwd, Dir]}} | Options] [{include, {file_system, [Cwd, aeso_utils:canonical_dir(Dir)]}} | Options]
end. end.
-spec from_string(binary() | string(), options()) -> {ok, map()} | {error, [aeso_errors:error()]}. -spec from_string(binary() | string(), options()) -> {ok, map()} | {error, [aeso_errors:error()]}.

View File

@ -6,10 +6,22 @@
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
-module(aeso_utils). -module(aeso_utils).
-export([scc/1]). -export([scc/1, canonical_dir/1]).
-export_type([graph/1]). -export_type([graph/1]).
%% -- Simplistic canonical directory
%% Note: no attempts to be 100% complete
canonical_dir(Dir) ->
{ok, Cwd} = file:get_cwd(),
AbsName = filename:absname(Dir),
RelAbsName = filename:join(tl(filename:split(AbsName))),
case filelib:safe_relative_path(RelAbsName, Cwd) of
unsafe -> AbsName;
Simplified -> filename:absname(Simplified, "")
end.
%% -- Topological sort %% -- Topological sort
-type graph(Node) :: #{Node => [Node]}. %% List of incoming edges (dependencies). -type graph(Node) :: #{Node => [Node]}. %% List of incoming edges (dependencies).