浏览代码

include app.src.script in app discover and always use if available

pull/654/head
Tristan Sloughter 9 年前
父节点
当前提交
806f7f9219
共有 5 个文件被更改,包括 59 次插入13 次删除
  1. +18
    -6
      src/rebar_app_discover.erl
  2. +19
    -0
      src/rebar_app_info.erl
  3. +8
    -1
      src/rebar_app_utils.erl
  4. +2
    -1
      src/rebar_config.erl
  5. +12
    -5
      src/rebar_otp_app.erl

+ 18
- 6
src/rebar_app_discover.erl 查看文件

@ -102,13 +102,17 @@ app_dirs(LibDir) ->
"*.app.src"]), "*.app.src"]),
Path2 = filename:join([LibDir, Path2 = filename:join([LibDir,
"src",
"*.app.src.script"]),
Path3 = filename:join([LibDir,
"ebin", "ebin",
"*.app"]), "*.app"]),
lists:usort(lists:foldl(fun(Path, Acc) -> lists:usort(lists:foldl(fun(Path, Acc) ->
Files = filelib:wildcard(ec_cnv:to_list(Path)), Files = filelib:wildcard(ec_cnv:to_list(Path)),
[app_dir(File) || File <- Files] ++ Acc [app_dir(File) || File <- Files] ++ Acc
end, [], [Path1, Path2])).
end, [], [Path1, Path2, Path3])).
find_unbuilt_apps(LibDirs) -> find_unbuilt_apps(LibDirs) ->
find_apps(LibDirs, invalid). find_apps(LibDirs, invalid).
@ -127,7 +131,8 @@ find_apps(LibDirs, Validate) ->
find_app(AppDir, Validate) -> find_app(AppDir, Validate) ->
AppFile = filelib:wildcard(filename:join([AppDir, "ebin", "*.app"])), AppFile = filelib:wildcard(filename:join([AppDir, "ebin", "*.app"])),
AppSrcFile = filelib:wildcard(filename:join([AppDir, "src", "*.app.src"])), AppSrcFile = filelib:wildcard(filename:join([AppDir, "src", "*.app.src"])),
AppInfo = try_handle_app_file(AppFile, AppDir, AppSrcFile, Validate),
AppSrcScriptFile = filelib:wildcard(filename:join([AppDir, "src", "*.app.src.script"])),
AppInfo = try_handle_app_file(AppFile, AppDir, AppSrcFile, AppSrcScriptFile, Validate),
AppInfo. AppInfo.
app_dir(AppFile) -> app_dir(AppFile) ->
@ -158,9 +163,11 @@ dedup([H|T]) -> [H|dedup(T)].
%% Read in and parse the .app file if it is availabe. Do the same for %% Read in and parse the .app file if it is availabe. Do the same for
%% the .app.src file if it exists. %% the .app.src file if it exists.
try_handle_app_file([], AppDir, AppSrcFile, Validate) ->
try_handle_app_file([], AppDir, [], AppSrcScriptFile, Validate) ->
try_handle_app_src_file([], AppDir, AppSrcScriptFile, Validate);
try_handle_app_file([], AppDir, AppSrcFile, _, Validate) ->
try_handle_app_src_file([], AppDir, AppSrcFile, Validate); try_handle_app_src_file([], AppDir, AppSrcFile, Validate);
try_handle_app_file([File], AppDir, AppSrcFile, Validate) ->
try_handle_app_file([File], AppDir, AppSrcFile, _, Validate) ->
try create_app_info(AppDir, File) of try create_app_info(AppDir, File) of
AppInfo -> AppInfo ->
AppInfo1 = rebar_app_info:app_file(AppInfo, File), AppInfo1 = rebar_app_info:app_file(AppInfo, File),
@ -195,7 +202,7 @@ try_handle_app_file([File], AppDir, AppSrcFile, Validate) ->
?DEBUG("Falling back to app.src file because .app failed: ~s", [Module:format_error(Reason)]), ?DEBUG("Falling back to app.src file because .app failed: ~s", [Module:format_error(Reason)]),
try_handle_app_src_file(File, AppDir, AppSrcFile, Validate) try_handle_app_src_file(File, AppDir, AppSrcFile, Validate)
end; end;
try_handle_app_file(Other, _AppDir, _AppSrcFile, _Validate) ->
try_handle_app_file(Other, _AppDir, _AppSrcFile, _, _Validate) ->
throw({error, {multiple_app_files, Other}}). throw({error, {multiple_app_files, Other}}).
%% Read in the .app.src file if we aren't looking for a valid (already built) app %% Read in the .app.src file if we aren't looking for a valid (already built) app
@ -210,7 +217,12 @@ try_handle_app_src_file(_, AppDir, [File], Validate) when Validate =:= invalid
{error, Reason} -> {error, Reason} ->
throw({error, {invalid_app_file, File, Reason}}); throw({error, {invalid_app_file, File, Reason}});
_ -> _ ->
{true, rebar_app_info:app_file_src(AppInfo, File)}
case filename:extension(File) of
".script" ->
{true, rebar_app_info:app_file_src_script(AppInfo, File)};
_ ->
{true, rebar_app_info:app_file_src(AppInfo, File)}
end
end; end;
try_handle_app_src_file(_, _AppDir, Other, _Validate) -> try_handle_app_src_file(_, _AppDir, Other, _Validate) ->
throw({error, {multiple_app_files, Other}}). throw({error, {multiple_app_files, Other}}).

+ 19
- 0
src/rebar_app_info.erl 查看文件

@ -11,6 +11,8 @@
config/2, config/2,
app_file_src/1, app_file_src/1,
app_file_src/2, app_file_src/2,
app_file_src_script/1,
app_file_src_script/2,
app_file/1, app_file/1,
app_file/2, app_file/2,
app_details/1, app_details/1,
@ -48,6 +50,7 @@
-record(app_info_t, {name :: binary(), -record(app_info_t, {name :: binary(),
app_file_src :: file:filename_all() | undefined, app_file_src :: file:filename_all() | undefined,
app_file_src_script:: file:filename_all() | undefined,
app_file :: file:filename_all() | undefined, app_file :: file:filename_all() | undefined,
config :: rebar_state:t() | undefined, config :: rebar_state:t() | undefined,
original_vsn :: binary() | string() | undefined, original_vsn :: binary() | string() | undefined,
@ -146,6 +149,22 @@ app_file_src(#app_info_t{app_file_src=AppFileSrc}) ->
app_file_src(AppInfo=#app_info_t{}, AppFileSrc) -> app_file_src(AppInfo=#app_info_t{}, AppFileSrc) ->
AppInfo#app_info_t{app_file_src=ec_cnv:to_list(AppFileSrc)}. AppInfo#app_info_t{app_file_src=ec_cnv:to_list(AppFileSrc)}.
-spec app_file_src_script(t()) -> file:filename_all() | undefined.
app_file_src_script(#app_info_t{app_file_src_script=undefined, dir=Dir, name=Name}) ->
AppFileSrcScript = filename:join([ec_cnv:to_list(Dir), "src", ec_cnv:to_list(Name)++".app.src.script"]),
case filelib:is_file(AppFileSrcScript) of
true ->
AppFileSrcScript;
false ->
undefined
end;
app_file_src_script(#app_info_t{app_file_src_script=AppFileSrcScript}) ->
ec_cnv:to_list(AppFileSrcScript).
-spec app_file_src_script(t(), file:filename_all()) -> t().
app_file_src_script(AppInfo=#app_info_t{}, AppFileSrcScript) ->
AppInfo#app_info_t{app_file_src_script=ec_cnv:to_list(AppFileSrcScript)}.
-spec app_file(t()) -> file:filename_all() | undefined. -spec app_file(t()) -> file:filename_all() | undefined.
app_file(#app_info_t{app_file=undefined, out_dir=Dir, name=Name}) -> app_file(#app_info_t{app_file=undefined, out_dir=Dir, name=Name}) ->
AppFile = filename:join([ec_cnv:to_list(Dir), "ebin", ec_cnv:to_list(Name)++".app"]), AppFile = filename:join([ec_cnv:to_list(Dir), "ebin", ec_cnv:to_list(Name)++".app"]),

+ 8
- 1
src/rebar_app_utils.erl 查看文件

@ -58,7 +58,14 @@ is_app_src(Filename) ->
Filename =/= filename:rootname(Filename, ".app.src"). Filename =/= filename:rootname(Filename, ".app.src").
app_src_to_app(OutDir, Filename) -> app_src_to_app(OutDir, Filename) ->
AppFile = filename:join([OutDir, "ebin", filename:basename(Filename, ".app.src") ++ ".app"]),
AppFile =
case lists:suffix(".app.src", Filename) of
true ->
filename:join([OutDir, "ebin", filename:basename(Filename, ".app.src") ++ ".app"]);
false ->
filename:join([OutDir, "ebin", filename:basename(Filename,
".app.src.script") ++ ".app"])
end,
filelib:ensure_dir(AppFile), filelib:ensure_dir(AppFile),
AppFile. AppFile.

+ 2
- 1
src/rebar_config.erl 查看文件

@ -63,7 +63,8 @@ consult_file_(File) when is_binary(File) ->
consult_file_(File) -> consult_file_(File) ->
case filename:extension(File) of case filename:extension(File) of
".script" -> ".script" ->
consult_and_eval(remove_script_ext(File), File);
{ok, Terms} = consult_and_eval(remove_script_ext(File), File),
[Terms];
_ -> _ ->
Script = File ++ ".script", Script = File ++ ".script",
case filelib:is_regular(Script) of case filelib:is_regular(Script) of

+ 12
- 5
src/rebar_otp_app.erl 查看文件

@ -40,11 +40,17 @@ compile(State, App) ->
%% If we get an .app.src file, it needs to be pre-processed and %% If we get an .app.src file, it needs to be pre-processed and
%% written out as a ebin/*.app file. That resulting file will then %% written out as a ebin/*.app file. That resulting file will then
%% be validated as usual. %% be validated as usual.
App1 = case rebar_app_info:app_file_src(App) of
App1 = case rebar_app_info:app_file_src_script(App) of
undefined -> undefined ->
App;
AppFileSrc ->
File = preprocess(State, App, AppFileSrc),
case rebar_app_info:app_file_src(App) of
undefined ->
App;
AppFileSrc ->
File = preprocess(State, App, AppFileSrc),
rebar_app_info:app_file(App, File)
end;
AppFileSrcScript ->
File = preprocess(State, App, AppFileSrcScript),
rebar_app_info:app_file(App, File) rebar_app_info:app_file(App, File)
end, end,
@ -199,7 +205,8 @@ consult_app_file(Filename) ->
false -> false ->
{error, enoent}; {error, enoent};
true -> true ->
case lists:suffix(".app.src", Filename) of
case lists:suffix(".app.src", Filename)
orelse lists:suffix(".app.src.script", Filename) of
false -> false ->
file:consult(Filename); file:consult(Filename);
true -> true ->

正在加载...
取消
保存