From 07a4a14af6a88a47bed3af994d1814b3045777c8 Mon Sep 17 00:00:00 2001 From: David Kubecka Date: Sun, 5 Apr 2015 01:34:25 +0200 Subject: [PATCH] Fix error when processing non-existent include_lib file Since process_attr/3 searches source code for attributes, it can happen that it finds an attribute which is eventually not needed by the compilation, e.g. hidden by ifdef macro - see enclosed test. Such attribute can reference a file which is not in the path or which even doesn't exist at all, and current code doesn't expect such a situation. We fix things by simply ignoring such files. --- inttest/erlc_dep_graph/src/lisp.erl | 3 +++ src/rebar_erlc_compiler.erl | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/inttest/erlc_dep_graph/src/lisp.erl b/inttest/erlc_dep_graph/src/lisp.erl index eceb157..31fc8b5 100644 --- a/inttest/erlc_dep_graph/src/lisp.erl +++ b/inttest/erlc_dep_graph/src/lisp.erl @@ -5,6 +5,9 @@ -export([parse_transform/2]). -include("lambda.hrl"). +-ifdef(NOT_DEFINED). +-include_lib("include/non/existent.hrl"). +-endif. parse_transform(Forms, _Options) -> Forms. diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index dd49b2e..6a1bbe5 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -594,8 +594,7 @@ process_attr(include, Form, Includes) -> process_attr(include_lib, Form, Includes) -> [FileNode] = erl_syntax:attribute_arguments(Form), RawFile = erl_syntax:string_value(FileNode), - File = maybe_expand_include_lib_path(RawFile), - [File|Includes]; + maybe_expand_include_lib_path(RawFile) ++ Includes; process_attr(behaviour, Form, Includes) -> [FileNode] = erl_syntax:attribute_arguments(Form), File = module_to_erl(erl_syntax:atom_value(FileNode)), @@ -631,7 +630,7 @@ module_to_erl(Mod) -> maybe_expand_include_lib_path(File) -> case filelib:is_regular(File) of true -> - File; + [File]; false -> expand_include_lib_path(File) end. @@ -646,8 +645,10 @@ expand_include_lib_path(File) -> Split = filename:split(filename:dirname(File)), Lib = hd(Split), SubDir = filename:join(tl(Split)), - Dir = code:lib_dir(list_to_atom(Lib), list_to_atom(SubDir)), - filename:join(Dir, File1). + case code:lib_dir(list_to_atom(Lib), list_to_atom(SubDir)) of + {error, bad_name} -> []; + Dir -> [filename:join(Dir, File1)] + end. %% %% Ensure all files in a list are present and abort if one is missing