Skip to content
Newer
Older
100644 333 lines (291 sloc) 7.63 KB
84adefa The R13B03 release.
Erlang/OTP authored
1 %%
2 %% %CopyrightBegin%
3 %%
4 %% Copyright Ericsson AB 1997-2009. All Rights Reserved.
5 %%
6 %% The contents of this file are subject to the Erlang Public License,
7 %% Version 1.1, (the "License"); you may not use this file except in
8 %% compliance with the License. You should have received a copy of the
9 %% Erlang Public License along with this software. If not, it can be
10 %% retrieved online at http://www.erlang.org/.
11 %%
12 %% Software distributed under the License is distributed on an "AS IS"
13 %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14 %% the License for the specific language governing rights and limitations
15 %% under the License.
16 %%
17 %% %CopyrightEnd%
18 %%
19 %% To be used from makefiles on the unix side executing things on the NT-side
20 -module(ntbuild).
21
22 -export([nmake/1, omake/1, waitnode/1, restart/1,
23 setdir/1, run_tests/1, run_command/1]).
24 -export([serv_nmake/2, serv_omake/2, serv_restart/0, serv_run_tests/2,
25 serv_run_command/1]).
26
27 waitnode([NtNode]) ->
28 % First, wait for node to disappear.
29 case wait_disappear(NtNode, 0) of
30 ok ->
31 case wait_appear(NtNode, 0) of
32 ok ->
33 halt(0);
34 fail ->
35 halt(1)
36 end;
37 fail ->
38 halt(1)
39 end.
40
41 % Wait for nt node to appear within 5 minutes.
42 wait_appear(_NtNode, 300) ->
43 fail;
44 wait_appear(NtNode, N) ->
45 receive after 1000 -> ok end,
46 case nt_node_alive(NtNode, quiet) of
47 no ->
48 wait_appear(NtNode, N+1);
49 yes ->
50 ok
51 end.
52
53
54
55 % Waits for nt node to disappear within 3 minutes.
56 wait_disappear(NtNode, 300) ->
57 fail;
58 wait_disappear(NtNode, N) ->
59 receive after 1000 -> ok end,
60 case nt_node_alive(NtNode, quiet) of
61 yes ->
62 wait_disappear(NtNode, N+1);
63 no ->
64 ok
65 end.
66
67 restart([NtNode]) ->
68 case nt_node_alive(NtNode) of
69 yes ->
70 case rpc:call(NtNode, ntbuild, serv_restart, []) of
71 ok ->
72 io:format("halt(0)~n"),
73 halt();
74 Error ->
75 io:format("halt(1)~n"),
76 halt(1)
77 end;
78 no ->
79 halt(1)
80 end.
81
82
83 setdir([NtNode, Dir0]) ->
84 Dir = atom_to_list(Dir0),
85 case nt_node_alive(NtNode) of
86 yes ->
87 case rpc:call(NtNode, file, set_cwd, [Dir]) of
88 ok ->
89 io:format("halt(0)~n"),
90 halt();
91 Error ->
92 io:format("halt(1) (Error: ~p) (~p not found) ~n", [Error, Dir]),
93 halt(1)
94 end;
95 no ->
96 halt(1)
97 end.
98
99 run_tests([NtNode, Vsn0, Logdir]) ->
100 Vsn = atom_to_list(Vsn0),
101 case nt_node_alive(NtNode) of
102 yes ->
103 case rpc:call(NtNode, ntbuild, serv_run_tests, [Vsn, Logdir]) of
104 ok ->
105 io:format("halt(0)~n"),
106 halt();
107 Error ->
108 io:format("RPC To Windows Node Failed: ~p~n", [Error]),
109 io:format("halt(1)~n"),
110 halt(1)
111 end;
112 no ->
113 halt(1)
114 end.
115
116 run_command([NtNode, Cmd]) ->
117 case nt_node_alive(NtNode) of
118 yes ->
119 case rpc:call(NtNode, ntbuild, serv_run_command, [Cmd]) of
120 ok ->
121 io:format("halt(0)~n"),
122 halt();
123 Error ->
124 io:format("RPC To Windows Node Failed: ~p~n", [Error]),
125 io:format("halt(1)~n"),
126 halt(1)
127 end;
128 no ->
129 halt(1)
130 end.
131
132 nmake([NtNode, Path, Options]) ->
133 % io:format("nmake2(~w,~w)~n",[Path, Options]),
134 Dir=atom_to_list(Path),
135 Opt=atom_to_list(Options),
136 case nt_node_alive(NtNode) of
137 yes ->
138 case rpc:call(NtNode, ntbuild, serv_nmake, [Dir, Opt]) of
139 ok ->
140 io:format("halt(0)~n"),
141 halt();
142 Error ->
143 io:format("Error: ~n", [Error]),
144 halt(1)
145 end;
146 no ->
147 halt(1)
148 end.
149
150 omake([NtNode, Path, Options]) ->
151 Dir=atom_to_list(Path),
152 Opt=atom_to_list(Options),
153 case nt_node_alive(NtNode) of
154 yes ->
155 case rpc:call(NtNode, ntbuild, serv_omake, [Dir, Opt]) of
156 ok ->
157 io:format("halt(0)~n"),
158 halt();
159 Error ->
160 io:format("RPC To Windows Node Failed: ~p~n", [Error]),
161 io:format("~p ~p~n", [Dir, Opt]),
162 io:format("halt(1)~n"),
163 halt(1)
164 end;
165 no ->
166 halt(1)
167 end.
168
169
170
171
172
173 nt_node_alive(NtNode) ->
174 case net:ping(NtNode) of
175 pong ->
176 yes;
177 pang ->
178 io:format("The NT node (~p) is not up. ~n",[NtNode]),
179 no
180 end.
181
182 nt_node_alive(NtNode, quiet) ->
183 case net:ping(NtNode) of
184 pong ->
185 yes;
186 pang ->
187 no
188 end.
189
190
191
192 %%%
193 %%% The 'serv_' functions. Theese are the routines run on the WinNT node.
194 %%%
195
196 %%-----------------------
197 %% serv_run_tests()
198 %% Runs the tests.
199 serv_run_tests(Vsn, Logdir) ->
200 {ok, Cwd}=file:get_cwd(),
201 io:format("serv_run_tests ~p ~p ~n", [Vsn, Logdir]),
202 Cmd0= "set central_log_dir=" ++ Logdir,
203 Erl = "C:/progra~1/erl"++Vsn++"/bin/erl",
204 Cmd1 = Erl++" -sname a -setcookie a -noshell -noinput -s ts install -s ts run -s ts save -s erlang halt",
205 %% Dir = "C:/temp/test_suite/test_server",
206 Cmd= Cmd0 ++ "/r/n" ++ Cmd1,
207 Dir = "C:/temp/test_server/p7a/test_server",
208 file:set_cwd(Dir),
209 Res=run_make_bat(Dir, Cmd),
210 file:set_cwd(Cwd),
211 Res.
212
213 %%-----------------------
214 %% serv_run_command()
215 %% Runs a command.
216 serv_run_command(Cmd) ->
217 {ok, Cwd}=file:get_cwd(),
218 Res=run_make_bat("", Cmd),
219 file:set_cwd(Cwd),
220 Res.
221
222 %%-----------------------
223 %% serv_restart()
224 %% Reboots the NT machine.
225 serv_restart() ->
226 Exe="\\erts\\install_nt\\reboot.exe",
227 open_port({spawn, Exe}, [stream, eof, in]),
228 ok.
229
230
231 %%-----------------------
232 %% serv_nmake(Path, Options)
233 %% Runs `nmake' in the given directory.
234 %% Result: ok | error
235 serv_nmake(Path, Options) ->
236 {ok, Cwd}=file:get_cwd(),
237 Command="nmake -e -f Makefile.win32 " ++ Options ++ " 2>&1",
238 Res=run_make_bat(Path, Command),
239 file:set_cwd(Cwd),
240 Res.
241
242 %%-----------------------
243 %% serv_omake(Path, Options)
244 %% Runs `omake' in the given directory.
245 %% Result: ok | error
246 serv_omake(Path, Options) ->
247 {ok, Cwd}=file:get_cwd(),
248 Command="omake -W -E -EN -f Makefile.win32 " ++ Options ++ " 2>&1",
249 Res=run_make_bat(Path, Command),
250 file:set_cwd(Cwd),
251 Res.
252
253
254 read_output(Port, SoFar) ->
255 % io:format("(read_output)~n"),
256 case get_data_from_port(Port) of
257 eof ->
258 io:format("*** eof ***~n"),
259 io:format("Never reached a real message"),
260 halt(1);
261 {ok, Data} ->
262 case print_line([SoFar|Data]) of
263 {ok, Rest} ->
264 read_output(Port, Rest);
265 {done, Res} ->
266 Res
267 end
268 end.
269
270 print_line(Data) ->
271 print_line(Data, []).
272
273 print_line([], Acc) ->
274 {ok, lists:reverse(Acc)};
275 print_line([$*,$o,$k,$*|Rest], _Acc) ->
276 io:format("*ok*~n"),
277 {done, ok};
278 print_line([$*,$e,$r,$r,$o,$r|Rest], _Acc) ->
279 io:format("*error*~n"),
280 {done, error};
281 print_line([$\r,$\n|Rest], Acc) ->
282 io:format("~s~n", [lists:reverse(Acc)]),
283 print_line(Rest, []);
284 print_line([Chr|Rest], Acc) ->
285 print_line(Rest, [Chr|Acc]).
286
287 get_data_from_port(Port) ->
288 receive
289 {Port, {data, Bytes}} ->
290 {ok, Bytes};
291 {Port, eof} ->
292 unlink(Port),
293 exit(Port, die),
294 eof;
295 Other ->
296 io:format("Strange message received: ~p~n", [Other]),
297 get_data_from_port(Port)
298 end.
299
300
301 run_make_bat(Dir, Make) ->
302 {Name, Exe, Script}=create_make_script(Dir, Make),
303 io:format("Exe:~p Cwd:~p Script:~p ~n",[Exe, Dir, Script]),
304 case file:write_file(Name, Script) of
305 ok ->
306 case catch open_port({spawn, Exe}, [stderr_to_stdout, stream, hide,
307 eof, in]) of
308 Port when port(Port) ->
309 read_output(Port, []);
310 Other ->
311 io:format("Error, open_port failed: ~p~n", [Other]),
312 {open_port, Other, Exe}
313 end;
314 Error ->
315 {write_file, Error, Name}
316 end.
317
318 create_make_script(Dir, Make) when atom(Make) ->
319 create_make_script(Dir, atom_to_list(Make));
320 create_make_script(Dir, Make) ->
321 {"run_make_bs.bat",
322 "run_make_bs 2>&1",
323 ["@echo off\r\n",
324 "@cd ", Dir, "\r\n",
325 Make++"\r\n",
326 "if errorlevel 1 echo *run_make_bs error*\r\n",
327 "if not errorlevel 1 echo *ok*\r\n"]}.
328
329
330
331
332
Something went wrong with that request. Please try again.