- Timestamp:
- 07/15/09 04:39:24 (3 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
-
compiler.erl (modified) (3 diffs)
-
compiler_test.erl (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/compiler.erl
r68 r69 4 4 init (Notify, Dir) -> 5 5 Watcher = spawn_link (directory_watcher, init_recursive, [Dir, notify_me ()]), 6 loop (Notify, Watcher, dict: new () ).6 loop (Notify, Watcher, dict: new (), [], []). 7 7 8 loop (Notify, Watcher, Modules ) ->8 loop (Notify, Watcher, Modules, Binaries, Removed) -> 9 9 receive 10 10 check -> 11 11 Watcher ! check, 12 receive_files (Notify, Watcher, Modules, Modules );12 receive_files (Notify, Watcher, Modules, Modules, Binaries, Removed); 13 13 {Pid, stop} -> 14 14 Pid ! {self (), bye} 15 15 end. 16 16 17 receive_files (Notify, Watcher, Modules, New ) ->17 receive_files (Notify, Watcher, Modules, New, Binaries, Removed) -> 18 18 receive 19 19 {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); 21 21 {Watcher, _} -> 22 receive_files (Notify, Watcher, Modules, New )22 receive_files (Notify, Watcher, Modules, New, Binaries, Removed) 23 23 after 500 -> 24 compile (Notify, Watcher, Modules, New )24 compile (Notify, Watcher, Modules, New, Binaries, Removed) 25 25 end. 26 26 27 compile (Notify, Watcher, Modules, Modules ) ->28 loop (Notify, Watcher, Modules );29 compile (Notify, Watcher, _, Modules ) ->27 compile (Notify, Watcher, Modules, Modules, Binaries, Removed) -> 28 loop (Notify, Watcher, Modules, Binaries, Removed); 29 compile (Notify, Watcher, _, Modules, Binaries, Removed) -> 30 30 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). 35 35 36 36 process (File, Event, Acc) when Event == found; Event == changed -> … … 55 55 56 56 notify_totals (Modules, Notify) -> 57 Notify (dict: fold (fun count/3, {0, 0, 0}, Modules)). 57 Notify (totals (Modules)). 58 59 totals (Modules) -> 60 dict: fold (fun count/3, {0, 0, 0}, Modules). 58 61 59 62 count (_, lost, Acc) -> … … 73 76 Notify ({Errors, Warnings}). 74 77 75 binaries (_, errors) ->76 errors;77 78 binaries ({ok, _, B, _}, Bs) -> 78 79 [B | Bs]; 79 binaries ({error, _, _}, _) ->80 errors.80 binaries ({error, _, _}, Bs) -> 81 Bs. 81 82 82 notify_end (errors, _, _) -> 83 pass; 84 notify_end (Binaries, Removed, Notify) -> 85 Notify ({{binaries, Binaries}, {removed, Removed}}). 83 notify_end ({N, N, N}, Binaries, Removed, Notify) -> 84 Notify ({{binaries, Binaries}, {removed, Removed}}), 85 {[], []}; 86 notify_end (_, Binaries, Removed, _) -> 87 {Binaries, Removed}. -
trunk/src/compiler_test.erl
r68 r69 12 12 -export ([notifies_removed_files/0]). 13 13 -export ([notifies_removed_files_even_if_never_compiled/0]). 14 -export ([provides_all_binaries_not_just_latest_when_all_compiled/0]). 14 15 -include_lib("stdlib/include/ms_transform.hrl"). 15 16 … … 38 39 ok = fixtures: use_tree (good_erl_tree (), F). 39 40 41 provides_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 40 45 can_start_empty_and_add_files () -> 41 46 F = fun can_start_empty_and_add_files/2, … … 61 66 Modules = [M || {ok, {M, [{exports, [_, _, {run, 0}]}]}} <- Chunks], 62 67 [gdbye, hello] = lists: sort (Modules), 68 ok. 69 70 provides_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 (), 63 79 ok. 64 80 … … 132 148 {file, "gdbye.erl", "-module(gdbye). -export([run/0]). run()->gdbye."}]. 133 149 150 bad_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 134 154 notify_me () -> 135 155 Self = self (),
Note: See TracChangeset
for help on using the changeset viewer.
