Skip to content

Commit

Permalink
Merge pull request #248 from basho/develop-3.0-mergerebar3
Browse files Browse the repository at this point in the history
Develop 3.0 mergerebar3
  • Loading branch information
martinsumner authored May 7, 2020
2 parents c4bcb11 + ff12621 commit 9273682
Show file tree
Hide file tree
Showing 19 changed files with 988 additions and 276 deletions.
50 changes: 37 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
.rebar3
_build
.DS_Store
generated.config
generated.conf
ebin/*
doc/*
.eunit
deps
cuttlefish
# rebar and tools
*.crashdump
.cache/
.rebar3/
_build/
_checkouts
rebar.lock
log/

# work environments
*.bak
*.dump
*.iml
*.plt
*.sublime-project
*.sublime-workspace
log
.local_dialyzer_plt
*.tmp
*.txt
*_plt
*~
.DS_Store
.idea/
.project
.settings/
.tm_properties
erln8.config
tmp/

# Erlang artifacts
*.app
*.beam
/doc/
/ebin/

# build/test artifacts
/cuttlefish
generated.conf
generated.config
src/conf_parse.erl
src/cuttlefish_duration_parse.erl
test_fixtures/escript_prune_test/generated.config/*
rebar.lock
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: erlang
otp_release:
- 20.3.8
- 21.3
- 22.1
- 22.3
script:
- chmod u+x rebar3
- ./rebar3 do upgrade, compile, dialyzer, eunit
- ./rebar3 do upgrade, compile, xref, dialyzer, eunit
111 changes: 111 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# -------------------------------------------------------------------
#
# Copyright (c) 2013-2017 Basho Technologies, Inc.
#
# This file is provided to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# -------------------------------------------------------------------

prj_dir := $(CURDIR)
cache := $(prj_dir)/.cache

dl_tgts :=
#
# tools
#
ifeq ($(REBAR3),)
REBAR3 := $(cache)/rebar3
dl_tgts += $(REBAR3)
endif
export REBAR3
CP := /bin/cp -p
RM := /bin/rm

.PHONY : check clean clean-deps clean-docs clean-dist compile dialyzer \
default docs escript prereqs test validate veryclean xref

default : compile

prereqs ::

compile :: prereqs
$(REBAR3) as prod compile

check :: prereqs
$(REBAR3) as check do brt-deps --check, dialyzer, xref

clean :: prereqs
$(REBAR3) clean --all

clean-deps :: clean
$(RM) -rf $(prj_dir)/_build

clean-docs ::
$(REBAR3) as docs clean

clean-dist ::
$(RM) -f $(prj_dir)/cuttlefish

docs :: prereqs
$(REBAR3) edoc

dialyzer :: prereqs
$(REBAR3) as check dialyzer

escript :: prereqs
$(REBAR3) as prod escriptize
$(CP) _build/prod/bin/cuttlefish $(prj_dir)/cuttlefish

test :: prereqs
$(REBAR3) eunit

validate :: prereqs
$(REBAR3) as validate compile

veryclean :: clean clean-docs clean-deps clean-dist
$(RM) -rf $(cache)

xref :: prereqs
$(REBAR3) as check xref

#
# how to download files if we need to
#
ifneq ($(dl_tgts),)

dlcmd := $(shell which wget 2>/dev/null || true)
ifneq ($(wildcard $(dlcmd)),)
dlcmd += -O
else
dlcmd := $(shell which curl 2>/dev/null || true)
ifneq ($(wildcard $(dlcmd)),)
dlcmd += -o
else
$(error Need wget or curl to download files)
endif
endif

prereqs :: $(dl_tgts)

veryclean ::
$(RM) -rf $(dl_tgts)

$(cache)/rebar3 :
@test -d $(@D) || /bin/mkdir -p $(@D)
@echo Downloading $@ ...
@$(dlcmd) $@ https://s3.amazonaws.com/rebar3/rebar3
@/bin/chmod +x $@

endif # dl_tgts
12 changes: 11 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{minimum_otp_vsn, "R16"}.
{minimum_otp_vsn, "20"}.

{erl_opts, [warnings_as_errors,
{parse_transform, lager_transform},
Expand All @@ -15,6 +15,14 @@

{provider_hooks, [{post, [{compile, {default, escriptize}}]}]}.

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

{eunit_opts, [verbose]}.
{cover_enabled, true}.
{cover_print_enabled, true}.
Expand All @@ -23,3 +31,5 @@
{profiles, [{dev, [{deps, [neotoma]},
{plugins, [rebar3_neotoma_plugin]}]},
{test, [{deps, [bbmustache]}]}]}.


Binary file modified rebar3
Binary file not shown.
24 changes: 10 additions & 14 deletions src/conf_parse.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

%% -------------------------------------------------------------------
%%
%% conf_parse: for all your .conf parsing needs.
%%
%% Copyright (c) 2013 Basho Technologies, Inc. All Rights Reserved.
%% Copyright (c) 2019 Pivotal Software, Inc. All rights reserved.
%% Copyright (c) 2013-2017 Basho Technologies, Inc.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
Expand All @@ -37,10 +34,13 @@
%% under the License.
%%
%% -------------------------------------------------------------------
%%
%% This is a generated file, changes should be made to conf_parse.peg.
%%

%% This module implements the parser for a sysctl-style
%% configuration format. Example:
%% This module implements the parser for a sysctl-style configuration format.
%%
%% Example:
%% ```
%% riak.local.node = riak@127.0.0.1
%% riak.local.http = 127.0.0.1:8098
Expand All @@ -57,7 +57,8 @@
%%
%% Other modules in this application interpret and validate the
%% result of a successful parse.
%% @end
%%

-define(line, true).
-define(FMT(F,A), lists:flatten(io_lib:format(F,A))).

Expand All @@ -80,7 +81,7 @@ unescape_dots([C|Rest]) ->

-ifdef(TEST).
file_test() ->
Conf = conf_parse:file("test/riak.conf"),
Conf = conf_parse:file(cuttlefish_test_util:test_file("riak.conf")),
?assertEqual([
{["ring_size"],"32"},
{["anti_entropy"],"debug"},
Expand Down Expand Up @@ -118,12 +119,7 @@ gh_1_three_tab_test() ->
-endif.

-spec file(file:name()) -> any().
file(Filename) ->
AbsFilename = filename:absname(Filename),
case erl_prim_loader:get_file(AbsFilename) of
{ok, Bin, _} -> parse(Bin);
error -> {error, undefined}
end.
file(Filename) -> case file:read_file(Filename) of {ok,Bin} -> parse(Bin); Err -> Err end.

-spec parse(binary() | list()) -> any().
parse(List) when is_list(List) -> parse(unicode:characters_to_binary(List));
Expand Down
16 changes: 9 additions & 7 deletions src/conf_parse.peg
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ ws <- [ \t]+ `ws`;

%% -------------------------------------------------------------------
%%
%% conf_parse: for all your .conf parsing needs.
%%
%% Copyright (c) 2013 Basho Technologies, Inc. All Rights Reserved.
%% Copyright (c) 2013-2017 Basho Technologies, Inc.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
Expand All @@ -120,10 +118,13 @@ ws <- [ \t]+ `ws`;
%% under the License.
%%
%% -------------------------------------------------------------------
%%
%% This is a generated file, changes should be made to conf_parse.peg.
%%

%% This module implements the parser for a sysctl-style
%% configuration format. Example:
%% This module implements the parser for a sysctl-style configuration format.
%%
%% Example:
%% ```
%% riak.local.node = riak@127.0.0.1
%% riak.local.http = 127.0.0.1:8098
Expand All @@ -140,7 +141,8 @@ ws <- [ \t]+ `ws`;
%%
%% Other modules in this application interpret and validate the
%% result of a successful parse.
%% @end
%%

-define(line, true).
-define(FMT(F,A), lists:flatten(io_lib:format(F,A))).

Expand All @@ -163,7 +165,7 @@ unescape_dots([C|Rest]) ->

-ifdef(TEST).
file_test() ->
Conf = conf_parse:file("test/riak.conf"),
Conf = conf_parse:file(cuttlefish_test_util:test_file("riak.conf")),
?assertEqual([
{["ring_size"],"32"},
{["anti_entropy"],"debug"},
Expand Down
18 changes: 10 additions & 8 deletions src/cuttlefish.app.src
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{application,cuttlefish,
[{description,"cuttlefish configuration abstraction"},
{vsn,"2.3.0"},
{registered,[]},
{applications,[kernel,stdlib]},
{env,[]},
{licenses,["Apache"]},
{links,[{"GitHub","https://github.com/Kyorai/cuttlefish"}]}]}.
{application, cuttlefish, [
{description, "cuttlefish configuration abstraction"},
{vsn, git},
{registered, []},
{applications, [kernel, sasl, stdlib, syntax_tools, getopt, lager]},
{env, []},
{modules, []},
{licenses, ["Apache 2.0"]},
{links, [{"Github", "https://github.com/basho/cuttlefish"}]}
]}.
24 changes: 15 additions & 9 deletions src/cuttlefish_conf.erl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
%% -------------------------------------------------------------------
%%
%% cuttlefish_conf: handles the reading and generation of .conf files
%%
%% Copyright (c) 2013 Basho Technologies, Inc. All Rights Reserved.
%% Copyright (c) 2013-2017 Basho Technologies, Inc.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
Expand All @@ -19,6 +17,10 @@
%% under the License.
%%
%% -------------------------------------------------------------------

%%
%% @doc Handles the reading and generation of .conf files.
%%
-module(cuttlefish_conf).

-export([
Expand Down Expand Up @@ -297,27 +299,31 @@ generate_comments_test() ->
?assertEqual(["## Hi!", "## Bye!", "## ", "## Acceptable values:", "## - text"], Comments).

duplicates_test() ->
Conf = file("test/multi1.conf"),
Conf = file(cuttlefish_test_util:test_file("multi1.conf")),
?assertEqual(2, length(Conf)),
?assertEqual("3", proplists:get_value(["a","b","c"], Conf)),
?assertEqual("1", proplists:get_value(["a","b","d"], Conf)),
ok.

duplicates_multi_test() ->
Conf = files(["test/multi1.conf", "test/multi2.conf"]),
Conf = files([
cuttlefish_test_util:test_file("multi1.conf"),
cuttlefish_test_util:test_file("multi2.conf") ]),
?assertEqual(2, length(Conf)),
?assertEqual("4", proplists:get_value(["a","b","c"], Conf)),
?assertEqual("1", proplists:get_value(["a","b","d"], Conf)),
ok.

files_one_nonent_test() ->
Conf = files(["test/multi1.conf", "test/nonent.conf"]),
?assertMatch({errorlist,[{error, {file_open, {"test/nonent.conf", _}}}]}, Conf),
NonEnt = cuttlefish_test_util:test_file("nonent.conf"),
Conf = files([cuttlefish_test_util:test_file("multi1.conf"), NonEnt]),
?assertEqual({errorlist,[{error, {file_open, {NonEnt, enoent}}}]}, Conf),
ok.

files_incomplete_parse_test() ->
Conf = file("test/incomplete.conf"),
?assertEqual({errorlist, [{error, {conf_syntax, {"test/incomplete.conf", {3, 1}}}}]}, Conf),
File = cuttlefish_test_util:test_file("incomplete.conf"),
Conf = file(File),
?assertEqual({errorlist, [{error, {conf_syntax, {File, {3, 1}}}}]}, Conf),
ok.

generate_element_level_advanced_test() ->
Expand Down
Loading

0 comments on commit 9273682

Please sign in to comment.