6
%% Copyright Ericsson AB 2010. All Rights Reserved.
8
%% The contents of this file are subject to the Erlang Public License,
9
%% Version 1.1, (the "License"); you may not use this file except in
10
%% compliance with the License. You should have received a copy of the
11
%% Erlang Public License along with this software. If not, it can be
12
%% retrieved online at http://www.erlang.org/.
14
%% Software distributed under the License is distributed on an "AS IS"
15
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
16
%% the License for the specific language governing rights and limitations
21
-include_lib("reltool/src/reltool.hrl").
24
process_flag(trap_exit, true),
26
Tokens = scan_args(Args, [], []),
27
{Options, Actions} = parse_args(Tokens, []),
28
case invoke(Options, Actions) of
31
{error, ReasonString} ->
32
fatal_error(ReasonString, 2)
39
String = lists:flatten(io_lib:format("EXIT: ~p", [Reason])),
40
fatal_error(String, 3)
46
"[Config] [--window]",
47
"[Config] --create_config [-defaults] [-derived] [ConfigFile]",
48
"[Config] --create_rel RelName [RelFile]",
49
"[Config] --create_script RelName [ScriptFile]",
50
"[Config] --create_target TargetDir",
51
"[Config] --create_target_spec [SpecFile]",
52
"[Config] --eval_target_spec Spec TargetDir RootDir"
54
Script = script_name(),
55
String = lists:flatten([[Script, " ", U, "\n"] || U <- Usage]),
56
io:format("Erlang/OTP release management tool\n\n"
57
"~s\nConfig = ConfigFile | '{sys, [sys()]}'\n"
58
"Spec = SpecFile | '{spec, [target_spec()}']\n\n"
59
"See User's guide and Reference manual for more info.\n",
64
timer:sleep(infinity).
66
invoke(Options, Actions) ->
69
invoke(Options, [["--window"]]);
71
start_window(Options);
72
[["--create_config" | OptArgs]] ->
74
DerivArg = "-derived",
75
InclDef = lists:member(DefArg, OptArgs),
76
InclDeriv = lists:member(DerivArg, OptArgs),
77
case reltool:get_config(Options, InclDef, InclDeriv) of
79
String = pretty("config", Config),
80
case OptArgs -- [DefArg, DerivArg] of
82
format("~s", [String]);
84
write_file(ConfigFile, String);
91
[["--create_rel", RelName | OptArgs]] ->
92
case reltool:get_rel(Options, RelName) of
94
String = pretty("rel", Rel),
97
format("~s", [String]);
99
write_file(RelFile, String);
106
[["--create_script", RelName | OptArgs]] ->
107
case reltool:get_script(Options, RelName) of
109
String = pretty("script", Script),
112
format("~s", [String]);
114
write_file(ScriptFile, String);
121
[["--create_target", TargetDir]] ->
122
reltool:create_target(Options, TargetDir);
123
[["--create_target_spec" | OptArgs]] ->
124
case reltool:get_target_spec(Options) of
126
String = pretty("target_spec", Script),
129
format("~s", [String]);
131
write_file(SpecFile, String);
138
[["--eval_target_spec", TargetSpec, TargetDir, RootDir]] ->
140
{ok, Tokens, _} = erl_scan:string(TargetSpec ++ ". "),
141
{ok, {spec, Spec}} = erl_parse:parse_term(Tokens),
142
reltool:eval_target_spec(Spec, TargetDir, RootDir)
144
error:{badmatch, _} ->
145
case file:consult(TargetSpec) of
147
reltool:eval_target_spec(Spec2, TargetDir, RootDir);
149
Text = file:format_error(Reason),
150
{error, TargetSpec ++ ": " ++ Text}
157
start_window(Options) ->
158
case reltool:start_link(Options) of
161
{'EXIT', WinPid, shutdown} ->
163
{'EXIT', WinPid, normal} ->
165
{'EXIT', WinPid, Reason} ->
172
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177
filename:basename(escript:script_name(), ".escript").
179
fatal_error(String, Code) ->
180
io:format(standard_error, "~s: ~s\n", [script_name(), String]),
183
write_file(File, IoList) ->
184
case file:write_file(File, IoList) of
188
{error, file:format_error(Reason)}
191
format(Format, Args) ->
192
io:format(Format, Args),
193
%% Wait a while for the I/O to be processed
194
timer:sleep(timer:seconds(1)).
197
lists:flatten(io_lib:format("%% ~s generated at ~w ~w\n~p.\n\n",
198
[Tag, date(), time(), Term])).
200
scan_args([H | T], Single, Multi) ->
202
"--" ++ _ when Single =:= [] ->
203
scan_args(T, [H], Multi);
205
scan_args(T, [H], [lists:reverse(Single) | Multi]);
207
scan_args(T, [H | Single], Multi)
209
scan_args([], [], Multi) ->
210
lists:reverse(Multi);
211
scan_args([], Single, Multi) ->
212
lists:reverse([lists:reverse(Single) | Multi]).
214
parse_args([H | T] = Args, Options) ->
216
["--wx_debug" | Levels] ->
219
case catch list_to_integer(L) of
221
case catch list_to_atom(L) of
223
exit("Illegal wx debug level: " ++ L);
231
Levels2 = lists:map(Dbg, Levels),
232
parse_args(T, [{wx_debug, Levels2} | Options]);
235
{lists:reverse(Options), Args};
238
{ok, Tokens, _} = erl_scan:string(Config ++ ". "),
239
{ok, {sys, _} = Sys} = erl_parse:parse_term(Tokens),
240
parse_args(T, [{config, Sys} | Options])
242
error:{badmatch, _} ->
243
parse_args(T, [{config, Config} | Options]);
245
io:format("\n\n~p\n\n", [{X, Y}])
248
parse_args([], Options) ->
249
{lists:reverse(Options), []}.