Skip to content

Commit

Permalink
NextRoll-ize this Project (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brujo Benavides authored Feb 26, 2021
1 parent 8915cca commit a88d07b
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
doc/
.rebar3
_*
.eunit
Expand All @@ -13,5 +14,6 @@ erl_crash.dump
.rebar
logs
_build
rebar3.crashdump
priv/libzstd/libzstd.a
priv/zstd_nif.so
17 changes: 14 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
language: erlang

os:
- linux

otp_release:
- 18.3
- 19.2
- 20.2
- 22.3

notifications:
email: rtb-team+travis@adroll.com

script:
- rebar3 --version
- erl -version
- rebar3 format --verify
- rebar3 test
17 changes: 17 additions & 0 deletions elvis.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[{elvis,
[{config,
[#{dirs => ["src"],
filter => "*.erl",
ruleset => erl_files},
#{dirs => ["test"],
filter => "*.erl",
ruleset => erl_files,
rules =>
%% Variables in eunit macros are called, for instance, __V
[{elvis_style, variable_naming_convention, #{regex => "^_?_?([A-Z][0-9a-zA-Z]*)_?$"}}]},
#{dirs => ["."],
filter => "*rebar.config",
ruleset => rebar_config},
#{dirs => ["."],
filter => "elvis.config",
ruleset => elvis_config}]}]}].
57 changes: 48 additions & 9 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
{erl_opts, [debug_info]}.
{erl_opts,
[warn_unused_vars,
warn_export_all,
warn_shadow_vars,
warn_unused_import,
warn_unused_function,
warn_bif_clash,
warn_unused_record,
warn_deprecated_function,
warn_obsolete_guard,
strict_validation,
warn_export_vars,
warn_exported_vars,
debug_info]}.

{minimum_otp_vsn, "21"}.

{deps, []}.

{pre_hooks,
[{"(linux|darwin|solaris)", compile, "make MOREFLAGS=-fPIC -C priv/zstd/lib libzstd.a"},
{"(linux|darwin|solaris)", compile, "make -C c_src"},
{"(freebsd)", compile, "gmake MOREFLAGS=-fPIC -C priv/zstd/lib libzstd.a"},
{"(freebsd)", compile, "gmake -C c_src"}]}.
[{"(linux|darwin|solaris)", compile, "make MOREFLAGS=-fPIC -C priv/zstd/lib libzstd.a"},
{"(linux|darwin|solaris)", compile, "make -C c_src"},
{"(freebsd)", compile, "gmake MOREFLAGS=-fPIC -C priv/zstd/lib libzstd.a"},
{"(freebsd)", compile, "gmake -C c_src"}]}.

{post_hooks,
[{"(linux|darwin|solaris)", clean, "make -C c_src clean"},
{"(linux|darwin|solaris)", clean, "make -C priv/zstd/lib clean"},
{"(freebsd)", clean, "gmake -C c_src clean"},
{"(freebsd)", clean, "gmake -C priv/zstd/lib clean"}]}.
[{"(linux|darwin|solaris)", clean, "make -C c_src clean"},
{"(linux|darwin|solaris)", clean, "make -C priv/zstd/lib clean"},
{"(freebsd)", clean, "gmake -C c_src clean"},
{"(freebsd)", clean, "gmake -C priv/zstd/lib clean"}]}.

{dialyzer,
[{warnings, [no_return, error_handling]},
{plt_apps, top_level_deps},
{plt_extra_apps, []},
{plt_location, local},
{base_plt_apps, [erts, stdlib, kernel]},
{base_plt_location, global}]}.

{xref_checks,
[undefined_function_calls,
locals_not_used,
deprecated_function_calls,
deprecated_functions]}.

{alias, [{test, [format, lint, hank, xref, dialyzer, eunit]}]}.

{project_plugins,
[{rebar3_format, "~> 0.10.0"}, {rebar3_lint, "~> 0.3.2"}, {rebar3_hank, "~> 0.2.1"}]}.

%% @todo Remove this when rebar3_hank reaches 0.3.0
{hank, [{ignore, [{"src/zstd.erl", unused_ignored_function_params}]}]}.
21 changes: 11 additions & 10 deletions src/zstd.app.src
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{application,zstd,
[{description,"Zstd binding for Erlang/Elixir"},
{vsn,"0.2.0"},
{registered,[]},
{applications,[kernel,stdlib]},
{env,[]},
{modules,[]},
{maintainers,["Yuki Ito"]},
{licenses,["BSD"]},
{links,[{"GitHub","https://github.com/mururu/zstd-erlang"}]}]}.
{application,
zstd,
[{description, "Zstd binding for Erlang/Elixir"},
{vsn, "0.2.0"},
{registered, []},
{applications, [kernel, stdlib]},
{env, []},
{modules, []},
{maintainers, ["Yuki Ito"]},
{licenses, ["BSD"]},
{links, [{"GitHub", "https://github.com/mururu/zstd-erlang"}]}]}.
30 changes: 17 additions & 13 deletions src/zstd.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-export([compress/1, compress/2]).
-export([decompress/1]).

-on_load(init/0).
-on_load init/0.

-define(APPNAME, zstd).
-define(LIBNAME, zstd_nif).
Expand All @@ -12,7 +12,8 @@
compress(Binary) ->
compress(Binary, 1).

-spec compress(Uncompressed :: binary(), CompressionLevel :: 0..22) -> Compressed :: binary().
-spec compress(Uncompressed :: binary(), CompressionLevel :: 0..22) ->
Compressed :: binary().
compress(_, _) ->
erlang:nif_error(?LINE).

Expand All @@ -21,15 +22,18 @@ decompress(_) ->
erlang:nif_error(?LINE).

init() ->
SoName = case code:priv_dir(?APPNAME) of
{error, bad_name} ->
case filelib:is_dir(filename:join(["..", priv])) of
true ->
filename:join(["..", priv, ?LIBNAME]);
_ ->
filename:join([priv, ?LIBNAME])
end;
Dir ->
filename:join(Dir, ?LIBNAME)
end,
SoName =
case code:priv_dir(?APPNAME) of
{error, bad_name} ->
case filelib:is_dir(
filename:join(["..", priv]))
of
true ->
filename:join(["..", priv, ?LIBNAME]);
_ ->
filename:join([priv, ?LIBNAME])
end;
Dir ->
filename:join(Dir, ?LIBNAME)
end,
erlang:load_nif(SoName, 0).
6 changes: 4 additions & 2 deletions test/zstd_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
-include_lib("eunit/include/eunit.hrl").

zstd_test() ->
Data = <<"Hello, World!">>,
?assertEqual(Data, zstd:decompress(zstd:compress(Data))).
Data = <<"Hello, World!">>,
?assertEqual(Data,
zstd:decompress(
zstd:compress(Data))).

0 comments on commit a88d07b

Please sign in to comment.