Trim a little
% TODO: Don't concurrently print warnings and errors
--record(arguments, {
- lib = "./" :: string(),
- out = "./" :: string(),
- modules = [] :: list(string())
-}).
+-record(arguments, {lib = "./", out = "./", modules = []}).
-%% # Usage
-%%
-%% ```shell
-%% escript compile_erlang.erl \
-%% --lib path/to/libs \
-%% --out package/ebin \
-%% package/src/one.erl package/src/two.erl
-%% ```
-%%
main(Args) ->
#arguments{out = Out, lib = Lib, modules = Modules} = parse(Args),
ok = add_lib_to_erlang_path(Lib),
ok = filelib:ensure_dir([Out, $/]),
Workers = start_compiler_workers(Out),
ok = producer_loop(Modules, Workers),
- case any_failures() of
- true -> erlang:halt(1);
- false -> ok
+ receive
+ failed -> erlang:halt(1)
+ after 0 -> ok
end.
producer_loop([], 0) ->
@@ -41,19 +28,11 @@ producer_loop([Module | Modules], Workers) ->
producer_loop(Modules, Workers)
end.
-any_failures() ->
- receive
- failed -> true
- after 0 -> false
- end.
-
start_compiler_workers(Out) ->
Parent = self(),
NumSchedulers = erlang:system_info(schedulers),
SpawnWorker = fun(_) ->
- erlang:spawn_link(fun() ->
- worker_loop(Parent, Out)
- end)
+ erlang:spawn_link(fun() -> worker_loop(Parent, Out) end)
end,
lists:foreach(SpawnWorker, lists:seq(1, NumSchedulers)),
NumSchedulers.
@@ -71,9 +50,7 @@ worker_loop(Parent, Out) ->
end.
add_lib_to_erlang_path(Lib) ->
- Ebins = filelib:wildcard([Lib, "/*/ebin"]),
- ok = code:add_paths(Ebins),
- ok.
+ code:add_paths(filelib:wildcard([Lib, "/*/ebin"])) .
parse(Args) ->
parse(Args, #arguments{}).
