anchor.diff:              {error, Error} ->
                   {error, Error};
               no_cycle ->
  -                case rebar_digraph:compile_order(Source) of
  -                    {ok, Sort} ->
  -                        {ok, rebar_state:deps_to_build(State1,
  -                                                    lists:dropwhile(fun rebar_app_info:valid/1,
  -                                                                    Sort -- ProjectApps))};
  +                case compile_order(Source, ProjectApps) of
  +                    {ok, ToCompile} ->
  +                        {ok, rebar_state:deps_to_build(State1, ToCompile)};
                       {error, Error} ->
                           {error, Error}
                   end
  
positive.code: %% Internal functions
  %% ===================================================================
  
  update_pkg_deps(Profile, Pkgs, Packages, Upgrade, Seen, State) ->
      %% Create app_info record for each pkg dep
      DepsDir = rebar_dir:deps_dir(State),
      {Solved, _, State1}
          = lists:foldl(fun(Pkg, {Acc, SeenAcc, StateAcc}) ->
                                AppInfo = package_to_app(DepsDir
                                                        ,Packages
                                                        ,Pkg),
                                {SeenAcc1, StateAcc1} = maybe_lock(Profile, AppInfo, SeenAcc, StateAcc, 0),
                                case maybe_fetch(AppInfo, Upgrade, SeenAcc1, State) of
                                    true ->
                                        {[AppInfo | Acc], SeenAcc1, StateAcc1};
                                    false ->
                                        {Acc, SeenAcc1, StateAcc1}
                                end
                        end, {[], Seen, State}, Pkgs),
      {Solved, State1}.
  
  maybe_lock(Profile, AppInfo, Seen, State, Level) ->
      Name = rebar_app_info:name(AppInfo),
      case Profile of
          default ->
              case sets:is_element(Name, Seen) of
                  false ->
                      AppName = rebar_app_info:name(AppInfo),
                      Locks = rebar_state:lock(State),
                      case lists:any(fun(App) -> rebar_app_info:name(App) =:= AppName end, Locks) of
                          true ->
                              {sets:add_element(Name, Seen), State};
                          false ->
  
negative.code:         %% maybe_fetch will maybe_throw an exception to break out of some loops
          _:{error, Reason} ->
              {error, Reason}
      end.
  
  -spec format_error(any()) -> iolist().
  