Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Run update-deps hooks again #277

Open
wants to merge 5 commits into from

4 participants

@Vagabond
Owner

Fix regression caused by making update-deps actually work.

Vagabond added some commits
@Vagabond Vagabond Run pre/post hooks for update-deps
This is a bit of a kludge, but because we are operating outside of
rebar_core when doing update-deps it seems necessary.
4bb4375
@Vagabond Vagabond Actually run the hooks, not just the plugins f911f8f
@Vagabond Vagabond Fix handling of raw deps f1b1dd8
@Vagabond Vagabond Handle sub_dirs in update-deps 780b85c
@Vagabond Vagabond Unused vars
f23af3a
@tuncer tuncer commented on the diff
src/rebar_core.erl
@@ -28,6 +28,8 @@
-export([process_commands/2, help/2]).
+-export([execute_pre/5, execute_post/5, apply_hooks/4]).
@tuncer
tuncer added a note

We should probably add a %% for internal use only comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@tuncer tuncer commented on the diff
src/rebar_deps.erl
@@ -47,6 +47,8 @@
source,
is_raw }). %% is_raw = true means non-Erlang/OTP dependency
+-record(subdir, {dir }).
@tuncer
tuncer added a note

Deliberate space before } in {dir }?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@tuncer

Hi @Vagabond, even though it may fix a regression, I don't think rebar_core functions should be called by anything but rebar.erl. Actually, we may have a conceptual design flaw to fix instead. The initial update-deps kludge added to rebar_core was tolerable, but this one doesn't seem right.

Regardless, if we're going to merge this, you should squash the commits, as the last four look like fixups for the first commit. Also, 780b85c introduces overlong lines, and a regression test would be great.

cc @dizzyd

@Vagabond
Owner

Yeah, it is unfortunate, but I was unable to find another way to do it. I do have plans to fix the conceptual flaw, but it is unclear if/when I'll have to time to actually write that code.

@tuncer

It sounds like the chances of somebody fixing it properly will be much lower once we merge the kludge. With that being said, if you provide a regression test, I'll try to investigate a proper fix.

@tsloughter
Owner

So this fixes a regression, right? I don't think the 'kludge' is much. I think we should get this in soon...

@tuncer

@tsloughter wrote:

So this fixes a regression, right? I don't think the 'kludge' is much. I think we should get this in soon...

It turns the code inside out, and this appears to be an unfortunate regression caused by #142. Of course we should fix regressions, but this one should be followed up with a proper fix that removes the kludge. Also, it's best to add a NOTE/TODO comment explaining the kludge (in rebar_core and rebar_deps) and what needs to be fixed.

@ferd ferd added the bug label
@ferd ferd referenced this pull request
Open

Slow update-deps #369

@tuncer

So, what do we do about this? As I said earlier, given a clear NOTE/TODO comment, it's okay to merge, assuming this fixes the regression.

@ferd
Owner

I frankly have no idea. I don't understand this code base, don't understand the implications, never know what may break or not. I'm fine with merging it and reversing if it breaks more stuff, though.

@tuncer

So, how about merging this to master after the next release, and see if anything breaks?

@ferd
Owner

Sure, that sounds like a plan. The current release is still blocked on getting the proper protobuffs configs fixed, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 12, 2014
  1. @Vagabond

    Run pre/post hooks for update-deps

    Vagabond authored
    This is a bit of a kludge, but because we are operating outside of
    rebar_core when doing update-deps it seems necessary.
  2. @Vagabond
  3. @Vagabond

    Fix handling of raw deps

    Vagabond authored
Commits on Mar 13, 2014
  1. @Vagabond
Commits on Mar 26, 2014
  1. @Vagabond

    Unused vars

    Vagabond authored
This page is out of date. Refresh to see the latest.
Showing with 77 additions and 5 deletions.
  1. +2 −0  src/rebar_core.erl
  2. +75 −5 src/rebar_deps.erl
View
2  src/rebar_core.erl
@@ -28,6 +28,8 @@
-export([process_commands/2, help/2]).
+-export([execute_pre/5, execute_post/5, apply_hooks/4]).
@tuncer
tuncer added a note

We should probably add a %% for internal use only comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
-include("rebar.hrl").
%% ===================================================================
View
80 src/rebar_deps.erl
@@ -47,6 +47,8 @@
source,
is_raw }). %% is_raw = true means non-Erlang/OTP dependency
+-record(subdir, {dir }).
@tuncer
tuncer added a note

Deliberate space before } in {dir }?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
%% ===================================================================
%% Public API
%% ===================================================================
@@ -78,12 +80,18 @@ preprocess(Config, _) ->
%% any other calls to preprocess() for update-deps beyond the
%% toplevel directory. They aren't actually harmful, but they slow
%% things down unnecessarily.
+ SubDirs = collect_subdirs(rebar_utils:get_cwd(), Config3),
NewConfig = lists:foldl(
+ fun(D, Acc) ->
+ rebar_config:set_skip_dir(Acc, D#subdir.dir)
+ end,
+ lists:foldl(
fun(D, Acc) ->
rebar_config:set_skip_dir(Acc, D#dep.dir)
end,
Config3,
collect_deps(rebar_utils:get_cwd(), Config3)),
+ SubDirs),
%% Return the empty list, as we don't want anything processed before
%% us.
{ok, NewConfig, []};
@@ -189,12 +197,19 @@ do_check_deps(Config) ->
{ok, save_dep_dirs(Config2, lists:reverse(PulledDeps))}.
'update-deps'(Config, _) ->
- Config1 = rebar_config:set_xconf(Config, depowner, dict:new()),
- {Config2, UpdatedDeps} = update_deps_int(Config1, []),
- DepOwners = rebar_config:get_xconf(Config2, depowner, dict:new()),
+ SubDirs = collect_subdirs(rebar_utils:get_cwd(), Config),
+
+ {UpdatedDeps, DepOwners} = lists:foldl(fun(Dir, {UpdatedDepsAcc, DepOwnersAcc}) ->
+ ok = file:set_cwd(Dir),
+ Config0 = rebar_config:new(Config),
+ Config1 = rebar_config:set_xconf(Config0, depowner, DepOwnersAcc),
+ {Config2, UpdatedDeps} = update_deps_int(Config1, UpdatedDepsAcc),
+ DepOwners = rebar_config:get_xconf(Config2, depowner, DepOwnersAcc),
+ {UpdatedDeps, DepOwners}
+ end, {[], dict:new()}, [rebar_utils:get_cwd()|[S#subdir.dir || S <- SubDirs]]),
%% check for conflicting deps
- _ = [?ERROR("Conflicting dependencies for ~p: ~p~n",
+ _ = [?WARN("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(
@@ -564,8 +579,37 @@ update_source(Config, Dep) ->
case has_vcs_dir(element(1, Dep#dep.source), AppDir) of
true ->
?CONSOLE("Updating ~p from ~p\n", [Dep#dep.app, Dep#dep.source]),
+ %% Check for and get command specific environments
+ {ok, CWD} = file:get_cwd(),
+ ok = file:set_cwd(AppDir),
+ Config1 = rebar_config:new(Config),
+
+ Env = setup_env(Config1),
+
+ case Dep#dep.is_raw of
+ false ->
+ {true, ModuleSetFile} = rebar_app_utils:is_app_dir(AppDir);
+ true ->
+ %% I have no idea...
+ ModuleSetFile = ""
+ end,
+
+ %% Execute any before_command plugins on this directory
+ Config2 = rebar_core:execute_pre('update-deps', [],
+ Config1, ModuleSetFile, Env),
+
+ rebar_core:apply_hooks(pre_hooks, Config2, 'update-deps', Env),
+
require_source_engine(Dep#dep.source),
update_source1(AppDir, Dep#dep.source),
+
+ rebar_core:apply_hooks(post_hooks, Config2, 'update-deps', Env),
+
+ %% Execute any after_command plugins on this directory
+ rebar_core:execute_post('update-deps', [],
+ Config2, ModuleSetFile, Env),
+
+ ok = file:set_cwd(CWD),
Dep;
false ->
?WARN("Skipping update for ~p: "
@@ -670,17 +714,43 @@ should_skip_update_dep(Config, Dep) ->
%% Recursively walk the deps and build a list of them.
collect_deps(Dir, C) ->
+ CWD = rebar_utils:get_cwd(),
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),
+ ListSubdirs = [filename:absname(F) || F <- rebar_config:get_local(Config, sub_dirs, [])],
+
+ ok = file:set_cwd(CWD),
lists:flatten(Deps ++ [begin
{true, AppDir} = get_deps_dir(
Config1, Dep#dep.app),
collect_deps(AppDir, C)
- end || Dep <- Deps]);
+ end || Dep <- Deps] ++ [collect_deps(SubDir, C) || SubDir <- ListSubdirs]);
+ _ ->
+ []
+ end.
+
+
+collect_subdirs(Dir, C) ->
+ CWD = rebar_utils:get_cwd(),
+ case file:set_cwd(Dir) of
+ ok ->
+ Config = rebar_config:new(C),
+ RawDeps = rebar_config:get_local(Config, deps, []),
+ ListSubdirs = [#subdir{dir=filename:absname(F)} || F <- rebar_config:get_local(Config, sub_dirs, [])],
+ {Config1, Deps} = find_deps(Config, read, RawDeps),
+
+ ok = file:set_cwd(CWD),
+
+ lists:flatten(ListSubdirs ++ [begin
+ {true, AppDir} = get_deps_dir(
+ Config1, Dep#dep.app),
+ collect_subdirs(AppDir, C)
+ end || Dep <- Deps] ++
+ [collect_subdirs(D#subdir.dir, C) || D <- ListSubdirs]);
_ ->
[]
end.
Something went wrong with that request. Please try again.