diff options
Diffstat (limited to 'src/rebar_deps.erl')
-rw-r--r-- | src/rebar_deps.erl | 223 |
1 files changed, 171 insertions, 52 deletions
diff --git a/src/rebar_deps.erl b/src/rebar_deps.erl index be6283d..43bde04 100644 --- a/src/rebar_deps.erl +++ b/src/rebar_deps.erl @@ -68,37 +68,57 @@ preprocess(Config, _) -> %% Add available deps to code path Config3 = update_deps_code_path(Config2, AvailableDeps), - %% If skip_deps=true, mark each dep dir as a skip_dir w/ the core so that - %% the current command doesn't run on the dep dir. However, pre/postprocess - %% WILL run (and we want it to) for transitivity purposes. - %% - %% Also, if skip_deps=comma,separated,app,list, then only the given - %% dependencies are skipped. - NewConfig = case rebar_config:get_global(Config3, skip_deps, false) of - "true" -> - lists:foldl( - fun(#dep{dir = Dir}, C) -> - rebar_config:set_skip_dir(C, Dir) - end, Config3, AvailableDeps); - Apps when is_list(Apps) -> - SkipApps = [list_to_atom(App) || App <- string:tokens(Apps, ",")], - lists:foldl( - fun(#dep{dir = Dir, app = App}, C) -> - case lists:member(App, SkipApps) of - true -> rebar_config:set_skip_dir(C, Dir); - false -> C - end - end, Config3, AvailableDeps); - _ -> - Config3 - end, - %% Filtering out 'raw' dependencies so that no commands other than %% deps-related can be executed on their directories. NonRawAvailableDeps = [D || D <- AvailableDeps, not D#dep.is_raw], - %% Return all the available dep directories for process - {ok, NewConfig, dep_dirs(NonRawAvailableDeps)}. + case rebar_config:get_xconf(Config, current_command, undefined) of + 'update-deps' -> + %% Skip ALL of the dep folders, we do this because we don't want + %% any other calls to preprocess() for update-deps beyond the + %% toplevel directory. They aren't actually harmful, but they slow + %% things down unnecessarily. + NewConfig = lists:foldl( + fun(D, Acc) -> + rebar_config:set_skip_dir(Acc, D#dep.dir) + end, + Config3, + collect_deps(rebar_utils:get_cwd(), Config3)), + %% Return the empty list, as we don't want anything processed before + %% us. + {ok, NewConfig, []}; + _ -> + %% If skip_deps=true, mark each dep dir as a skip_dir w/ the core + %% so that the current command doesn't run on the dep dir. + %% However, pre/postprocess WILL run (and we want it to) for + %% transitivity purposes. + %% + %% Also, if skip_deps=comma,separated,app,list, then only the given + %% dependencies are skipped. + NewConfig = + case rebar_config:get_global(Config3, skip_deps, false) of + "true" -> + lists:foldl( + fun(#dep{dir = Dir}, C) -> + rebar_config:set_skip_dir(C, Dir) + end, Config3, AvailableDeps); + Apps when is_list(Apps) -> + SkipApps = [list_to_atom(App) || + App <- string:tokens(Apps, ",")], + lists:foldl( + fun(#dep{dir = Dir, app = App}, C) -> + case lists:member(App, SkipApps) of + true -> rebar_config:set_skip_dir(C, Dir); + false -> C + end + end, Config3, AvailableDeps); + _ -> + Config3 + end, + + %% Return all the available dep directories for process + {ok, NewConfig, dep_dirs(NonRawAvailableDeps)} + end. postprocess(Config, _) -> case rebar_config:get_xconf(Config, ?MODULE, undefined) of @@ -169,17 +189,24 @@ do_check_deps(Config) -> {ok, save_dep_dirs(Config2, lists:reverse(PulledDeps))}. 'update-deps'(Config, _) -> - %% Determine what deps are required - RawDeps = rebar_config:get_local(Config, deps, []), - {Config1, Deps} = find_deps(Config, read, RawDeps), - - %% Update each dep - UpdatedDeps = [update_source(Config1, D) - || D <- Deps, D#dep.source =/= undefined], + Config1 = rebar_config:set_xconf(Config, depowner, dict:new()), + {Config2, UpdatedDeps} = update_deps_int(Config1, []), + DepOwners = rebar_config:get_xconf(Config2, depowner, dict:new()), + + %% check for conflicting deps + _ = [?ERROR("Conflicting dependencies for ~p: ~p~n", + [K, [{"From: " ++ string:join(dict:fetch(D, DepOwners), ", "), + {D#dep.vsn_regex, D#dep.source}} || D <- V]]) + || {K, V} <- dict:to_list( + lists:foldl( + fun(Dep, Acc) -> + dict:append(Dep#dep.app, Dep, Acc) + end, dict:new(), UpdatedDeps)), + length(V) > 1], %% Add each updated dep to our list of dirs for post-processing. This yields %% the necessary transitivity of the deps - {ok, save_dep_dirs(Config1, UpdatedDeps)}. + {ok, save_dep_dirs(Config, UpdatedDeps)}. 'delete-deps'(Config, _) -> %% Delete all the available deps in our deps/ directory, if any @@ -230,13 +257,27 @@ info_help(Description) -> [ Description, {deps_dir, "deps"}, - {deps, [application_name, - {application_name, "1.0.*"}, - {application_name, "1.0.*", - {git, "git://github.com/rebar/rebar.git", {branch, "master"}}}, - {application_name, "", - {git, "git://github.com/rebar/rebar.git", {branch, "master"}}, - [raw]}]} + {deps, + [app_name, + {rebar, "1.0.*"}, + {rebar, ".*", + {git, "git://github.com/rebar/rebar.git"}}, + {rebar, ".*", + {git, "git://github.com/rebar/rebar.git", "Rev"}}, + {rebar, "1.0.*", + {git, "git://github.com/rebar/rebar.git", {branch, "master"}}}, + {rebar, "1.0.0", + {git, "git://github.com/rebar/rebar.git", {tag, "1.0.0"}}}, + {rebar, "", + {git, "git://github.com/rebar/rebar.git", {branch, "master"}}, + [raw]}, + {app_name, ".*", {hg, "https://www.example.org/url"}}, + {app_name, ".*", {rsync, "Url"}}, + {app_name, ".*", {svn, "https://www.example.org/url"}}, + {app_name, ".*", {svn, "svn://svn.example.org/url"}}, + {app_name, ".*", {bzr, "https://www.example.org/url", "Rev"}}, + {app_name, ".*", {fossil, "https://www.example.org/url"}}, + {app_name, ".*", {fossil, "https://www.example.org/url", "Vsn"}}]} ]). %% Added because of trans deps, @@ -263,7 +304,7 @@ get_deps_dir(Config) -> get_deps_dir(Config, ""). get_deps_dir(Config, App) -> - BaseDir = rebar_config:get_xconf(Config, base_dir, []), + BaseDir = rebar_utils:base_dir(Config), DepsDir = get_shared_deps_dir(Config, "deps"), {true, filename:join([BaseDir, DepsDir, App])}. @@ -419,7 +460,8 @@ is_app_available(Config, App, VsnRegex, Path, _IsRaw = false) -> {Config, {false, {missing_app_file, Path}}} end; is_app_available(Config, App, _VsnRegex, Path, _IsRaw = true) -> - ?DEBUG("is_app_available, looking for Raw Depencency ~p with Path ~p~n", [App, Path]), + ?DEBUG("is_app_available, looking for Raw Depencency ~p with Path ~p~n", + [App, Path]), case filelib:is_dir(Path) of true -> %% TODO: look for version string in <Path>/VERSION file? Not clear @@ -442,8 +484,8 @@ use_source(Config, Dep, Count) -> case filelib:is_dir(Dep#dep.dir) of true -> %% Already downloaded -- verify the versioning matches the regex - case is_app_available(Config, Dep#dep.app, - Dep#dep.vsn_regex, Dep#dep.dir, Dep#dep.is_raw) of + case is_app_available(Config, Dep#dep.app, Dep#dep.vsn_regex, + Dep#dep.dir, Dep#dep.is_raw) of {Config1, {true, _}} -> Dir = filename:join(Dep#dep.dir, "ebin"), ok = filelib:ensure_dir(filename:join(Dir, "dummy")), @@ -504,8 +546,6 @@ download_source(AppDir, {rsync, Url}) -> rebar_utils:sh(?FMT("rsync -az --delete ~s/ ~s", [Url, AppDir]), []); download_source(AppDir, {fossil, Url}) -> download_source(AppDir, {fossil, Url, ""}); -download_source(AppDir, {fossil, Url, latest}) -> - download_source(AppDir, {fossil, Url, ""}); download_source(AppDir, {fossil, Url, Version}) -> Repository = filename:join(AppDir, filename:basename(AppDir) ++ ".fossil"), ok = filelib:ensure_dir(Repository), @@ -540,10 +580,12 @@ update_source1(AppDir, {git, Url, ""}) -> update_source1(AppDir, {git, _Url, {branch, Branch}}) -> ShOpts = [{cd, AppDir}], rebar_utils:sh("git fetch origin", ShOpts), - rebar_utils:sh(?FMT("git checkout -q origin/~s", [Branch]), ShOpts); + rebar_utils:sh(?FMT("git checkout -q ~s", [Branch]), ShOpts), + rebar_utils:sh( + ?FMT("git pull --ff-only --no-rebase -q origin ~s", [Branch]),ShOpts); update_source1(AppDir, {git, _Url, {tag, Tag}}) -> ShOpts = [{cd, AppDir}], - rebar_utils:sh("git fetch --tags origin", ShOpts), + rebar_utils:sh("git fetch origin", ShOpts), rebar_utils:sh(?FMT("git checkout -q ~s", [Tag]), ShOpts); update_source1(AppDir, {git, _Url, Refspec}) -> ShOpts = [{cd, AppDir}], @@ -559,13 +601,90 @@ update_source1(AppDir, {rsync, Url}) -> rebar_utils:sh(?FMT("rsync -az --delete ~s/ ~s",[Url,AppDir]),[]); update_source1(AppDir, {fossil, Url}) -> update_source1(AppDir, {fossil, Url, ""}); -update_source1(AppDir, {fossil, Url, latest}) -> - update_source1(AppDir, {fossil, Url, ""}); update_source1(AppDir, {fossil, _Url, Version}) -> ok = file:set_cwd(AppDir), rebar_utils:sh("fossil pull", [{cd, AppDir}]), rebar_utils:sh(?FMT("fossil update ~s", [Version]), []). +%% Recursively update deps, this is not done via rebar's usual dep traversal as +%% that is the wrong order (tips are updated before branches). Instead we do a +%% traverse the deps at each level completely before traversing *their* deps. +%% This allows updates to actually propogate down the tree, rather than fail to +%% flow up the tree, which was the previous behaviour. +update_deps_int(Config0, UDD) -> + %% Determine what deps are required + ConfDir = filename:basename(rebar_utils:get_cwd()), + RawDeps = rebar_config:get_local(Config0, deps, []), + {Config1, Deps} = find_deps(Config0, read, RawDeps), + + %% Update each dep + UpdatedDeps = [update_source(Config1, D) + || D <- Deps, D#dep.source =/= undefined, + not lists:member(D, UDD), + not should_skip_update_dep(Config1, D) + ], + + lists:foldl(fun(Dep, {Config, Updated}) -> + {true, AppDir} = get_deps_dir(Config, Dep#dep.app), + Config2 = case has_vcs_dir(element(1, Dep#dep.source), + AppDir) of + false -> + %% If the dep did not exist (maybe it + %% was added), clone it. + %% We'll traverse ITS deps below and + %% clone them if needed. + {C1, _D1} = use_source(Config, Dep), + C1; + true -> + Config + end, + ok = file:set_cwd(AppDir), + Config3 = rebar_config:new(Config2), + %% track where a dep comes from... + DepOwner = dict:append( + Dep, ConfDir, + rebar_config:get_xconf(Config3, depowner, + dict:new())), + Config4 = rebar_config:set_xconf(Config3, depowner, + DepOwner), + + {Config5, Res} = update_deps_int(Config4, Updated), + {Config5, lists:umerge(lists:sort(Res), + lists:sort(Updated))} + end, {Config1, lists:umerge(lists:sort(UpdatedDeps), + lists:sort(UDD))}, UpdatedDeps). + +should_skip_update_dep(Config, Dep) -> + {true, AppDir} = get_deps_dir(Config, Dep#dep.app), + case rebar_app_utils:is_app_dir(AppDir) of + false -> + false; + {true, AppFile} -> + case rebar_app_utils:is_skipped_app(Config, AppFile) of + {_Config, {true, _SkippedApp}} -> + true; + _ -> + false + end + end. + +%% Recursively walk the deps and build a list of them. +collect_deps(Dir, C) -> + case file:set_cwd(Dir) of + ok -> + Config = rebar_config:new(C), + RawDeps = rebar_config:get_local(Config, deps, []), + {Config1, Deps} = find_deps(Config, read, RawDeps), + + lists:flatten(Deps ++ [begin + {true, AppDir} = get_deps_dir( + Config1, Dep#dep.app), + collect_deps(AppDir, C) + end || Dep <- Deps]); + _ -> + [] + end. + %% =================================================================== %% Source helper functions |