Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

verbose (-v) flag; warn on missing files

  • Loading branch information...
commit 4446e701544396a89fcdaec1888d1c12ca0d8fc6 1 parent 7e7bcc3
Ulf Wiger authored

Showing 1 changed file with 25 additions and 10 deletions. Show diff stats Hide diff stats

  1. +25 10 src/setup_gen.erl
35 src/setup_gen.erl
@@ -19,6 +19,12 @@
19 19 run/1, % when called from within erlang
20 20 help/0]). % prints help text.
21 21
  22 +-define(if_verbose(Expr),
  23 + case get(verbose) of
  24 + true -> Expr;
  25 + _ -> ok
  26 + end).
  27 +
22 28 main([]) ->
23 29 help(),
24 30 halt(1);
@@ -67,7 +73,11 @@ run(Options) ->
67 73 %% dbg:tracer(),
68 74 %% dbg:tpl(?MODULE,x),
69 75 %% dbg:p(all,[c]),
70   - io:fwrite("Options = ~p~n", [Options]),
  76 + case lists:keyfind(verbose, 1, Options) of
  77 + {_, true} -> put(verbose, true);
  78 + _ -> ignore
  79 + end,
  80 + ?if_verbose(io:fwrite("Options = ~p~n", [Options])),
71 81 [Name, RelDir] =
72 82 [option(K, Options) || K <- [name, outdir]],
73 83 ensure_dir(RelDir),
@@ -79,7 +89,7 @@ run(Options) ->
79 89 add_paths(Roots),
80 90 RelVsn = rel_vsn(RelDir, Options),
81 91 Rel = {release, {Name, RelVsn}, {erts, erts_vsn()}, apps(Config, Options)},
82   - io:fwrite("Rel: ~p~n", [Rel]),
  92 + ?if_verbose(io:fwrite("Rel: ~p~n", [Rel])),
83 93 in_dir(RelDir,
84 94 fun() ->
85 95 write_eterm("start.rel", Rel),
@@ -121,6 +131,7 @@ help() ->
121 131 "-sys F : Name of pre-existing sys.config file~n"
122 132 "-vsn V : System version (otherwise derived from outdir)~n"
123 133 "-install B : B:: true|false - whether to create install boot script~n"
  134 + "-v : Verbose - generate lots of output~n"
124 135 , []).
125 136
126 137 options(["-name" , N|T]) -> [{name, N}|options(T)];
@@ -133,6 +144,7 @@ options(["-install" | ["-" ++ _|_] = T]) -> [{install, true}|options(T)];
133 144 options(["-install" , D|T]) -> [{install, mk_bool(D)}|options(T)];
134 145 options(["-sys" , D|T]) -> [{sys, D}|options(T)];
135 146 options(["-vsn" , D|T]) -> [{vsn, D}|options(T)];
  147 +options(["-v" |T]) -> [{verbose, true}|options(T)];
136 148 options(["-V" ++ VarName, ExprStr | T]) ->
137 149 Var = list_to_atom(VarName),
138 150 Term = parse_term(ExprStr),
@@ -321,7 +333,7 @@ in_dir(D, F) ->
321 333 {ok, Old} = file:get_cwd(),
322 334 try file:set_cwd(D) of
323 335 ok ->
324   - io:fwrite("entering directory ~s~n", [D]),
  336 + ?if_verbose(io:fwrite("entering directory ~s~n", [D])),
325 337 F();
326 338 Error ->
327 339 abort("Error entering rel dir (~p): ~p~n", [D,Error])
@@ -335,7 +347,7 @@ apps(Config, Options) ->
335 347 fun() ->
336 348 ensure_setup(Apps0)
337 349 end, Apps0),
338   - io:fwrite("Apps1 = ~p~n", [Apps1]),
  350 + ?if_verbose(io:fwrite("Apps1 = ~p~n", [Apps1])),
339 351 AppVsns = lists:map(fun({App,load}) ->
340 352 {App, app_vsn(App), load};
341 353 ({_,_,load} = A) ->
@@ -346,7 +358,7 @@ apps(Config, Options) ->
346 358 end,
347 359 {A, app_vsn(A)}
348 360 end, Apps1),
349   - io:fwrite("AppVsns = ~p~n", [AppVsns]),
  361 + ?if_verbose(io:fwrite("AppVsns = ~p~n", [AppVsns])),
350 362 %% setup_is_load_only(replace_versions(AppVsns, Apps1)).
351 363 setup_is_load_only(AppVsns).
352 364
@@ -369,9 +381,9 @@ add_paths(Roots) ->
369 381 Paths = lists:foldl(fun(R, Acc) ->
370 382 expand_root(R, Acc)
371 383 end, [], Roots),
372   - io:fwrite("Paths = ~p~n", [Paths]),
  384 + ?if_verbose(io:fwrite("Paths = ~p~n", [Paths])),
373 385 Res = code:add_paths(Paths -- code:get_path()),
374   - io:fwrite("add path Res = ~p~n", [Res]).
  386 + ?if_verbose(io:fwrite("add path Res = ~p~n", [Res])).
375 387
376 388 expand_root(R, Acc) ->
377 389 case filename:basename(R) of
@@ -384,6 +396,9 @@ expand_root(R, Acc) ->
384 396 expand_root(filename:join(R, F), Acc1)
385 397 end, Acc, Fs);
386 398 {error,enotdir} ->
  399 + Acc;
  400 + {error,_} = E ->
  401 + ?if_verbose(io:fwrite("warning: ~p (~s)~n", [E, R])),
387 402 Acc
388 403 end
389 404 end.
@@ -415,7 +430,7 @@ app_vsn(A) ->
415 430 case file:consult(AppFile) of
416 431 {ok, [{application, _, Opts}]} ->
417 432 V = proplists:get_value(vsn, Opts),
418   - io:fwrite("app_vsn(~p) -> ~p~n", [A,V]),
  433 + ?if_verbose(io:fwrite("app_vsn(~p) -> ~p~n", [A,V])),
419 434 V;
420 435 Other ->
421 436 abort("Oops reading .app file (~p): ~p~n", [AppFile, Other])
@@ -443,11 +458,11 @@ make_boot(Rel, Roots) ->
443 458 V = var_name(N),
444 459 {{V, R}, N+1}
445 460 end, 1, Roots),
446   - io:fwrite("Path = ~p~n", [Path]),
  461 + ?if_verbose(io:fwrite("Path = ~p~n", [Path])),
447 462 Res = systools:make_script(Rel, [no_module_tests, local,
448 463 {variables, Vars},
449 464 {path, path(Roots)}]),
450   - io:fwrite("make_script() -> ~p~n", [Res]).
  465 + ?if_verbose(io:fwrite("make_script() -> ~p~n", [Res])).
451 466
452 467
453 468 make_install_rel({release, R, Erts, Apps}) ->

0 comments on commit 4446e70

Please sign in to comment.
Something went wrong with that request. Please try again.