This repository has been archived by the owner on May 27, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add enscript runner (TODO create a binary like rebar does)
- Loading branch information
1 parent
c32a10e
commit c10aef7
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env escript | ||
%%! -smp enable -sname espec_runner -pa deps/*/ebin -pa ebin | ||
|
||
-define(SPEC_FILE_REGEXP, ".*_espec.erl$"). | ||
|
||
main([]) -> | ||
usage(); | ||
main(Args) -> | ||
SpecFiles = expand_files_from_args(Args), | ||
run_spec_files(SpecFiles). | ||
|
||
-spec usage() -> term(). | ||
usage() -> | ||
io:format("Usage: espec [files or directories]\n"), | ||
halt(1). | ||
|
||
-spec expand_files_from_args(list()) -> list(). | ||
expand_files_from_args(FilesOrDirs) -> | ||
lists:append(lists:map(fun(FileOrDir) -> | ||
case filelib:is_dir(FileOrDir) of | ||
true -> | ||
filelib:fold_files(FileOrDir, ?SPEC_FILE_REGEXP, true, fun(File, Acc) -> | ||
[File | Acc] | ||
end, []); | ||
false -> | ||
[FileOrDir] | ||
end | ||
end, FilesOrDirs)). | ||
|
||
-spec run_spec_files(list()) -> term(). | ||
run_spec_files(SpecFiles) -> | ||
CompileOptions = [ | ||
binary, | ||
{i, "ebin"}, | ||
{i, "include"}, | ||
report, | ||
warnings_as_errors | ||
], | ||
Modules = lists:foldl(fun(SpecFile, Acc) -> | ||
case compile:file(SpecFile, CompileOptions) of | ||
{ok, Module, Binary} -> | ||
{module, Module} = code:load_binary(Module, SpecFile, Binary), | ||
[Module | Acc]; | ||
error -> | ||
% errors and warnings are automatically printed to stdout | ||
Acc | ||
end | ||
end, [], SpecFiles), | ||
espec:run_no_shell(Modules). |