Changeset 69 for trunk


Ignore:
Timestamp:
07/15/09 04:39:24 (3 years ago)
Author:
dom
Message:

Fixed defect in compiler that not all binaries were notified after compile errors got fixed.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/compiler.erl

    r68 r69  
    44init (Notify, Dir) -> 
    55    Watcher = spawn_link (directory_watcher, init_recursive, [Dir, notify_me ()]), 
    6     loop (Notify, Watcher, dict: new ()). 
     6    loop (Notify, Watcher, dict: new (), [], []). 
    77 
    8 loop (Notify, Watcher, Modules) -> 
     8loop (Notify, Watcher, Modules, Binaries, Removed) -> 
    99    receive 
    1010        check -> 
    1111            Watcher ! check, 
    12             receive_files (Notify, Watcher, Modules, Modules); 
     12            receive_files (Notify, Watcher, Modules, Modules, Binaries, Removed); 
    1313        {Pid, stop} -> 
    1414            Pid ! {self (), bye} 
    1515    end. 
    1616 
    17 receive_files (Notify, Watcher, Modules, New) -> 
     17receive_files (Notify, Watcher, Modules, New, Binaries, Removed) -> 
    1818    receive 
    1919        {Watcher, {{file, ".erl"}, File, Event}} -> 
    20             receive_files (Notify, Watcher, Modules, dict: store (File, Event, New)); 
     20            receive_files (Notify, Watcher, Modules, dict: store (File, Event, New), Binaries, Removed); 
    2121        {Watcher, _} -> 
    22             receive_files (Notify, Watcher, Modules, New) 
     22            receive_files (Notify, Watcher, Modules, New, Binaries, Removed) 
    2323    after 500 -> 
    24             compile (Notify, Watcher, Modules, New) 
     24            compile (Notify, Watcher, Modules, New, Binaries, Removed) 
    2525    end. 
    2626 
    27 compile (Notify, Watcher, Modules, Modules) -> 
    28     loop (Notify, Watcher, Modules); 
    29 compile (Notify, Watcher, _, Modules) -> 
     27compile (Notify, Watcher, Modules, Modules, Binaries, Removed) -> 
     28    loop (Notify, Watcher, Modules, Binaries, Removed); 
     29compile (Notify, Watcher, _, Modules, Binaries, Removed) -> 
    3030    notify_totals (Modules, Notify), 
    31     Init = {Modules, Notify, [], []}, 
    32     {Processed, _, Binaries, Removed} = dict: fold (fun process/3, Init, Modules), 
    33     notify_end (Binaries, Removed, Notify), 
    34     loop (Notify, Watcher, Processed). 
     31    Init = {Modules, Notify, Binaries, Removed}, 
     32    {Processed, _, New_binaries, New_removed} = dict: fold (fun process/3, Init, Modules), 
     33    {Final_binaries, Final_removed} = notify_end (totals (Processed), New_binaries, New_removed, Notify), 
     34    loop (Notify, Watcher, Processed, Final_binaries, Final_removed). 
    3535 
    3636process (File, Event, Acc) when Event == found; Event == changed -> 
     
    5555             
    5656notify_totals (Modules, Notify) -> 
    57     Notify (dict: fold (fun count/3, {0, 0, 0}, Modules)). 
     57    Notify (totals (Modules)). 
     58 
     59totals (Modules) -> 
     60    dict: fold (fun count/3, {0, 0, 0}, Modules). 
    5861 
    5962count (_, lost, Acc) -> 
     
    7376    Notify ({Errors, Warnings}). 
    7477 
    75 binaries (_, errors) -> 
    76     errors; 
    7778binaries ({ok, _, B, _}, Bs) -> 
    7879    [B | Bs]; 
    79 binaries ({error, _, _}, _) -> 
    80     errors. 
     80binaries ({error, _, _}, Bs) -> 
     81    Bs. 
    8182 
    82 notify_end (errors, _, _) -> 
    83     pass; 
    84 notify_end (Binaries, Removed, Notify) -> 
    85     Notify ({{binaries, Binaries}, {removed, Removed}}). 
     83notify_end ({N, N, N}, Binaries, Removed, Notify) -> 
     84    Notify ({{binaries, Binaries}, {removed, Removed}}), 
     85    {[], []}; 
     86notify_end (_, Binaries, Removed, _) -> 
     87    {Binaries, Removed}. 
  • trunk/src/compiler_test.erl

    r68 r69  
    1212-export ([notifies_removed_files/0]). 
    1313-export ([notifies_removed_files_even_if_never_compiled/0]). 
     14-export ([provides_all_binaries_not_just_latest_when_all_compiled/0]). 
    1415-include_lib("stdlib/include/ms_transform.hrl"). 
    1516 
     
    3839    ok = fixtures: use_tree (good_erl_tree (), F). 
    3940 
     41provides_all_binaries_not_just_latest_when_all_compiled () -> 
     42    F = fun provides_all_binaries_not_just_latest_when_all_compiled/2, 
     43    ok = fixtures: use_tree (bad_erl_tree (), F). 
     44 
    4045can_start_empty_and_add_files () -> 
    4146    F = fun can_start_empty_and_add_files/2, 
     
    6166    Modules = [M || {ok, {M, [{exports, [_, _, {run, 0}]}]}} <- Chunks], 
    6267    [gdbye, hello] = lists: sort (Modules), 
     68    ok. 
     69 
     70provides_all_binaries_not_just_latest_when_all_compiled (Root, [_, File]) -> 
     71    Compiler = spawn_link (compiler, init, [notify_me (), Root]), 
     72    Compiler ! check, 
     73    [{2, 0, 0}, {_, _}, {2, 1, 0}, {2, 2, 1}] = receive_all (), 
     74    {file, Filename, _} = File, 
     75    Code = "-module(gdbye). -export([run/0]). run()->gdbye.", 
     76    file: write_file (filename: join (Root, Filename), Code), 
     77    Compiler ! check, 
     78    [{2, 1, 1}, {2, 2, 2}, {{binaries, [_, _]}, _}] = receive_all (), 
    6379    ok. 
    6480 
     
    132148     {file, "gdbye.erl", "-module(gdbye). -export([run/0]). run()->gdbye."}]. 
    133149 
     150bad_erl_tree () -> 
     151    [{file, "hello.erl", "-module(hello). -export([run/0]). run()->hello."}, 
     152     {file, "gdbye.erl", "-module(gdbye) -export([run/0]) run()->gdbye"}]. 
     153 
    134154notify_me () -> 
    135155    Self = self (), 
Note: See TracChangeset for help on using the changeset viewer.