Changeset 95

Show
Ignore:
Timestamp:
04/11/10 19:19:02 (5 months ago)
Author:
dom
Message:

Two improvements (and new start API): multiple directories watched, and slave started if no node given

Location:
trunk
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/install

    r92 r95  
    66cd ebin 
    77erl -make 
    8 erl -sname extremeforge_install_tester@$hostname -noinput & 
    98erl -kernel error_logger "{file,\"../install_errors.log\"}" \ 
    109    -sname extremeforge_installer@$hostname \ 
    1110    -noinput \ 
    12     -run directory_tester run_once ".." extremeforge_install_tester@$hostname \ 
    13     -s shells stop_node extremeforge_install_tester@$hostname \ 
     11    -run directory_tester run_once ".." \ 
    1412    -s init stop 
  • trunk/src/compiler.erl

    r94 r95  
    88-export ([reset_includes/2]). 
    99 
    10 init (Notify, Dir) -> 
    11     init (Notify, Dir, []). 
     10init (Notify, Dirs) -> 
     11    init (Notify, Dirs, []). 
    1212 
    13 init (Notify, Dir, Options) -> 
     13init (Notify, Dirs, Options) -> 
     14    Watchers = lists: foldl (fun watcher/2, [], Dirs), 
     15    Includes = [{i, D} || D <- Dirs], 
     16    State = {dict: new (), dict: new (), [], [], Includes ++ Options}, 
     17    loop (Notify, Watchers, State). 
     18 
     19watcher (Dir, Acc) -> 
    1420    Args = [Dir, notify_me ()], 
    1521    Watcher = spawn_link (directory_watcher, init_recursive, Args), 
    16     State = {dict: new (), dict: new (), [], [], [{i, Dir} | Options]}, 
    17     loop (Notify, Watcher, State). 
    18  
    19 loop (Notify, Watcher, State) -> 
     22    [Watcher | Acc]. 
     23     
     24loop (Notify, Watchers, State) -> 
    2025    receive 
    2126        check -> 
    22             Watcher ! check, 
     27            [W ! check || W <- Watchers], 
    2328            {Modules, Includes, Binaries, Removed, Options} = State, 
    24             Received = receive_files (Watcher, Modules, Includes), 
     29            Received = receive_files (Modules, Includes), 
    2530            {New_modules, New_includes} = Received, 
    2631            New_options = reset_includes (New_includes, Options), 
    27             New_state = {New_modules, New_includes, Binaries, Removed, New_options}, 
     32            New_state = {New_modules, New_includes, Binaries, 
     33                         Removed, New_options}, 
    2834            Last_state = 
    2935                if 
     
    3339                        New_state 
    3440                end, 
    35             loop (Notify, Watcher, Last_state); 
     41            loop (Notify, Watchers, Last_state); 
    3642        {Pid, stop} -> 
    3743            Pid ! {self (), bye} 
    3844    end. 
    3945 
    40 receive_files (Watcher, Modules, Includes) -> 
     46receive_files (Modules, Includes) -> 
    4147%%          Includes = sets: from_list ([D || {i, D} <- Options]), 
    4248    receive 
    43         {Watcher, {{file, ".erl"}, File, Event}} -> 
    44             receive_files (Watcher, dict: store (File, Event, Modules), Includes); 
    45         {Watcher, {{file, ".hrl"}, File, Event}} -> 
    46             receive_files (Watcher, Modules, dict: store (File, Event, Includes)); 
    47         {Watcher, _} -> 
    48             receive_files (Watcher, Modules, Includes) 
     49        {watcher, {{file, ".erl"}, File, Event}} -> 
     50            receive_files (dict: store (File, Event, Modules), Includes); 
     51        {watcher, {{file, ".hrl"}, File, Event}} -> 
     52            receive_files (Modules, dict: store (File, Event, Includes)); 
     53        {watcher, _} -> 
     54            receive_files (Modules, Includes) 
    4955    after 500 -> 
    5056            {Modules, Includes} 
     
    9298notify_me () -> 
    9399    Self = self (), 
    94     fun (E) -> Self ! {self (), E} end. 
     100    fun (E) -> Self ! {watcher, E} end. 
    95101             
    96102totals (Modules) -> 
  • trunk/src/compiler_test.erl

    r94 r95  
    1818-export ([reset_includes_none/0]). 
    1919-export ([reset_includes_found/0]). 
     20-export ([can_be_given_several_directories/0]). 
    2021-include_lib("stdlib/include/ms_transform.hrl"). 
    2122 
     
    2526     
    2627compiles_and_reports_progress_warnings_and_errors (Root, _) -> 
    27     Compiler = spawn_link (compiler, init, [notify_me (), Root]), 
     28    Compiler = spawn_link (compiler, init, [notify_me (), [Root]]), 
    2829    Compiler ! check, 
    2930    Ms = receive_all (), 
     
    3536 
    3637stops (Root, _) -> 
    37     Compiler = spawn_link (compiler, init, [notify_me (), Root]), 
     38    Compiler = spawn_link (compiler, init, [notify_me (), [Root]]), 
    3839    Compiler ! check, 
    3940    receive_all (), 
     
    6869    ok = fixtures: use_tree (Tree, F). 
    6970 
     71can_be_given_several_directories () -> 
     72    Tree = [{directory, "src1", good_erl_tree ()}, 
     73            {directory, "src2", [{file, "yo.erl", "-module(yo)."}]}], 
     74    ok = fixtures: use_tree (Tree, fun can_be_given_several_directories/2). 
     75 
     76can_be_given_several_directories (Root, _) -> 
     77    Dirs = [filename: join (Root, D) || D <- ["src1", "src2"]], 
     78    Compiler = spawn_link (compiler, init, [notify_me (), Dirs]), 
     79    Compiler ! check, 
     80    Ms = receive_all (), 
     81    Compiler ! stop, 
     82    [{3, 0, 0}, _, _, {3, 3, 3}, {{binaries, _}, _}] = Ms, 
     83    ok. 
     84     
    7085can_be_given_include_directories () -> 
    7186    Src = "-module(inc).\n-include(\"inc.hrl\").", 
     
    91106 
    92107adds_root_to_include_path (Root, _) -> 
    93     Compiler = spawn_link (compiler, init, [notify_me (), Root]), 
     108    Compiler = spawn_link (compiler, init, [notify_me (), [Root]]), 
    94109    Compiler ! check, 
    95110    Ms = receive_all (), 
     
    113128 
    114129discovers_hrl (Root, _) -> 
    115     Compiler = spawn_link (compiler, init, [notify_me (), Root]), 
     130    Compiler = spawn_link (compiler, init, [notify_me (), [Root]]), 
    116131    Compiler ! check, 
    117132    Ms = receive_all (), 
     
    121136 
    122137provides_binaries_when_all_compiled (Root, _) -> 
    123     Compiler = spawn_link (compiler, init, [notify_me (), Root]), 
     138    Compiler = spawn_link (compiler, init, [notify_me (), [Root]]), 
    124139    Compiler ! check, 
    125140    Ms = receive_all (), 
     
    133148 
    134149provides_all_binaries_not_just_latest_when_all_compiled (Root, [_, File]) -> 
    135     Compiler = spawn_link (compiler, init, [notify_me (), Root]), 
     150    Compiler = spawn_link (compiler, init, [notify_me (), [Root]]), 
    136151    Compiler ! check, 
    137152    [{2, 0, 0}, _, _, {2, 2, 1}] = receive_all (), 
     
    144159 
    145160recompiles_minimally_after_change (Root, _) -> 
    146     Compiler = spawn_link (compiler, init, [notify_me (), Root]), 
     161    Compiler = spawn_link (compiler, init, [notify_me (), [Root]]), 
    147162    Compiler ! check, 
    148163    receive_all (), 
     
    158173 
    159174can_start_empty_and_add_files (Root, []) -> 
    160     Compiler = spawn_link (compiler, init, [notify_me (), Root]), 
     175    Compiler = spawn_link (compiler, init, [notify_me (), [Root]]), 
    161176    Compiler ! check, 
    162177    [timeout] = receive_all (), 
     
    170185 
    171186notifies_removed_files (Root, [F, _]) -> 
    172     Compiler = spawn_link (compiler, init, [notify_me (), Root]), 
     187    Compiler = spawn_link (compiler, init, [notify_me (), [Root]]), 
    173188    Compiler ! check, 
    174189    receive_all (), 
     
    181196 
    182197notifies_removed_files_even_if_never_compiled (Root, [F]) -> 
    183     Compiler = spawn_link (compiler, init, [notify_me (), Root]), 
     198    Compiler = spawn_link (compiler, init, [notify_me (), [Root]]), 
    184199    Compiler ! check, 
    185200    [{1, 0, 0}, {_, _}, {1, 1, 0}] = receive_all (), 
     
    195210include_no_directory (Root, _) -> 
    196211    Src = filename: join (Root, "src"), 
    197     Compiler = spawn_link (compiler, init, [notify_me (), Src]), 
     212    Compiler = spawn_link (compiler, init, [notify_me (), [Src]]), 
    198213    Compiler ! check, 
    199214    [{1, 0, 0}, {_, _}, {1, 1, 0}] = receive_all (), 
     
    204219    Src = filename: join (Root, "src"), 
    205220    Inc = filename: join (Root, "include"), 
    206     Compiler = spawn_link (compiler, init, [notify_me (), Src, [{i, Inc}]]), 
     221    Compiler = spawn_link (compiler, init, [notify_me (), [Src], [{i, Inc}]]), 
    207222    Compiler ! check, 
    208223    [{1, 0, 0}, {1, 1, 1}, {{binaries, _}, _}] = receive_all (), 
  • trunk/src/directory_tester.erl

    r93 r95  
    44 
    55-module (directory_tester). 
    6 -export ([init/1, init/3]). 
    7 -export ([run_once/1, run_once/3]). 
     6-export ([init/1, init/2, init/3]). 
     7-export ([run_once/1, run_once/2, run_once/3]). 
     8-export ([slave_node/1]). 
     9-export ([read_args/1]). 
    810 
    9 run_once ([Directory, Node | Include_directories]) when is_list (Node) -> 
    10     Options = [{i, I} || I <- Include_directories], 
    11     run_once (Directory, list_to_atom (Node), [{compiler, Options}]). 
     11run_once (Args) -> 
     12    {Directories, Options} = read_args (Args), 
     13    run_once (Directories, Options). 
    1214 
    13 run_once (Directory, Node, Options) -> 
    14     run (start (Directory, Node, Options)). 
     15run_once (Directories, All_options) -> 
     16    Slave_args = proplists: get_value (slave, All_options), 
     17    Options = proplists: delete (slave, All_options), 
     18    run_once (Directories, slave (Slave_args), Options). 
    1519 
    16 init ([Directory, Node | Include_directories]) when is_list (Node) -> 
    17     Options = [{i, I} || I <- Include_directories], 
    18     init (Directory, list_to_atom (Node), [{compiler, Options}]). 
     20run_once (Directories, Node, Options) -> 
     21    run (start (Directories, Node, Options)). 
     22 
     23init (Args) -> 
     24    {Directories, Options} = read_args (Args), 
     25    init (Directories, Options). 
     26 
     27init (Directories, All_options) -> 
     28    Slave_args = proplists: get_value (slave, All_options), 
     29    Options = proplists: delete (slave, All_options), 
     30    init (Directories, slave (Slave_args), Options).  
    1931     
    20 init (Directory, Node, Options) -> 
    21     loop (start (Directory, Node, Options)). 
     32init (Directories, Node, Options) -> 
     33    loop (start (Directories, Node, Options)). 
    2234 
    23 start (Directory, Node, Options) -> 
     35slave (undefined) -> 
     36    {Host, Name} = slave_node (node ()), 
     37    {ok, Slave} = slave: start_link (Host, Name), 
     38    Slave; 
     39slave (Args) when is_list (Args) -> 
     40    {Host, Name} = slave_node (node ()), 
     41    {ok, Slave} = slave: start_link (Host, Name, Args), 
     42    Slave. 
     43 
     44start (Directories, Node, Options) -> 
    2445    Compiler_options = options (compiler, Options), 
    25     Compiler_args = [notify_me (compiler), Directory, Compiler_options], 
     46    Compiler_args = [notify_me (compiler), Directories, Compiler_options], 
    2647    Compiler = spawn_link (compiler, init, Compiler_args), 
    2748    Tester = spawn_link (tester, init, [notify_me (tester), Node]), 
     
    2950    Printer = spawn_link (text_printer, init, [standard_io]), 
    3051    {Compiler, Tester, Printer}. 
     52 
     53 
     54slave_node (nonode@nohost) -> 
     55    not_alive; 
     56slave_node (Node) -> 
     57    Node_string = atom_to_list (Node), 
     58    [Name, Host_string] = string: tokens (Node_string, "@"), 
     59    Slave_name_string = Name ++ "_extremeforge_slave", 
     60    Slave_name = list_to_atom (Slave_name_string), 
     61    Host = list_to_atom (Host_string), 
     62    {Host, Slave_name}. 
     63 
     64read_args (Args) when length (Args) == 1 -> 
     65    [Dirs] = read_path_args (Args), 
     66    {Dirs, []}; 
     67read_args (Args) when length (Args) == 2 -> 
     68    [Dirs, Incs] = read_path_args (Args), 
     69    Options = [{compiler, [{i, I} || I <- Incs]}], 
     70    {Dirs, Options}; 
     71read_args ([Arg1, Arg2, Slave_args]) -> 
     72    {Dirs, C_options} = read_args ([Arg1, Arg2]), 
     73    {Dirs, [{slave, Slave_args} | C_options]}. 
     74 
     75read_path_args (Paths) -> 
     76    Dirs = [string: tokens (P, ":") || P <- Paths], 
     77    Not_dir = [D || D <- lists: concat (Dirs), not filelib: is_dir (D)], 
     78    {not_dir, []} = {not_dir, Not_dir}, 
     79    Dirs. 
    3180 
    3281notify_me (Atom) ->