diff --git a/.gitignore b/.gitignore index 5ba80d7..227c3a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +doc/ .rebar3 _* .eunit @@ -13,5 +14,6 @@ erl_crash.dump .rebar logs _build +rebar3.crashdump priv/libzstd/libzstd.a priv/zstd_nif.so diff --git a/.travis.yml b/.travis.yml index 2588174..0b263a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/elvis.config b/elvis.config new file mode 100644 index 0000000..1d6b2d9 --- /dev/null +++ b/elvis.config @@ -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}]}]}]. diff --git a/rebar.config b/rebar.config index bfa369d..8b8ba21 100644 --- a/rebar.config +++ b/rebar.config @@ -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}]}]}. diff --git a/src/zstd.app.src b/src/zstd.app.src index c0921d7..79d8c3d 100644 --- a/src/zstd.app.src +++ b/src/zstd.app.src @@ -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"}]}]}. diff --git a/src/zstd.erl b/src/zstd.erl index 70d35b5..edea336 100644 --- a/src/zstd.erl +++ b/src/zstd.erl @@ -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). @@ -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). @@ -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). diff --git a/test/zstd_tests.erl b/test/zstd_tests.erl index c3049b3..4927a04 100644 --- a/test/zstd_tests.erl +++ b/test/zstd_tests.erl @@ -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))).