anchor.diff:  %% Preprocessing
   process_archives([], State, _WorkId) -> {ok, State};
   process_archives([A|O], #state{unpack_state=UnpackState, build_path=BuildPath}=State, WorkId) ->
  +    Vsn = ?CPU:get_archive_version(A),
       case can_prepare(A, State) of
           true ->
  -            Preparing = [?CPU:get_archive_version(A)|State#state.queued],
  +            Preparing = [Vsn|State#state.queued],
               Prebuild = State#state.prebuild,
               process_archive(BuildPath, A, UnpackState, WorkId);
           false ->
               Preparing = State#state.queued,
  -            Prebuild = lists:ukeysort(1, [{A, WorkId}|State#state.prebuild])
  +            Prebuild = lists:ukeysort(1, [{Vsn, A, WorkId}|State#state.prebuild])
       end,
       process_archives(O, State#state{queued=Preparing, prebuild=Prebuild}, WorkId).
   
  
positive.code:         {false, false} -> get_build_candidate(both, State)
      end.
  
  
  get_build_candidate(main_queue, State) ->
      {{value, Candidate}, MainQueue} = queue:out(State#state.main_queue),
      case check_build_deps(Candidate, State) of
          independent ->
              ?CBS:update_dep_state(State#state.deps, Candidate, <<"in_progress">>),
              {ok, State#state{
                  main_queue=MainQueue, 
                  next_to_build=Candidate,
                  queued=lists:delete(?VERSION(Candidate), State#state.queued)
              }};
  
          dependent ->
              WaitQueue = queue:in(Candidate, State#state.wait_queue),
              {ok, State#state{main_queue=MainQueue, wait_queue=WaitQueue}};
          missing ->
              {ok, State#state{
                      main_queue=MainQueue,
                      queued=lists:delete(?VERSION(Candidate), State#state.queued)
                  }};
          _Other ->
              RolledMainQueue = queue:in(Candidate, MainQueue),
              {ok, State#state{main_queue=RolledMainQueue}}
      end;
  get_build_candidate(wait_queue, State) ->
      {{value, Candidate}, WaitQueue} = queue:out(State#state.wait_queue),
      case check_build_deps(Candidate, State) of
          independent ->
              ?CBS:update_dep_state(State#state.deps, Candidate, <<"in_progress">>),
              {ok, State#state{
                      wait_queue=WaitQueue, 
                      queued=lists:delete(?VERSION(Candidate), State#state.queued),
                      next_to_build=Candidate}};
          dependent ->
              RolledWaitQueue = queue:in(Candidate, WaitQueue),
              {ok, State#state{wait_queue=RolledWaitQueue}};
          missing ->
              {ok, State#state{
                      queued=lists:delete(?VERSION(Candidate), State#state.queued),
                      wait_queue=WaitQueue}};
          Other ->
              Subject = io_lib:format("Build for ~p", [Candidate]),
              Body = io_lib:format("Error while processing dependencies: ~n~p~n", [Other]),
              notify(Subject, Body),
              {error, broken_deps}
      end;
  get_build_candidate(both, State) ->
      {{value, Candidate}, WaitQueue} = queue:out(State#state.wait_queue),
      case check_build_deps(Candidate, State) of
          independent ->
              ?CBS:update_dep_state(State#state.deps, Candidate, <<"in_progress">>),
              {ok, State#state{
                      queued=lists:delete(?VERSION(Candidate), State#state.queued),
                      wait_queue=WaitQueue, 
                      next_to_build=Candidate}};
          dependent ->
              RolledWaitQueue = queue:in(Candidate, WaitQueue),
              get_build_candidate(main_queue,
                  State#state{wait_queue=RolledWaitQueue});
          missing ->
              {ok, State#state{
                      wait_queue=WaitQueue,
                      queued=lists:delete(?VERSION(Candidate), State#state.queued)
                  }};
          _Other ->
              {error, broken_deps}
      end.
  
  
  
negative.code: -include_lib("caterpillar_builder_internal.hrl").
  -behaviour(gen_server).
  
  -export([start_link/1, state/0]).
  -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
           terminate/2, code_change/3, prepare/3]).
  
  