Changeset 68


Ignore:
Timestamp:
07/14/09 09:37:03 (3 years ago)
Author:
dom
Message:

compiler now notifies of removed files (but still imperfect...)

Location:
trunk/src
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/compiler.erl

    r65 r68  
    1717receive_files (Notify, Watcher, Modules, New) -> 
    1818    receive 
    19         {Watcher, {{file, ".erl"}, File, Event}} when Event == found; Event == changed -> 
     19        {Watcher, {{file, ".erl"}, File, Event}} -> 
    2020            receive_files (Notify, Watcher, Modules, dict: store (File, Event, New)); 
    2121        {Watcher, _} -> 
     
    2929compile (Notify, Watcher, _, Modules) -> 
    3030    notify_totals (Modules, Notify), 
    31     Init = {Modules, Notify, []}, 
    32     {Processed, _, Binaries} = dict: fold (fun process/3, Init, Modules), 
    33     notify_binaries (Binaries, Notify), 
     31    Init = {Modules, Notify, [], []}, 
     32    {Processed, _, Binaries, Removed} = dict: fold (fun process/3, Init, Modules), 
     33    notify_end (Binaries, Removed, Notify), 
    3434    loop (Notify, Watcher, Processed). 
    3535 
    36 process (File, Event, {Modules, Notify, Binaries}) when Event == found; 
    37                                                         Event == changed -> 
     36process (File, Event, Acc) when Event == found; Event == changed -> 
     37    {Modules, Notify, Binaries, Removed} = Acc, 
    3838    Result = modules: compile (File), 
    3939    notify_result (Result, Notify), 
     
    4141    notify_totals (New_modules, Notify), 
    4242    New_binaries = binaries (Result, Binaries), 
    43     {New_modules, Notify, New_binaries}; 
     43    {New_modules, Notify, New_binaries, Removed}; 
     44process (File, Event, Acc) when Event == lost -> 
     45    {Modules, Notify, Binaries, Removed} = Acc, 
     46    New_modules = dict: erase (File, Modules), 
     47    New_removed = [modules: module_name (File) | Removed], 
     48    {New_modules, Notify, Binaries, New_removed}; 
    4449process (_, _, Acc) -> 
    4550    Acc. 
     
    5257    Notify (dict: fold (fun count/3, {0, 0, 0}, Modules)). 
    5358 
     59count (_, lost, Acc) -> 
     60    Acc; 
    5461count (_, {ok, _, _, _}, {Total, Compiled, Successful}) -> 
    5562    {Total + 1, Compiled + 1, Successful + 1}; 
     
    7380    errors. 
    7481 
    75 notify_binaries (errors, _) -> 
     82notify_end (errors, _, _) -> 
    7683    pass; 
    77 notify_binaries (Bs, Notify) when is_list (Bs) -> 
    78     Notify ({binaries, Bs}). 
     84notify_end (Binaries, Removed, Notify) -> 
     85    Notify ({{binaries, Binaries}, {removed, Removed}}). 
  • trunk/src/compiler_test.erl

    r67 r68  
    1010-export ([stops/0]). 
    1111-export ([can_start_empty_and_add_files/0]). 
     12-export ([notifies_removed_files/0]). 
     13-export ([notifies_removed_files_even_if_never_compiled/0]). 
    1214-include_lib("stdlib/include/ms_transform.hrl"). 
    1315 
     
    4042    ok = fixtures: use_tree ([], F). 
    4143 
     44notifies_removed_files () -> 
     45    F = fun notifies_removed_files/2, 
     46    ok = fixtures: use_tree (good_erl_tree (), F). 
     47 
     48notifies_removed_files_even_if_never_compiled () -> 
     49    F = fun notifies_removed_files_even_if_never_compiled/2, 
     50    Tree = [{file, "hello.erl", "rubbish"}], 
     51    ok = fixtures: use_tree (Tree, F). 
     52 
    4253provides_binaries_when_all_compiled (Root, _) -> 
    4354    Compiler = spawn_link (compiler, init, [notify_me (), Root]), 
     
    4657    Compiler ! stop, 
    4758    ok = check (Ms, unknown), 
    48     {binaries, Bs} = lists: last (Ms), 
     59    {{binaries, Bs}, _} = lists: last (Ms), 
    4960    Chunks = [ beam_lib: chunks (B, [exports]) || B <- Bs], 
    5061    Modules = [M || {ok, {M, [{exports, [_, _, {run, 0}]}]}} <- Chunks], 
     
    6071    ok = file: write_file (File, Bin), 
    6172    Compiler ! check, 
    62     [{2, 1, 1}, {2, 2, 2}, {binaries, [B]}] = receive_all (), 
     73    [{2, 1, 1}, {2, 2, 2}, {{binaries, [B]}, _}] = receive_all (), 
    6374    Compiler ! stop, 
    6475    {ok, {hello, _}} = beam_lib: chunks (B, [exports]), 
     
    7384    ok = file: write_file (File, Bin), 
    7485    Compiler ! check, 
    75     [{1, 0, 0}, {1, 1, 1}, {binaries, [_]}] = receive_all (), 
     86    [{1, 0, 0}, {1, 1, 1}, {{binaries, [_]}, _}] = receive_all (), 
    7687    Compiler ! stop, 
    7788    ok. 
    7889 
    79 %% More tests: 
    80 %% - remove a file 
     90notifies_removed_files (Root, [F, _]) -> 
     91    Compiler = spawn_link (compiler, init, [notify_me (), Root]), 
     92    Compiler ! check, 
     93    receive_all (), 
     94    {file, File, _} = F, 
     95    ok = file: delete (filename: join (Root, File)), 
     96    Compiler ! check, 
     97    [{1, 1, 1}, {{binaries, []}, {removed, [hello]}}] = receive_all (), 
     98    Compiler ! {self (), stop}, 
     99    ok. 
     100 
     101notifies_removed_files_even_if_never_compiled (Root, [F]) -> 
     102    Compiler = spawn_link (compiler, init, [notify_me (), Root]), 
     103    Compiler ! check, 
     104    [{1, 0, 0}, {_, _}, {1, 1, 0}] = receive_all (), 
     105    {file, File, _} = F, 
     106    Filename = filename: join (Root, File), 
     107    Module = modules: module_name (Filename), 
     108    ok = file: delete (Filename), 
     109    Compiler ! check, 
     110    [{0, 0, 0}, {{binaries, []}, {removed, [Module]}}] = receive_all (), 
     111    Compiler ! {self (), stop}, 
     112    ok. 
    81113 
    82114check ([{Total, 0, 0} | _] = Xs, unknown) -> 
     
    93125check ([{Total, Total, N}], Total) when N < Total -> 
    94126    ok; 
    95 check ([{Total, Total, Total}, {binaries, _}], Total) -> 
     127check ([{Total, Total, Total}, {{binaries, _}, {removed, _}}], Total) -> 
    96128    ok. 
    97129 
     
    110142    receive 
    111143        {Total, Total, Total} = Ts -> 
    112             receive {binaries, _} = Bs -> 
     144            receive {{binaries, _}, {removed, _}} = Bs -> 
    113145                    lists: reverse ([Bs, Ts | Ms]) 
    114146            end; 
  • trunk/src/modules.erl

    r61 r68  
    88-export ([forms_to_binary/1]). 
    99-export ([compile/1]). 
     10-export ([module_name/1]). 
    1011 
    1112to_binary (File_name) -> 
     
    2728compile (File) -> 
    2829    compile (fun compile: file/2, File). 
     30 
     31module_name (Filename) -> 
     32    {extension, ".erl"} = {extension, filename: extension (Filename)}, 
     33    String = filename: rootname (filename: basename (Filename)), 
     34    list_to_atom (String). 
  • trunk/src/shells.erl

    r64 r68  
    1111        receive {Self, done} -> ok; 
    1212                M -> io:fwrite ("tests_crash: ~p~n", [M]) 
    13         after 20000 -> throw ("tests timed out~n") 
     13        after 30000 -> throw ("tests timed out~n") 
    1414        end 
    1515 
  • trunk/src/shells_tests.erl

    r64 r68  
    1313    Modules = [fixtures_test, fixtures, 
    1414               directory_watcher_test, directory_watcher, 
    15                compiler_test, compiler, modules], 
     15               compiler_test, compiler, 
     16               modules_test, modules], 
    1617    ok = hand_send_to_tester (Modules, Test_node), 
    1718    Caller ! {Caller, done}. 
Note: See TracChangeset for help on using the changeset viewer.