From 958213def79409b15dd61d51f3cfef1fb77cb82b Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 22 May 2015 13:52:23 -0500 Subject: fall back to .app.src file if .app file fails to parse --- src/rebar_app_discover.erl | 111 +++++++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl index 34310c7..74ab332 100644 --- a/src/rebar_app_discover.erl +++ b/src/rebar_app_discover.erl @@ -7,6 +7,7 @@ find_apps/2, find_app/2]). +-include("rebar.hrl"). -include_lib("providers/include/providers.hrl"). do(State, LibDirs) -> @@ -123,59 +124,7 @@ find_apps(LibDirs, Validate) -> find_app(AppDir, Validate) -> AppFile = filelib:wildcard(filename:join([AppDir, "ebin", "*.app"])), AppSrcFile = filelib:wildcard(filename:join([AppDir, "src", "*.app.src"])), - case AppFile of - [File] -> - AppInfo = create_app_info(AppDir, File), - AppInfo1 = rebar_app_info:app_file(AppInfo, File), - AppInfo2 = case AppSrcFile of - [F] -> - rebar_app_info:app_file_src(AppInfo1, F); - [] -> - AppInfo1; - Other when is_list(Other) -> - throw({error, {multiple_app_files, Other}}) - end, - case Validate of - valid -> - case rebar_app_utils:validate_application_info(AppInfo2) of - true -> - {true, AppInfo2}; - _ -> - false - end; - invalid -> - case rebar_app_utils:validate_application_info(AppInfo2) of - true -> - false; - _ -> - {true, AppInfo2} - end; - all -> - {true, AppInfo2} - end; - [] -> - case AppSrcFile of - [File] -> - case Validate of - V when V =:= invalid ; V =:= all -> - AppInfo = create_app_info(AppDir, File), - case AppInfo of - {error, Reason} -> - throw({error, {invalid_app_file, File, Reason}}); - _ -> - {true, rebar_app_info:app_file_src(AppInfo, File)} - end; - valid -> - false - end; - [] -> - false; - Other when is_list(Other) -> - throw({error, {multiple_app_files, Other}}) - end; - Other when is_list(Other) -> - throw({error, {multiple_app_files, Other}}) - end. + try_handle_app_file(AppFile, AppDir, AppSrcFile, Validate). app_dir(AppFile) -> filename:join(rebar_utils:droplast(filename:split(filename:dirname(AppFile)))). @@ -202,3 +151,59 @@ dedup([]) -> []; dedup([A]) -> [A]; dedup([H,H|T]) -> dedup([H|T]); dedup([H|T]) -> [H|dedup(T)]. + +try_handle_app_file([], AppDir, AppSrcFile, Validate) -> + try_handle_app_src_file([], AppDir, AppSrcFile, Validate); +try_handle_app_file([File], AppDir, AppSrcFile, Validate) -> + try create_app_info(AppDir, File) of + AppInfo -> + AppInfo1 = rebar_app_info:app_file(AppInfo, File), + AppInfo2 = case AppSrcFile of + [F] -> + rebar_app_info:app_file_src(AppInfo1, F); + [] -> + AppInfo1; + Other when is_list(Other) -> + throw({error, {multiple_app_files, Other}}) + end, + case Validate of + valid -> + case rebar_app_utils:validate_application_info(AppInfo2) of + true -> + {true, AppInfo2}; + _ -> + false + end; + invalid -> + case rebar_app_utils:validate_application_info(AppInfo2) of + true -> + false; + _ -> + {true, AppInfo2} + end; + all -> + {true, AppInfo2} + end + catch + throw:{error, {Module, 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) + end; +try_handle_app_file(Other, _AppDir, _AppSrcFile, _Validate) -> + throw({error, {multiple_app_files, Other}}). + +try_handle_app_src_file(_, _AppDir, [], _Validate) -> + false; +try_handle_app_src_file(_, _AppDir, _AppSrcFile, valid) -> + false; +try_handle_app_src_file(_, AppDir, [File], Validate) when Validate =:= invalid + ; Validate =:= all -> + AppInfo = create_app_info(AppDir, File), + case AppInfo of + {error, Reason} -> + throw({error, {invalid_app_file, File, Reason}}); + _ -> + {true, rebar_app_info:app_file_src(AppInfo, File)} + end; +try_handle_app_src_file(_, _AppDir, Other, _Validate) -> + throw({error, {multiple_app_files, Other}}). -- cgit v1.1 From 37ac2b78333d23abfa9274ce773eb620f5813657 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 22 May 2015 14:56:33 -0500 Subject: read in app information after fetch so we have the deps --- src/rebar_app_discover.erl | 7 ++++--- src/rebar_prv_install_deps.erl | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl index 74ab332..a79611d 100644 --- a/src/rebar_app_discover.erl +++ b/src/rebar_app_discover.erl @@ -124,7 +124,8 @@ find_apps(LibDirs, Validate) -> find_app(AppDir, Validate) -> AppFile = filelib:wildcard(filename:join([AppDir, "ebin", "*.app"])), AppSrcFile = filelib:wildcard(filename:join([AppDir, "src", "*.app.src"])), - try_handle_app_file(AppFile, AppDir, AppSrcFile, Validate). + AppInfo = try_handle_app_file(AppFile, AppDir, AppSrcFile, Validate), + AppInfo. app_dir(AppFile) -> filename:join(rebar_utils:droplast(filename:split(filename:dirname(AppFile)))). @@ -165,7 +166,7 @@ try_handle_app_file([File], AppDir, AppSrcFile, Validate) -> AppInfo1; Other when is_list(Other) -> throw({error, {multiple_app_files, Other}}) - end, + end, case Validate of valid -> case rebar_app_utils:validate_application_info(AppInfo2) of @@ -197,7 +198,7 @@ try_handle_app_src_file(_, _AppDir, [], _Validate) -> try_handle_app_src_file(_, _AppDir, _AppSrcFile, valid) -> false; try_handle_app_src_file(_, AppDir, [File], Validate) when Validate =:= invalid - ; Validate =:= all -> + ; Validate =:= all -> AppInfo = create_app_info(AppDir, File), case AppInfo of {error, Reason} -> diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index cdc008c..815d6c8 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -410,7 +410,7 @@ maybe_fetch(AppInfo, Profile, Upgrade, Seen, State) -> case fetch_app(AppInfo, AppDir, State) of true -> maybe_symlink_default(State, Profile, AppDir, AppInfo), - {true, update_app_info(AppInfo)}; + {true, update_app_info(AppDir, AppInfo)}; Other -> {Other, AppInfo} end; @@ -577,8 +577,9 @@ fetch_app(AppInfo, AppDir, State) -> throw(Error) end. -update_app_info(AppInfo) -> - AppDetails = rebar_app_info:app_details(AppInfo), +update_app_info(AppDir, AppInfo) -> + {true, Found} = rebar_app_discover:find_app(AppDir, all), + AppDetails = rebar_app_info:app_details(Found), Applications = proplists:get_value(applications, AppDetails, []), IncludedApplications = proplists:get_value(included_applications, AppDetails, []), AppInfo1 = rebar_app_info:applications( -- cgit v1.1 From f772dcee2e7082f3da4520043de888d5d68aa750 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 22 May 2015 15:15:36 -0500 Subject: fix storing of pkg and src deps in app_info --- src/rebar_digraph.erl | 5 +++-- src/rebar_prv_install_deps.erl | 6 ++---- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/rebar_digraph.erl b/src/rebar_digraph.erl index 9e10d49..7f7909e 100644 --- a/src/rebar_digraph.erl +++ b/src/rebar_digraph.erl @@ -125,5 +125,6 @@ find_app_by_name(Name, Apps) -> end, Apps). all_apps_deps(App) -> - Applications = [atom_to_binary(X, utf8) || X <- rebar_app_info:applications(App)], - lists:usort(rebar_app_info:deps(App) ++ Applications). + Applications = lists:usort([atom_to_binary(X, utf8) || X <- rebar_app_info:applications(App)]), + Deps = lists:usort(lists:map(fun({Name, _}) -> Name; (Name) -> Name end, rebar_app_info:deps(App))), + lists:umerge(Deps, Applications). diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 815d6c8..90bd70c 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -261,9 +261,7 @@ package_to_app(DepsDir, Packages, {Name, Vsn, Level}, IsLock, State) -> false -> throw(?PRV_ERROR({missing_package, Name, Vsn})) end; - {ok, P} -> - PkgDeps = [{PkgName, PkgVsn} - || {PkgName,PkgVsn} <- proplists:get_value(<<"deps">>, P, [])], + {ok, PkgDeps} -> {ok, AppInfo} = rebar_app_info:new(Name, Vsn), AppInfo1 = rebar_app_info:deps(AppInfo, PkgDeps), AppInfo2 = rebar_app_info:dir(AppInfo1, filename:join([DepsDir, Name])), @@ -578,7 +576,7 @@ fetch_app(AppInfo, AppDir, State) -> end. update_app_info(AppDir, AppInfo) -> - {true, Found} = rebar_app_discover:find_app(AppDir, all), + {ok, Found} = rebar_app_info:discover(AppDir), AppDetails = rebar_app_info:app_details(Found), Applications = proplists:get_value(applications, AppDetails, []), IncludedApplications = proplists:get_value(included_applications, AppDetails, []), -- cgit v1.1 From e45c67b023e310bd60de88f07f9429d66d18d4b0 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 22 May 2015 18:42:24 -0500 Subject: add additional comments --- src/rebar_app_discover.erl | 3 +++ src/rebar_digraph.erl | 3 +++ src/rebar_prv_install_deps.erl | 3 +++ 3 files changed, 9 insertions(+) (limited to 'src') diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl index a79611d..e2ef179 100644 --- a/src/rebar_app_discover.erl +++ b/src/rebar_app_discover.erl @@ -153,6 +153,8 @@ dedup([A]) -> [A]; dedup([H,H|T]) -> dedup([H|T]); dedup([H|T]) -> [H|dedup(T)]. +%% Read in and parse the .app file if it is availabe. Do the same for +%% the .app.src file if it exists. try_handle_app_file([], AppDir, AppSrcFile, Validate) -> try_handle_app_src_file([], AppDir, AppSrcFile, Validate); try_handle_app_file([File], AppDir, AppSrcFile, Validate) -> @@ -193,6 +195,7 @@ try_handle_app_file([File], AppDir, AppSrcFile, Validate) -> try_handle_app_file(Other, _AppDir, _AppSrcFile, _Validate) -> throw({error, {multiple_app_files, Other}}). +%% Read in the .app.src file if we aren't looking for a valid (already built) app try_handle_app_src_file(_, _AppDir, [], _Validate) -> false; try_handle_app_src_file(_, _AppDir, _AppSrcFile, valid) -> diff --git a/src/rebar_digraph.erl b/src/rebar_digraph.erl index 7f7909e..d52a811 100644 --- a/src/rebar_digraph.erl +++ b/src/rebar_digraph.erl @@ -124,6 +124,9 @@ find_app_by_name(Name, Apps) -> rebar_app_info:name(App) =:= Name end, Apps). +%% The union of all entries in the applications list for an app and +%% the deps listed in its rebar.config is all deps that may be needed +%% for building the app. all_apps_deps(App) -> Applications = lists:usort([atom_to_binary(X, utf8) || X <- rebar_app_info:applications(App)]), Deps = lists:usort(lists:map(fun({Name, _}) -> Name; (Name) -> Name end, rebar_app_info:deps(App))), diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 90bd70c..80fdbc3 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -575,6 +575,9 @@ fetch_app(AppInfo, AppDir, State) -> throw(Error) end. +%% This is called after the dep has been downloaded and unpacked, if it hadn't been already. +%% So this is the first time for newly downloaded apps that its .app/.app.src data can +%% be read in an parsed. update_app_info(AppDir, AppInfo) -> {ok, Found} = rebar_app_info:discover(AppDir), AppDetails = rebar_app_info:app_details(Found), -- cgit v1.1