mirror of
https://github.com/correl/rebar.git
synced 2024-11-23 11:09:55 +00:00
Fix OS X resource fork handling (Reported-by: Richard O'Keefe)
If you happen to fetch a zip archive of the git repo and try to build from that, you may, for example, ask erlc to build src/._rebar.erl. ._* are OS X resource forks and not real .erl files. This may also happen with network filesystems on OS X. To fix that, limit the files compiled by rebar to include only those which start with a letter or a digit.
This commit is contained in:
parent
e8a6cfe04a
commit
3fb4a7c540
9 changed files with 28 additions and 16 deletions
|
@ -47,7 +47,9 @@ main(Args) ->
|
||||||
end,
|
end,
|
||||||
|
|
||||||
%% Compile all src/*.erl to ebin
|
%% Compile all src/*.erl to ebin
|
||||||
case make:files(filelib:wildcard("src/*.erl"),
|
%% To not accidentally try to compile files like Mac OS X resource forks,
|
||||||
|
%% we only look for rebar source files that start with a letter.
|
||||||
|
case make:files(filelib:wildcard("src/[a-zA-Z]*.erl"),
|
||||||
[{outdir, "ebin"}, {i, "include"},
|
[{outdir, "ebin"}, {i, "include"},
|
||||||
DebugFlag,
|
DebugFlag,
|
||||||
NamespacedTypes,
|
NamespacedTypes,
|
||||||
|
|
4
inttest/erlc/src/._do_not_compile.erl
Normal file
4
inttest/erlc/src/._do_not_compile.erl
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
syntax error
|
||||||
|
this is file is here to verify that rebar does not try to
|
||||||
|
compile files like OS X resource forks and should not be
|
||||||
|
processed at all
|
|
@ -70,7 +70,7 @@
|
||||||
|
|
||||||
%% Get a list of any appup files that exist in the new release
|
%% Get a list of any appup files that exist in the new release
|
||||||
NewAppUpFiles = rebar_utils:find_files(
|
NewAppUpFiles = rebar_utils:find_files(
|
||||||
filename:join([NewVerPath, "lib"]), "^.*.appup$"),
|
filename:join([NewVerPath, "lib"]), "^[^._].*.appup$"),
|
||||||
|
|
||||||
%% Convert the list of appup files into app names
|
%% Convert the list of appup files into app names
|
||||||
AppUpApps = [file_to_name(File) || File <- NewAppUpFiles],
|
AppUpApps = [file_to_name(File) || File <- NewAppUpFiles],
|
||||||
|
|
|
@ -28,8 +28,11 @@
|
||||||
|
|
||||||
-include("rebar.hrl").
|
-include("rebar.hrl").
|
||||||
|
|
||||||
-export([run/4, run/7, run/8,
|
-export([run/4,
|
||||||
ok_tuple/3, error_tuple/5]).
|
run/7,
|
||||||
|
run/8,
|
||||||
|
ok_tuple/3,
|
||||||
|
error_tuple/5]).
|
||||||
|
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
%% Public API
|
%% Public API
|
||||||
|
@ -60,7 +63,7 @@ run(Config, FirstFiles, SourceDir, SourceExt, TargetDir, TargetExt,
|
||||||
run(Config, FirstFiles, SourceDir, SourceExt, TargetDir, TargetExt,
|
run(Config, FirstFiles, SourceDir, SourceExt, TargetDir, TargetExt,
|
||||||
Compile3Fn, Opts) ->
|
Compile3Fn, Opts) ->
|
||||||
%% Convert simple extension to proper regex
|
%% Convert simple extension to proper regex
|
||||||
SourceExtRe = ".*\\" ++ SourceExt ++ [$$],
|
SourceExtRe = "^[^._].*\\" ++ SourceExt ++ [$$],
|
||||||
|
|
||||||
Recursive = proplists:get_value(recursive, Opts, true),
|
Recursive = proplists:get_value(recursive, Opts, true),
|
||||||
%% Find all possible source files
|
%% Find all possible source files
|
||||||
|
|
|
@ -593,8 +593,7 @@ load_plugin_modules(Config, PredirsAssoc, Modules) ->
|
||||||
?DEBUG("Plugin dirs for ~s:~n~p~n", [Cwd, PluginDirs]),
|
?DEBUG("Plugin dirs for ~s:~n~p~n", [Cwd, PluginDirs]),
|
||||||
|
|
||||||
%% Find relevant sources in base_dir and plugin_dir
|
%% Find relevant sources in base_dir and plugin_dir
|
||||||
Erls = string:join([atom_to_list(M)++"\\.erl" || M <- Modules], "|"),
|
RE = string:join([atom_to_list(M)++"\\.erl" || M <- Modules], "|"),
|
||||||
RE = "^" ++ Erls ++ "\$",
|
|
||||||
%% If a plugin is found both in base_dir and plugin_dir, the clash
|
%% If a plugin is found both in base_dir and plugin_dir, the clash
|
||||||
%% will provoke an error and we'll abort.
|
%% will provoke an error and we'll abort.
|
||||||
Sources = [rebar_utils:find_files(PD, RE, false) || PD <- PluginDirs],
|
Sources = [rebar_utils:find_files(PD, RE, false) || PD <- PluginDirs],
|
||||||
|
|
|
@ -47,6 +47,8 @@
|
||||||
info = {[], []} :: erlc_info()
|
info = {[], []} :: erlc_info()
|
||||||
}).
|
}).
|
||||||
|
|
||||||
|
-define(RE_PREFIX, "^[^._]").
|
||||||
|
|
||||||
-ifdef(namespaced_types).
|
-ifdef(namespaced_types).
|
||||||
%% digraph:graph() exists starting from Erlang 17.
|
%% digraph:graph() exists starting from Erlang 17.
|
||||||
-type rebar_digraph() :: digraph:graph().
|
-type rebar_digraph() :: digraph:graph().
|
||||||
|
@ -110,14 +112,14 @@ compile(Config, _AppFile) ->
|
||||||
|
|
||||||
-spec clean(rebar_config:config(), file:filename()) -> 'ok'.
|
-spec clean(rebar_config:config(), file:filename()) -> 'ok'.
|
||||||
clean(Config, _AppFile) ->
|
clean(Config, _AppFile) ->
|
||||||
MibFiles = rebar_utils:find_files("mibs", "^.*\\.mib\$"),
|
MibFiles = rebar_utils:find_files("mibs", ?RE_PREFIX".*\\.mib\$"),
|
||||||
MIBs = [filename:rootname(filename:basename(MIB)) || MIB <- MibFiles],
|
MIBs = [filename:rootname(filename:basename(MIB)) || MIB <- MibFiles],
|
||||||
rebar_file_utils:delete_each(
|
rebar_file_utils:delete_each(
|
||||||
[filename:join(["include",MIB++".hrl"]) || MIB <- MIBs]),
|
[filename:join(["include",MIB++".hrl"]) || MIB <- MIBs]),
|
||||||
lists:foreach(fun(F) -> ok = rebar_file_utils:rm_rf(F) end,
|
lists:foreach(fun(F) -> ok = rebar_file_utils:rm_rf(F) end,
|
||||||
["ebin/*.beam", "priv/mibs/*.bin"]),
|
["ebin/*.beam", "priv/mibs/*.bin"]),
|
||||||
|
|
||||||
YrlFiles = rebar_utils:find_files("src", "^.*\\.[x|y]rl\$"),
|
YrlFiles = rebar_utils:find_files("src", ?RE_PREFIX".*\\.[x|y]rl\$"),
|
||||||
rebar_file_utils:delete_each(
|
rebar_file_utils:delete_each(
|
||||||
[ binary_to_list(iolist_to_binary(re:replace(F, "\\.[x|y]rl$", ".erl")))
|
[ binary_to_list(iolist_to_binary(re:replace(F, "\\.[x|y]rl$", ".erl")))
|
||||||
|| F <- YrlFiles ]),
|
|| F <- YrlFiles ]),
|
||||||
|
@ -129,7 +131,7 @@ clean(Config, _AppFile) ->
|
||||||
%% directory structure in ebin with .beam files within. As such, we want
|
%% directory structure in ebin with .beam files within. As such, we want
|
||||||
%% to scan whatever is left in the ebin/ directory for sub-dirs which
|
%% to scan whatever is left in the ebin/ directory for sub-dirs which
|
||||||
%% satisfy our criteria.
|
%% satisfy our criteria.
|
||||||
BeamFiles = rebar_utils:find_files("ebin", "^.*\\.beam\$"),
|
BeamFiles = rebar_utils:find_files("ebin", ?RE_PREFIX".*\\.beam\$"),
|
||||||
rebar_file_utils:delete_each(BeamFiles),
|
rebar_file_utils:delete_each(BeamFiles),
|
||||||
lists:foreach(fun(Dir) -> delete_dir(Dir, dirs(Dir)) end, dirs("ebin")),
|
lists:foreach(fun(Dir) -> delete_dir(Dir, dirs(Dir)) end, dirs("ebin")),
|
||||||
ok.
|
ok.
|
||||||
|
@ -140,7 +142,7 @@ clean(Config, _AppFile) ->
|
||||||
|
|
||||||
test_compile(Config, Cmd, OutDir) ->
|
test_compile(Config, Cmd, OutDir) ->
|
||||||
%% Obtain all the test modules for inclusion in the compile stage.
|
%% Obtain all the test modules for inclusion in the compile stage.
|
||||||
TestErls = rebar_utils:find_files("test", ".*\\.erl\$"),
|
TestErls = rebar_utils:find_files("test", ?RE_PREFIX".*\\.erl\$"),
|
||||||
|
|
||||||
ErlOpts = rebar_utils:erl_opts(Config),
|
ErlOpts = rebar_utils:erl_opts(Config),
|
||||||
{Config1, ErlOpts1} = test_compile_config_and_opts(Config, ErlOpts, Cmd),
|
{Config1, ErlOpts1} = test_compile_config_and_opts(Config, ErlOpts, Cmd),
|
||||||
|
@ -151,7 +153,8 @@ test_compile(Config, Cmd, OutDir) ->
|
||||||
SrcDirs = rebar_utils:src_dirs(proplists:append_values(src_dirs, ErlOpts1)),
|
SrcDirs = rebar_utils:src_dirs(proplists:append_values(src_dirs, ErlOpts1)),
|
||||||
SrcErls = lists:foldl(
|
SrcErls = lists:foldl(
|
||||||
fun(Dir, Acc) ->
|
fun(Dir, Acc) ->
|
||||||
Files = rebar_utils:find_files(Dir, ".*\\.erl\$"),
|
Files = rebar_utils:find_files(
|
||||||
|
Dir, ?RE_PREFIX".*\\.erl\$"),
|
||||||
lists:append(Acc, Files)
|
lists:append(Acc, Files)
|
||||||
end, [], SrcDirs),
|
end, [], SrcDirs),
|
||||||
|
|
||||||
|
@ -645,7 +648,8 @@ compile_xrl_yrl(Config, Source, Target, Opts, Mod) ->
|
||||||
gather_src([], Srcs) ->
|
gather_src([], Srcs) ->
|
||||||
Srcs;
|
Srcs;
|
||||||
gather_src([Dir|Rest], Srcs) ->
|
gather_src([Dir|Rest], Srcs) ->
|
||||||
gather_src(Rest, Srcs ++ rebar_utils:find_files(Dir, ".*\\.erl\$")).
|
gather_src(
|
||||||
|
Rest, Srcs ++ rebar_utils:find_files(Dir, ?RE_PREFIX".*\\.erl\$")).
|
||||||
|
|
||||||
-spec dirs(file:filename()) -> [file:filename()].
|
-spec dirs(file:filename()) -> [file:filename()].
|
||||||
dirs(Dir) ->
|
dirs(Dir) ->
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
|
||||||
compile(Config, _AppFile) ->
|
compile(Config, _AppFile) ->
|
||||||
case rebar_utils:find_files("src", ".*\\.proto$") of
|
case rebar_utils:find_files("src", "^[^._].*\\.proto$") of
|
||||||
[] ->
|
[] ->
|
||||||
ok;
|
ok;
|
||||||
FoundFiles ->
|
FoundFiles ->
|
||||||
|
|
|
@ -208,7 +208,7 @@ qc_module(QC=eqc, [], M) -> QC:module(M);
|
||||||
qc_module(QC=eqc, QCOpts, M) -> QC:module(QCOpts, M).
|
qc_module(QC=eqc, QCOpts, M) -> QC:module(QCOpts, M).
|
||||||
|
|
||||||
find_prop_mods() ->
|
find_prop_mods() ->
|
||||||
Beams = rebar_utils:find_files(?QC_DIR, ".*\\.beam\$"),
|
Beams = rebar_utils:find_files(?QC_DIR, "^[^._].*\\.beam\$"),
|
||||||
[M || M <- [rebar_utils:erl_to_mod(Beam) || Beam <- Beams], has_prop(M)].
|
[M || M <- [rebar_utils:erl_to_mod(Beam) || Beam <- Beams], has_prop(M)].
|
||||||
|
|
||||||
has_prop(Mod) ->
|
has_prop(Mod) ->
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
|
|
||||||
-include("rebar.hrl").
|
-include("rebar.hrl").
|
||||||
|
|
||||||
-define(TEMPLATE_RE, ".*\\.template\$").
|
-define(TEMPLATE_RE, "^[^._].*\\.template\$").
|
||||||
|
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
%% Public API
|
%% Public API
|
||||||
|
|
Loading…
Reference in a new issue