Browse Source

Migrate to Rebar3

Alexander Petrovsky 9 years ago
parent
commit
2fac9a8d64
11 changed files with 137 additions and 393 deletions
  1. 24 10
      .gitignore
  2. 43 35
      Makefile
  3. 3 3
      README.org
  4. 0 230
      concrete.mk
  5. 0 0
      config/demo.config
  6. 0 0
      config/pooler-example.config
  7. 49 16
      rebar.config
  8. 0 97
      rebar.config.script
  9. BIN
      rebar3
  10. 0 0
      src/pooled_gs.erl
  11. 18 2
      src/pooler.erl

+ 24 - 10
.gitignore

@@ -1,13 +1,27 @@
-ebin
+.rebar3
+_*
+.eunit
+*.o
 *.beam
+*.plt
+*.swp
+*.swo
+.erlang.cookie
+ebin
+log
+erl_crash.dump
+.rebar
+_rel
+_deps
+_plugins
+_tdeps
+logs
+_build
+doc/stylesheet.css
+doc/erlang.png
+doc/edoc-info
 doc/*.html
-.eunit
-/doc/stylesheet.css
-/doc/erlang.png
-/doc/edoc-info
-/bench/tests
-/bench/deps
+doc/*.md
+bench/tests
+bench/deps
 
-/.concrete/
-/.rebar/
-/deps/

+ 43 - 35
Makefile

@@ -1,38 +1,46 @@
-# This Makefile written by concrete
-#
-# {concrete_makefile_version, 2}
-#
-# ANY CHANGES TO THIS FILE WILL BE OVERWRITTEN on `concrete update`
-# IF YOU WANT TO CHANGE ANY OF THESE LINES BELOW, COPY THEM INTO
-# custom.mk FIRST
-
-# Use this to override concrete's default dialyzer options of
-# -Wunderspecs
-# DIALYZER_OPTS = ...
-
-# List dependencies that you do NOT want to be included in the
-# dialyzer PLT for the project here.  Typically, you would list a
-# dependency here if it isn't spec'd well and doesn't play nice with
-# dialyzer or otherwise mucks things up.
-#
-# DIALYZER_SKIP_DEPS = bad_dep_1 \
-#                      bad_dep_2
-
-# If you want to add dependencies to the default "all" target provided
-# by concrete, add them here (along with make rules to build them if needed)
-# ALL_HOOK = ...
-
-# custom.mk is totally optional
-custom_rules_file = $(wildcard custom.mk)
-ifeq ($(custom_rules_file),custom.mk)
-    include custom.mk
-endif
+.PHONY: all compile run test doc clean
+.PHONY: build_plt add_to_plt dialyzer
+
+REBAR=./rebar3
+
+DIALYZER_APPS = asn1 compiler crypto erts inets kernel public_key sasl ssl stdlib syntax_tools tools
+
+all: $(REBAR) compile
+
+compile:
+		$(REBAR) as dev compile
+
+run:
+		erl -pa _build/dev/lib/*/ebin -boot start_sasl -config config/demo.config -run pooler
+
+test:
+		$(REBAR) eunit skip_deps=true verbose=3
+		$(REBAR) ct skip_deps=true verbose=3
 
-concrete_rules_file = $(wildcard concrete.mk)
-ifeq ($(concrete_rules_file),concrete.mk)
-    include concrete.mk
+doc:
+		$(REBAR) as dev edoc
+
+clean:
+		$(REBAR) clean
+		rm -rf ./erl_crash.dump
+
+build_plt: clean compile
+ifneq ("$(wildcard erlang.plt)","")
+		@echo "Erlang plt file already exists"
+else
+		dialyzer --build_plt --output_plt erlang.plt --apps $(DIALYZER_APPS)
+endif
+ifneq ("$(wildcard pooler.plt)","")
+		@echo "redis_pool plt file already exists"
 else
-    all:
-	@echo "ERROR: missing concrete.mk"
-	@echo "  run: concrete update"
+		dialyzer --build_plt --output_plt pooler.plt _build/default/lib/*/ebin/
 endif
+
+add_to_plt: build_plt
+		dialyzer --add_to_plt --plt erlang.plt --output_plt erlang.plt.new --apps $(DIALYZER_APPS)
+		dialyzer --add_to_plt --plt pooler.plt --output_plt pooler.plt.new _build/default/lib/*/ebin/
+		mv erlang.plt.new erlang.plt
+		mv pooler.plt.new pooler.plt
+
+dialyzer:
+		dialyzer --src src -r src --plts erlang.plt pooler.plt -Wno_return -Werror_handling -Wrace_conditions -Wunderspecs | fgrep -v -f ./dialyzer.ignore-warnings

+ 3 - 3
README.org

@@ -175,7 +175,7 @@ pooler:new_pool(PoolConfig).
 Here's an example session:
 
 #+BEGIN_SRC erlang
-application:start(pooler).
+pooler:start().
 P = pooler:take_member(mysql),
 % use P
 pooler:return_member(mysql, P, ok).
@@ -265,12 +265,12 @@ When enabled, the following metrics will be tracked:
    #+END_EXAMPLE
 3. Start a demo
    #+BEGIN_EXAMPLE
-   erl -pa .eunit ebin -config demo
+   make run
 
    Erlang R16B03 (erts-5.10.4) [source] [64-bit] [smp:8:8] [async-threads:10] [kernel-poll:false]
 
    Eshell V5.10.4  (abort with ^G)
-   1> application:start(pooler).
+   1> pooler:start().
    ok
    2> M = pooler:take_member(pool1).
    <0.44.0>

+ 0 - 230
concrete.mk

@@ -1,230 +0,0 @@
-# =============================================================================
-# Verify that the programs we need to run are installed on this system
-# =============================================================================
-ERL = $(shell which erl)
-
-ifeq ($(ERL),)
-$(error "Erlang not available on this system")
-endif
-
-# If building on travis, use the rebar in the current directory
-ifeq ($(TRAVIS),true)
-REBAR = $(CURDIR)/rebar
-endif
-
-# If there is a rebar in the current directory, use it
-ifeq ($(wildcard rebar),rebar)
-REBAR = $(CURDIR)/rebar
-endif
-
-# Fallback to rebar on PATH
-REBAR ?= $(shell which rebar)
-
-# And finally, prep to download rebar if all else fails
-ifeq ($(REBAR),)
-REBAR = $(CURDIR)/rebar
-endif
-
-# If we have a rebar.config.lock file, use it!
-ifeq ($(wildcard rebar.config.lock),rebar.config.lock)
-REBAR_CONFIG = rebar.config.lock
-else
-REBAR_CONFIG = rebar.config
-endif
-
-# This is the variable to use to respect the lock file
-REBARC = $(REBAR) -C $(REBAR_CONFIG)
-
-# For use on Travis CI, skip dialyzer for R14 and R15. Newer versions
-# have a faster dialyzer that is less likely to cause a build timeout.
-DIALYZER = dialyzer
-R14 = $(findstring R14,$(TRAVIS_OTP_RELEASE))
-R15 = $(findstring R15,$(TRAVIS_OTP_RELEASE))
-ifneq ($(R14),)
-DIALYZER = echo "SKIPPING dialyzer"
-endif
-ifneq ($(R15),)
-DIALYZER = echo "SKIPPING dialyzer"
-endif
-ifneq ($(SKIP_DIALYZER),)
-DIALYZER = echo "SKIPPING dialyzer"
-endif
-
-REBAR_URL=https://github.com/rebar/rebar/wiki/rebar
-
-DEPS ?= $(CURDIR)/deps
-
-DIALYZER_OPTS ?=
-
-# Find all the deps the project has by searching the deps dir
-ALL_DEPS = $(notdir $(wildcard deps/*))
-# Create a list of deps that should be used by dialyzer by doing a
-# complement on the sets
-DEPS_LIST = $(filter-out $(DIALYZER_SKIP_DEPS), $(ALL_DEPS))
-# Create the path structure from the dep names
-# so dialyzer can find the .beam files in the ebin dir
-# This list is then used by dialyzer in creating the local PLT
-DIALYZER_DEPS = $(foreach dep,$(DEPS_LIST),deps/$(dep)/ebin)
-
-DEPS_PLT = deps.plt
-
-ERLANG_DIALYZER_APPS ?= asn1 \
-                        compiler \
-                        crypto \
-                        edoc \
-                        erts \
-                        inets \
-                        kernel \
-                        mnesia \
-                        public_key \
-                        ssl \
-                        stdlib \
-                        syntax_tools \
-                        tools \
-                        xmerl
-
-PROJ = $(notdir $(CURDIR))
-
-# Let's compute $(BASE_PLT_ID) that identifies the base PLT to use for this project
-# and depends on your `$(ERLANG_DIALYZER_APPS)' list and your erlang version
-ERLANG_VERSION := $(shell $(ERL) -eval 'io:format("~s~n", [erlang:system_info(otp_release)]), halt().' -noshell)
-MD5_BIN := $(shell which md5 || which md5sum)
-ifeq ($(MD5_BIN),)
-# neither md5 nor md5sum, we just take the project name
-BASE_PLT_ID := $(PROJ)
-else
-BASE_PLT_ID := $(word 1, $(shell echo $(ERLANG_DIALYZER_APPS) $(ERLANG_VERSION) | $(MD5_BIN)))
-endif
-BASE_PLT := ~/.concrete_dialyzer_plt_$(BASE_PLT_ID)_$(ERLANG_VERSION).plt
-
-all: all_but_dialyzer dialyzer
-
-all_but_dialyzer: .concrete/DEV_MODE compile eunit $(ALL_HOOK)
-
-$(REBAR):
-	curl -Lo rebar $(REBAR_URL) || wget $(REBAR_URL)
-	chmod a+x rebar
-
-get-rebar: $(REBAR)
-
-.concrete/DEV_MODE:
-	@mkdir -p .concrete
-	@touch $@
-
-# Clean ebin and .eunit of this project
-clean:
-	@$(REBARC) clean skip_deps=true
-
-# Clean this project and all deps
-# Newer rebar requires -r to recursively clean
-allclean:
-	@($(REBARC) --help 2>&1|grep -q recursive && $(REBARC) -r clean) || $(REBARC) clean
-
-compile: $(DEPS)
-	@$(REBARC) compile
-
-$(DEPS):
-	@$(REBARC) get-deps
-
-# Full clean and removal of all deps. Remove deps first to avoid
-# wasted effort of cleaning deps before nuking them.
-distclean:
-	@rm -rf deps $(DEPS_PLT)
-	@$(REBARC) clean
-
-eunit:
-	@$(REBARC) skip_deps=true eunit
-
-test: eunit
-
-# Only include local PLT if we have deps that we are going to analyze
-ifeq ($(strip $(DIALYZER_DEPS)),)
-dialyzer: $(BASE_PLT)
-	@$(DIALYZER) $(DIALYZER_OPTS) -r ebin
-else
-dialyzer: $(BASE_PLT) $(DEPS_PLT)
-	@$(DIALYZER) $(DIALYZER_OPTS) --plts $(BASE_PLT) $(DEPS_PLT) -r ebin
-
-$(DEPS_PLT):
-	@$(DIALYZER) --build_plt $(DIALYZER_DEPS) --output_plt $(DEPS_PLT)
-endif
-
-$(BASE_PLT):
-	@echo "Missing $(BASE_PLT). Please wait while a new PLT is compiled."
-	$(DIALYZER) --build_plt --apps $(ERLANG_DIALYZER_APPS) --output_plt $(BASE_PLT)
-	@echo "now try your build again"
-
-doc:
-	@$(REBARC) doc skip_deps=true
-
-shell:
-	@$(ERL) -pa deps/*/ebin ebin .eunit
-
-tags:
-	find src deps -name "*.[he]rl" -print | etags -
-
-# Releases via relx. we will install a local relx, as we do for rebar,
-# if we don't find one on PATH.
-RELX_CONFIG ?= $(CURDIR)/relx.config
-RELX = $(shell which relx)
-RELX_OPTS ?=
-RELX_OUTPUT_DIR ?= _rel
-ifeq ($(RELX),)
-RELX = $(CURDIR)/relx
-RELX_VERSION = 1.0.4
-else
-RELX_VERSION = $(shell relx --version)
-endif
-RELX_URL = https://github.com/erlware/relx/releases/download/v$(RELX_VERSION)/relx
-
-# relx introduced a breaking change in v1: the output doesn't have the same structure
-# see https://github.com/erlware/relx/releases/tag/v1.0.0
-ifeq ($(shell echo $(RELX_VERSION) | head -c 1), 0)
-RELX_RELEASE_DIR = $(RELX_OUTPUT_DIR)
-else
-RELX_RELEASE_DIR = $(RELX_OUTPUT_DIR)/$(PROJ)
-endif
-
-$(RELX):
-	curl -Lo relx $(RELX_URL) || wget $(RELX_URL)
-	chmod a+x relx
-
-rel: relclean all_but_dialyzer $(RELX)
-	@$(RELX) -c $(RELX_CONFIG) -o $(RELX_OUTPUT_DIR) $(RELX_OPTS)
-
-devrel: rel
-devrel: lib_dir=$(wildcard $(RELX_RELEASE_DIR)/lib/$(PROJ)-* )
-devrel:
-	@/bin/echo Symlinking deps and apps into release
-	@rm -rf $(lib_dir); mkdir -p $(lib_dir)
-	@ln -sf `pwd`/ebin $(lib_dir)
-	@ln -sf `pwd`/priv $(lib_dir)
-	@ln -sf `pwd`/src $(lib_dir)
-
-relclean:
-	rm -rf $(RELX_OUTPUT_DIR)
-
-## Release prep and dep locking. These recipes use $(REBAR), not
-## $(REBARC) in order to NOT use the lock file since they are
-## concerned with the task of updating the lock file.
-BUMP ?= patch
-prepare_release: distclean unlocked_deps unlocked_compile update_locked_config rel
-	@echo 'release prepared, bumping version'
-	@$(REBAR) bump-rel-version version=$(BUMP)
-
-unlocked_deps:
-	@echo 'Fetching deps as: rebar -C rebar.config'
-	@$(REBAR) -C rebar.config get-deps
-
-# When running the prepare_release target, we have to ensure that a
-# compile occurs using the unlocked rebar.config. If a dependency has
-# been removed, then using the locked version that contains the stale
-# dep will cause a compile error.
-unlocked_compile:
-	@$(REBAR) -C rebar.config compile
-
-update_locked_config:
-	@$(REBAR) lock-deps skip_deps=true
-
-
-.PHONY: all all_but_dialyzer compile eunit test dialyzer clean allclean relclean distclean doc tags get-rebar rel devrel

+ 0 - 0
demo.config → config/demo.config


+ 0 - 0
pooler-example.config → config/pooler-example.config


+ 49 - 16
rebar.config

@@ -1,18 +1,51 @@
-%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
-%% ex: ts=4 sw=4 ft=erlang et
-
-%% Type spec dict() is deprecated in R17 to be removed in R18 in
-%% preference for dict:dict(). But the fix is not compatible with <=
-%% R16.
-%% Compiler Options ============================================================
-{erl_opts,
-    [{platform_define, "^[0-9]+", namespaced_types},
-     debug_info,
-     warnings_as_errors,
-     inline]}.
-
-%% EUnit =======================================================================
-{eunit_opts,
- [{report, {eunit_surefire, [{dir, "."}]}}]}.
+{erl_opts, [
+    {platform_define, "^[0-9]+", namespaced_types},
+
+    debug_info,
+
+    bin_opt_info,
+
+    warn_bif_clash,
+    warn_export_all,
+    warn_obsolete_guard,
+
+    warn_unused_import,
+
+    warn_unused_record,
+    warn_untyped_record,
+
+    warn_shadow_vars,
+    warn_unused_vars,
+    warn_export_vars,
+    warn_exported_vars,
+
+    warn_unused_function,
+    warn_deprecated_function,
+
+    strict_validation,
+    warn_missing_spec
+]}.
+
+{deps, [
+]}.
+
+{profiles, [
+    {dev, [
+        {edoc_opts, [{doclet, edown_doclet}]},
+
+        {deps, [
+            {edown, ".*",
+                {git, "git://github.com/uwiger/edown.git", {tag, "0.8"}}}
+        ]}
+    ]}
+]}.
+
+{eunit_opts, [verbose, {report, {eunit_progress, [colored, profile]}}]}.
+{eunit_compile_opts, [export_all]}.
+
+{ct_opts, []}.
+{ct_compile_opts, [{i, "./include/"}]}.
+
 {cover_enabled, true}.
 {cover_print_enabled, true}.
+

+ 0 - 97
rebar.config.script

@@ -1,97 +0,0 @@
-%% -*- mode: erlang -*-
-%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*-
-%% ex: ts=4 sw=4 ft=erlang et
-
-%% rebar.config.script GENERATED BY concrete
-%%
-%% YOU SHOULDN'T NEED TO EDIT THIS FILE
-%%
-{concrete_rebar_script_version, 3}.
-
-%% We need the following helper function to merge dev only options
-%% into the values provided by rebar.config.
-
-%% Merge the list values in `ToAdd' into the list found at key `Key'
-%% in proplist `C'. Don't duplicate items. New Items are added to the
-%% front of existing items. It is an error if the value at `Key' is
-%% not a list in `C'.
-MergeConfig = fun(skip, C) ->
-                      C;
-                 ({Key, ToAdd}, C) ->
-                      case lists:keyfind(Key, 1, C) of
-                          false ->
-                              lists:keystore(Key, 1, C, {Key, ToAdd});
-                          {Key, List} when is_list(List) ->
-                              %% remove items in ToAdd already in List
-                              ToAdd1 = [ I || I <- ToAdd, not lists:member(I, List) ],
-                              lists:keystore(Key, 1, C, {Key, List ++ ToAdd1 })
-                      end
-              end,
-
-%% -- Add development only options if we are a top-level build  --
-%%
-%% If a file named `.concrete/DEV_MODE' exists, we assume we are a
-%% top-level build (not being built as a dep of another project). We
-%% add the deps from dev_only_deps defined in rebar.config, add
-%% concrete as a dep, and define the compiler macro DEV_ONLY.
-
-%% This macro can be used to conditionally enable code (e.g. tests)
-%% that depend on development only dependencies.
-ErlOpts = {erl_opts, [{d, 'DEV_ONLY'}]},
-
-%% Development only dependencies can be specified in the main
-%% rebar.config. This file should not need to be edited directly.
-DevOnlyDeps = case lists:keyfind(dev_only_deps, 1, CONFIG) of
-                  false ->
-                      skip;
-                  {dev_only_deps, DOD} ->
-                      {deps, DOD}
-              end,
-
-EDown = case proplists:get_value(use_edown, CONFIG) of
-               false ->
-                   skip;
-               _ ->
-                DocOpts = case lists:keymember(edoc_opts, 1, CONFIG) of
-                              true ->
-                                  skip;
-                              false ->
-                                  {edoc_opts, [{doclet, edown_doclet}]}
-                          end,
-                [DocOpts,
-                 {deps,
-                  [{edown, ".*",
-                    {git, "git://github.com/uwiger/edown.git",
-                     {branch, "master"}}}]}]
-           end,
-
-LockDeps = case proplists:get_value(use_lock_deps, CONFIG) of
-               false ->
-                   skip;
-               V ->
-                   Tag = case V of
-                             {_, _} = T -> T;
-                             _ -> {branch, "master"}
-                         end,
-                   [{deps,
-                     [{rebar_lock_deps_plugin, ".*",
-                       {git, "git://github.com/seth/rebar_lock_deps_plugin.git",
-                        Tag}}]},
-                    {plugins, [rebar_lock_deps_plugin]}]
-           end,
-
-ConfigPath = filename:dirname(SCRIPT),
-DevMarker = filename:join([ConfigPath, ".concrete/DEV_MODE"]),
-
-case filelib:is_file(DevMarker) of
-    true ->
-        ToMerge = lists:flatten([DevOnlyDeps, LockDeps, EDown, ErlOpts]),
-        lists:foldl(fun(I, C) -> MergeConfig(I, C) end,
-                    CONFIG, ToMerge);
-    false ->
-        %% If the .concrete/ marker is not present, this script simply
-        %% returns the config specified in rebar.config. This will be
-        %% the behavior when the project is built as a dependency of
-        %% another project.
-        CONFIG
-end.

BIN
rebar3


+ 0 - 0
test/pooled_gs.erl → src/pooled_gs.erl


+ 18 - 2
src/pooler.erl

@@ -27,6 +27,9 @@
 %% API Function Exports
 %% ------------------------------------------------------------------
 
+-export([start/0,
+         stop/0]).
+
 -export([accept_member/2,
          start_link/1,
          take_member/1,
@@ -63,6 +66,19 @@
 -endif.
 
 %% ------------------------------------------------------------------
+%% Application API
+%% ------------------------------------------------------------------
+
+-spec start() -> 'ok'.
+start() ->
+    {ok, _} = application:ensure_all_started(pooler),
+    ok.
+
+-spec stop() -> 'ok'.
+stop() ->
+    ok = application:stop(pooler).
+
+%% ------------------------------------------------------------------
 %% API Function Definitions
 %% ------------------------------------------------------------------
 
@@ -127,8 +143,8 @@ rm_pool(PoolName) ->
 
 %% @doc Terminates the group and all pools in that group.
 %%
-%% If termination of any member pool fails, `rm_group/1` returns
-%% `{error, {failed_delete_pools, Pools}}`, where `Pools` is a list
+%% If termination of any member pool fails, `rm_group/1' returns
+%% `{error, {failed_delete_pools, Pools}}', where `Pools' is a list
 %% of pools that failed to terminate.
 %%
 %% The group is NOT terminated if any member pool did not