changed Makefile
 
@@ -2,7 2,7 @@
2
2
3
3
PROJECT = ranch
4
4
PROJECT_DESCRIPTION = Socket acceptor pool for TCP protocols.
5
- PROJECT_VERSION = 1.8.0
5
PROJECT_VERSION = 2.0.0-rc.1
6
6
PROJECT_REGISTERED = ranch_server
7
7
8
8
# Options.
 
@@ -16,8 16,9 @@ LOCAL_DEPS = ssl
16
16
17
17
DOC_DEPS = asciideck
18
18
19
- TEST_DEPS = $(if $(CI_ERLANG_MK),ci.erlang.mk) ct_helper
19
TEST_DEPS = $(if $(CI_ERLANG_MK),ci.erlang.mk) ct_helper havoc
20
20
dep_ct_helper = git https://github.com/ninenines/ct_helper master
21
dep_havoc = git https://github.com/ankhers/havoc master
21
22
22
23
# CI configuration.
23
24
 
@@ -29,26 30,19 @@ AUTO_CI_HIPE ?= OTP-LATEST
29
30
# AUTO_CI_ERLLVM ?= OTP-LATEST
30
31
AUTO_CI_WINDOWS ?= OTP-21
31
32
32
- # Hex configuration.
33
-
34
- define HEX_TARBALL_EXTRA_METADATA
35
- #{
36
- licenses => [<<"ISC">>],
37
- links => #{
38
- <<"User guide">> => <<"https://ninenines.eu/docs/en/ranch/1.8/guide/">>,
39
- <<"Function reference">> => <<"https://ninenines.eu/docs/en/ranch/1.8/manual/">>,
40
- <<"GitHub">> => <<"https://github.com/ninenines/ranch">>,
41
- <<"Sponsor">> => <<"https://github.com/sponsors/essen">>
42
- }
43
- }
44
- endef
45
-
46
33
# Standard targets.
47
34
48
35
include erlang.mk
49
36
37
# Don't run the havoc test suite by default.
38
39
ifndef FULL
40
CT_SUITES := $(filter-out havoc,$(CT_SUITES))
41
endif
42
50
43
# Compile options.
51
44
45
ERLC_OPTS = warn_missing_spec warn_untyped_record
52
46
TEST_ERLC_OPTS = '{parse_transform, eunit_autoexport}'
53
47
54
48
# Dialyze the tests.
 
@@ -68,18 62,19 @@ ci-setup:: $(DEPS_DIR)/ct_helper
68
62
# Prepare for the release.
69
63
70
64
prepare_tag:
71
- $(verbose) $(warning Hex metadata: $(HEX_TARBALL_EXTRA_METADATA))
72
- $(verbose) echo
73
65
$(verbose) echo -n "Most recent tag: "
74
- $(verbose) git tag --sort taggerdate | tail -n1
75
- $(verbose) git verify-tag `git tag --sort taggerdate | tail -n1`
66
$(verbose) git tag | tail -n1
67
$(verbose) git verify-tag `git tag | tail -n1`
76
68
$(verbose) echo -n "MAKEFILE: "
77
69
$(verbose) grep -m1 PROJECT_VERSION Makefile
78
70
$(verbose) echo -n "APP: "
79
71
$(verbose) grep -m1 vsn ebin/$(PROJECT).app | sed 's/ //g'
80
- $(verbose) echo -n "GUIDE: "
81
- $(verbose) grep -h dep_$(PROJECT)_commit doc/src/guide/*.asciidoc || true
82
72
$(verbose) echo
83
- $(verbose) echo "Dependencies:"
84
- $(verbose) grep ^DEPS Makefile || echo "DEPS ="
85
- $(verbose) grep ^dep_ Makefile || true
73
$(verbose) echo "Links in the README:"
74
$(verbose) grep http.*:// README.asciidoc
75
$(verbose) echo
76
$(verbose) echo "Titles in most recent CHANGELOG:"
77
$(verbose) for f in `ls -rv doc/src/guide/migrating_from_*.asciidoc | head -n1`; do \
78
echo $$f:; \
79
grep == $$f; \
80
done
changed README.asciidoc
 
@@ -19,8 19,8 @@ to close any of the currently opened sockets.
19
19
20
20
== Online documentation
21
21
22
- * https://ninenines.eu/docs/en/ranch/1.7/guide[User guide]
23
- * https://ninenines.eu/docs/en/ranch/1.7/manual[Function reference]
22
* https://ninenines.eu/docs/en/ranch/2.0/guide[User guide]
23
* https://ninenines.eu/docs/en/ranch/2.0/manual[Function reference]
24
24
25
25
== Offline documentation
removed ebin/ranch.app
 
@@ -1,9 0,0 @@
1
- {application, 'ranch', [
2
- {description, "Socket acceptor pool for TCP protocols."},
3
- {vsn, "1.8.0"},
4
- {modules, ['ranch','ranch_acceptor','ranch_acceptors_sup','ranch_app','ranch_conns_sup','ranch_crc32c','ranch_listener_sup','ranch_protocol','ranch_proxy_header','ranch_server','ranch_ssl','ranch_sup','ranch_tcp','ranch_transport']},
5
- {registered, [ranch_sup,ranch_server]},
6
- {applications, [kernel,stdlib,ssl]},
7
- {mod, {ranch_app, []}},
8
- {env, []}
9
- ]}.
\ No newline at end of file
changed erlang.mk
 
@@ -17,16 17,16 @@
17
17
ERLANG_MK_FILENAME := $(realpath $(lastword $(MAKEFILE_LIST)))
18
18
export ERLANG_MK_FILENAME
19
19
20
- ERLANG_MK_VERSION = d80984c
20
ERLANG_MK_VERSION = 6c8664c
21
21
ERLANG_MK_WITHOUT =
22
22
23
23
# Make 3.81 and 3.82 are deprecated.
24
24
25
- ifeq ($(MAKELEVEL)$(MAKE_VERSION),03.81)
25
ifeq ($(MAKE_VERSION),3.81)
26
26
$(warning Please upgrade to GNU Make 4 or later: https://erlang.mk/guide/installation.html)
27
27
endif
28
28
29
- ifeq ($(MAKELEVEL)$(MAKE_VERSION),03.82)
29
ifeq ($(MAKE_VERSION),3.82)
30
30
$(warning Please upgrade to GNU Make 4 or later: https://erlang.mk/guide/installation.html)
31
31
endif
32
32
 
@@ -47,18 47,10 @@ verbose_0 = @
47
47
verbose_2 = set -x;
48
48
verbose = $(verbose_$(V))
49
49
50
- ifeq ($(V),3)
51
- SHELL := $(SHELL) -x
52
- endif
53
-
54
50
gen_verbose_0 = @echo " GEN " $@;
55
51
gen_verbose_2 = set -x;
56
52
gen_verbose = $(gen_verbose_$(V))
57
53
58
- gen_verbose_esc_0 = @echo " GEN " $$@;
59
- gen_verbose_esc_2 = set -x;
60
- gen_verbose_esc = $(gen_verbose_esc_$(V))
61
-
62
54
# Temporary files directory.
63
55
64
56
ERLANG_MK_TMP ?= $(CURDIR)/.erlang.mk
 
@@ -66,7 58,7 @@ export ERLANG_MK_TMP
66
58
67
59
# "erl" command.
68
60
69
- ERL = erl A1 -noinput -boot no_dot_erlang
61
ERL = erl A0 -noinput -boot start_clean
70
62
71
63
# Platform detection.
72
64
 
@@ -119,9 111,6 @@ endif
119
111
120
112
distclean:: clean distclean-tmp
121
113
122
- $(ERLANG_MK_TMP):
123
- $(verbose) mkdir -p $(ERLANG_MK_TMP)
124
-
125
114
distclean-tmp:
126
115
$(gen_verbose) rm -rf $(ERLANG_MK_TMP)
127
116
 
@@ -175,7 164,7 @@ $(ERL) $2 -pz $(ERLANG_MK_TMP)/rebar/ebin -eval "$(subst $(newline),,$(call esca
175
164
endef
176
165
177
166
ifeq ($(PLATFORM),msys2)
178
- core_native_path = $(shell cygpath -m $1)
167
core_native_path = $(subst \,\\\\,$(shell cygpath -w $1))
179
168
else
180
169
core_native_path = $1
181
170
endif
 
@@ -184,8 173,7 @@ core_http_get = curl -Lf$(if $(filter-out 0,$(V)),,s)o $(call core_native_path,$
184
173
185
174
core_eq = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))
186
175
187
- # We skip files that contain spaces because they end up causing issues.
188
- core_find = $(if $(wildcard $1),$(shell find $(1:%/=%) \( -type l -o -type f \) -name $(subst *,\*,$2) | grep -v " "))
176
core_find = $(if $(wildcard $1),$(shell find $(1:%/=%) -type f -name $(subst *,\*,$2)))
189
177
190
178
core_lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$(1)))))))))))))))))))))))))))
191
179
 
@@ -194,10 182,6 @@ core_ls = $(filter-out $(1),$(shell echo $(1)))
194
182
# @todo Use a solution that does not require using perl.
195
183
core_relpath = $(shell perl -e 'use File::Spec; print File::Spec->abs2rel(@ARGV) . "\n"' $1 $2)
196
184
197
- define core_render
198
- printf -- '$(subst $(newline),\n,$(subst %,%%,$(subst ','\'',$(subst $(tab),$(WS),$(call $(1))))))\n' > $(2)
199
- endef
200
-
201
185
# Automated update.
202
186
203
187
ERLANG_MK_REPO ?= https://github.com/ninenines/erlang.mk
 
@@ -208,16 192,15 @@ ERLANG_MK_BUILD_DIR ?= .erlang.mk.build
208
192
erlang-mk: WITHOUT ?= $(ERLANG_MK_WITHOUT)
209
193
erlang-mk:
210
194
ifdef ERLANG_MK_COMMIT
211
- $(verbose) git clone $(ERLANG_MK_REPO) $(ERLANG_MK_BUILD_DIR)
212
- $(verbose) cd $(ERLANG_MK_BUILD_DIR) && git checkout $(ERLANG_MK_COMMIT)
195
git clone $(ERLANG_MK_REPO) $(ERLANG_MK_BUILD_DIR)
196
cd $(ERLANG_MK_BUILD_DIR) && git checkout $(ERLANG_MK_COMMIT)
213
197
else
214
- $(verbose) git clone --depth 1 $(ERLANG_MK_REPO) $(ERLANG_MK_BUILD_DIR)
198
git clone --depth 1 $(ERLANG_MK_REPO) $(ERLANG_MK_BUILD_DIR)
215
199
endif
216
- $(verbose) if [ -f $(ERLANG_MK_BUILD_CONFIG) ]; then cp $(ERLANG_MK_BUILD_CONFIG) $(ERLANG_MK_BUILD_DIR)/build.config; fi
217
- $(gen_verbose) $(MAKE) --no-print-directory -C $(ERLANG_MK_BUILD_DIR) WITHOUT='$(strip $(WITHOUT))' UPGRADE=1
218
- $(verbose) cp $(ERLANG_MK_BUILD_DIR)/erlang.mk ./erlang.mk
219
- $(verbose) rm -rf $(ERLANG_MK_BUILD_DIR)
220
- $(verbose) rm -rf $(ERLANG_MK_TMP)
200
if [ -f $(ERLANG_MK_BUILD_CONFIG) ]; then cp $(ERLANG_MK_BUILD_CONFIG) $(ERLANG_MK_BUILD_DIR)/build.config; fi
201
$(MAKE) -C $(ERLANG_MK_BUILD_DIR) WITHOUT='$(strip $(WITHOUT))'
202
cp $(ERLANG_MK_BUILD_DIR)/erlang.mk ./erlang.mk
203
rm -rf $(ERLANG_MK_BUILD_DIR)
221
204
222
205
# The erlang.mk package index is bundled in the default erlang.mk build.
223
206
# Search for the string "copyright" to skip to the rest of the code.
 
@@ -233,8 216,6 @@ ifeq ($(strip $(KERL)),)
233
216
KERL := $(ERLANG_MK_TMP)/kerl/kerl
234
217
endif
235
218
236
- KERL_DIR = $(ERLANG_MK_TMP)/kerl
237
-
238
219
export KERL
239
220
240
221
KERL_GIT ?= https://github.com/kerl/kerl
 
@@ -245,25 226,24 @@ KERL_MAKEFLAGS ?=
245
226
OTP_GIT ?= https://github.com/erlang/otp
246
227
247
228
define kerl_otp_target
229
ifeq ($(wildcard $(KERL_INSTALL_DIR)/$(1)),)
248
230
$(KERL_INSTALL_DIR)/$(1): $(KERL)
249
- $(verbose) if [ ! -d $$@ ]; then \
250
- MAKEFLAGS="$(KERL_MAKEFLAGS)" $(KERL) build git $(OTP_GIT) $(1) $(1); \
251
- $(KERL) install $(1) $(KERL_INSTALL_DIR)/$(1); \
252
- fi
231
MAKEFLAGS="$(KERL_MAKEFLAGS)" $(KERL) build git $(OTP_GIT) $(1) $(1)
232
$(KERL) install $(1) $(KERL_INSTALL_DIR)/$(1)
233
endif
253
234
endef
254
235
255
236
define kerl_hipe_target
237
ifeq ($(wildcard $(KERL_INSTALL_DIR)/$1-native),)
256
238
$(KERL_INSTALL_DIR)/$1-native: $(KERL)
257
- $(verbose) if [ ! -d $$@ ]; then \
258
- KERL_CONFIGURE_OPTIONS=--enable-native-libs \
259
- MAKEFLAGS="$(KERL_MAKEFLAGS)" $(KERL) build git $(OTP_GIT) $1 $1-native; \
260
- $(KERL) install $1-native $(KERL_INSTALL_DIR)/$1-native; \
261
- fi
239
KERL_CONFIGURE_OPTIONS=--enable-native-libs \
240
MAKEFLAGS="$(KERL_MAKEFLAGS)" $(KERL) build git $(OTP_GIT) $1 $1-native
241
$(KERL) install $1-native $(KERL_INSTALL_DIR)/$1-native
242
endif
262
243
endef
263
244
264
- $(KERL): $(KERL_DIR)
265
-
266
- $(KERL_DIR): | $(ERLANG_MK_TMP)
245
$(KERL):
246
$(verbose) mkdir -p $(ERLANG_MK_TMP)
267
247
$(gen_verbose) git clone --depth 1 $(KERL_GIT) $(ERLANG_MK_TMP)/kerl
268
248
$(verbose) cd $(ERLANG_MK_TMP)/kerl && git checkout $(KERL_COMMIT)
269
249
$(verbose) chmod x $(KERL)
 
@@ -271,14 251,12 @@ $(KERL_DIR): | $(ERLANG_MK_TMP)
271
251
distclean:: distclean-kerl
272
252
273
253
distclean-kerl:
274
- $(gen_verbose) rm -rf $(KERL_DIR)
254
$(gen_verbose) rm -rf $(KERL)
275
255
276
256
# Allow users to select which version of Erlang/OTP to use for a project.
277
257
278
258
ifneq ($(strip $(LATEST_ERLANG_OTP)),)
279
- # In some environments it is necessary to filter out master.
280
- ERLANG_OTP := $(notdir $(lastword $(sort\
281
- $(filter-out $(KERL_INSTALL_DIR)/master $(KERL_INSTALL_DIR)/OTP_R%,\
259
ERLANG_OTP := $(notdir $(lastword $(sort $(filter-out $(KERL_INSTALL_DIR)/OTP_R%,\
282
260
$(filter-out %-rc1 %-rc2 %-rc3,$(wildcard $(KERL_INSTALL_DIR)/*[^-native]))))))
283
261
endif
284
262
 
@@ -305,9 283,9 @@ SHELL := env PATH=$(PATH) $(SHELL)
305
283
$(eval $(call kerl_hipe_target,$(ERLANG_HIPE)))
306
284
307
285
# Build Erlang/OTP only if it doesn't already exist.
308
- ifeq ($(wildcard $(KERL_INSTALL_DIR)/$(ERLANG_HIPE)-native)$(BUILD_ERLANG_OTP),)
286
ifeq ($(wildcard $(KERL_INSTALL_DIR)/$(ERLANG_HIPE))$(BUILD_ERLANG_OTP),)
309
287
$(info Building HiPE-enabled Erlang/OTP $(ERLANG_OTP)... Please wait...)
310
- $(shell $(MAKE) $(KERL_INSTALL_DIR)/$(ERLANG_HIPE)-native ERLANG_HIPE=$(ERLANG_HIPE) BUILD_ERLANG_OTP=1 >&2)
288
$(shell $(MAKE) $(KERL_INSTALL_DIR)/$(ERLANG_HIPE) ERLANG_HIPE=$(ERLANG_HIPE) BUILD_ERLANG_OTP=1 >&2)
311
289
endif
312
290
313
291
endif
 
@@ -955,10 933,10 @@ pkg_cr_commit = master
955
933
956
934
PACKAGES = cuttlefish
957
935
pkg_cuttlefish_name = cuttlefish
958
- pkg_cuttlefish_description = cuttlefish configuration abstraction
959
- pkg_cuttlefish_homepage = https://github.com/Kyorai/cuttlefish
936
pkg_cuttlefish_description = never lose your childlike sense of wonder baby cuttlefish, promise me?
937
pkg_cuttlefish_homepage = https://github.com/basho/cuttlefish
960
938
pkg_cuttlefish_fetch = git
961
- pkg_cuttlefish_repo = https://github.com/Kyorai/cuttlefish
939
pkg_cuttlefish_repo = https://github.com/basho/cuttlefish
962
940
pkg_cuttlefish_commit = master
963
941
964
942
PACKAGES = damocles
 
@@ -1225,20 1203,12 @@ pkg_eleveldb_fetch = git
1225
1203
pkg_eleveldb_repo = https://github.com/basho/eleveldb
1226
1204
pkg_eleveldb_commit = master
1227
1205
1228
- PACKAGES = elixir
1229
- pkg_elixir_name = elixir
1230
- pkg_elixir_description = Elixir is a dynamic, functional language designed for building scalable and maintainable applications
1231
- pkg_elixir_homepage = https://elixir-lang.org/
1232
- pkg_elixir_fetch = git
1233
- pkg_elixir_repo = https://github.com/elixir-lang/elixir
1234
- pkg_elixir_commit = master
1235
-
1236
1206
PACKAGES = elli
1237
1207
pkg_elli_name = elli
1238
1208
pkg_elli_description = Simple, robust and performant Erlang web server
1239
- pkg_elli_homepage = https://github.com/elli-lib/elli
1209
pkg_elli_homepage = https://github.com/knutin/elli
1240
1210
pkg_elli_fetch = git
1241
- pkg_elli_repo = https://github.com/elli-lib/elli
1211
pkg_elli_repo = https://github.com/knutin/elli
1242
1212
pkg_elli_commit = master
1243
1213
1244
1214
PACKAGES = elvis
 
@@ -1633,14 1603,6 @@ pkg_escalus_fetch = git
1633
1603
pkg_escalus_repo = https://github.com/esl/escalus
1634
1604
pkg_escalus_commit = master
1635
1605
1636
- PACKAGES = esh_mk
1637
- pkg_esh_mk_name = esh_mk
1638
- pkg_esh_mk_description = esh template engine plugin for erlang.mk
1639
- pkg_esh_mk_homepage = https://github.com/crownedgrouse/esh.mk
1640
- pkg_esh_mk_fetch = git
1641
- pkg_esh_mk_repo = https://github.com/crownedgrouse/esh.mk.git
1642
- pkg_esh_mk_commit = master
1643
-
1644
1606
PACKAGES = espec
1645
1607
pkg_espec_name = espec
1646
1608
pkg_espec_description = ESpec: Behaviour driven development framework for Erlang
 
@@ -1937,14 1899,6 @@ pkg_gen_icmp_fetch = git
1937
1899
pkg_gen_icmp_repo = https://github.com/msantos/gen_icmp
1938
1900
pkg_gen_icmp_commit = master
1939
1901
1940
- PACKAGES = gen_leader
1941
- pkg_gen_leader_name = gen_leader
1942
- pkg_gen_leader_description = leader election behavior
1943
- pkg_gen_leader_homepage = https://github.com/garret-smith/gen_leader_revival
1944
- pkg_gen_leader_fetch = git
1945
- pkg_gen_leader_repo = https://github.com/garret-smith/gen_leader_revival
1946
- pkg_gen_leader_commit = master
1947
-
1948
1902
PACKAGES = gen_nb_server
1949
1903
pkg_gen_nb_server_name = gen_nb_server
1950
1904
pkg_gen_nb_server_description = OTP behavior for writing non-blocking servers
 
@@ -1961,14 1915,6 @@ pkg_gen_paxos_fetch = git
1961
1915
pkg_gen_paxos_repo = https://github.com/gburd/gen_paxos
1962
1916
pkg_gen_paxos_commit = master
1963
1917
1964
- PACKAGES = gen_rpc
1965
- pkg_gen_rpc_name = gen_rpc
1966
- pkg_gen_rpc_description = A scalable RPC library for Erlang-VM based languages
1967
- pkg_gen_rpc_homepage = https://github.com/priestjim/gen_rpc.git
1968
- pkg_gen_rpc_fetch = git
1969
- pkg_gen_rpc_repo = https://github.com/priestjim/gen_rpc.git
1970
- pkg_gen_rpc_commit = master
1971
-
1972
1918
PACKAGES = gen_smtp
1973
1919
pkg_gen_smtp_name = gen_smtp
1974
1920
pkg_gen_smtp_description = A generic Erlang SMTP server and client that can be extended via callback modules
 
@@ -2335,7 2281,7 @@ pkg_jsx_description = An Erlang application for consuming, producing and manipul
2335
2281
pkg_jsx_homepage = https://github.com/talentdeficit/jsx
2336
2282
pkg_jsx_fetch = git
2337
2283
pkg_jsx_repo = https://github.com/talentdeficit/jsx
2338
- pkg_jsx_commit = main
2284
pkg_jsx_commit = master
2339
2285
2340
2286
PACKAGES = kafka
2341
2287
pkg_kafka_name = kafka
 
@@ -2819,11 2765,11 @@ pkg_myproto_commit = master
2819
2765
2820
2766
PACKAGES = mysql
2821
2767
pkg_mysql_name = mysql
2822
- pkg_mysql_description = MySQL client library for Erlang/OTP
2823
- pkg_mysql_homepage = https://github.com/mysql-otp/mysql-otp
2768
pkg_mysql_description = Erlang MySQL Driver (from code.google.com)
2769
pkg_mysql_homepage = https://github.com/dizzyd/erlang-mysql-driver
2824
2770
pkg_mysql_fetch = git
2825
- pkg_mysql_repo = https://github.com/mysql-otp/mysql-otp
2826
- pkg_mysql_commit = 1.7.0
2771
pkg_mysql_repo = https://github.com/dizzyd/erlang-mysql-driver
2772
pkg_mysql_commit = master
2827
2773
2828
2774
PACKAGES = n2o
2829
2775
pkg_n2o_name = n2o
 
@@ -3033,14 2979,6 @@ pkg_parsexml_fetch = git
3033
2979
pkg_parsexml_repo = https://github.com/maxlapshin/parsexml
3034
2980
pkg_parsexml_commit = master
3035
2981
3036
- PACKAGES = partisan
3037
- pkg_partisan_name = partisan
3038
- pkg_partisan_description = High-performance, high-scalability distributed computing with Erlang and Elixir.
3039
- pkg_partisan_homepage = http://partisan.cloud
3040
- pkg_partisan_fetch = git
3041
- pkg_partisan_repo = https://github.com/lasp-lang/partisan
3042
- pkg_partisan_commit = master
3043
-
3044
2982
PACKAGES = pegjs
3045
2983
pkg_pegjs_name = pegjs
3046
2984
pkg_pegjs_description = An implementation of PEG.js grammar for Erlang.
 
@@ -3057,14 2995,6 @@ pkg_percept2_fetch = git
3057
2995
pkg_percept2_repo = https://github.com/huiqing/percept2
3058
2996
pkg_percept2_commit = master
3059
2997
3060
- PACKAGES = pgo
3061
- pkg_pgo_name = pgo
3062
- pkg_pgo_description = Erlang Postgres client and connection pool
3063
- pkg_pgo_homepage = https://github.com/erleans/pgo.git
3064
- pkg_pgo_fetch = git
3065
- pkg_pgo_repo = https://github.com/erleans/pgo.git
3066
- pkg_pgo_commit = master
3067
-
3068
2998
PACKAGES = pgsql
3069
2999
pkg_pgsql_name = pgsql
3070
3000
pkg_pgsql_description = Erlang PostgreSQL driver
 
@@ -3161,14 3091,6 @@ pkg_procket_fetch = git
3161
3091
pkg_procket_repo = https://github.com/msantos/procket
3162
3092
pkg_procket_commit = master
3163
3093
3164
- PACKAGES = prometheus
3165
- pkg_prometheus_name = prometheus
3166
- pkg_prometheus_description = Prometheus.io client in Erlang
3167
- pkg_prometheus_homepage = https://github.com/deadtrickster/prometheus.erl
3168
- pkg_prometheus_fetch = git
3169
- pkg_prometheus_repo = https://github.com/deadtrickster/prometheus.erl
3170
- pkg_prometheus_commit = master
3171
-
3172
3094
PACKAGES = prop
3173
3095
pkg_prop_name = prop
3174
3096
pkg_prop_description = An Erlang code scaffolding and generator system.
 
@@ -4331,9 4253,6 @@ export DEPS_DIR
4331
4253
REBAR_DEPS_DIR = $(DEPS_DIR)
4332
4254
export REBAR_DEPS_DIR
4333
4255
4334
- REBAR_GIT ?= https://github.com/rebar/rebar
4335
- REBAR_COMMIT ?= 576e12171ab8d69b048b827b92aa65d067deea01
4336
-
4337
4256
# External "early" plugins (see core/plugins.mk for regular plugins).
4338
4257
# They both use the core_dep_plugin macro.
4339
4258
 
@@ -4354,77 4273,14 @@ $(foreach p,$(DEP_EARLY_PLUGINS),\
4354
4273
$(call core_dep_plugin,$p,$(firstword $(subst /, ,$p))),\
4355
4274
$(call core_dep_plugin,$p/early-plugins.mk,$p))))
4356
4275
4357
- # Query functions.
4358
-
4359
- query_fetch_method = $(if $(dep_$(1)),$(call _qfm_dep,$(word 1,$(dep_$(1)))),$(call _qfm_pkg,$(1)))
4360
- _qfm_dep = $(if $(dep_fetch_$(1)),$(1),$(if $(IS_DEP),legacy,fail))
4361
- _qfm_pkg = $(if $(pkg_$(1)_fetch),$(pkg_$(1)_fetch),fail)
4362
-
4363
- query_name = $(if $(dep_$(1)),$(1),$(if $(pkg_$(1)_name),$(pkg_$(1)_name),$(1)))
4364
-
4365
- query_repo = $(call _qr,$(1),$(call query_fetch_method,$(1)))
4366
- _qr = $(if $(query_repo_$(2)),$(call query_repo_$(2),$(1)),$(call dep_repo,$(1)))
4367
-
4368
- query_repo_default = $(if $(dep_$(1)),$(word 2,$(dep_$(1))),$(pkg_$(1)_repo))
4369
- query_repo_git = $(patsubst git://github.com/%,https://github.com/%,$(call query_repo_default,$(1)))
4370
- query_repo_git-subfolder = $(call query_repo_git,$(1))
4371
- query_repo_git-submodule = -
4372
- query_repo_hg = $(call query_repo_default,$(1))
4373
- query_repo_svn = $(call query_repo_default,$(1))
4374
- query_repo_cp = $(call query_repo_default,$(1))
4375
- query_repo_ln = $(call query_repo_default,$(1))
4376
- query_repo_hex = https://hex.pm/packages/$(if $(word 3,$(dep_$(1))),$(word 3,$(dep_$(1))),$(1))
4377
- query_repo_fail = -
4378
- query_repo_legacy = -
4379
-
4380
- query_version = $(call _qv,$(1),$(call query_fetch_method,$(1)))
4381
- _qv = $(if $(query_version_$(2)),$(call query_version_$(2),$(1)),$(call dep_commit,$(1)))
4382
-
4383
- query_version_default = $(if $(dep_$(1)_commit),$(dep_$(1)_commit),$(if $(dep_$(1)),$(word 3,$(dep_$(1))),$(pkg_$(1)_commit)))
4384
- query_version_git = $(call query_version_default,$(1))
4385
- query_version_git-subfolder = $(call query_version_git,$(1))
4386
- query_version_git-submodule = -
4387
- query_version_hg = $(call query_version_default,$(1))
4388
- query_version_svn = -
4389
- query_version_cp = -
4390
- query_version_ln = -
4391
- query_version_hex = $(if $(dep_$(1)_commit),$(dep_$(1)_commit),$(if $(dep_$(1)),$(word 2,$(dep_$(1))),$(pkg_$(1)_commit)))
4392
- query_version_fail = -
4393
- query_version_legacy = -
4394
-
4395
- query_extra = $(call _qe,$(1),$(call query_fetch_method,$(1)))
4396
- _qe = $(if $(query_extra_$(2)),$(call query_extra_$(2),$(1)),-)
4397
-
4398
- query_extra_git = -
4399
- query_extra_git-subfolder = $(if $(dep_$(1)),subfolder=$(word 4,$(dep_$(1))),-)
4400
- query_extra_git-submodule = -
4401
- query_extra_hg = -
4402
- query_extra_svn = -
4403
- query_extra_cp = -
4404
- query_extra_ln = -
4405
- query_extra_hex = $(if $(dep_$(1)),package-name=$(word 3,$(dep_$(1))),-)
4406
- query_extra_fail = -
4407
- query_extra_legacy = -
4408
-
4409
- query_absolute_path = $(addprefix $(DEPS_DIR)/,$(call query_name,$(1)))
4410
-
4411
- # Deprecated legacy query functions.
4412
- dep_fetch = $(call query_fetch_method,$(1))
4413
- dep_name = $(call query_name,$(1))
4414
- dep_repo = $(call query_repo_git,$(1))
4415
- dep_commit = $(if $(dep_$(1)_commit),$(dep_$(1)_commit),$(if $(dep_$(1)),$(if $(filter hex,$(word 1,$(dep_$(1)))),$(word 2,$(dep_$(1))),$(word 3,$(dep_$(1)))),$(pkg_$(1)_commit)))
4276
dep_name = $(if $(dep_$(1)),$(1),$(if $(pkg_$(1)_name),$(pkg_$(1)_name),$(1)))
4277
dep_repo = $(patsubst git://github.com/%,https://github.com/%, \
4278
$(if $(dep_$(1)),$(word 2,$(dep_$(1))),$(pkg_$(1)_repo)))
4279
dep_commit = $(if $(dep_$(1)_commit),$(dep_$(1)_commit),$(if $(dep_$(1)),$(word 3,$(dep_$(1))),$(pkg_$(1)_commit)))
4416
4280
4417
4281
LOCAL_DEPS_DIRS = $(foreach a,$(LOCAL_DEPS),$(if $(wildcard $(APPS_DIR)/$(a)),$(APPS_DIR)/$(a)))
4418
- ALL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(foreach dep,$(filter-out $(IGNORE_DEPS),$(BUILD_DEPS) $(DEPS)),$(call dep_name,$(dep))))
4419
-
4420
- # When we are calling an app directly we don't want to include it here
4421
- # otherwise it'll be treated both as an apps and a top-level project.
4422
4282
ALL_APPS_DIRS = $(if $(wildcard $(APPS_DIR)/),$(filter-out $(APPS_DIR),$(shell find $(APPS_DIR) -maxdepth 1 -type d)))
4423
- ifdef ROOT_DIR
4424
- ifndef IS_APP
4425
- ALL_APPS_DIRS := $(filter-out $(APPS_DIR)/$(notdir $(CURDIR)),$(ALL_APPS_DIRS))
4426
- endif
4427
- endif
4283
ALL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(foreach dep,$(filter-out $(IGNORE_DEPS),$(BUILD_DEPS) $(DEPS)),$(call dep_name,$(dep))))
4428
4284
4429
4285
ifeq ($(filter $(APPS_DIR) $(DEPS_DIR),$(subst :, ,$(ERL_LIBS))),)
4430
4286
ifeq ($(ERL_LIBS),)
 
@@ -4443,82 4299,50 @@ dep_verbose_0 = @echo " DEP $1 ($(call dep_commit,$1))";
4443
4299
dep_verbose_2 = set -x;
4444
4300
dep_verbose = $(dep_verbose_$(V))
4445
4301
4446
- # Optimization: don't recompile deps unless truly necessary.
4447
-
4448
- ifndef IS_DEP
4449
- ifneq ($(MAKELEVEL),0)
4450
- $(shell rm -f ebin/dep_built)
4451
- endif
4452
- endif
4453
-
4454
4302
# Core targets.
4455
4303
4456
- ALL_APPS_DIRS_TO_BUILD = $(if $(LOCAL_DEPS_DIRS)$(IS_APP),$(LOCAL_DEPS_DIRS),$(ALL_APPS_DIRS))
4457
-
4458
- apps:: $(ALL_APPS_DIRS) clean-tmp-deps.log | $(ERLANG_MK_TMP)
4304
apps:: $(ALL_APPS_DIRS) clean-tmp-deps.log
4305
ifeq ($(IS_APP)$(IS_DEP),)
4306
$(verbose) rm -f $(ERLANG_MK_TMP)/apps.log
4307
endif
4308
$(verbose) mkdir -p $(ERLANG_MK_TMP)
4459
4309
# Create ebin directory for all apps to make sure Erlang recognizes them
4460
4310
# as proper OTP applications when using -include_lib. This is a temporary
4461
4311
# fix, a proper fix would be to compile apps/* in the right order.
4462
4312
ifndef IS_APP
4463
- ifneq ($(ALL_APPS_DIRS),)
4464
4313
$(verbose) set -e; for dep in $(ALL_APPS_DIRS) ; do \
4465
4314
mkdir -p $$dep/ebin; \
4466
4315
done
4467
4316
endif
4468
- endif
4469
- # At the toplevel: if LOCAL_DEPS is defined with at least one local app, only
4470
- # compile that list of apps. Otherwise, compile everything.
4471
- # Within an app: compile all LOCAL_DEPS that are (uncompiled) local apps.
4472
- ifneq ($(ALL_APPS_DIRS_TO_BUILD),)
4473
- $(verbose) set -e; for dep in $(ALL_APPS_DIRS_TO_BUILD); do \
4317
# at the toplevel: if LOCAL_DEPS is defined with at least one local app, only
4318
# compile that list of apps. otherwise, compile everything.
4319
# within an app: compile all LOCAL_DEPS that are (uncompiled) local apps
4320
$(verbose) set -e; for dep in $(if $(LOCAL_DEPS_DIRS)$(IS_APP),$(LOCAL_DEPS_DIRS),$(ALL_APPS_DIRS)) ; do \
4474
4321
if grep -qs ^$$dep$$ $(ERLANG_MK_TMP)/apps.log; then \
4475
4322
:; \
4476
4323
else \
4477
4324
echo $$dep >> $(ERLANG_MK_TMP)/apps.log; \
4478
- $(MAKE) -C $$dep $(if $(IS_TEST),test-build-app) IS_APP=1; \
4325
$(MAKE) -C $$dep IS_APP=1; \
4479
4326
fi \
4480
4327
done
4481
- endif
4482
4328
4483
4329
clean-tmp-deps.log:
4484
4330
ifeq ($(IS_APP)$(IS_DEP),)
4485
- $(verbose) rm -f $(ERLANG_MK_TMP)/apps.log $(ERLANG_MK_TMP)/deps.log
4486
- endif
4487
-
4488
- # Erlang.mk does not rebuild dependencies after they were compiled
4489
- # once. If a developer is working on the top-level project and some
4490
- # dependencies at the same time, he may want to change this behavior.
4491
- # There are two solutions:
4492
- # 1. Set `FULL=1` so that all dependencies are visited and
4493
- # recursively recompiled if necessary.
4494
- # 2. Set `FORCE_REBUILD=` to the specific list of dependencies that
4495
- # should be recompiled (instead of the whole set).
4496
-
4497
- FORCE_REBUILD ?=
4498
-
4499
- ifeq ($(origin FULL),undefined)
4500
- ifneq ($(strip $(force_rebuild_dep)$(FORCE_REBUILD)),)
4501
- define force_rebuild_dep
4502
- echo "$(FORCE_REBUILD)" | grep -qw "$$(basename "$1")"
4503
- endef
4504
- endif
4331
$(verbose) rm -f $(ERLANG_MK_TMP)/deps.log
4505
4332
endif
4506
4333
4507
4334
ifneq ($(SKIP_DEPS),)
4508
4335
deps::
4509
4336
else
4510
- deps:: $(ALL_DEPS_DIRS) apps clean-tmp-deps.log | $(ERLANG_MK_TMP)
4511
- ifneq ($(ALL_DEPS_DIRS),)
4512
- $(verbose) set -e; for dep in $(ALL_DEPS_DIRS); do \
4337
deps:: $(ALL_DEPS_DIRS) apps clean-tmp-deps.log
4338
$(verbose) mkdir -p $(ERLANG_MK_TMP)
4339
$(verbose) set -e; for dep in $(ALL_DEPS_DIRS) ; do \
4513
4340
if grep -qs ^$$dep$$ $(ERLANG_MK_TMP)/deps.log; then \
4514
4341
:; \
4515
4342
else \
4516
4343
echo $$dep >> $(ERLANG_MK_TMP)/deps.log; \
4517
- if [ -z "$(strip $(FULL))" ] $(if $(force_rebuild_dep),&& ! ($(call force_rebuild_dep,$$dep)),) && [ ! -L $$dep ] && [ -f $$dep/ebin/dep_built ]; then \
4518
- :; \
4519
- elif [ -f $$dep/GNUmakefile ] || [ -f $$dep/makefile ] || [ -f $$dep/Makefile ]; then \
4344
if [ -f $$dep/GNUmakefile ] || [ -f $$dep/makefile ] || [ -f $$dep/Makefile ]; then \
4520
4345
$(MAKE) -C $$dep IS_DEP=1; \
4521
- if [ ! -L $$dep ] && [ -d $$dep/ebin ]; then touch $$dep/ebin/dep_built; fi; \
4522
4346
else \
4523
4347
echo "Error: No Makefile to build dependency $$dep." >&2; \
4524
4348
exit 2; \
 
@@ -4526,7 4350,6 @@ ifneq ($(ALL_DEPS_DIRS),)
4526
4350
fi \
4527
4351
done
4528
4352
endif
4529
- endif
4530
4353
4531
4354
# Deps related targets.
4532
4355
 
@@ -4599,23 4422,13 @@ define dep_autopatch_gen
4599
4422
"include ../../erlang.mk" > $(DEPS_DIR)/$(1)/Makefile
4600
4423
endef
4601
4424
4602
- # We use flock/lockf when available to avoid concurrency issues.
4603
4425
define dep_autopatch_fetch_rebar
4604
- if command -v flock >/dev/null; then \
4605
- flock $(ERLANG_MK_TMP)/rebar.lock sh -c "$(call dep_autopatch_fetch_rebar2)"; \
4606
- elif command -v lockf >/dev/null; then \
4607
- lockf $(ERLANG_MK_TMP)/rebar.lock sh -c "$(call dep_autopatch_fetch_rebar2)"; \
4608
- else \
4609
- $(call dep_autopatch_fetch_rebar2); \
4610
- fi
4611
- endef
4612
-
4613
- define dep_autopatch_fetch_rebar2
4426
mkdir -p $(ERLANG_MK_TMP); \
4614
4427
if [ ! -d $(ERLANG_MK_TMP)/rebar ]; then \
4615
- git clone -q -n -- $(REBAR_GIT) $(ERLANG_MK_TMP)/rebar; \
4428
git clone -q -n -- https://github.com/rebar/rebar $(ERLANG_MK_TMP)/rebar; \
4616
4429
cd $(ERLANG_MK_TMP)/rebar; \
4617
- git checkout -q $(REBAR_COMMIT); \
4618
- ./bootstrap; \
4430
git checkout -q 576e12171ab8d69b048b827b92aa65d067deea01; \
4431
$(MAKE); \
4619
4432
cd -; \
4620
4433
fi
4621
4434
endef
 
@@ -4688,60 4501,34 @@ define dep_autopatch_rebar.erl
4688
4501
end,
4689
4502
Write("\n")
4690
4503
end(),
4691
- GetHexVsn = fun(N, NP) ->
4504
GetHexVsn = fun(N) ->
4692
4505
case file:consult("$(call core_native_path,$(DEPS_DIR)/$1/rebar.lock)") of
4693
4506
{ok, Lock} ->
4694
4507
io:format("~p~n", [Lock]),
4695
- LockPkgs = case lists:keyfind("1.2.0", 1, Lock) of
4696
- {_, LP} ->
4697
- LP;
4698
- _ ->
4699
- case lists:keyfind("1.1.0", 1, Lock) of
4700
- {_, LP} ->
4701
- LP;
4702
- _ ->
4703
- false
4704
- end
4705
- end,
4706
- if
4707
- is_list(LockPkgs) ->
4508
case lists:keyfind("1.1.0", 1, Lock) of
4509
{_, LockPkgs} ->
4708
4510
io:format("~p~n", [LockPkgs]),
4709
4511
case lists:keyfind(atom_to_binary(N, latin1), 1, LockPkgs) of
4710
4512
{_, {pkg, _, Vsn}, _} ->
4711
4513
io:format("~p~n", [Vsn]),
4712
- {N, {hex, NP, binary_to_list(Vsn)}};
4514
{N, {hex, binary_to_list(Vsn)}};
4713
4515
_ ->
4714
4516
false
4715
4517
end;
4716
- true ->
4518
_ ->
4717
4519
false
4718
4520
end;
4719
4521
_ ->
4720
4522
false
4721
4523
end
4722
4524
end,
4723
- SemVsn = fun
4724
- ("~>" S0) ->
4725
- S = case S0 of
4726
- " " S1 -> S1;
4727
- _ -> S0
4728
- end,
4729
- case length([ok || $$. <- S]) of
4730
- 0 -> S ".0.0";
4731
- 1 -> S ".0";
4732
- _ -> S
4733
- end;
4734
- (S) -> S
4735
- end,
4736
4525
fun() ->
4737
4526
File = case lists:keyfind(deps, 1, Conf) of
4738
4527
false -> [];
4739
4528
{_, Deps} ->
4740
4529
[begin case case Dep of
4741
- N when is_atom(N) -> GetHexVsn(N, N);
4742
- {N, S} when is_atom(N), is_list(S) -> {N, {hex, N, SemVsn(S)}};
4743
- {N, {pkg, NP}} when is_atom(N) -> GetHexVsn(N, NP);
4744
- {N, S, {pkg, NP}} -> {N, {hex, NP, S}};
4530
N when is_atom(N) -> GetHexVsn(N);
4531
{N, S} when is_atom(N), is_list(S) -> {N, {hex, S}};
4745
4532
{N, S} when is_tuple(S) -> {N, S};
4746
4533
{N, _, S} -> {N, S};
4747
4534
{N, _, S, _} -> {N, S};
 
@@ -4750,7 4537,7 @@ define dep_autopatch_rebar.erl
4750
4537
false -> ok;
4751
4538
{Name, Source} ->
4752
4539
{Method, Repo, Commit} = case Source of
4753
- {hex, NPV, V} -> {hex, V, NPV};
4540
{hex, V} -> {hex, V, undefined};
4754
4541
{git, R} -> {git, R, master};
4755
4542
{M, R, {branch, C}} -> {M, R, C};
4756
4543
{M, R, {ref, C}} -> {M, R, C};
 
@@ -4767,8 4554,6 @@ define dep_autopatch_rebar.erl
4767
4554
{_, Files} ->
4768
4555
Names = [[" ", case lists:reverse(F) of
4769
4556
"lre." Elif -> lists:reverse(Elif);
4770
- "lrx." Elif -> lists:reverse(Elif);
4771
- "lry." Elif -> lists:reverse(Elif);
4772
4557
Elif -> lists:reverse(Elif)
4773
4558
end] || "src/" F <- Files],
4774
4559
Write(io_lib:format("COMPILE_FIRST =~s\n", [Names]))
 
@@ -4806,10 4591,9 @@ define dep_autopatch_rebar.erl
4806
4591
end || H <- Hooks]
4807
4592
end
4808
4593
end(),
4809
- ShellToMk = fun(V0) ->
4810
- V1 = re:replace(V0, "[$$][(]", "$$\(shell ", [global]),
4811
- V = re:replace(V1, "([$$])(?![(])(\\\\w*)", "\\\\1(\\\\2)", [global]),
4812
- re:replace(V, "-Werror\\\\b", "", [{return, list}, global])
4863
ShellToMk = fun(V) ->
4595
re:replace(re:replace(V, "(\\\\$$)(\\\\w*)", "\\\\1(\\\\2)", [global]),
4596
"-Werror\\\\b", "", [{return, list}, global])
4813
4597
end,
4814
4598
PortSpecs = fun() ->
4815
4599
case lists:keyfind(port_specs, 1, Conf) of
 
@@ -4842,10 4626,10 @@ define dep_autopatch_rebar.erl
4842
4626
case PortSpecs of
4843
4627
[] -> ok;
4844
4628
_ ->
4845
- Write("\npre-app::\n\t@$$\(MAKE) --no-print-directory -f c_src/Makefile.erlang.mk\n"),
4629
Write("\npre-app::\n\t$$\(MAKE) -f c_src/Makefile.erlang.mk\n"),
4846
4630
PortSpecWrite(io_lib:format("ERL_CFLAGS ?= -finline-functions -Wall -fPIC -I \\"~s/erts-~s/include\\" -I \\"~s\\"\n",
4847
4631
[code:root_dir(), erlang:system_info(version), code:lib_dir(erl_interface, include)])),
4848
- PortSpecWrite(io_lib:format("ERL_LDFLAGS ?= -L \\"~s\\" -lei\n",
4632
PortSpecWrite(io_lib:format("ERL_LDFLAGS ?= -L \\"~s\\" -lerl_interface -lei\n",
4849
4633
[code:lib_dir(erl_interface, lib)])),
4850
4634
[PortSpecWrite(["\n", E, "\n"]) || E <- OsEnv],
4851
4635
FilterEnv = fun(Env) ->
 
@@ -4879,7 4663,7 @@ define dep_autopatch_rebar.erl
4879
4663
darwin -> "\n\nLDFLAGS = -flat_namespace -undefined suppress";
4880
4664
_ -> ""
4881
4665
end,
4882
- "\n\nall:: ", Output, "\n\t@:\n\n",
4666
"\n\nall:: ", Output, "\n\n",
4883
4667
"%.o: %.c\n\t$$\(CC) -c -o $$\@ $$\< $$\(CFLAGS) $$\(ERL_CFLAGS) $$\(DRV_CFLAGS) $$\(EXE_CFLAGS)\n\n",
4884
4668
"%.o: %.C\n\t$$\(CXX) -c -o $$\@ $$\< $$\(CXXFLAGS) $$\(ERL_CFLAGS) $$\(DRV_CFLAGS) $$\(EXE_CFLAGS)\n\n",
4885
4669
"%.o: %.cc\n\t$$\(CXX) -c -o $$\@ $$\< $$\(CXXFLAGS) $$\(ERL_CFLAGS) $$\(DRV_CFLAGS) $$\(EXE_CFLAGS)\n\n",
 
@@ -4896,17 4680,6 @@ define dep_autopatch_rebar.erl
4896
4680
end,
4897
4681
[PortSpec(S) || S <- PortSpecs]
4898
4682
end,
4899
- fun() ->
4900
- case lists:keyfind(plugins, 1, Conf) of
4901
- false -> ok;
4902
- {_, Plugins0} ->
4903
- Plugins = [P || P <- Plugins0, is_tuple(P)],
4904
- case lists:keyfind('lfe-compile', 1, Plugins) of
4905
- false -> ok;
4906
- _ -> Write("\nBUILD_DEPS = lfe lfe.mk\ndep_lfe.mk = git https://github.com/ninenines/lfe.mk master\nDEP_PLUGINS = lfe.mk\n")
4907
- end
4908
- end
4909
- end(),
4910
4683
Write("\ninclude $$\(if $$\(ERLANG_MK_FILENAME),$$\(ERLANG_MK_FILENAME),erlang.mk)"),
4911
4684
RunPlugin = fun(Plugin, Step) ->
4912
4685
case erlang:function_exported(Plugin, Step, 2) of
 
@@ -4921,8 4694,7 @@ define dep_autopatch_rebar.erl
4921
4694
fun() ->
4922
4695
case lists:keyfind(plugins, 1, Conf) of
4923
4696
false -> ok;
4924
- {_, Plugins0} ->
4925
- Plugins = [P || P <- Plugins0, is_atom(P)],
4697
{_, Plugins} ->
4926
4698
[begin
4927
4699
case lists:keyfind(deps, 1, Conf) of
4928
4700
false -> ok;
 
@@ -4980,7 4752,7 @@ define dep_autopatch_appsrc.erl
4980
4752
{ok, [{application, $(1), L0}]} = file:consult(AppSrcIn),
4981
4753
L1 = lists:keystore(modules, 1, L0, {modules, []}),
4982
4754
L2 = case lists:keyfind(vsn, 1, L1) of
4983
- {_, git} -> lists:keyreplace(vsn, 1, L1, {vsn, lists:droplast(os:cmd("git -C $(DEPS_DIR)/$1 describe --dirty --tags --always"))});
4755
{_, git} -> lists:keyreplace(vsn, 1, L1, {vsn, "git"});
4984
4756
{_, {cmd, _}} -> lists:keyreplace(vsn, 1, L1, {vsn, "cmd"});
4985
4757
_ -> L1
4986
4758
end,
 
@@ -4996,16 4768,6 @@ define dep_fetch_git
4996
4768
cd $(DEPS_DIR)/$(call dep_name,$(1)) && git checkout -q $(call dep_commit,$(1));
4997
4769
endef
4998
4770
4999
- define dep_fetch_git-subfolder
5000
- mkdir -p $(ERLANG_MK_TMP)/git-subfolder; \
5001
- git clone -q -n -- $(call dep_repo,$1) \
5002
- $(ERLANG_MK_TMP)/git-subfolder/$(call dep_name,$1); \
5003
- cd $(ERLANG_MK_TMP)/git-subfolder/$(call dep_name,$1) \
5004
- && git checkout -q $(call dep_commit,$1); \
5005
- ln -s $(ERLANG_MK_TMP)/git-subfolder/$(call dep_name,$1)/$(word 4,$(dep_$(1))) \
5006
- $(DEPS_DIR)/$(call dep_name,$1);
5007
- endef
5008
-
5009
4771
define dep_fetch_git-submodule
5010
4772
git submodule update --init -- $(DEPS_DIR)/$1;
5011
4773
endef
 
@@ -5031,7 4793,7 @@ endef
5031
4793
define dep_fetch_hex
5032
4794
mkdir -p $(ERLANG_MK_TMP)/hex $(DEPS_DIR)/$1; \
5033
4795
$(call core_http_get,$(ERLANG_MK_TMP)/hex/$1.tar,\
5034
- https://repo.hex.pm/tarballs/$(if $(word 3,$(dep_$1)),$(word 3,$(dep_$1)),$1)-$(strip $(word 2,$(dep_$1))).tar); \
4796
https://repo.hex.pm/tarballs/$1-$(strip $(word 2,$(dep_$1))).tar); \
5035
4797
tar -xOf $(ERLANG_MK_TMP)/hex/$1.tar contents.tar.gz | tar -C $(DEPS_DIR)/$1 -xzf -;
5036
4798
endef
5037
4799
 
@@ -5047,10 4809,20 @@ define dep_fetch_legacy
5047
4809
cd $(DEPS_DIR)/$(1) && git checkout -q $(if $(word 2,$(dep_$(1))),$(word 2,$(dep_$(1))),master);
5048
4810
endef
5049
4811
4812
define dep_fetch
4813
$(if $(dep_$(1)), \
4814
$(if $(dep_fetch_$(word 1,$(dep_$(1)))), \
4815
$(word 1,$(dep_$(1))), \
4816
$(if $(IS_DEP),legacy,fail)), \
4817
$(if $(filter $(1),$(PACKAGES)), \
4818
$(pkg_$(1)_fetch), \
4819
fail))
4820
endef
4821
5050
4822
define dep_target
5051
- $(DEPS_DIR)/$(call dep_name,$1): | $(ERLANG_MK_TMP)
4823
$(DEPS_DIR)/$(call dep_name,$1):
5052
4824
$(eval DEP_NAME := $(call dep_name,$1))
5053
- $(eval DEP_STR := $(if $(filter $1,$(DEP_NAME)),$1,"$1 ($(DEP_NAME))"))
4825
$(eval DEP_STR := $(if $(filter-out $1,$(DEP_NAME)),$1,"$1 ($(DEP_NAME))"))
5054
4826
$(verbose) if test -d $(APPS_DIR)/$(DEP_NAME); then \
5055
4827
echo "Error: Dependency" $(DEP_STR) "conflicts with application found in $(APPS_DIR)/$(DEP_NAME)." >&2; \
5056
4828
exit 17; \
 
@@ -5059,7 4831,7 @@ $(DEPS_DIR)/$(call dep_name,$1): | $(ERLANG_MK_TMP)
5059
4831
$(dep_verbose) $(call dep_fetch_$(strip $(call dep_fetch,$(1))),$(1))
5060
4832
$(verbose) if [ -f $(DEPS_DIR)/$(1)/configure.ac -o -f $(DEPS_DIR)/$(1)/configure.in ] \
5061
4833
&& [ ! -f $(DEPS_DIR)/$(1)/configure ]; then \
5062
- echo " AUTO " $(DEP_STR); \
4834
echo " AUTO " $(1); \
5063
4835
cd $(DEPS_DIR)/$(1) && autoreconf -Wall -vif -I m4; \
5064
4836
fi
5065
4837
- $(verbose) if [ -f $(DEPS_DIR)/$(DEP_NAME)/configure ]; then \
 
@@ -5067,12 4839,6 @@ $(DEPS_DIR)/$(call dep_name,$1): | $(ERLANG_MK_TMP)
5067
4839
cd $(DEPS_DIR)/$(DEP_NAME) && ./configure; \
5068
4840
fi
5069
4841
ifeq ($(filter $(1),$(NO_AUTOPATCH)),)
5070
- $(verbose) $$(MAKE) --no-print-directory autopatch-$(DEP_NAME)
5071
- endif
5072
-
5073
- .PHONY: autopatch-$(call dep_name,$1)
5074
-
5075
- autopatch-$(call dep_name,$1)::
5076
4842
$(verbose) if [ "$(1)" = "amqp_client" -a "$(RABBITMQ_CLIENT_PATCH)" ]; then \
5077
4843
if [ ! -d $(DEPS_DIR)/rabbitmq-codegen ]; then \
5078
4844
echo " PATCH Downloading rabbitmq-codegen"; \
 
@@ -5088,11 4854,10 @@ autopatch-$(call dep_name,$1)::
5088
4854
echo " PATCH Downloading rabbitmq-codegen"; \
5089
4855
git clone https://github.com/rabbitmq/rabbitmq-codegen.git $(DEPS_DIR)/rabbitmq-codegen; \
5090
4856
fi \
5091
- elif [ "$1" = "elixir" -a "$(ELIXIR_PATCH)" ]; then \
5092
- ln -s lib/elixir/ebin $(DEPS_DIR)/elixir/; \
5093
4857
else \
5094
- $$(call dep_autopatch,$(call dep_name,$1)) \
4858
$$(call dep_autopatch,$(DEP_NAME)) \
5095
4859
fi
4860
endif
5096
4861
endef
5097
4862
5098
4863
$(foreach dep,$(BUILD_DEPS) $(DEPS),$(eval $(call dep_target,$(dep))))
 
@@ -5129,11 4894,36 @@ ERLANG_MK_RECURSIVE_REL_DEPS_LIST = $(ERLANG_MK_TMP)/recursive-rel-deps-list.log
5129
4894
ERLANG_MK_RECURSIVE_TEST_DEPS_LIST = $(ERLANG_MK_TMP)/recursive-test-deps-list.log
5130
4895
ERLANG_MK_RECURSIVE_SHELL_DEPS_LIST = $(ERLANG_MK_TMP)/recursive-shell-deps-list.log
5131
4896
5132
- ERLANG_MK_QUERY_DEPS_FILE = $(ERLANG_MK_TMP)/query-deps.log
5133
- ERLANG_MK_QUERY_DOC_DEPS_FILE = $(ERLANG_MK_TMP)/query-doc-deps.log
5134
- ERLANG_MK_QUERY_REL_DEPS_FILE = $(ERLANG_MK_TMP)/query-rel-deps.log
5135
- ERLANG_MK_QUERY_TEST_DEPS_FILE = $(ERLANG_MK_TMP)/query-test-deps.log
5136
- ERLANG_MK_QUERY_SHELL_DEPS_FILE = $(ERLANG_MK_TMP)/query-shell-deps.log
4897
# Copyright (c) 2015-2016, Loïc Hoguin <[email protected]>
4898
# This file is part of erlang.mk and subject to the terms of the ISC License.
4899
4900
# Verbosity.
4901
4902
proto_verbose_0 = @echo " PROTO " $(filter %.proto,$(?F));
4903
proto_verbose = $(proto_verbose_$(V))
4904
4905
# Core targets.
4906
4907
define compile_proto
4908
$(verbose) mkdir -p ebin/ include/
4909
$(proto_verbose) $(call erlang,$(call compile_proto.erl,$(1)))
4910
$(proto_verbose) erlc debug_info -o ebin/ ebin/*.erl
4911
$(verbose) rm ebin/*.erl
4912
endef
4913
4914
define compile_proto.erl
4915
[begin
4916
protobuffs_compile:generate_source(F,
4917
[{output_include_dir, "./include"},
4918
{output_src_dir, "./ebin"}])
4919
end || F <- string:tokens("$(1)", " ")],
4920
halt().
4921
endef
4922
4923
ifneq ($(wildcard src/),)
4924
ebin/$(PROJECT).app:: $(sort $(call core_find,src/,*.proto))
4925
$(if $(strip $?),$(call compile_proto,$?))
4926
endif
5137
4927
5138
4928
# Copyright (c) 2013-2016, Loïc Hoguin <[email protected]>
5139
4929
# This file is part of erlang.mk and subject to the terms of the ISC License.
 
@@ -5190,9 4980,13 @@ ifneq ($(wildcard src/),)
5190
4980
5191
4981
# Targets.
5192
4982
5193
- app:: $(if $(wildcard ebin/test),clean) deps
5194
- $(verbose) $(MAKE) --no-print-directory $(PROJECT).d
4983
ifeq ($(wildcard ebin/test),)
4984
app:: deps $(PROJECT).d
5195
4985
$(verbose) $(MAKE) --no-print-directory app-build
4986
else
4987
app:: clean deps $(PROJECT).d
4988
$(verbose) $(MAKE) --no-print-directory app-build
4989
endif
5196
4990
5197
4991
ifeq ($(wildcard src/$(PROJECT_MOD).erl),)
5198
4992
define app_file
 
@@ -5241,7 5035,7 @@ define compile_asn1
5241
5035
$(verbose) mkdir -p include/
5242
5036
$(asn1_verbose) erlc -v -I include/ -o asn1/ noobj $(ERLC_ASN1_OPTS) $(1)
5243
5037
$(verbose) mv asn1/*.erl src/
5244
- -$(verbose) mv asn1/*.hrl include/
5038
$(verbose) mv asn1/*.hrl include/
5245
5039
$(verbose) mv asn1/*.asn1db include/
5246
5040
endef
5247
5041
 
@@ -5378,10 5172,8 @@ define makedep.erl
5378
5172
end,
5379
5173
[begin
5380
5174
Mod = list_to_atom(filename:basename(F, ".erl")),
5381
- case file:open(F, [read]) of
5382
- {ok, Fd} -> MakeDepend(MakeDepend, Fd, Mod,0);
5383
- {error, enoent} -> ok
5384
- end
5175
{ok, Fd} = file:open(F, [read]),
5176
MakeDepend(MakeDepend, Fd, Mod,0)
5385
5177
end || F <- ErlFiles],
5386
5178
Depend = sofs:to_external(sofs:relation_to_family(sofs:relation(ets:tab2list(E)))),
5387
5179
CompileFirst = [X || X <- lists:reverse(digraph_utils:topsort(G)), [] =/= digraph:in_neighbours(G, X)],
 
@@ -5393,16 5185,10 @@ define makedep.erl
5393
5185
string:join(DirSubname [atom_to_list(Target)], "/")
5394
5186
end
5395
5187
end,
5396
- Output0 = [
5397
- "# Generated by Erlang.mk. Edit at your own risk!\n\n",
5188
ok = file:write_file("$(1)", [
5398
5189
[[F, "::", [[" ", D] || D <- Deps], "; @touch \$$@\n"] || {F, Deps} <- Depend],
5399
5190
"\nCOMPILE_FIRST =", [[" ", TargetPath(CF)] || CF <- CompileFirst], "\n"
5400
- ],
5401
- Output = case "é" of
5402
- [233] -> unicode:characters_to_binary(Output0);
5403
- _ -> Output0
5404
- end,
5405
- ok = file:write_file("$(1)", Output),
5191
]),
5406
5192
halt()
5407
5193
endef
5408
5194
 
@@ -5411,10 5197,10 @@ $(PROJECT).d:: $(ERL_FILES) $(call core_find,include/,*.hrl) $(MAKEFILE_LIST)
5411
5197
$(makedep_verbose) $(call erlang,$(call makedep.erl,$@))
5412
5198
endif
5413
5199
5414
- ifeq ($(IS_APP)$(IS_DEP),)
5415
5200
ifneq ($(words $(ERL_FILES) $(CORE_FILES) $(ASN1_FILES) $(MIB_FILES) $(XRL_FILES) $(YRL_FILES)),0)
5416
5201
# Rebuild everything when the Makefile changes.
5417
- $(ERLANG_MK_TMP)/last-makefile-change: $(MAKEFILE_LIST) | $(ERLANG_MK_TMP)
5202
$(ERLANG_MK_TMP)/last-makefile-change: $(MAKEFILE_LIST)
5203
$(verbose) mkdir -p $(ERLANG_MK_TMP)
5418
5204
$(verbose) if test -f $@; then \
5419
5205
touch $(ERL_FILES) $(CORE_FILES) $(ASN1_FILES) $(MIB_FILES) $(XRL_FILES) $(YRL_FILES); \
5420
5206
touch -c $(PROJECT).d; \
 
@@ -5424,10 5210,6 @@ $(ERLANG_MK_TMP)/last-makefile-change: $(MAKEFILE_LIST) | $(ERLANG_MK_TMP)
5424
5210
$(ERL_FILES) $(CORE_FILES) $(ASN1_FILES) $(MIB_FILES) $(XRL_FILES) $(YRL_FILES):: $(ERLANG_MK_TMP)/last-makefile-change
5425
5211
ebin/$(PROJECT).app:: $(ERLANG_MK_TMP)/last-makefile-change
5426
5212
endif
5427
- endif
5428
-
5429
- $(PROJECT).d::
5430
- $(verbose) :
5431
5213
5432
5214
include $(wildcard $(PROJECT).d)
5433
5215
 
@@ -5441,31 5223,18 @@ define compile_erl
5441
5223
-pa ebin/ -I include/ $(filter-out $(ERLC_EXCLUDE_PATHS),$(COMPILE_FIRST_PATHS) $(1))
5442
5224
endef
5443
5225
5444
- define validate_app_file
5445
- case file:consult("ebin/$(PROJECT).app") of
5446
- {ok, _} -> halt();
5447
- _ -> halt(1)
5448
- end
5449
- endef
5450
-
5451
5226
ebin/$(PROJECT).app:: $(ERL_FILES) $(CORE_FILES) $(wildcard src/$(PROJECT).app.src)
5452
5227
$(eval FILES_TO_COMPILE := $(filter-out src/$(PROJECT).app.src,$?))
5453
5228
$(if $(strip $(FILES_TO_COMPILE)),$(call compile_erl,$(FILES_TO_COMPILE)))
5454
- # Older git versions do not have the --first-parent flag. Do without in that case.
5455
- $(eval GITDESCRIBE := $(shell git describe --dirty --abbrev=7 --tags --always --first-parent 2>/dev/null \
5456
- || git describe --dirty --abbrev=7 --tags --always 2>/dev/null || true))
5229
$(eval GITDESCRIBE := $(shell git describe --dirty --abbrev=7 --tags --always --first-parent 2>/dev/null || true))
5457
5230
$(eval MODULES := $(patsubst %,'%',$(sort $(notdir $(basename \
5458
5231
$(filter-out $(ERLC_EXCLUDE_PATHS),$(ERL_FILES) $(CORE_FILES) $(BEAM_FILES)))))))
5459
5232
ifeq ($(wildcard src/$(PROJECT).app.src),)
5460
5233
$(app_verbose) printf '$(subst %,%%,$(subst $(newline),\n,$(subst ','\'',$(call app_file,$(GITDESCRIBE),$(MODULES)))))' \
5461
5234
> ebin/$(PROJECT).app
5462
- $(verbose) if ! $(call erlang,$(call validate_app_file)); then \
5463
- echo "The .app file produced is invalid. Please verify the value of PROJECT_ENV." >&2; \
5464
- exit 1; \
5465
- fi
5466
5235
else
5467
5236
$(verbose) if [ -z "$$(grep -e '^[^%]*{\s*modules\s*,' src/$(PROJECT).app.src)" ]; then \
5468
- echo "Empty modules entry not found in $(PROJECT).app.src. Please consult the erlang.mk documentation for instructions." >&2; \
5237
echo "Empty modules entry not found in $(PROJECT).app.src. Please consult the erlang.mk README for instructions." >&2; \
5469
5238
exit 1; \
5470
5239
fi
5471
5240
$(appsrc_verbose) cat src/$(PROJECT).app.src \
 
@@ -5473,9 5242,6 @@ else
5473
5242
| sed "s/{id,[[:space:]]*\"git\"}/{id, \"$(subst /,\/,$(GITDESCRIBE))\"}/" \
5474
5243
> ebin/$(PROJECT).app
5475
5244
endif
5476
- ifneq ($(wildcard src/$(PROJECT).appup),)
5477
- $(verbose) cp src/$(PROJECT).appup ebin/
5478
- endif
5479
5245
5480
5246
clean:: clean-app
5481
5247
 
@@ -5551,71 5317,37 @@ ifneq ($(SKIP_DEPS),)
5551
5317
test-deps:
5552
5318
else
5553
5319
test-deps: $(ALL_TEST_DEPS_DIRS)
5554
- $(verbose) set -e; for dep in $(ALL_TEST_DEPS_DIRS) ; do \
5555
- if [ -z "$(strip $(FULL))" ] && [ ! -L $$dep ] && [ -f $$dep/ebin/dep_built ]; then \
5556
- :; \
5557
- else \
5558
- $(MAKE) -C $$dep IS_DEP=1; \
5559
- if [ ! -L $$dep ] && [ -d $$dep/ebin ]; then touch $$dep/ebin/dep_built; fi; \
5560
- fi \
5561
- done
5320
$(verbose) set -e; for dep in $(ALL_TEST_DEPS_DIRS) ; do $(MAKE) -C $$dep IS_DEP=1; done
5562
5321
endif
5563
5322
5564
5323
ifneq ($(wildcard $(TEST_DIR)),)
5565
- test-dir: $(ERLANG_MK_TMP)/$(PROJECT).last-testdir-build
5566
- @:
5567
-
5568
- test_erlc_verbose_0 = @echo " ERLC " $(filter-out $(patsubst %,%.erl,$(ERLC_EXCLUDE)),\
5569
- $(filter %.erl %.core,$(notdir $(FILES_TO_COMPILE))));
5570
- test_erlc_verbose_2 = set -x;
5571
- test_erlc_verbose = $(test_erlc_verbose_$(V))
5572
-
5573
- define compile_test_erl
5574
- $(test_erlc_verbose) erlc -v $(TEST_ERLC_OPTS) -o $(TEST_DIR) \
5575
- -pa ebin/ -I include/ $(1)
5576
- endef
5577
-
5578
- ERL_TEST_FILES = $(call core_find,$(TEST_DIR)/,*.erl)
5579
- $(ERLANG_MK_TMP)/$(PROJECT).last-testdir-build: $(ERL_TEST_FILES) $(MAKEFILE_LIST)
5580
- $(eval FILES_TO_COMPILE := $(if $(filter $(MAKEFILE_LIST),$?),$(filter $(ERL_TEST_FILES),$^),$?))
5581
- $(if $(strip $(FILES_TO_COMPILE)),$(call compile_test_erl,$(FILES_TO_COMPILE)) && touch $@)
5324
test-dir:
5325
$(gen_verbose) erlc -v $(TEST_ERLC_OPTS) -I include/ -o $(TEST_DIR) \
5326
$(call core_find,$(TEST_DIR)/,*.erl) -pa ebin/
5582
5327
endif
5583
5328
5584
- test-build:: IS_TEST=1
5329
ifeq ($(wildcard src),)
5585
5330
test-build:: ERLC_OPTS=$(TEST_ERLC_OPTS)
5586
- test-build:: $(if $(wildcard src),$(if $(wildcard ebin/test),,clean)) $(if $(IS_APP),,deps test-deps)
5587
- # We already compiled everything when IS_APP=1.
5588
- ifndef IS_APP
5589
- ifneq ($(wildcard src),)
5590
- $(verbose) $(MAKE) --no-print-directory $(PROJECT).d ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
5591
- $(verbose) $(MAKE) --no-print-directory app-build ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
5592
- $(gen_verbose) touch ebin/test
5593
- endif
5863
- ifneq ($(wildcard $(TEST_DIR)),)
5331
test-build:: clean deps test-deps
5595
5332
$(verbose) $(MAKE) --no-print-directory test-dir ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
5596
- endif
5597
- endif
5598
-
5599
- # Roughly the same as test-build, but when IS_APP=1.
5600
- # We only care about compiling the current application.
5601
- ifdef IS_APP
5602
- test-build-app:: ERLC_OPTS=$(TEST_ERLC_OPTS)
5603
- test-build-app:: deps test-deps
5604
- ifneq ($(wildcard src),)
5605
- $(verbose) $(MAKE) --no-print-directory $(PROJECT).d ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
5606
- $(verbose) $(MAKE) --no-print-directory app-build ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
5333
else
5334
ifeq ($(wildcard ebin/test),)
5335
test-build:: ERLC_OPTS=$(TEST_ERLC_OPTS)
5336
test-build:: clean deps test-deps $(PROJECT).d
5337
$(verbose) $(MAKE) --no-print-directory app-build test-dir ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
5607
5338
$(gen_verbose) touch ebin/test
5608
- endif
5609
- ifneq ($(wildcard $(TEST_DIR)),)
5610
- $(verbose) $(MAKE) --no-print-directory test-dir ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
5611
- endif
5339
else
5340
test-build:: ERLC_OPTS=$(TEST_ERLC_OPTS)
5341
test-build:: deps test-deps $(PROJECT).d
5342
$(verbose) $(MAKE) --no-print-directory app-build test-dir ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
5612
5343
endif
5613
5344
5614
5345
clean:: clean-test-dir
5615
5346
5616
5347
clean-test-dir:
5617
5348
ifneq ($(wildcard $(TEST_DIR)/*.beam),)
5618
- $(gen_verbose) rm -f $(TEST_DIR)/*.beam $(ERLANG_MK_TMP)/$(PROJECT).last-testdir-build
5349
$(gen_verbose) rm -f $(TEST_DIR)/*.beam
5350
endif
5619
5351
endif
5620
5352
5621
5353
# Copyright (c) 2015-2016, Loïc Hoguin <[email protected]>
 
@@ -5648,8 5380,11 @@ $(call comma_list,$(foreach d,$(DEPS),\
5648
5380
{erl_opts, $(call compat_erlc_opts_to_list,$(ERLC_OPTS))}.
5649
5381
endef
5650
5382
5383
$(eval _compat_rebar_config = $$(compat_rebar_config))
5384
$(eval export _compat_rebar_config)
5385
5651
5386
rebar.config:
5652
- $(gen_verbose) $(call core_render,compat_rebar_config,rebar.config)
5387
$(gen_verbose) echo "$${_compat_rebar_config}" > rebar.config
5653
5388
5654
5389
# Copyright (c) 2015-2016, Loïc Hoguin <[email protected]>
5655
5390
# This file is part of erlang.mk and subject to the terms of the ISC License.
 
@@ -5719,8 5454,8 @@ endef
5719
5454
asciidoc-manual:: doc-deps
5720
5455
5721
5456
asciidoc-manual:: $(ASCIIDOC_MANUAL_FILES)
5722
- $(gen_verbose) $(call erlang,$(call asciidoc2man.erl,$?))
5723
- $(verbose) $(foreach s,$(MAN_SECTIONS),mkdir -p doc/man$s/ && mv doc/src/manual/*.$s.gz doc/man$s/;)
5457
$(call erlang,$(call asciidoc2man.erl,$?))
5458
$(foreach s,$(MAN_SECTIONS),mkdir -p doc/man$s/ && mv doc/src/manual/*.$s.gz doc/man$s/;)
5724
5459
5725
5460
install-docs:: install-asciidoc
5726
5461
 
@@ -5787,30 5522,31 @@ endef
5787
5522
5788
5523
# To prevent autocompletion issues with ZSH, we add "include erlang.mk"
5789
5524
# separately during the actual bootstrap.
5525
ifdef SP
5790
5526
define bs_Makefile
5791
5527
PROJECT = $p
5792
5528
PROJECT_DESCRIPTION = New project
5793
5529
PROJECT_VERSION = 0.1.0
5794
- $(if $(SP),
5530
5795
5531
# Whitespace to be used when creating files from templates.
5796
5532
SP = $(SP)
5797
- )
5533
5798
5534
endef
5535
else
5536
define bs_Makefile
5537
PROJECT = $p
5538
PROJECT_DESCRIPTION = New project
5539
PROJECT_VERSION = 0.1.0
5540
5541
endef
5542
endif
5799
5543
5800
5544
define bs_apps_Makefile
5801
5545
PROJECT = $p
5802
5546
PROJECT_DESCRIPTION = New project
5803
5547
PROJECT_VERSION = 0.1.0
5804
- $(if $(SP),
5805
- # Whitespace to be used when creating files from templates.
5806
- SP = $(SP)
5807
- )
5808
- # Make sure we know where the applications are located.
5809
- ROOT_DIR ?= $(call core_relpath,$(dir $(ERLANG_MK_FILENAME)),$(APPS_DIR)/app)
5810
- APPS_DIR ?= ..
5811
- DEPS_DIR ?= $(call core_relpath,$(DEPS_DIR),$(APPS_DIR)/app)
5812
5548
5813
- include $$(ROOT_DIR)/erlang.mk
5549
include $(call core_relpath,$(dir $(ERLANG_MK_FILENAME)),$(APPS_DIR)/app)/erlang.mk
5814
5550
endef
5815
5551
5816
5552
define bs_app
 
@@ -5830,8 5566,8 @@ endef
5830
5566
define bs_relx_config
5831
5567
{release, {$p_release, "1"}, [$p, sasl, runtime_tools]}.
5832
5568
{extended_start_script, true}.
5833
- {sys_config, "config/sys.config"}.
5834
- {vm_args, "config/vm.args"}.
5569
{sys_config, "rel/sys.config"}.
5570
{vm_args, "rel/vm.args"}.
5835
5571
endef
5836
5572
5837
5573
define bs_sys_config
 
@@ -6134,6 5870,10 @@ endef
6134
5870
6135
5871
# Plugin-specific targets.
6136
5872
5873
define render_template
5874
$(verbose) printf -- '$(subst $(newline),\n,$(subst %,%%,$(subst ','\'',$(subst $(tab),$(WS),$(call $(1))))))\n' > $(2)
5875
endef
5876
6137
5877
ifndef WS
6138
5878
ifdef SP
6139
5879
WS = $(subst a,,a $(wordlist 1,$(SP),a a a a a a a a a a a a a a a a a a a a))
 
@@ -6147,44 5887,40 @@ ifneq ($(wildcard src/),)
6147
5887
$(error Error: src/ directory already exists)
6148
5888
endif
6149
5889
$(eval p := $(PROJECT))
6150
- $(if $(shell echo $p | LC_ALL=C grep -x "[a-z0-9_]*"),,\
6151
- $(error Error: Invalid characters in the application name))
6152
5890
$(eval n := $(PROJECT)_sup)
6153
- $(verbose) $(call core_render,bs_Makefile,Makefile)
5891
$(call render_template,bs_Makefile,Makefile)
6154
5892
$(verbose) echo "include erlang.mk" >> Makefile
6155
5893
$(verbose) mkdir src/
6156
5894
ifdef LEGACY
6157
- $(verbose) $(call core_render,bs_appsrc,src/$(PROJECT).app.src)
5895
$(call render_template,bs_appsrc,src/$(PROJECT).app.src)
6158
5896
endif
6159
- $(verbose) $(call core_render,bs_app,src/$(PROJECT)_app.erl)
6160
- $(verbose) $(call core_render,tpl_supervisor,src/$(PROJECT)_sup.erl)
5897
$(call render_template,bs_app,src/$(PROJECT)_app.erl)
5898
$(call render_template,tpl_supervisor,src/$(PROJECT)_sup.erl)
6161
5899
6162
5900
bootstrap-lib:
6163
5901
ifneq ($(wildcard src/),)
6164
5902
$(error Error: src/ directory already exists)
6165
5903
endif
6166
5904
$(eval p := $(PROJECT))
6167
- $(if $(shell echo $p | LC_ALL=C grep -x "[a-z0-9_]*"),,\
6168
- $(error Error: Invalid characters in the application name))
6169
- $(verbose) $(call core_render,bs_Makefile,Makefile)
5905
$(call render_template,bs_Makefile,Makefile)
6170
5906
$(verbose) echo "include erlang.mk" >> Makefile
6171
5907
$(verbose) mkdir src/
6172
5908
ifdef LEGACY
6173
- $(verbose) $(call core_render,bs_appsrc_lib,src/$(PROJECT).app.src)
5909
$(call render_template,bs_appsrc_lib,src/$(PROJECT).app.src)
6174
5910
endif
6175
5911
6176
5912
bootstrap-rel:
6177
5913
ifneq ($(wildcard relx.config),)
6178
5914
$(error Error: relx.config already exists)
6179
5915
endif
6180
- ifneq ($(wildcard config/),)
6181
- $(error Error: config/ directory already exists)
5916
ifneq ($(wildcard rel/),)
5917
$(error Error: rel/ directory already exists)
6182
5918
endif
6183
5919
$(eval p := $(PROJECT))
6184
- $(verbose) $(call core_render,bs_relx_config,relx.config)
6185
- $(verbose) mkdir config/
6186
- $(verbose) $(call core_render,bs_sys_config,config/sys.config)
6187
- $(verbose) $(call core_render,bs_vm_args,config/vm.args)
5920
$(call render_template,bs_relx_config,relx.config)
5921
$(verbose) mkdir rel/
5922
$(call render_template,bs_sys_config,rel/sys.config)
5923
$(call render_template,bs_vm_args,rel/vm.args)
6188
5924
6189
5925
new-app:
6190
5926
ifndef in
 
@@ -6194,16 5930,14 @@ ifneq ($(wildcard $(APPS_DIR)/$in),)
6194
5930
$(error Error: Application $in already exists)
6195
5931
endif
6196
5932
$(eval p := $(in))
6197
- $(if $(shell echo $p | LC_ALL=C grep -x "[a-z0-9_]*"),,\
6198
- $(error Error: Invalid characters in the application name))
6199
5933
$(eval n := $(in)_sup)
6200
5934
$(verbose) mkdir -p $(APPS_DIR)/$p/src/
6201
- $(verbose) $(call core_render,bs_apps_Makefile,$(APPS_DIR)/$p/Makefile)
5935
$(call render_template,bs_apps_Makefile,$(APPS_DIR)/$p/Makefile)
6202
5936
ifdef LEGACY
6203
- $(verbose) $(call core_render,bs_appsrc,$(APPS_DIR)/$p/src/$p.app.src)
5937
$(call render_template,bs_appsrc,$(APPS_DIR)/$p/src/$p.app.src)
6204
5938
endif
6205
- $(verbose) $(call core_render,bs_app,$(APPS_DIR)/$p/src/$p_app.erl)
6206
- $(verbose) $(call core_render,tpl_supervisor,$(APPS_DIR)/$p/src/$p_sup.erl)
5939
$(call render_template,bs_app,$(APPS_DIR)/$p/src/$p_app.erl)
8630
$(call render_template,tpl_supervisor,$(APPS_DIR)/$p/src/$p_sup.erl)
6207
8631
6208
8632
new-lib:
6209
8633
ifndef in
 
@@ -6213,12 8637,10 @@ ifneq ($(wildcard $(APPS_DIR)/$in),)
6213
8637
$(error Error: Application $in already exists)
6214
8638
endif
6215
8639
$(eval p := $(in))
6216
- $(if $(shell echo $p | LC_ALL=C grep -x "[a-z0-9_]*"),,\
6217
- $(error Error: Invalid characters in the application name))
6218
5950
$(verbose) mkdir -p $(APPS_DIR)/$p/src/
6219
- $(verbose) $(call core_render,bs_apps_Makefile,$(APPS_DIR)/$p/Makefile)
5951
$(call render_template,bs_apps_Makefile,$(APPS_DIR)/$p/Makefile)
6220
5952
ifdef LEGACY
6221
- $(verbose) $(call core_render,bs_appsrc_lib,$(APPS_DIR)/$p/src/$p.app.src)
5953
$(call render_template,bs_appsrc_lib,$(APPS_DIR)/$p/src/$p.app.src)
6222
5954
endif
6223
5955
6224
5956
new:
 
@@ -6232,9 5964,9 @@ ifndef n
6232
5964
$(error Usage: $(MAKE) new t=TEMPLATE n=NAME [in=APP])
6233
5965
endif
6234
5966
ifdef in
6235
- $(verbose) $(call core_render,tpl_$(t),$(APPS_DIR)/$(in)/src/$(n).erl)
5967
$(call render_template,tpl_$(t),$(APPS_DIR)/$(in)/src/$(n).erl)
6236
5968
else
6237
- $(verbose) $(call core_render,tpl_$(t),src/$(n).erl)
5969
$(call render_template,tpl_$(t),src/$(n).erl)
6238
5970
endif
6239
5971
6240
5972
list-templates:
 
@@ -6278,8 6010,8 @@ ifeq ($(PLATFORM),msys2)
6278
6010
CXXFLAGS ?= -O3 -finline-functions -Wall
6279
6011
else ifeq ($(PLATFORM),darwin)
6280
6012
CC ?= cc
6281
- CFLAGS ?= -O3 -std=c99 -arch x86_64 -Wall -Wmissing-prototypes
6282
- CXXFLAGS ?= -O3 -arch x86_64 -Wall
6013
CFLAGS ?= -O3 -std=c99 -arch x86_64 -finline-functions -Wall -Wmissing-prototypes
6014
CXXFLAGS ?= -O3 -arch x86_64 -finline-functions -Wall
6283
6015
LDFLAGS ?= -arch x86_64 -flat_namespace -undefined suppress
6284
6016
else ifeq ($(PLATFORM),freebsd)
6285
6017
CC ?= cc
 
@@ -6299,14 6031,14 @@ endif
6299
6031
CFLAGS = -I"$(ERTS_INCLUDE_DIR)" -I"$(ERL_INTERFACE_INCLUDE_DIR)"
6300
6032
CXXFLAGS = -I"$(ERTS_INCLUDE_DIR)" -I"$(ERL_INTERFACE_INCLUDE_DIR)"
6301
6033
6302
- LDLIBS = -L"$(ERL_INTERFACE_LIB_DIR)" -lei
6034
LDLIBS = -L"$(ERL_INTERFACE_LIB_DIR)" -lerl_interface -lei
6303
6035
6304
6036
# Verbosity.
6305
6037
6306
- c_verbose_0 = @echo " C " $(filter-out $(notdir $(MAKEFILE_LIST) $(C_SRC_ENV)),$(^F));
6038
c_verbose_0 = @echo " C " $(?F);
6307
6039
c_verbose = $(c_verbose_$(V))
6308
6040
6309
- cpp_verbose_0 = @echo " CPP " $(filter-out $(notdir $(MAKEFILE_LIST) $(C_SRC_ENV)),$(^F));
6041
cpp_verbose_0 = @echo " CPP " $(?F);
6310
6042
cpp_verbose = $(cpp_verbose_$(V))
6311
6043
6312
6044
link_verbose_0 = @echo " LD " $(@F);
 
@@ -6341,13 6073,11 @@ app:: $(C_SRC_ENV) $(C_SRC_OUTPUT_FILE)
6341
6073
test-build:: $(C_SRC_ENV) $(C_SRC_OUTPUT_FILE)
6342
6074
6343
6075
$(C_SRC_OUTPUT_FILE): $(OBJECTS)
6344
- $(verbose) mkdir -p $(dir $@)
6076
$(verbose) mkdir -p priv/
6345
6077
$(link_verbose) $(CC) $(OBJECTS) \
6346
6078
$(LDFLAGS) $(if $(filter $(C_SRC_TYPE),shared),-shared) $(LDLIBS) \
6347
6079
-o $(C_SRC_OUTPUT_FILE)
6348
6080
6349
- $(OBJECTS): $(MAKEFILE_LIST) $(C_SRC_ENV)
6350
-
6351
6081
%.o: %.c
6352
6082
$(COMPILE_C) $(OUTPUT_OPTION) $<
6353
6083
 
@@ -6368,16 6098,12 @@ clean-c_src:
6368
6098
endif
6369
6099
6370
6100
ifneq ($(wildcard $(C_SRC_DIR)),)
6371
- ERL_ERTS_DIR = $(shell $(ERL) -eval 'io:format("~s~n", [code:lib_dir(erts)]), halt().')
6372
-
6373
6101
$(C_SRC_ENV):
6374
6102
$(verbose) $(ERL) -eval "file:write_file(\"$(call core_native_path,$(C_SRC_ENV))\", \
6375
6103
io_lib:format( \
6376
- \"# Generated by Erlang.mk. Edit at your own risk!~n~n\" \
6377
6104
\"ERTS_INCLUDE_DIR ?= ~s/erts-~s/include/~n\" \
6378
6105
\"ERL_INTERFACE_INCLUDE_DIR ?= ~s~n\" \
6379
- \"ERL_INTERFACE_LIB_DIR ?= ~s~n\" \
6380
- \"ERTS_DIR ?= $(ERL_ERTS_DIR)~n\", \
6106
\"ERL_INTERFACE_LIB_DIR ?= ~s~n\", \
6381
6107
[code:root_dir(), erlang:system_info(version), \
6382
6108
code:lib_dir(erl_interface, include), \
6383
6109
code:lib_dir(erl_interface, lib)])), \
 
@@ -6389,10 6115,6 @@ distclean-c_src-env:
6389
6115
$(gen_verbose) rm -f $(C_SRC_ENV)
6390
6116
6391
6117
-include $(C_SRC_ENV)
6392
-
6393
- ifneq ($(ERL_ERTS_DIR),$(ERTS_DIR))
6394
- $(shell rm -f $(C_SRC_ENV))
6395
- endif
6396
6118
endif
6397
6119
6398
6120
# Templates.
 
@@ -6478,15 6200,12 @@ endif
6478
6200
ifneq ($(wildcard src/$n.erl),)
6479
6201
$(error Error: src/$n.erl already exists)
6480
6202
endif
6481
- ifndef n
6482
- $(error Usage: $(MAKE) new-nif n=NAME [in=APP])
6483
- endif
6484
6203
ifdef in
6485
6204
$(verbose) $(MAKE) -C $(APPS_DIR)/$(in)/ new-nif n=$n in=
6486
6205
else
6487
6206
$(verbose) mkdir -p $(C_SRC_DIR) src/
6488
- $(verbose) $(call core_render,bs_c_nif,$(C_SRC_DIR)/$n.c)
6489
- $(verbose) $(call core_render,bs_erl_nif,src/$n.erl)
6207
$(call render_template,bs_c_nif,$(C_SRC_DIR)/$n.c)
6208
$(call render_template,bs_erl_nif,src/$n.erl)
6490
6209
endif
6491
6210
6492
6211
# Copyright (c) 2015-2017, Loïc Hoguin <[email protected]>
 
@@ -6515,17 6234,15 @@ ci:: $(addprefix ci-,$(CI_OTP) $(addsuffix -native,$(CI_HIPE)) $(addsuffix -erll
6515
6234
ci-prepare: $(addprefix $(KERL_INSTALL_DIR)/,$(CI_OTP) $(addsuffix -native,$(CI_HIPE)))
6516
6235
6517
6236
ci-setup::
6518
- $(verbose) :
6519
6237
6520
6238
ci-extra::
6521
- $(verbose) :
6522
6239
6523
6240
ci_verbose_0 = @echo " CI " $(1);
6524
6241
ci_verbose = $(ci_verbose_$(V))
6525
6242
6526
6243
define ci_target
6527
6244
ci-$1: $(KERL_INSTALL_DIR)/$2
6528
- $(verbose) $(MAKE) --no-print-directory clean
6245
$(verbose) $(MAKE) --no-print-directory clean distclean-c_src-env
6529
6246
$(ci_verbose) \
6530
6247
PATH="$(KERL_INSTALL_DIR)/$2/bin:$(PATH)" \
6531
6248
CI_OTP_RELEASE="$1" \
 
@@ -6539,8 6256,8 @@ $(foreach otp,$(CI_OTP),$(eval $(call ci_target,$(otp),$(otp),otp)))
6539
6256
$(foreach otp,$(CI_HIPE),$(eval $(call ci_target,$(otp)-native,$(otp)-native,native)))
6540
6257
$(foreach otp,$(CI_ERLLVM),$(eval $(call ci_target,$(otp)-erllvm,$(otp)-native,erllvm)))
6541
6258
6542
- $(foreach otp,$(filter-out $(ERLANG_OTP),$(CI_OTP)),$(eval $(call kerl_otp_target,$(otp))))
6543
- $(foreach otp,$(filter-out $(ERLANG_HIPE),$(sort $(CI_HIPE) $(CI_ERLLLVM))),$(eval $(call kerl_hipe_target,$(otp))))
6259
$(foreach otp,$(CI_OTP),$(eval $(call kerl_otp_target,$(otp))))
6260
$(foreach otp,$(sort $(CI_HIPE) $(CI_ERLLLVM)),$(eval $(call kerl_hipe_target,$(otp))))
6544
6261
6545
6262
help::
6546
6263
$(verbose) printf "%s\n" "" \
 
@@ -6552,74 6269,6 @@ help::
6552
6269
6553
6270
endif
6554
6271
6555
- # Copyright (c) 2020, Loïc Hoguin <[email protected]>
6556
- # This file is part of erlang.mk and subject to the terms of the ISC License.
6557
-
6558
- ifdef CONCUERROR_TESTS
6559
-
6560
- .PHONY: concuerror distclean-concuerror
6561
-
6562
- # Configuration
6563
-
6564
- CONCUERROR_LOGS_DIR ?= $(CURDIR)/logs
6565
- CONCUERROR_OPTS ?=
6566
-
6567
- # Core targets.
6568
-
6569
- check:: concuerror
6570
-
6571
- ifndef KEEP_LOGS
6572
- distclean:: distclean-concuerror
6573
- endif
6574
-
6575
- # Plugin-specific targets.
6576
-
6577
- $(ERLANG_MK_TMP)/Concuerror/bin/concuerror: | $(ERLANG_MK_TMP)
6578
- $(verbose) git clone https://github.com/parapluu/Concuerror $(ERLANG_MK_TMP)/Concuerror
6579
- $(verbose) $(MAKE) -C $(ERLANG_MK_TMP)/Concuerror
6580
-
6581
- $(CONCUERROR_LOGS_DIR):
6582
- $(verbose) mkdir -p $(CONCUERROR_LOGS_DIR)
6583
-
6584
- define concuerror_html_report
6585
- <!DOCTYPE html>
6586
- <html lang="en">
6587
- <head>
6588
- <meta charset="utf-8">
6589
- <title>Concuerror HTML report</title>
6590
- </head>
6591
- <body>
6592
- <h1>Concuerror HTML report</h1>
6593
- <p>Generated on $(concuerror_date)</p>
6863
- <ul>
6595
- $(foreach t,$(concuerror_targets),<li><a href="$(t).txt">$(t)</a></li>)
6596
- </ul>
6597
- </body>
6598
- </html>
6599
- endef
6600
-
6601
- concuerror: $(addprefix concuerror-,$(subst :,-,$(CONCUERROR_TESTS)))
6602
- $(eval concuerror_date := $(shell date))
6603
- $(eval concuerror_targets := $^)
6604
- $(verbose) $(call core_render,concuerror_html_report,$(CONCUERROR_LOGS_DIR)/concuerror.html)
6605
-
6606
- define concuerror_target
6607
- .PHONY: concuerror-$1-$2
6608
-
6609
- concuerror-$1-$2: test-build | $(ERLANG_MK_TMP)/Concuerror/bin/concuerror $(CONCUERROR_LOGS_DIR)
6610
- $(ERLANG_MK_TMP)/Concuerror/bin/concuerror \
6611
- --pa $(CURDIR)/ebin --pa $(TEST_DIR) \
6612
- -o $(CONCUERROR_LOGS_DIR)/concuerror-$1-$2.txt \
6613
- $$(CONCUERROR_OPTS) -m $1 -t $2
6614
- endef
6615
-
6616
- $(foreach test,$(CONCUERROR_TESTS),$(eval $(call concuerror_target,$(firstword $(subst :, ,$(test))),$(lastword $(subst :, ,$(test))))))
6617
-
6618
- distclean-concuerror:
6619
- $(gen_verbose) rm -rf $(CONCUERROR_LOGS_DIR)
6620
-
6621
- endif
6622
-
6623
6272
# Copyright (c) 2013-2016, Loïc Hoguin <[email protected]>
6624
6273
# This file is part of erlang.mk and subject to the terms of the ISC License.
6625
6274
 
@@ -6641,9 6290,7 @@ CT_LOGS_DIR ?= $(CURDIR)/logs
6641
6290
6642
6291
tests:: ct
6643
6292
6644
- ifndef KEEP_LOGS
6645
6293
distclean:: distclean-ct
6646
- endif
6647
6294
6648
6295
help::
6649
6296
$(verbose) printf "%s\n" "" \
 
@@ -6658,16 6305,16 @@ help::
6658
6305
CT_RUN = ct_run \
6659
6306
-no_auto_compile \
6660
6307
-noinput \
6661
- -pa $(CURDIR)/ebin $(TEST_DIR) \
6308
-pa $(CURDIR)/ebin $(DEPS_DIR)/*/ebin $(APPS_DIR)/*/ebin $(TEST_DIR) \
6662
6309
-dir $(TEST_DIR) \
6663
6310
-logdir $(CT_LOGS_DIR)
6664
6311
6665
6312
ifeq ($(CT_SUITES),)
6666
- ct: $(if $(IS_APP)$(ROOT_DIR),,apps-ct)
6313
ct: $(if $(IS_APP),,apps-ct)
6667
6314
else
6668
6315
# We do not run tests if we are in an apps/* with no test directory.
6669
6316
ifneq ($(IS_APP)$(wildcard $(TEST_DIR)),1)
6670
- ct: test-build $(if $(IS_APP)$(ROOT_DIR),,apps-ct)
6317
ct: test-build $(if $(IS_APP),,apps-ct)
6671
6318
$(verbose) mkdir -p $(CT_LOGS_DIR)
6672
6319
$(gen_verbose) $(CT_RUN) -sname ct_$(PROJECT) -suite $(addsuffix _SUITE,$(CT_SUITES)) $(CT_OPTS)
6673
6320
endif
 
@@ -6675,34 6322,30 @@ endif
6675
6322
6676
6323
ifneq ($(ALL_APPS_DIRS),)
6677
6324
define ct_app_target
6678
- apps-ct-$1: test-build
6679
- $$(MAKE) -C $1 ct IS_APP=1
6325
apps-ct-$1:
6326
$(MAKE) -C $1 ct IS_APP=1
6680
6327
endef
6681
6328
6682
6329
$(foreach app,$(ALL_APPS_DIRS),$(eval $(call ct_app_target,$(app))))
6683
6330
6684
- apps-ct: $(addprefix apps-ct-,$(ALL_APPS_DIRS))
6331
apps-ct: test-build $(addprefix apps-ct-,$(ALL_APPS_DIRS))
6685
6332
endif
6686
6333
6687
- ifdef t
6334
ifndef t
6335
CT_EXTRA =
6336
else
6688
6337
ifeq (,$(findstring :,$t))
6689
6338
CT_EXTRA = -group $t
6690
6339
else
6691
6340
t_words = $(subst :, ,$t)
6692
6341
CT_EXTRA = -group $(firstword $(t_words)) -case $(lastword $(t_words))
6693
6342
endif
6694
- else
6695
- ifdef c
6696
- CT_EXTRA = -case $c
6697
- else
6698
- CT_EXTRA =
6699
- endif
6700
6343
endif
6701
6344
6702
6345
define ct_suite_target
6703
6346
ct-$(1): test-build
6704
6347
$(verbose) mkdir -p $(CT_LOGS_DIR)
6705
- $(gen_verbose_esc) $(CT_RUN) -sname ct_$(PROJECT) -suite $(addsuffix _SUITE,$(1)) $(CT_EXTRA) $(CT_OPTS)
6348
$(gen_verbose) $(CT_RUN) -sname ct_$(PROJECT) -suite $(addsuffix _SUITE,$(1)) $(CT_EXTRA) $(CT_OPTS)
6706
6349
endef
6707
6350
6708
6351
$(foreach test,$(CT_SUITES),$(eval $(call ct_suite_target,$(test))))
 
@@ -6754,17 6397,11 @@ define filter_opts.erl
6754
6397
halt().
6755
6398
endef
6756
6399
6757
- # DIALYZER_PLT is a variable understood directly by Dialyzer.
6758
- #
6759
- # We append the path to erts at the end of the PLT. This works
6760
- # because the PLT file is in the external term format and the
6761
- # function binary_to_term/1 ignores any trailing data.
6762
6400
$(DIALYZER_PLT): deps app
6763
6401
$(eval DEPS_LOG := $(shell test -f $(ERLANG_MK_TMP)/deps.log && \
6764
6402
while read p; do test -d $$p/ebin && echo $$p/ebin; done <$(ERLANG_MK_TMP)/deps.log))
6765
6403
$(verbose) dialyzer --build_plt $(DIALYZER_PLT_OPTS) --apps \
6766
6404
erts kernel stdlib $(PLT_APPS) $(OTP_DEPS) $(LOCAL_DEPS) $(DEPS_LOG) || test $$? -eq 2
6767
- $(verbose) $(ERL) -eval 'io:format("~n~s~n", [code:lib_dir(erts)]), halt().' >> $@
6768
6405
6769
6406
plt: $(DIALYZER_PLT)
6770
6407
 
@@ -6772,18 6409,11 @@ distclean-plt:
6772
6409
$(gen_verbose) rm -f $(DIALYZER_PLT)
6773
6410
6774
6411
ifneq ($(wildcard $(DIALYZER_PLT)),)
6775
- dialyze: $(if $(filter --src,$(DIALYZER_DIRS)),,deps app)
6776
- $(verbose) if ! tail -n1 $(DIALYZER_PLT) | \
6777
- grep -q "^`$(ERL) -eval 'io:format("~s", [code:lib_dir(erts)]), halt().'`$$"; then \
6778
- rm $(DIALYZER_PLT); \
6779
- $(MAKE) plt; \
6780
- fi
6412
dialyze:
6781
6413
else
6782
6414
dialyze: $(DIALYZER_PLT)
6783
6415
endif
6784
- $(verbose) dialyzer --no_native `$(ERL) \
6785
- -eval "$(subst $(newline),,$(call escape_dquotes,$(call filter_opts.erl)))" \
6786
- -extra $(ERLC_OPTS)` $(DIALYZER_DIRS) $(DIALYZER_OPTS) $(if $(wildcard ebin/),-pa ebin/)
6416
$(verbose) dialyzer --no_native `$(ERL) -eval "$(subst $(newline),,$(call escape_dquotes,$(call filter_opts.erl)))" -extra $(ERLC_OPTS)` $(DIALYZER_DIRS) $(DIALYZER_OPTS)
6787
6417
6788
6418
# Copyright (c) 2013-2016, Loïc Hoguin <[email protected]>
6789
6419
# This file is part of erlang.mk and subject to the terms of the ISC License.
 
@@ -6799,7 6429,7 @@ EDOC_OUTPUT ?= doc
6799
6429
define edoc.erl
6800
6430
SrcPaths = lists:foldl(fun(P, Acc) ->
6801
6431
filelib:wildcard(atom_to_list(P) "/{src,c_src}") Acc
6802
- end, [], [$(call comma_list,$(patsubst %,'%',$(call core_native_path,$(EDOC_SRC_DIRS))))]),
6432
end, [], [$(call comma_list,$(patsubst %,'%',$(EDOC_SRC_DIRS)))]),
6803
6433
DefaultOpts = [{dir, "$(EDOC_OUTPUT)"}, {source_path, SrcPaths}, {subpackages, false}],
6804
6434
edoc:application($(1), ".", [$(2)] DefaultOpts),
6805
6435
halt(0).
 
@@ -6828,7 6458,6 @@ distclean-edoc:
6828
6458
6829
6459
DTL_FULL_PATH ?=
6830
6460
DTL_PATH ?= templates/
6831
- DTL_PREFIX ?=
6832
6461
DTL_SUFFIX ?= _dtl
6833
6462
DTL_OPTS ?=
6834
6463
 
@@ -6844,17 6473,18 @@ DTL_FILES := $(sort $(call core_find,$(DTL_PATH),*.dtl))
6844
6473
6845
6474
ifneq ($(DTL_FILES),)
6846
6475
6847
- DTL_NAMES = $(addprefix $(DTL_PREFIX),$(addsuffix $(DTL_SUFFIX),$(DTL_FILES:$(DTL_PATH)/%.dtl=%)))
6476
DTL_NAMES = $(addsuffix $(DTL_SUFFIX),$(DTL_FILES:$(DTL_PATH)/%.dtl=%))
6848
6477
DTL_MODULES = $(if $(DTL_FULL_PATH),$(subst /,_,$(DTL_NAMES)),$(notdir $(DTL_NAMES)))
6849
6478
BEAM_FILES = $(addsuffix .beam,$(addprefix ebin/,$(DTL_MODULES)))
6850
6479
6851
6480
ifneq ($(words $(DTL_FILES)),0)
6852
6481
# Rebuild templates when the Makefile changes.
6853
- $(ERLANG_MK_TMP)/last-makefile-change-erlydtl: $(MAKEFILE_LIST) | $(ERLANG_MK_TMP)
6854
- $(verbose) if test -f $@; then \
6482
$(ERLANG_MK_TMP)/last-makefile-change-erlydtl: $(MAKEFILE_LIST)
6483
@mkdir -p $(ERLANG_MK_TMP)
6484
@if test -f $@; then \
6855
6485
touch $(DTL_FILES); \
6856
6486
fi
6857
- $(verbose) touch $@
6487
@touch $@
6858
6488
6859
6489
ebin/$(PROJECT).app:: $(ERLANG_MK_TMP)/last-makefile-change-erlydtl
6860
6490
endif
 
@@ -6865,10 6495,10 @@ define erlydtl_compile.erl
6865
6495
"" ->
6866
6496
filename:basename(F, ".dtl");
6867
6497
_ ->
6868
- "$(call core_native_path,$(DTL_PATH))/" F2 = filename:rootname(F, ".dtl"),
6498
"$(DTL_PATH)/" F2 = filename:rootname(F, ".dtl"),
6869
6499
re:replace(F2, "/", "_", [{return, list}, global])
6870
6500
end,
6871
- Module = list_to_atom("$(DTL_PREFIX)" string:to_lower(Module0) "$(DTL_SUFFIX)"),
6501
Module = list_to_atom(string:to_lower(Module0) "$(DTL_SUFFIX)"),
6872
6502
case erlydtl:compile(F, Module, [$(DTL_OPTS)] [{out_dir, "ebin/"}, return_errors]) of
6873
6503
ok -> ok;
6874
6504
{ok, _} -> ok
 
@@ -6880,7 6510,7 @@ endef
6880
6510
ebin/$(PROJECT).app:: $(DTL_FILES) | ebin/
6881
6511
$(if $(strip $?),\
6882
6512
$(dtl_verbose) $(call erlang,$(call erlydtl_compile.erl,$(call core_native_path,$?)),\
6883
- -pa ebin/))
6513
-pa ebin/ $(DEPS_DIR)/erlydtl/ebin/))
6884
6514
6885
6515
endif
6886
6516
 
@@ -6913,15 6543,13 @@ help::
6913
6543
6914
6544
# Plugin-specific targets.
6915
6545
6916
- escript-zip:: FULL=1
6917
6546
escript-zip:: deps app
6918
6547
$(verbose) mkdir -p $(dir $(ESCRIPT_ZIP))
6919
6548
$(verbose) rm -f $(ESCRIPT_ZIP_FILE)
6920
6549
$(gen_verbose) cd .. && $(ESCRIPT_ZIP) $(ESCRIPT_ZIP_FILE) $(PROJECT)/ebin/*
6921
6550
ifneq ($(DEPS),)
6922
6551
$(verbose) cd $(DEPS_DIR) && $(ESCRIPT_ZIP) $(ESCRIPT_ZIP_FILE) \
6923
- $(subst $(DEPS_DIR)/,,$(addsuffix /*,$(wildcard \
6924
- $(addsuffix /ebin,$(shell cat $(ERLANG_MK_TMP)/deps.log)))))
6552
`cat $(ERLANG_MK_TMP)/deps.log | sed 's/^$(subst /,\/,$(DEPS_DIR))\///' | sed 's/$$/\/ebin\/\*/'`
6925
6553
endif
6926
6554
6927
6555
escript:: escript-zip
 
@@ -6958,17 6586,32 @@ help::
6958
6586
# Plugin-specific targets.
6959
6587
6960
6588
define eunit.erl
6961
- $(call cover.erl)
6962
- CoverSetup(),
6589
Enabled = case "$(COVER)" of
6590
"" -> false;
6591
_ ->
6592
case filelib:is_dir("ebin") of
6593
false -> false;
6863
true ->
6595
case cover:compile_beam_directory("ebin") of
6596
{error, _} -> halt(1);
6597
_ -> true
6598
end
6599
end
6600
end,
6963
6601
case eunit:test($1, [$(EUNIT_OPTS)]) of
6964
6602
ok -> ok;
6965
6603
error -> halt(2)
6966
6604
end,
6967
- CoverExport("$(call core_native_path,$(COVER_DATA_DIR))/eunit.coverdata"),
6605
case {Enabled, "$(COVER)"} of
6606
{false, _} -> ok;
6607
{_, ""} -> ok;
6608
_ ->
6609
cover:export("$(COVER_DATA_DIR)/eunit.coverdata")
6610
end,
6968
6611
halt()
6969
6612
endef
6970
6613
6971
- EUNIT_ERL_OPTS = -pa $(TEST_DIR) $(CURDIR)/ebin
6614
EUNIT_ERL_OPTS = -pa $(TEST_DIR) $(DEPS_DIR)/*/ebin $(APPS_DIR)/*/ebin $(CURDIR)/ebin
6972
6615
6973
6616
ifdef t
6974
6617
ifeq (,$(findstring :,$(t)))
 
@@ -6985,356 6628,17 @@ EUNIT_TEST_MODS = $(notdir $(basename $(call core_find,$(TEST_DIR)/,*.erl)))
6985
6628
EUNIT_MODS = $(foreach mod,$(EUNIT_EBIN_MODS) $(filter-out \
6986
6629
$(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(EUNIT_TEST_MODS)),'$(mod)')
6987
6630
6988
- eunit: test-build $(if $(IS_APP)$(ROOT_DIR),,apps-eunit) cover-data-dir
6989
- ifneq ($(wildcard src/ $(TEST_DIR)),)
6631
eunit: test-build $(if $(IS_APP),,apps-eunit) cover-data-dir
6990
6632
$(gen_verbose) $(call erlang,$(call eunit.erl,[$(call comma_list,$(EUNIT_MODS))]),$(EUNIT_ERL_OPTS))
6991
- endif
6992
6633
6993
6634
ifneq ($(ALL_APPS_DIRS),)
6994
- apps-eunit: test-build
6635
apps-eunit:
6995
6636
$(verbose) eunit_retcode=0 ; for app in $(ALL_APPS_DIRS); do $(MAKE) -C $$app eunit IS_APP=1; \
6996
6637
[ $$? -ne 0 ] && eunit_retcode=1 ; done ; \
6997
6638
exit $$eunit_retcode
6998
6639
endif
6999
6640
endif
7000
6641
7001
- # Copyright (c) 2020, Loïc Hoguin <[email protected]>
7002
- # This file is part of erlang.mk and subject to the terms of the ISC License.
7003
-
7004
- HEX_CORE_GIT ?= https://github.com/hexpm/hex_core
7005
- HEX_CORE_COMMIT ?= v0.7.0
7006
-
7007
- PACKAGES = hex_core
7008
- pkg_hex_core_name = hex_core
7009
- pkg_hex_core_description = Reference implementation of Hex specifications
7010
- pkg_hex_core_homepage = $(HEX_CORE_GIT)
7011
- pkg_hex_core_fetch = git
7012
- pkg_hex_core_repo = $(HEX_CORE_GIT)
7013
- pkg_hex_core_commit = $(HEX_CORE_COMMIT)
7014
-
7015
- # We automatically depend on hex_core when the project isn't already.
7016
- $(if $(filter hex_core,$(DEPS) $(BUILD_DEPS) $(DOC_DEPS) $(REL_DEPS) $(TEST_DEPS)),,\
7017
- $(eval $(call dep_target,hex_core)))
7018
-
7019
- hex-core: $(DEPS_DIR)/hex_core
7020
- $(verbose) if [ ! -e $(DEPS_DIR)/hex_core/ebin/dep_built ]; then \
7021
- $(MAKE) -C $(DEPS_DIR)/hex_core IS_DEP=1; \
7022
- touch $(DEPS_DIR)/hex_core/ebin/dep_built; \
7023
- fi
7024
-
7025
- # @todo This must also apply to fetching.
7026
- HEX_CONFIG ?=
7027
-
7028
- define hex_config.erl
7029
- begin
7030
- Config0 = hex_core:default_config(),
7031
- Config0$(HEX_CONFIG)
7032
- end
7033
- endef
7034
-
7035
- define hex_user_create.erl
7036
- {ok, _} = application:ensure_all_started(ssl),
7037
- {ok, _} = application:ensure_all_started(inets),
7038
- Config = $(hex_config.erl),
7039
- case hex_api_user:create(Config, <<"$(strip $1)">>, <<"$(strip $2)">>, <<"$(strip $3)">>) of
7040
- {ok, {201, _, #{<<"email">> := Email, <<"url">> := URL, <<"username">> := Username}}} ->
7041
- io:format("User ~s (~s) created at ~s~n"
7042
- "Please check your inbox for a confirmation email.~n"
7043
- "You must confirm before you are allowed to publish packages.~n",
7044
- [Username, Email, URL]),
7045
- halt(0);
7046
- {ok, {Status, _, Errors}} ->
7047
- io:format("Error ~b: ~0p~n", [Status, Errors]),
7048
- halt(80)
7049
- end
7050
- endef
7051
-
7052
- # The $(info ) call inserts a new line after the password prompt.
7053
- hex-user-create: hex-core
7054
- $(if $(HEX_USERNAME),,$(eval HEX_USERNAME := $(shell read -p "Username: " username; echo $$username)))
7055
- $(if $(HEX_PASSWORD),,$(eval HEX_PASSWORD := $(shell stty -echo; read -p "Password: " password; stty echo; echo $$password) $(info )))
7056
- $(if $(HEX_EMAIL),,$(eval HEX_EMAIL := $(shell read -p "Email: " email; echo $$email)))
7057
- $(gen_verbose) $(call erlang,$(call hex_user_create.erl,$(HEX_USERNAME),$(HEX_PASSWORD),$(HEX_EMAIL)))
7058
-
7059
- define hex_key_add.erl
7060
- {ok, _} = application:ensure_all_started(ssl),
7061
- {ok, _} = application:ensure_all_started(inets),
7062
- Config = $(hex_config.erl),
7063
- ConfigF = Config#{api_key => iolist_to_binary([<<"Basic ">>, base64:encode(<<"$(strip $1):$(strip $2)">>)])},
7064
- Permissions = [
7065
- case string:split(P, <<":">>) of
7066
- [D] -> #{domain => D};
7067
- [D, R] -> #{domain => D, resource => R}
7068
- end
7069
- || P <- string:split(<<"$(strip $4)">>, <<",">>, all)],
7070
- case hex_api_key:add(ConfigF, <<"$(strip $3)">>, Permissions) of
7071
- {ok, {201, _, #{<<"secret">> := Secret}}} ->
7072
- io:format("Key ~s created for user ~s~nSecret: ~s~n"
7073
- "Please store the secret in a secure location, such as a password store.~n"
7074
- "The secret will be requested for most Hex-related operations.~n",
7075
- [<<"$(strip $3)">>, <<"$(strip $1)">>, Secret]),
7076
- halt(0);
7077
- {ok, {Status, _, Errors}} ->
7078
- io:format("Error ~b: ~0p~n", [Status, Errors]),
7079
- halt(81)
7080
- end
7081
- endef
7082
-
7083
- hex-key-add: hex-core
7084
- $(if $(HEX_USERNAME),,$(eval HEX_USERNAME := $(shell read -p "Username: " username; echo $$username)))
7085
- $(if $(HEX_PASSWORD),,$(eval HEX_PASSWORD := $(shell stty -echo; read -p "Password: " password; stty echo; echo $$password) $(info )))
7086
- $(gen_verbose) $(call erlang,$(call hex_key_add.erl,$(HEX_USERNAME),$(HEX_PASSWORD),\
7087
- $(if $(name),$(name),$(shell hostname)-erlang-mk),\
7088
- $(if $(perm),$(perm),api)))
7089
-
7090
- HEX_TARBALL_EXTRA_METADATA ?=
7091
-
7092
- # @todo Check that we can = files
7093
- HEX_TARBALL_FILES ?= \
7094
- $(wildcard early-plugins.mk) \
7095
- $(wildcard ebin/$(PROJECT).app) \
7096
- $(wildcard ebin/$(PROJECT).appup) \
7097
- $(wildcard $(notdir $(ERLANG_MK_FILENAME))) \
7098
- $(sort $(call core_find,include/,*.hrl)) \
7099
- $(wildcard LICENSE*) \
7100
- $(wildcard Makefile) \
7101
- $(wildcard plugins.mk) \
7102
- $(sort $(call core_find,priv/,*)) \
7103
- $(wildcard README*) \
7104
- $(wildcard rebar.config) \
7105
- $(sort $(call core_find,src/,*))
7106
-
7107
- HEX_TARBALL_OUTPUT_FILE ?= $(ERLANG_MK_TMP)/$(PROJECT).tar
7108
-
7109
- # @todo Need to check for rebar.config and/or the absence of DEPS to know
7110
- # whether a project will work with Rebar.
7111
- #
7112
- # @todo contributors licenses links in HEX_TARBALL_EXTRA_METADATA
7113
-
7114
- # In order to build the requirements metadata we look into DEPS.
7115
- # We do not require that the project use Hex dependencies, however
7116
- # Hex.pm does require that the package name and version numbers
7117
- # correspond to a real Hex package.
7118
- define hex_tarball_create.erl
7119
- Files0 = [$(call comma_list,$(patsubst %,"%",$(HEX_TARBALL_FILES)))],
7120
- Requirements0 = #{
7121
- $(foreach d,$(DEPS),
7122
- <<"$(if $(subst hex,,$(call query_fetch_method,$d)),$d,$(if $(word 3,$(dep_$d)),$(word 3,$(dep_$d)),$d))">> => #{
7123
- <<"app">> => <<"$d">>,
7124
- <<"optional">> => false,
7125
- <<"requirement">> => <<"$(call query_version,$d)">>
7126
- },)
7127
- $(if $(DEPS),dummy => dummy)
7128
- },
7129
- Requirements = maps:remove(dummy, Requirements0),
7130
- Metadata0 = #{
7131
- app => <<"$(strip $(PROJECT))">>,
7132
- build_tools => [<<"make">>, <<"rebar3">>],
7133
- description => <<"$(strip $(PROJECT_DESCRIPTION))">>,
7134
- files => [unicode:characters_to_binary(F) || F <- Files0],
7135
- name => <<"$(strip $(PROJECT))">>,
7136
- requirements => Requirements,
7137
- version => <<"$(strip $(PROJECT_VERSION))">>
7138
- },
7139
- Metadata = Metadata0$(HEX_TARBALL_EXTRA_METADATA),
7140
- Files = [case file:read_file(F) of
7141
- {ok, Bin} ->
7142
- {F, Bin};
7143
- {error, Reason} ->
7144
- io:format("Error trying to open file ~0p: ~0p~n", [F, Reason]),
7145
- halt(82)
7146
- end || F <- Files0],
7147
- case hex_tarball:create(Metadata, Files) of
7148
- {ok, #{tarball := Tarball}} ->
7149
- ok = file:write_file("$(strip $(HEX_TARBALL_OUTPUT_FILE))", Tarball),
7150
- halt(0);
7151
- {error, Reason} ->
7152
- io:format("Error ~0p~n", [Reason]),
7153
- halt(83)
7154
- end
7155
- endef
7156
-
7157
- hex_tar_verbose_0 = @echo " TAR $(notdir $(ERLANG_MK_TMP))/$(@F)";
7158
- hex_tar_verbose_2 = set -x;
7159
- hex_tar_verbose = $(hex_tar_verbose_$(V))
7160
-
7161
- $(HEX_TARBALL_OUTPUT_FILE): hex-core app
7162
- $(hex_tar_verbose) $(call erlang,$(call hex_tarball_create.erl))
7163
-
7164
- hex-tarball-create: $(HEX_TARBALL_OUTPUT_FILE)
7165
-
7166
- define hex_release_publish_summary.erl
7167
- {ok, Tarball} = erl_tar:open("$(strip $(HEX_TARBALL_OUTPUT_FILE))", [read]),
7168
- ok = erl_tar:extract(Tarball, [{cwd, "$(ERLANG_MK_TMP)"}, {files, ["metadata.config"]}]),
7169
- {ok, Metadata} = file:consult("$(ERLANG_MK_TMP)/metadata.config"),
7170
- #{
7171
- <<"name">> := Name,
7172
- <<"version">> := Version,
7173
- <<"files">> := Files,
7174
- <<"requirements">> := Deps
7175
- } = maps:from_list(Metadata),
7176
- io:format("Publishing ~s ~s~n Dependencies:~n", [Name, Version]),
7177
- case Deps of
7178
- [] ->
7179
- io:format(" (none)~n");
7180
- _ ->
7181
- [begin
7182
- #{<<"app">> := DA, <<"requirement">> := DR} = maps:from_list(D),
7183
- io:format(" ~s ~s~n", [DA, DR])
7184
- end || {_, D} <- Deps]
7185
- end,
7186
- io:format(" Included files:~n"),
7187
- [io:format(" ~s~n", [F]) || F <- Files],
7188
- io:format("You may also review the contents of the tarball file.~n"
7189
- "Please enter your secret key to proceed.~n"),
7190
- halt(0)
7191
- endef
7192
-
7193
- define hex_release_publish.erl
7194
- {ok, _} = application:ensure_all_started(ssl),
7195
- {ok, _} = application:ensure_all_started(inets),
7196
- Config = $(hex_config.erl),
7197
- ConfigF = Config#{api_key => <<"$(strip $1)">>},
7198
- {ok, Tarball} = file:read_file("$(strip $(HEX_TARBALL_OUTPUT_FILE))"),
7199
- case hex_api_release:publish(ConfigF, Tarball, [{replace, $2}]) of
7200
- {ok, {200, _, #{}}} ->
7201
- io:format("Release replaced~n"),
7202
- halt(0);
7203
- {ok, {201, _, #{}}} ->
7204
- io:format("Release published~n"),
7205
- halt(0);
7206
- {ok, {Status, _, Errors}} ->
7207
- io:format("Error ~b: ~0p~n", [Status, Errors]),
7208
- halt(84)
7209
- end
7210
- endef
7211
-
7212
- hex-release-tarball: hex-core $(HEX_TARBALL_OUTPUT_FILE)
7213
- $(verbose) $(call erlang,$(call hex_release_publish_summary.erl))
7214
-
7215
- hex-release-publish: hex-core hex-release-tarball
7216
- $(if $(HEX_SECRET),,$(eval HEX_SECRET := $(shell stty -echo; read -p "Secret: " secret; stty echo; echo $$secret) $(info )))
7217
- $(gen_verbose) $(call erlang,$(call hex_release_publish.erl,$(HEX_SECRET),false))
7218
-
7219
- hex-release-replace: hex-core hex-release-tarball
7220
- $(if $(HEX_SECRET),,$(eval HEX_SECRET := $(shell stty -echo; read -p "Secret: " secret; stty echo; echo $$secret) $(info )))
7221
- $(gen_verbose) $(call erlang,$(call hex_release_publish.erl,$(HEX_SECRET),true))
7222
-
7223
- define hex_release_delete.erl
7224
- {ok, _} = application:ensure_all_started(ssl),
7225
- {ok, _} = application:ensure_all_started(inets),
7226
- Config = $(hex_config.erl),
7227
- ConfigF = Config#{api_key => <<"$(strip $1)">>},
7228
- case hex_api_release:delete(ConfigF, <<"$(strip $(PROJECT))">>, <<"$(strip $(PROJECT_VERSION))">>) of
7229
- {ok, {204, _, _}} ->
7230
- io:format("Release $(strip $(PROJECT_VERSION)) deleted~n"),
7231
- halt(0);
7232
- {ok, {Status, _, Errors}} ->
7233
- io:format("Error ~b: ~0p~n", [Status, Errors]),
7234
- halt(85)
7235
- end
7236
- endef
7237
-
7238
- hex-release-delete: hex-core
7239
- $(if $(HEX_SECRET),,$(eval HEX_SECRET := $(shell stty -echo; read -p "Secret: " secret; stty echo; echo $$secret) $(info )))
7240
- $(gen_verbose) $(call erlang,$(call hex_release_delete.erl,$(HEX_SECRET)))
7241
-
7242
- define hex_release_retire.erl
7243
- {ok, _} = application:ensure_all_started(ssl),
7244
- {ok, _} = application:ensure_all_started(inets),
7245
- Config = $(hex_config.erl),
7246
- ConfigF = Config#{api_key => <<"$(strip $1)">>},
7247
- Params = #{<<"reason">> => <<"$(strip $3)">>, <<"message">> => <<"$(strip $4)">>},
7248
- case hex_api_release:retire(ConfigF, <<"$(strip $(PROJECT))">>, <<"$(strip $2)">>, Params) of
7249
- {ok, {204, _, _}} ->
7250
- io:format("Release $(strip $2) has been retired~n"),
7251
- halt(0);
7252
- {ok, {Status, _, Errors}} ->
7253
- io:format("Error ~b: ~0p~n", [Status, Errors]),
7254
- halt(86)
7255
- end
7256
- endef
7257
-
7258
- hex-release-retire: hex-core
7259
- $(if $(HEX_SECRET),,$(eval HEX_SECRET := $(shell stty -echo; read -p "Secret: " secret; stty echo; echo $$secret) $(info )))
7260
- $(gen_verbose) $(call erlang,$(call hex_release_retire.erl,$(HEX_SECRET),\
7261
- $(if $(HEX_VERSION),$(HEX_VERSION),$(PROJECT_VERSION)),\
7262
- $(if $(HEX_REASON),$(HEX_REASON),invalid),\
7263
- $(HEX_MESSAGE)))
7264
-
7265
- define hex_release_unretire.erl
7266
- {ok, _} = application:ensure_all_started(ssl),
7267
- {ok, _} = application:ensure_all_started(inets),
7268
- Config = $(hex_config.erl),
7269
- ConfigF = Config#{api_key => <<"$(strip $1)">>},
7270
- case hex_api_release:unretire(ConfigF, <<"$(strip $(PROJECT))">>, <<"$(strip $2)">>) of
7271
- {ok, {204, _, _}} ->
7272
- io:format("Release $(strip $2) is not retired anymore~n"),
7273
- halt(0);
7274
- {ok, {Status, _, Errors}} ->
7275
- io:format("Error ~b: ~0p~n", [Status, Errors]),
7276
- halt(87)
7277
- end
7278
- endef
7279
-
7280
- hex-release-unretire: hex-core
7281
- $(if $(HEX_SECRET),,$(eval HEX_SECRET := $(shell stty -echo; read -p "Secret: " secret; stty echo; echo $$secret) $(info )))
7282
- $(gen_verbose) $(call erlang,$(call hex_release_unretire.erl,$(HEX_SECRET),\
7283
- $(if $(HEX_VERSION),$(HEX_VERSION),$(PROJECT_VERSION))))
7284
-
7285
- HEX_DOCS_DOC_DIR ?= doc/
7286
- HEX_DOCS_TARBALL_FILES ?= $(sort $(call core_find,$(HEX_DOCS_DOC_DIR),*))
7287
- HEX_DOCS_TARBALL_OUTPUT_FILE ?= $(ERLANG_MK_TMP)/$(PROJECT)-docs.tar.gz
7288
-
7289
- $(HEX_DOCS_TARBALL_OUTPUT_FILE): hex-core app docs
7290
- $(hex_tar_verbose) tar czf $(HEX_DOCS_TARBALL_OUTPUT_FILE) -C $(HEX_DOCS_DOC_DIR) \
7291
- $(HEX_DOCS_TARBALL_FILES:$(HEX_DOCS_DOC_DIR)%=%)
7292
-
7293
- hex-docs-tarball-create: $(HEX_DOCS_TARBALL_OUTPUT_FILE)
7294
-
7295
- define hex_docs_publish.erl
7296
- {ok, _} = application:ensure_all_started(ssl),
7297
- {ok, _} = application:ensure_all_started(inets),
7298
- Config = $(hex_config.erl),
7299
- ConfigF = Config#{api_key => <<"$(strip $1)">>},
7300
- {ok, Tarball} = file:read_file("$(strip $(HEX_DOCS_TARBALL_OUTPUT_FILE))"),
7301
- case hex_api:post(ConfigF,
7302
- ["packages", "$(strip $(PROJECT))", "releases", "$(strip $(PROJECT_VERSION))", "docs"],
7303
- {"application/octet-stream", Tarball}) of
7304
- {ok, {Status, _, _}} when Status >= 200, Status < 300 ->
7305
- io:format("Docs published~n"),
7306
- halt(0);
7307
- {ok, {Status, _, Errors}} ->
7308
- io:format("Error ~b: ~0p~n", [Status, Errors]),
7309
- halt(88)
7310
- end
7311
- endef
7312
-
7313
- hex-docs-publish: hex-core hex-docs-tarball-create
7314
- $(if $(HEX_SECRET),,$(eval HEX_SECRET := $(shell stty -echo; read -p "Secret: " secret; stty echo; echo $$secret) $(info )))
7315
- $(gen_verbose) $(call erlang,$(call hex_docs_publish.erl,$(HEX_SECRET)))
7316
-
7317
- define hex_docs_delete.erl
7318
- {ok, _} = application:ensure_all_started(ssl),
7319
- {ok, _} = application:ensure_all_started(inets),
7320
- Config = $(hex_config.erl),
7321
- ConfigF = Config#{api_key => <<"$(strip $1)">>},
7322
- case hex_api:delete(ConfigF,
7323
- ["packages", "$(strip $(PROJECT))", "releases", "$(strip $2)", "docs"]) of
7324
- {ok, {Status, _, _}} when Status >= 200, Status < 300 ->
7325
- io:format("Docs removed~n"),
7326
- halt(0);
7327
- {ok, {Status, _, Errors}} ->
7328
- io:format("Error ~b: ~0p~n", [Status, Errors]),
7329
- halt(89)
7330
- end
7331
- endef
7332
-
7333
- hex-docs-delete: hex-core
7334
- $(if $(HEX_SECRET),,$(eval HEX_SECRET := $(shell stty -echo; read -p "Secret: " secret; stty echo; echo $$secret) $(info )))
7335
- $(gen_verbose) $(call erlang,$(call hex_docs_delete.erl,$(HEX_SECRET),\
7336
- $(if $(HEX_VERSION),$(HEX_VERSION),$(PROJECT_VERSION))))
7337
-
7338
6642
# Copyright (c) 2015-2017, Loïc Hoguin <[email protected]>
7339
6643
# This file is part of erlang.mk and subject to the terms of the ISC License.
7340
6644
 
@@ -7346,7 6650,6 @@ ifeq ($(filter proper,$(DEPS) $(TEST_DEPS)),proper)
7346
6650
tests:: proper
7347
6651
7348
6652
define proper_check.erl
7349
- $(call cover.erl)
7350
6653
code:add_pathsa([
7351
6654
"$(call core_native_path,$(CURDIR)/ebin)",
7352
6655
"$(call core_native_path,$(DEPS_DIR)/*/ebin)",
 
@@ -7362,16 6665,13 @@ define proper_check.erl
7362
6665
end
7363
6666
|| {F, 0} <- M:module_info(exports)])
7364
6667
end,
7365
- try begin
7366
- CoverSetup(),
7367
- Res = case $(1) of
6668
try
6669
case $(1) of
7368
6670
all -> [true] =:= lists:usort([Module(M) || M <- [$(call comma_list,$(3))]]);
7369
6671
module -> Module($(2));
7370
6672
function -> proper:quickcheck($(2), nocolors)
7371
- end,
7372
- CoverExport("$(COVER_DATA_DIR)/proper.coverdata"),
7373
- Res
7374
- end of
6673
end
6674
of
7375
6675
true -> halt(0);
7376
6676
_ -> halt(1)
7377
6677
catch error:undef ->
 
@@ -7382,81 6682,21 @@ endef
7382
6682
7383
6683
ifdef t
7384
6684
ifeq (,$(findstring :,$(t)))
7385
- proper: test-build cover-data-dir
6685
proper: test-build
7386
6686
$(verbose) $(call erlang,$(call proper_check.erl,module,$(t)))
7387
6687
else
7388
- proper: test-build cover-data-dir
6688
proper: test-build
7389
6689
$(verbose) echo Testing $(t)/0
7390
6690
$(verbose) $(call erlang,$(call proper_check.erl,function,$(t)()))
7391
6691
endif
7392
6692
else
7393
- proper: test-build cover-data-dir
6693
proper: test-build
7394
6694
$(eval MODULES := $(patsubst %,'%',$(sort $(notdir $(basename \
7395
6695
$(wildcard ebin/*.beam) $(call core_find,$(TEST_DIR)/,*.beam))))))
7396
6696
$(gen_verbose) $(call erlang,$(call proper_check.erl,all,undefined,$(MODULES)))
7397
6697
endif
7398
6698
endif
7399
6699
7400
- # Copyright (c) 2015-2016, Loïc Hoguin <[email protected]>
7401
- # This file is part of erlang.mk and subject to the terms of the ISC License.
7402
-
7403
- # Verbosity.
7404
-
7405
- proto_verbose_0 = @echo " PROTO " $(filter %.proto,$(?F));
7406
- proto_verbose = $(proto_verbose_$(V))
7407
-
7408
- # Core targets.
7409
-
7410
- ifneq ($(wildcard src/),)
7411
- ifneq ($(filter gpb protobuffs,$(BUILD_DEPS) $(DEPS)),)
7412
- PROTO_FILES := $(filter %.proto,$(ALL_SRC_FILES))
7413
- ERL_FILES = $(addprefix src/,$(patsubst %.proto,%_pb.erl,$(notdir $(PROTO_FILES))))
7414
-
7415
- ifeq ($(PROTO_FILES),)
7416
- $(ERLANG_MK_TMP)/last-makefile-change-protobuffs:
7417
- $(verbose) :
7418
- else
7419
- # Rebuild proto files when the Makefile changes.
7420
- # We exclude $(PROJECT).d to avoid a circular dependency.
7421
- $(ERLANG_MK_TMP)/last-makefile-change-protobuffs: $(filter-out $(PROJECT).d,$(MAKEFILE_LIST)) | $(ERLANG_MK_TMP)
7422
- $(verbose) if test -f $@; then \
7423
- touch $(PROTO_FILES); \
7424
- fi
7425
- $(verbose) touch $@
7426
-
7427
- $(PROJECT).d:: $(ERLANG_MK_TMP)/last-makefile-change-protobuffs
7428
- endif
7429
-
7430
- ifeq ($(filter gpb,$(BUILD_DEPS) $(DEPS)),)
7431
- define compile_proto.erl
7432
- [begin
7433
- protobuffs_compile:generate_source(F, [
7434
- {output_include_dir, "./include"},
7435
- {output_src_dir, "./src"}])
7436
- end || F <- string:tokens("$1", " ")],
7437
- halt().
7438
- endef
7439
- else
7440
- define compile_proto.erl
7441
- [begin
7442
- gpb_compile:file(F, [
7443
- {include_as_lib, true},
7444
- {module_name_suffix, "_pb"},
7445
- {o_hrl, "./include"},
7446
- {o_erl, "./src"}])
7447
- end || F <- string:tokens("$1", " ")],
7448
- halt().
7449
- endef
7450
- endif
7451
-
7452
- ifneq ($(PROTO_FILES),)
7453
- $(PROJECT).d:: $(PROTO_FILES)
7454
- $(verbose) mkdir -p ebin/ include/
7455
- $(if $(strip $?),$(proto_verbose) $(call erlang,$(call compile_proto.erl,$?)))
7456
- endif
7457
- endif
7458
- endif
7459
-
7460
6700
# Copyright (c) 2013-2016, Loïc Hoguin <[email protected]>
7461
6701
# This file is part of erlang.mk and subject to the terms of the ISC License.
7462
6702
 
@@ -7467,7 6707,7 @@ endif
7467
6707
RELX ?= $(ERLANG_MK_TMP)/relx
7468
6708
RELX_CONFIG ?= $(CURDIR)/relx.config
7469
6709
7470
- RELX_URL ?= https://erlang.mk/res/relx-v3.27.0
6710
RELX_URL ?= https://erlang.mk/res/relx-v3.26.0
7471
6711
RELX_OPTS ?=
7472
6712
RELX_OUTPUT_DIR ?= _rel
7473
6713
RELX_REL_EXT ?=
 
@@ -7497,29 6737,20 @@ distclean:: distclean-relx-rel
7497
6737
7498
6738
# Plugin-specific targets.
7499
6739
7500
- $(RELX): | $(ERLANG_MK_TMP)
6740
$(RELX):
6741
$(verbose) mkdir -p $(ERLANG_MK_TMP)
7501
6742
$(gen_verbose) $(call core_http_get,$(RELX),$(RELX_URL))
7502
6743
$(verbose) chmod x $(RELX)
7503
6744
7504
6745
relx-rel: $(RELX) rel-deps app
7505
- $(verbose) $(RELX) $(if $(filter 1,$V),-V 3) -c $(RELX_CONFIG) $(RELX_OPTS) release
7506
- $(verbose) $(MAKE) relx-post-rel
7507
- ifeq ($(RELX_TAR),1)
7508
- $(verbose) $(RELX) $(if $(filter 1,$V),-V 3) -c $(RELX_CONFIG) $(RELX_OPTS) tar
7509
- endif
6746
$(verbose) $(RELX) -c $(RELX_CONFIG) $(RELX_OPTS) release $(if $(filter 1,$(RELX_TAR)),tar)
7510
6747
7511
6748
relx-relup: $(RELX) rel-deps app
7512
- $(verbose) $(RELX) $(if $(filter 1,$V),-V 3) -c $(RELX_CONFIG) $(RELX_OPTS) release
7513
- $(MAKE) relx-post-rel
7514
- $(verbose) $(RELX) $(if $(filter 1,$V),-V 3) -c $(RELX_CONFIG) $(RELX_OPTS) relup $(if $(filter 1,$(RELX_TAR)),tar)
6749
$(verbose) $(RELX) -c $(RELX_CONFIG) $(RELX_OPTS) release relup $(if $(filter 1,$(RELX_TAR)),tar)
7515
6750
7516
6751
distclean-relx-rel:
7517
6752
$(gen_verbose) rm -rf $(RELX_OUTPUT_DIR)
7518
6753
7519
- # Default hooks.
7520
- relx-post-rel::
7521
- $(verbose) :
7522
-
7523
6754
# Run target.
7524
6755
7525
6756
ifeq ($(wildcard $(RELX_CONFIG)),)
 
@@ -7535,25 6766,20 @@ define get_relx_release.erl
7535
6766
{semver, _} -> "";
7536
6767
VsnStr -> Vsn0
7537
6768
end,
7538
- Extended = case lists:keyfind(extended_start_script, 1, Config) of
7539
- {_, true} -> "1";
7540
- _ -> ""
7541
- end,
7542
- io:format("~s ~s ~s", [Name, Vsn, Extended]),
6769
io:format("~s ~s", [Name, Vsn]),
7543
6770
halt(0).
7544
6771
endef
7545
6772
7546
6773
RELX_REL := $(shell $(call erlang,$(get_relx_release.erl)))
7547
6774
RELX_REL_NAME := $(word 1,$(RELX_REL))
7548
6775
RELX_REL_VSN := $(word 2,$(RELX_REL))
7549
- RELX_REL_CMD := $(if $(word 3,$(RELX_REL)),console)
7550
6776
7551
6777
ifeq ($(PLATFORM),msys2)
7552
6778
RELX_REL_EXT := .cmd
7553
6779
endif
7554
6780
7555
6781
run:: all
7556
- $(verbose) $(RELX_OUTPUT_DIR)/$(RELX_REL_NAME)/bin/$(RELX_REL_NAME)$(RELX_REL_EXT) $(RELX_REL_CMD)
6782
$(verbose) $(RELX_OUTPUT_DIR)/$(RELX_REL_NAME)/bin/$(RELX_REL_NAME)$(RELX_REL_EXT) console
7557
6783
7558
6784
ifdef RELOAD
7559
6785
rel::
 
@@ -7578,7 6804,7 @@ endif
7578
6804
# Configuration.
7579
6805
7580
6806
SHELL_ERL ?= erl
7581
- SHELL_PATHS ?= $(CURDIR)/ebin $(TEST_DIR)
6807
SHELL_PATHS ?= $(CURDIR)/ebin $(APPS_DIR)/*/ebin $(DEPS_DIR)/*/ebin $(TEST_DIR)
7582
6808
SHELL_OPTS ?=
7583
6809
7584
6810
ALL_SHELL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(SHELL_DEPS))
 
@@ -7863,21 6820,10 @@ help::
7863
6820
7595
6821
$(foreach dep,$(SHELL_DEPS),$(eval $(call dep_target,$(dep))))
7596
6822
7597
- ifneq ($(SKIP_DEPS),)
7598
- build-shell-deps:
7599
- else
7600
6823
build-shell-deps: $(ALL_SHELL_DEPS_DIRS)
7601
- $(verbose) set -e; for dep in $(ALL_SHELL_DEPS_DIRS) ; do \
7602
- if [ -z "$(strip $(FULL))" ] && [ ! -L $$dep ] && [ -f $$dep/ebin/dep_built ]; then \
7603
- :; \
7604
- else \
7605
- $(MAKE) -C $$dep IS_DEP=1; \
7606
- if [ ! -L $$dep ] && [ -d $$dep/ebin ]; then touch $$dep/ebin/dep_built; fi; \
7607
- fi \
7608
- done
7609
- endif
6824
$(verbose) set -e; for dep in $(ALL_SHELL_DEPS_DIRS) ; do $(MAKE) -C $$dep ; done
7610
6825
7611
- shell:: build-shell-deps
6826
shell: build-shell-deps
7612
6827
$(gen_verbose) $(SHELL_ERL) -pa $(SHELL_PATHS) $(SHELL_OPTS)
7613
6828
7614
6829
# Copyright 2017, Stanislaw Klekot <[email protected]>
 
@@ -7699,21 6914,17 @@ ifeq ($(filter triq,$(DEPS) $(TEST_DEPS)),triq)
7699
6914
tests:: triq
7700
6915
7701
6916
define triq_check.erl
7702
- $(call cover.erl)
7703
6917
code:add_pathsa([
7704
6918
"$(call core_native_path,$(CURDIR)/ebin)",
7705
6919
"$(call core_native_path,$(DEPS_DIR)/*/ebin)",
7706
6920
"$(call core_native_path,$(TEST_DIR))"]),
7707
- try begin
7708
- CoverSetup(),
7709
- Res = case $(1) of
6921
try
6922
case $(1) of
7710
6923
all -> [true] =:= lists:usort([triq:check(M) || M <- [$(call comma_list,$(3))]]);
7711
6924
module -> triq:check($(2));
7712
6925
function -> triq:check($(2))
7713
- end,
7714
- CoverExport("$(COVER_DATA_DIR)/triq.coverdata"),
7715
- Res
7716
- end of
6926
end
6927
of
7717
6928
true -> halt(0);
7718
6929
_ -> halt(1)
7719
6930
catch error:undef ->
 
@@ -7724,15 6935,15 @@ endef
7724
6935
7725
6936
ifdef t
7726
6937
ifeq (,$(findstring :,$(t)))
7727
- triq: test-build cover-data-dir
6938
triq: test-build
7728
6939
$(verbose) $(call erlang,$(call triq_check.erl,module,$(t)))
7729
6940
else
7730
- triq: test-build cover-data-dir
6941
triq: test-build
7731
6942
$(verbose) echo Testing $(t)/0
7732
6943
$(verbose) $(call erlang,$(call triq_check.erl,function,$(t)()))
7733
6944
endif
7734
6945
else
7735
- triq: test-build cover-data-dir
6946
triq: test-build
7736
6947
$(eval MODULES := $(patsubst %,'%',$(sort $(notdir $(basename \
7737
6948
$(wildcard ebin/*.beam) $(call core_find,$(TEST_DIR)/,*.beam))))))
7738
6949
$(gen_verbose) $(call erlang,$(call triq_check.erl,all,undefined,$(MODULES)))
 
@@ -7784,14 6995,9 @@ distclean-xref:
7784
6995
# This file is part of erlang.mk and subject to the terms of the ISC License.
7785
6996
7786
6997
COVER_REPORT_DIR ?= cover
7787
- COVER_DATA_DIR ?= $(COVER_REPORT_DIR)
6998
COVER_DATA_DIR ?= $(CURDIR)
7788
6999
7789
- ifdef COVER
7790
- COVER_APPS ?= $(notdir $(ALL_APPS_DIRS))
7791
- COVER_DEPS ?=
7792
- endif
7793
-
7794
- # Code coverage for Common Test.
7000
# Hook in coverage to ct
7795
7001
7796
7002
ifdef COVER
7797
7003
ifdef CT_RUN
 
@@ -7801,44 7007,13 @@ test-build:: $(TEST_DIR)/ct.cover.spec
7801
7007
$(TEST_DIR)/ct.cover.spec: cover-data-dir
7802
7008
$(gen_verbose) printf "%s\n" \
7803
7009
"{incl_app, '$(PROJECT)', details}." \
7804
- "{incl_dirs, '$(PROJECT)', [\"$(call core_native_path,$(CURDIR)/ebin)\" \
7805
- $(foreach a,$(COVER_APPS),$(comma) \"$(call core_native_path,$(APPS_DIR)/$a/ebin)\") \
7806
- $(foreach d,$(COVER_DEPS),$(comma) \"$(call core_native_path,$(DEPS_DIR)/$d/ebin)\")]}." \
7807
- '{export,"$(call core_native_path,$(abspath $(COVER_DATA_DIR))/ct.coverdata)"}.' > $@
7010
'{export,"$(abspath $(COVER_DATA_DIR))/ct.coverdata"}.' > $@
7808
7011
7809
7012
CT_RUN = -cover $(TEST_DIR)/ct.cover.spec
7810
7013
endif
7811
7014
endif
7812
7015
endif
7813
7016
7814
- # Code coverage for other tools.
7815
-
7816
- ifdef COVER
7817
- define cover.erl
7818
- CoverSetup = fun() ->
7819
- Dirs = ["$(call core_native_path,$(CURDIR)/ebin)"
7820
- $(foreach a,$(COVER_APPS),$(comma) "$(call core_native_path,$(APPS_DIR)/$a/ebin)")
7821
- $(foreach d,$(COVER_DEPS),$(comma) "$(call core_native_path,$(DEPS_DIR)/$d/ebin)")],
7822
- [begin
7823
- case filelib:is_dir(Dir) of
7824
- false -> false;
7825
- true ->
7826
- case cover:compile_beam_directory(Dir) of
7827
- {error, _} -> halt(1);
7828
- _ -> true
7829
- end
7830
- end
7831
- end || Dir <- Dirs]
7832
- end,
7833
- CoverExport = fun(Filename) -> cover:export(Filename) end,
7834
- endef
7835
- else
7836
- define cover.erl
7837
- CoverSetup = fun() -> ok end,
7838
- CoverExport = fun(_) -> ok end,
7839
- endef
7840
- endif
7841
-
7842
7017
# Core targets
7843
7018
7844
7019
ifdef COVER
 
@@ -7898,9 7073,7 @@ ifneq ($(COVER_REPORT_DIR),)
7898
7073
7899
7074
cover-report-clean:
7900
7075
$(gen_verbose) rm -rf $(COVER_REPORT_DIR)
7901
- ifneq ($(COVER_REPORT_DIR),$(COVER_DATA_DIR))
7902
7076
$(if $(shell ls -A $(COVER_DATA_DIR)/),,$(verbose) rmdir $(COVER_DATA_DIR))
7903
- endif
7904
7077
7905
7078
ifeq ($(COVERDATA),)
7906
7079
cover-report:
 
@@ -7990,7 7163,7 @@ __ARCHIVE_BELOW__
7990
7163
endef
7991
7164
7992
7165
sfx:
7993
- $(verbose) $(call core_render,sfx_stub,$(SFX_OUTPUT_FILE))
7166
$(call render_template,sfx_stub,$(SFX_OUTPUT_FILE))
7994
7167
$(gen_verbose) cat $(SFX_ARCHIVE) >> $(SFX_OUTPUT_FILE)
7995
7168
$(verbose) chmod x $(SFX_OUTPUT_FILE)
7996
7169
 
@@ -8009,11 7182,6 @@ $(foreach p,$(DEP_PLUGINS),\
8009
7182
$(call core_dep_plugin,$p,$(firstword $(subst /, ,$p))),\
8010
7183
$(call core_dep_plugin,$p/plugins.mk,$p))))
8011
7184
8012
- help:: help-plugins
8013
-
8014
- help-plugins::
8015
- $(verbose) :
8016
-
8017
7185
# Copyright (c) 2013-2015, Loïc Hoguin <[email protected]>
8018
7186
# Copyright (c) 2015-2016, Jean-Sébastien Pédron <[email protected]>
8019
7187
# This file is part of erlang.mk and subject to the terms of the ISC License.
 
@@ -8048,11 7216,11 @@ else
8048
7216
#
8049
7217
# $(ALL_DEPS_DIRS) includes $(BUILD_DEPS).
8050
7218
8051
- $(ERLANG_MK_RECURSIVE_DEPS_LIST): $(LOCAL_DEPS_DIRS) $(ALL_DEPS_DIRS)
8052
- $(ERLANG_MK_RECURSIVE_DOC_DEPS_LIST): $(LOCAL_DEPS_DIRS) $(ALL_DEPS_DIRS) $(ALL_DOC_DEPS_DIRS)
8053
- $(ERLANG_MK_RECURSIVE_REL_DEPS_LIST): $(LOCAL_DEPS_DIRS) $(ALL_DEPS_DIRS) $(ALL_REL_DEPS_DIRS)
8054
- $(ERLANG_MK_RECURSIVE_TEST_DEPS_LIST): $(LOCAL_DEPS_DIRS) $(ALL_DEPS_DIRS) $(ALL_TEST_DEPS_DIRS)
8055
- $(ERLANG_MK_RECURSIVE_SHELL_DEPS_LIST): $(LOCAL_DEPS_DIRS) $(ALL_DEPS_DIRS) $(ALL_SHELL_DEPS_DIRS)
7219
$(ERLANG_MK_RECURSIVE_DEPS_LIST): $(ALL_DEPS_DIRS)
7220
$(ERLANG_MK_RECURSIVE_DOC_DEPS_LIST): $(ALL_DEPS_DIRS) $(ALL_DOC_DEPS_DIRS)
7221
$(ERLANG_MK_RECURSIVE_REL_DEPS_LIST): $(ALL_DEPS_DIRS) $(ALL_REL_DEPS_DIRS)
7222
$(ERLANG_MK_RECURSIVE_TEST_DEPS_LIST): $(ALL_DEPS_DIRS) $(ALL_TEST_DEPS_DIRS)
7223
$(ERLANG_MK_RECURSIVE_SHELL_DEPS_LIST): $(ALL_DEPS_DIRS) $(ALL_SHELL_DEPS_DIRS)
8056
7224
8057
7225
# Allow to use fetch-deps and $(DEP_TYPES) to fetch multiple types of
8058
7226
# dependencies with a single target.
 
@@ -8069,17 7237,24 @@ ifneq ($(filter shell,$(DEP_TYPES)),)
8069
7237
$(ERLANG_MK_RECURSIVE_DEPS_LIST): $(ALL_SHELL_DEPS_DIRS)
8070
7238
endif
8071
7239
8072
- ERLANG_MK_RECURSIVE_TMP_LIST := $(abspath $(ERLANG_MK_TMP)/recursive-tmp-deps-$(shell echo $$PPID).log)
7240
ERLANG_MK_RECURSIVE_TMP_LIST := $(abspath $(ERLANG_MK_TMP)/recursive-tmp-deps.log)
8073
7241
8074
7242
$(ERLANG_MK_RECURSIVE_DEPS_LIST) \
8075
7243
$(ERLANG_MK_RECURSIVE_DOC_DEPS_LIST) \
8076
7244
$(ERLANG_MK_RECURSIVE_REL_DEPS_LIST) \
8077
7245
$(ERLANG_MK_RECURSIVE_TEST_DEPS_LIST) \
8078
- $(ERLANG_MK_RECURSIVE_SHELL_DEPS_LIST): | $(ERLANG_MK_TMP)
7246
$(ERLANG_MK_RECURSIVE_SHELL_DEPS_LIST):
8079
7247
ifeq ($(IS_APP)$(IS_DEP),)
7248
$(verbose) mkdir -p $(ERLANG_MK_TMP)
8080
7249
$(verbose) rm -f $(ERLANG_MK_RECURSIVE_TMP_LIST)
8081
7250
endif
8082
- $(verbose) touch $(ERLANG_MK_RECURSIVE_TMP_LIST)
7251
ifndef IS_APP
7252
$(verbose) set -e; for dep in $(ALL_APPS_DIRS) ; do \
7253
$(MAKE) -C $$dep $@ \
7254
IS_APP=1 \
7255
ERLANG_MK_RECURSIVE_TMP_LIST=$(ERLANG_MK_RECURSIVE_TMP_LIST); \
7256
done
7257
endif
8083
7258
$(verbose) set -e; for dep in $^ ; do \
8084
7259
if ! grep -qs ^$$dep$$ $(ERLANG_MK_RECURSIVE_TMP_LIST); then \
8085
7260
echo $$dep >> $(ERLANG_MK_RECURSIVE_TMP_LIST); \
 
@@ -8092,11 7267,7 @@ endif
8092
7267
fi \
8093
7268
done
8094
7269
ifeq ($(IS_APP)$(IS_DEP),)
8095
- $(verbose) sort < $(ERLANG_MK_RECURSIVE_TMP_LIST) | \
8096
- uniq > $(ERLANG_MK_RECURSIVE_TMP_LIST).sorted
8097
- $(verbose) cmp -s $(ERLANG_MK_RECURSIVE_TMP_LIST).sorted $@ \
8098
- || mv $(ERLANG_MK_RECURSIVE_TMP_LIST).sorted $@
8099
- $(verbose) rm -f $(ERLANG_MK_RECURSIVE_TMP_LIST).sorted
7270
$(verbose) sort < $(ERLANG_MK_RECURSIVE_TMP_LIST) | uniq > $@
8100
7271
$(verbose) rm $(ERLANG_MK_RECURSIVE_TMP_LIST)
8101
7272
endif
8102
7273
endif # ifneq ($(SKIP_DEPS),)
 
@@ -8114,43 7285,3 @@ list-shell-deps: $(ERLANG_MK_RECURSIVE_SHELL_DEPS_LIST)
8114
7285
8115
7286
list-deps list-doc-deps list-rel-deps list-test-deps list-shell-deps:
8116
7287
$(verbose) cat $^
8117
-
8118
- # Query dependencies recursively.
8119
-
8120
- .PHONY: query-deps query-doc-deps query-rel-deps query-test-deps \
8121
- query-shell-deps
8122
-
8123
- QUERY ?= name fetch_method repo version
8124
-
8125
- define query_target
8126
- $(1): $(2) clean-tmp-query.log
8127
- ifeq ($(IS_APP)$(IS_DEP),)
8128
- $(verbose) rm -f $(4)
8129
- endif
8130
- $(verbose) $(foreach dep,$(3),\
8131
- echo $(PROJECT): $(foreach q,$(QUERY),$(call query_$(q),$(dep))) >> $(4) ;)
8132
- $(if $(filter-out query-deps,$(1)),,\
8133
- $(verbose) set -e; for dep in $(3) ; do \
8134
- if grep -qs ^$$$$dep$$$$ $(ERLANG_MK_TMP)/query.log; then \
8135
- :; \
8136
- else \
8137
- echo $$$$dep >> $(ERLANG_MK_TMP)/query.log; \
8138
- $(MAKE) -C $(DEPS_DIR)/$$$$dep $$@ QUERY="$(QUERY)" IS_DEP=1 || true; \
8139
- fi \
8140
- done)
8141
- ifeq ($(IS_APP)$(IS_DEP),)
8142
- $(verbose) touch $(4)
8143
- $(verbose) cat $(4)
8144
- endif
8145
- endef
8146
-
8147
- clean-tmp-query.log:
8148
- ifeq ($(IS_DEP),)
8149
- $(verbose) rm -f $(ERLANG_MK_TMP)/query.log
8150
- endif
8151
-
8152
- $(eval $(call query_target,query-deps,$(ERLANG_MK_RECURSIVE_DEPS_LIST),$(BUILD_DEPS) $(DEPS),$(ERLANG_MK_QUERY_DEPS_FILE)))
8153
- $(eval $(call query_target,query-doc-deps,$(ERLANG_MK_RECURSIVE_DOC_DEPS_LIST),$(DOC_DEPS),$(ERLANG_MK_QUERY_DOC_DEPS_FILE)))
8154
- $(eval $(call query_target,query-rel-deps,$(ERLANG_MK_RECURSIVE_REL_DEPS_LIST),$(REL_DEPS),$(ERLANG_MK_QUERY_REL_DEPS_FILE)))
8155
- $(eval $(call query_target,query-test-deps,$(ERLANG_MK_RECURSIVE_TEST_DEPS_LIST),$(TEST_DEPS),$(ERLANG_MK_QUERY_TEST_DEPS_FILE)))
8156
- $(eval $(call query_target,query-shell-deps,$(ERLANG_MK_RECURSIVE_SHELL_DEPS_LIST),$(SHELL_DEPS),$(ERLANG_MK_QUERY_SHELL_DEPS_FILE)))
changed hex_metadata.config
 
@@ -1,22 1,19 @@
1
1
{<<"app">>,<<"ranch">>}.
2
- {<<"build_tools">>,[<<"make">>,<<"rebar3">>]}.
2
{<<"build_tools">>,[<<"rebar3">>]}.
3
3
{<<"description">>,<<"Socket acceptor pool for TCP protocols.">>}.
4
4
{<<"files">>,
5
- [<<"ebin/ranch.app">>,<<"erlang.mk">>,<<"LICENSE">>,<<"Makefile">>,
6
- <<"README.asciidoc">>,<<"src/ranch.erl">>,<<"src/ranch_acceptor.erl">>,
7
- <<"src/ranch_acceptors_sup.erl">>,<<"src/ranch_app.erl">>,
8
- <<"src/ranch_conns_sup.erl">>,<<"src/ranch_crc32c.erl">>,
9
- <<"src/ranch_listener_sup.erl">>,<<"src/ranch_protocol.erl">>,
10
- <<"src/ranch_proxy_header.erl">>,<<"src/ranch_server.erl">>,
11
- <<"src/ranch_ssl.erl">>,<<"src/ranch_sup.erl">>,<<"src/ranch_tcp.erl">>,
12
- <<"src/ranch_transport.erl">>]}.
5
[<<"erlang.mk">>,<<"LICENSE">>,<<"Makefile">>,<<"README.asciidoc">>,
6
<<"src">>,<<"src/ranch.app.src">>,<<"src/ranch_proxy_header.erl">>,
7
<<"src/ranch_server.erl">>,<<"src/ranch_tcp.erl">>,<<"src/ranch_app.erl">>,
8
<<"src/ranch_ssl.erl">>,<<"src/ranch_conns_sup_sup.erl">>,
9
<<"src/ranch_listener_sup.erl">>,<<"src/ranch_crc32c.erl">>,
10
<<"src/ranch_acceptors_sup.erl">>,<<"src/ranch_server_proxy.erl">>,
11
<<"src/ranch.erl">>,<<"src/ranch_embedded_sup.erl">>,
12
<<"src/ranch_conns_sup.erl">>,<<"src/ranch_sup.erl">>,
13
<<"src/ranch_transport.erl">>,<<"src/ranch_acceptor.erl">>,
14
<<"src/ranch_protocol.erl">>]}.
13
15
{<<"licenses">>,[<<"ISC">>]}.
14
- {<<"links">>,
15
- [{<<"Function reference">>,
16
- <<"https://ninenines.eu/docs/en/ranch/1.8/manual/">>},
17
- {<<"GitHub">>,<<"https://github.com/ninenines/ranch">>},
18
- {<<"Sponsor">>,<<"https://github.com/sponsors/essen">>},
19
- {<<"User guide">>,<<"https://ninenines.eu/docs/en/ranch/1.8/guide/">>}]}.
16
{<<"links">>,[{<<"GitHub">>,<<"https://github.com/ninenines/ranch">>}]}.
20
17
{<<"name">>,<<"ranch">>}.
21
18
{<<"requirements">>,[]}.
22
- {<<"version">>,<<"1.8.0">>}.
19
{<<"version">>,<<"2.0.0-rc.1">>}.
added src/ranch.app.src
 
@@ -0,0 1,9 @@
1
{application, 'ranch', [
2
{description, "Socket acceptor pool for TCP protocols."},
3
{vsn, "2.0.0-rc.1"},
4
{modules, ['ranch','ranch_acceptor','ranch_acceptors_sup','ranch_app','ranch_conns_sup','ranch_conns_sup_sup','ranch_crc32c','ranch_embedded_sup','ranch_listener_sup','ranch_protocol','ranch_proxy_header','ranch_server','ranch_server_proxy','ranch_ssl','ranch_sup','ranch_tcp','ranch_transport']},
5
{registered, [ranch_sup,ranch_server]},
6
{applications, [kernel,stdlib,ssl]},
7
{mod, {ranch_app, []}},
8
{env, []}
9
]}.
\ No newline at end of file
changed src/ranch.erl
 
@@ -15,14 15,11 @@
15
15
-module(ranch).
16
16
17
17
-export([start_listener/5]).
18
- -export([start_listener/6]).
19
18
-export([normalize_opts/1]).
20
19
-export([stop_listener/1]).
21
20
-export([suspend_listener/1]).
22
21
-export([resume_listener/1]).
23
22
-export([child_spec/5]).
24
- -export([child_spec/6]).
25
- -export([accept_ack/1]).
26
23
-export([handshake/1]).
27
24
-export([handshake/2]).
28
25
-export([recv_proxy_header/2]).
 
@@ -41,36 38,29 @@
41
38
-export([procs/2]).
42
39
-export([wait_for_connections/3]).
43
40
-export([wait_for_connections/4]).
44
- -export([filter_options/3]).
41
-export([filter_options/4]).
45
42
-export([set_option_default/3]).
46
43
-export([require/1]).
47
44
-export([log/4]).
48
45
49
- -deprecated([start_listener/6, child_spec/6, accept_ack/1]).
50
-
51
46
-type max_conns() :: non_neg_integer() | infinity.
52
47
-export_type([max_conns/0]).
53
48
54
- %% This type is deprecated and will be removed in Ranch 2.0.
55
- -type opt() :: {ack_timeout, timeout()}
56
- | {connection_type, worker | supervisor}
57
- | {max_connections, max_conns()}
58
- | {num_acceptors, pos_integer()}
59
- | {shutdown, timeout() | brutal_kill}
60
- | {socket, any()}.
61
- -export_type([opt/0]).
49
-type opts() :: any() | transport_opts(any()).
50
-export_type([opts/0]).
62
51
63
- -type opts() :: any() | #{
52
-type transport_opts(SocketOpts) :: #{
64
53
connection_type => worker | supervisor,
65
54
handshake_timeout => timeout(),
66
55
max_connections => max_conns(),
67
56
logger => module(),
68
57
num_acceptors => pos_integer(),
58
num_conns_sups => pos_integer(),
59
num_listen_sockets => pos_integer(),
69
60
shutdown => timeout() | brutal_kill,
70
- socket => any(),
71
- socket_opts => any()
61
socket_opts => SocketOpts
72
62
}.
73
- -export_type([opts/0]).
63
-export_type([transport_opts/1]).
74
64
75
65
-type ref() :: any().
76
66
-export_type([ref/0]).
 
@@ -81,83 71,70 @@ start_listener(Ref, Transport, TransOpts0, Protocol, ProtoOpts)
81
71
when is_atom(Transport), is_atom(Protocol) ->
82
72
TransOpts = normalize_opts(TransOpts0),
83
73
_ = code:ensure_loaded(Transport),
84
- case erlang:function_exported(Transport, name, 0) of
85
- false ->
86
- {error, badarg};
87
- true ->
88
- Res = supervisor:start_child(ranch_sup, child_spec(Ref,
89
- Transport, TransOpts, Protocol, ProtoOpts)),
90
- Socket = maps:get(socket, TransOpts, undefined),
91
- case Res of
92
- {ok, Pid} when Socket =/= undefined ->
93
- %% Give ownership of the socket to ranch_acceptors_sup
94
- %% to make sure the socket stays open as long as the
95
- %% listener is alive. If the socket closes however there
96
- %% will be no way to recover because we don't know how
97
- %% to open it again.
98
- Children = supervisor:which_children(Pid),
99
- {_, AcceptorsSup, _, _}
100
- = lists:keyfind(ranch_acceptors_sup, 1, Children),
101
- Transport:controlling_process(Socket, AcceptorsSup);
102
- _ ->
103
- ok
104
- end,
105
- maybe_started(Res)
74
case {erlang:function_exported(Transport, name, 0), validate_transport_opts(TransOpts)} of
75
{true, ok} ->
76
ChildSpec = #{id => {ranch_listener_sup, Ref}, start => {ranch_listener_sup, start_link, [
77
Ref, Transport, TransOpts, Protocol, ProtoOpts
78
]}, type => supervisor},
79
maybe_started(supervisor:start_child(ranch_sup, ChildSpec));
80
{false, _} ->
81
{error, {bad_transport, Transport}};
82
{_, TransOptsError} ->
83
TransOptsError
106
84
end.
107
85
108
- -spec start_listener(ref(), non_neg_integer(), module(), opts(), module(), any())
109
- -> supervisor:startchild_ret().
110
- start_listener(Ref, NumAcceptors, Transport, TransOpts0, Protocol, ProtoOpts)
111
- when is_integer(NumAcceptors), is_atom(Transport), is_atom(Protocol) ->
112
- TransOpts = normalize_opts(TransOpts0),
113
- start_listener(Ref, Transport, TransOpts#{num_acceptors => NumAcceptors},
114
- Protocol, ProtoOpts).
115
-
116
- -spec normalize_opts(opts()) -> opts().
86
-spec normalize_opts(opts()) -> transport_opts(any()).
117
87
normalize_opts(Map) when is_map(Map) ->
118
88
Map;
119
- normalize_opts(List0) when is_list(List0) ->
120
- Map0 = #{},
121
- {Map1, List1} = case take(ack_timeout, List0) of
122
- {value, HandshakeTimeout, Tail0} ->
123
- {Map0#{handshake_timeout => HandshakeTimeout}, Tail0};
124
- false ->
125
- {Map0, List0}
126
- end,
127
- {Map, List} = lists:foldl(fun(Key, {Map2, List2}) ->
128
- case take(Key, List2) of
129
- {value, ConnectionType, Tail2} ->
130
- {Map2#{Key => ConnectionType}, Tail2};
131
- false ->
132
- {Map2, List2}
133
- end
134
- end, {Map1, List1}, [connection_type, max_connections, num_acceptors, shutdown, socket]),
135
- if
136
- Map =:= #{} ->
137
- ok;
138
- true ->
139
- log(warning,
140
- "Setting Ranch options together with socket options "
141
- "is deprecated. Please use the new map syntax that allows "
142
- "specifying socket options separately from other options.~n",
143
- [], Map)
144
- end,
145
- case List of
146
- [] -> Map;
147
- _ -> Map#{socket_opts => List}
148
- end;
149
89
normalize_opts(Any) ->
150
90
#{socket_opts => Any}.
151
91
152
- take(Key, List) ->
153
- take(Key, List, []).
92
-spec validate_transport_opts(transport_opts(any())) -> ok | {error, any()}.
93
validate_transport_opts(Opts) ->
94
maps:fold(fun
95
(Key, Value, ok) ->
96
case validate_transport_opt(Key, Value, Opts) of
97
true ->
98
ok;
99
false ->
100
{error, {bad_option, Key}}
101
end;
102
(_, _, Acc) ->
103
Acc
104
end, ok, Opts).
154
105
155
- take(_, [], _) ->
156
- false;
157
- take(Key, [{Key, Value}|Tail], Acc) ->
158
- {value, Value, lists:reverse(Acc, Tail)};
159
- take(Key, [Value|Tail], Acc) ->
160
- take(Key, Tail, [Value|Acc]).
106
-spec validate_transport_opt(any(), any(), transport_opts(any())) -> boolean().
107
validate_transport_opt(connection_type, worker, _) ->
108
true;
109
validate_transport_opt(connection_type, supervisor, _) ->
110
true;
111
validate_transport_opt(handshake_timeout, infinity, _) ->
112
true;
113
validate_transport_opt(handshake_timeout, Value, _) ->
114
is_integer(Value) andalso Value >= 0;
115
validate_transport_opt(max_connections, infinity, _) ->
116
true;
117
validate_transport_opt(max_connections, Value, _) ->
118
is_integer(Value) andalso Value >= 0;
119
validate_transport_opt(logger, Value, _) ->
120
is_atom(Value);
121
validate_transport_opt(num_acceptors, Value, _) ->
122
is_integer(Value) andalso Value > 0;
123
validate_transport_opt(num_conns_sups, Value, _) ->
124
is_integer(Value) andalso Value > 0;
125
validate_transport_opt(num_listen_sockets, Value, Opts) ->
126
is_integer(Value) andalso Value > 0
127
andalso Value =< maps:get(num_acceptors, Opts, 10);
128
validate_transport_opt(shutdown, brutal_kill, _) ->
129
true;
130
validate_transport_opt(shutdown, infinity, _) ->
131
true;
132
validate_transport_opt(shutdown, Value, _) ->
133
is_integer(Value) andalso Value >= 0;
134
validate_transport_opt(socket_opts, _, _) ->
135
true;
136
validate_transport_opt(_, _, _) ->
137
false.
161
138
162
139
maybe_started({error, {{shutdown,
163
140
{failed_to_start_child, ranch_acceptors_sup,
 
@@ -216,22 193,9 @@ maybe_resumed(Res) ->
216
193
-> supervisor:child_spec().
217
194
child_spec(Ref, Transport, TransOpts0, Protocol, ProtoOpts) ->
218
195
TransOpts = normalize_opts(TransOpts0),
219
- {{ranch_listener_sup, Ref}, {ranch_listener_sup, start_link, [
196
#{id => {ranch_embedded_sup, Ref}, start => {ranch_embedded_sup, start_link, [
220
197
Ref, Transport, TransOpts, Protocol, ProtoOpts
221
- ]}, permanent, infinity, supervisor, [ranch_listener_sup]}.
222
-
223
- -spec child_spec(ref(), non_neg_integer(), module(), opts(), module(), any())
224
- -> supervisor:child_spec().
225
- child_spec(Ref, NumAcceptors, Transport, TransOpts0, Protocol, ProtoOpts)
226
- when is_integer(NumAcceptors), is_atom(Transport), is_atom(Protocol) ->
227
- TransOpts = normalize_opts(TransOpts0),
228
- child_spec(Ref, Transport, TransOpts#{num_acceptors => NumAcceptors},
229
- Protocol, ProtoOpts).
230
-
231
- -spec accept_ack(ref()) -> ok.
232
- accept_ack(Ref) ->
233
- {ok, _} = handshake(Ref),
234
- ok.
198
]}, type => supervisor}.
235
199
236
200
-spec handshake(ref()) -> {ok, ranch_transport:socket()}.
237
201
handshake(Ref) ->
 
@@ -273,8 237,11 @@ recv_proxy_header(Ref, Timeout) ->
273
237
274
238
-spec remove_connection(ref()) -> ok.
275
239
remove_connection(Ref) ->
276
- ConnsSup = ranch_server:get_connections_sup(Ref),
277
- ConnsSup ! {remove_connection, Ref, self()},
240
ListenerSup = ranch_server:get_listener_sup(Ref),
241
{_, ConnsSupSup, _, _} = lists:keyfind(ranch_conns_sup_sup, 1,
242
supervisor:which_children(ListenerSup)),
243
_ = [ConnsSup ! {remove_connection, Ref, self()} ||
244
{_, ConnsSup, _, _} <- supervisor:which_children(ConnsSupSup)],
278
245
ok.
279
246
280
247
-spec get_status(ref()) -> running | suspended.
 
@@ -288,14 255,29 @@ get_status(Ref) ->
288
255
running
289
256
end.
290
257
291
- -spec get_addr(ref()) -> {inet:ip_address(), inet:port_number()} | {undefined, undefined}.
258
-spec get_addr(ref()) -> {inet:ip_address(), inet:port_number()} |
259
{local, binary()} | {undefined, undefined}.
292
260
get_addr(Ref) ->
293
261
ranch_server:get_addr(Ref).
294
262
295
263
-spec get_port(ref()) -> inet:port_number() | undefined.
296
264
get_port(Ref) ->
297
- {_, Port} = get_addr(Ref),
298
- Port.
265
case get_addr(Ref) of
266
{local, _} ->
267
undefined;
268
{_, Port} ->
269
Port
270
end.
271
272
-spec get_connections(ref(), active|all) -> non_neg_integer().
273
get_connections(Ref, active) ->
274
SupCounts = [ranch_conns_sup:active_connections(ConnsSup) ||
275
{_, ConnsSup} <- ranch_server:get_connections_sups(Ref)],
276
lists:sum(SupCounts);
277
get_connections(Ref, all) ->
278
SupCounts = [proplists:get_value(active, supervisor:count_children(ConnsSup)) ||
279
{_, ConnsSup} <- ranch_server:get_connections_sups(Ref)],
280
lists:sum(SupCounts).
299
281
300
282
-spec get_max_connections(ref()) -> max_conns().
301
283
get_max_connections(Ref) ->
 
@@ -305,21 287,27 @@ get_max_connections(Ref) ->
305
287
set_max_connections(Ref, MaxConnections) ->
306
288
ranch_server:set_max_connections(Ref, MaxConnections).
307
289
308
- -spec get_transport_options(ref()) -> any().
290
-spec get_transport_options(ref()) -> transport_opts(any()).
309
291
get_transport_options(Ref) ->
310
292
ranch_server:get_transport_options(Ref).
311
293
312
- -spec set_transport_options(ref(), opts()) -> ok | {error, running}.
294
-spec set_transport_options(ref(), opts()) -> ok | {error, term()}.
313
295
set_transport_options(Ref, TransOpts0) ->
314
296
TransOpts = normalize_opts(TransOpts0),
315
- case get_status(Ref) of
316
- suspended ->
317
- ok = ranch_server:set_transport_options(Ref, TransOpts);
318
- running ->
319
- {error, running}
297
case validate_transport_opts(TransOpts) of
298
ok ->
299
ok = ranch_server:set_transport_options(Ref, TransOpts),
300
ok = apply_transport_options(Ref, TransOpts);
301
TransOptsError ->
302
TransOptsError
320
303
end.
321
304
322
- -spec get_protocol_options(ref()) -> opts().
305
apply_transport_options(Ref, TransOpts) ->
306
_ = [ConnsSup ! {set_transport_options, TransOpts}
307
|| {_, ConnsSup} <- ranch_server:get_connections_sups(Ref)],
308
ok.
309
310
-spec get_protocol_options(ref()) -> any().
323
311
get_protocol_options(Ref) ->
324
312
ranch_server:get_protocol_options(Ref).
325
313
 
@@ -327,53 315,70 @@ get_protocol_options(Ref) ->
327
315
set_protocol_options(Ref, Opts) ->
328
316
ranch_server:set_protocol_options(Ref, Opts).
329
317
330
- -spec info() -> [{any(), [{atom(), any()}]}].
318
-spec info() -> #{ref() := #{atom() := term()}}.
331
319
info() ->
332
- [{Ref, listener_info(Ref, Pid)}
333
- || {Ref, Pid} <- ranch_server:get_listener_sups()].
320
lists:foldl(
321
fun ({Ref, Pid}, Acc) ->
322
Acc#{Ref => listener_info(Ref, Pid)}
323
end,
324
#{},
325
ranch_server:get_listener_sups()
326
).
334
327
335
- -spec info(ref()) -> [{atom(), any()}].
328
-spec info(ref()) -> #{atom() := term()}.
336
329
info(Ref) ->
337
330
Pid = ranch_server:get_listener_sup(Ref),
338
331
listener_info(Ref, Pid).
339
332
340
333
listener_info(Ref, Pid) ->
341
334
[_, Transport, _, Protocol, _] = ranch_server:get_listener_start_args(Ref),
342
- ConnsSup = ranch_server:get_connections_sup(Ref),
343
335
Status = get_status(Ref),
344
- {IP, Port} = get_addr(Ref),
336
{IP, Port} = case get_addr(Ref) of
337
Addr = {local, _} ->
338
{Addr, undefined};
339
Addr ->
340
Addr
341
end,
345
342
MaxConns = get_max_connections(Ref),
346
343
TransOpts = ranch_server:get_transport_options(Ref),
347
344
ProtoOpts = get_protocol_options(Ref),
348
- [
349
- {pid, Pid},
350
- {status, Status},
351
- {ip, IP},
352
- {port, Port},
353
- {max_connections, MaxConns},
354
- {active_connections, ranch_conns_sup:active_connections(ConnsSup)},
355
- {all_connections, proplists:get_value(active, supervisor:count_children(ConnsSup))},
356
- {transport, Transport},
357
- {transport_options, TransOpts},
358
- {protocol, Protocol},
359
- {protocol_options, ProtoOpts}
360
- ].
345
#{
346
pid => Pid,
347
status => Status,
348
ip => IP,
349
port => Port,
350
max_connections => MaxConns,
351
active_connections => get_connections(Ref, active),
352
all_connections => get_connections(Ref, all),
353
transport => Transport,
354
transport_options => TransOpts,
355
protocol => Protocol,
356
protocol_options => ProtoOpts
357
}.
361
358
362
359
-spec procs(ref(), acceptors | connections) -> [pid()].
363
- procs(Ref, acceptors) ->
364
- procs1(Ref, ranch_acceptors_sup);
365
- procs(Ref, connections) ->
366
- procs1(Ref, ranch_conns_sup).
367
-
368
- procs1(Ref, Sup) ->
360
procs(Ref, Type) ->
369
361
ListenerSup = ranch_server:get_listener_sup(Ref),
370
- {_, SupPid, _, _} = lists:keyfind(Sup, 1,
362
procs1(ListenerSup, Type).
363
364
procs1(ListenerSup, acceptors) ->
365
{_, SupPid, _, _} = lists:keyfind(ranch_acceptors_sup, 1,
371
366
supervisor:which_children(ListenerSup)),
372
367
try
373
368
[Pid || {_, Pid, _, _} <- supervisor:which_children(SupPid)]
374
- catch exit:{noproc, _} when Sup =:= ranch_acceptors_sup ->
369
catch exit:{noproc, _} ->
375
370
[]
376
- end.
371
end;
372
procs1(ListenerSup, connections) ->
373
{_, SupSupPid, _, _} = lists:keyfind(ranch_conns_sup_sup, 1,
374
supervisor:which_children(ListenerSup)),
375
Conns=
376
lists:map(fun ({_, SupPid, _, _}) ->
377
[Pid || {_, Pid, _, _} <- supervisor:which_children(SupPid)]
378
end,
379
supervisor:which_children(SupSupPid)
380
),
381
lists:flatten(Conns).
377
382
378
383
-spec wait_for_connections
379
384
(ref(), '>' | '>=' | '==' | '=<', non_neg_integer()) -> ok;
 
@@ -405,8 410,7 @@ validate_interval(_) -> error(badarg).
405
410
406
411
wait_for_connections_loop(Ref, Op, NumConns, Interval) ->
407
412
CurConns = try
408
- ConnsSup = ranch_server:get_connections_sup(Ref),
409
- proplists:get_value(active, supervisor:count_children(ConnsSup))
413
get_connections(Ref, all)
410
414
catch _:_ ->
411
415
0
412
416
end,
 
@@ -421,38 425,34 @@ wait_for_connections_loop(Ref, Op, NumConns, Interval) ->
421
425
end.
422
426
423
427
-spec filter_options([inet | inet6 | {atom(), any()} | {raw, any(), any(), any()}],
424
- [atom()], Acc) -> Acc when Acc :: [any()].
425
- filter_options(UserOptions, DisallowedKeys, DefaultOptions) ->
426
- AllowedOptions = filter_user_options(UserOptions, DisallowedKeys),
428
[atom()], Acc, module()) -> Acc when Acc :: [any()].
429
filter_options(UserOptions, DisallowedKeys, DefaultOptions, Logger) ->
430
AllowedOptions = filter_user_options(UserOptions, DisallowedKeys, Logger),
427
431
lists:foldl(fun merge_options/2, DefaultOptions, AllowedOptions).
428
432
429
433
%% 2-tuple options.
430
- filter_user_options([Opt = {Key, _}|Tail], DisallowedKeys) ->
434
filter_user_options([Opt = {Key, _}|Tail], DisallowedKeys, Logger) ->
431
435
case lists:member(Key, DisallowedKeys) of
432
436
false ->
433
- [Opt|filter_user_options(Tail, DisallowedKeys)];
437
[Opt|filter_user_options(Tail, DisallowedKeys, Logger)];
434
438
true ->
435
- filter_options_warning(Opt),
436
- filter_user_options(Tail, DisallowedKeys)
439
filter_options_warning(Opt, Logger),
440
filter_user_options(Tail, DisallowedKeys, Logger)
437
441
end;
438
442
%% Special option forms.
439
- filter_user_options([inet|Tail], DisallowedKeys) ->
440
- [inet|filter_user_options(Tail, DisallowedKeys)];
441
- filter_user_options([inet6|Tail], DisallowedKeys) ->
442
- [inet6|filter_user_options(Tail, DisallowedKeys)];
443
- filter_user_options([Opt = {raw, _, _, _}|Tail], DisallowedKeys) ->
444
- [Opt|filter_user_options(Tail, DisallowedKeys)];
445
- filter_user_options([Opt|Tail], DisallowedKeys) ->
446
- filter_options_warning(Opt),
447
- filter_user_options(Tail, DisallowedKeys);
448
- filter_user_options([], _) ->
443
filter_user_options([inet|Tail], DisallowedKeys, Logger) ->
444
[inet|filter_user_options(Tail, DisallowedKeys, Logger)];
445
filter_user_options([inet6|Tail], DisallowedKeys, Logger) ->
446
[inet6|filter_user_options(Tail, DisallowedKeys, Logger)];
447
filter_user_options([Opt = {raw, _, _, _}|Tail], DisallowedKeys, Logger) ->
448
[Opt|filter_user_options(Tail, DisallowedKeys, Logger)];
449
filter_user_options([Opt|Tail], DisallowedKeys, Logger) ->
450
filter_options_warning(Opt, Logger),
451
filter_user_options(Tail, DisallowedKeys, Logger);
452
filter_user_options([], _, _) ->
449
453
[].
450
454
451
- filter_options_warning(Opt) ->
452
- Logger = case get(logger) of
453
- undefined -> error_logger;
454
- Logger0 -> Logger0
455
- end,
455
filter_options_warning(Opt, Logger) ->
456
456
log(warning,
457
457
"Transport option ~p unknown or invalid.~n",
458
458
[Opt], Logger).
 
@@ -487,9 487,8 @@ log(Level, Format, Args, #{logger := Logger})
487
487
when Logger =/= error_logger ->
488
488
_ = Logger:Level(Format, Args),
489
489
ok;
490
- %% We use error_logger by default. Because error_logger does
491
- %% not have all the levels we accept we have to do some
492
- %% mapping to error_logger functions.
490
%% Because error_logger does not have all the levels
491
%% we accept we have to do some mapping to error_logger functions.
493
492
log(Level, Format, Args, _) ->
494
493
Function = case Level of
495
494
emergency -> error_msg;
changed src/ranch_acceptor.erl
 
@@ -14,24 14,32 @@
14
14
15
15
-module(ranch_acceptor).
16
16
17
- -export([start_link/4]).
18
- -export([loop/4]).
17
-export([start_link/5]).
18
-export([init/4]).
19
-export([loop/5]).
19
20
20
- -spec start_link(inet:socket(), module(), module(), pid())
21
-spec start_link(ranch:ref(), pos_integer(), inet:socket(), module(), module())
21
22
-> {ok, pid()}.
22
- start_link(LSocket, Transport, Logger, ConnsSup) ->
23
- Pid = spawn_link(?MODULE, loop, [LSocket, Transport, Logger, ConnsSup]),
23
start_link(Ref, AcceptorId, LSocket, Transport, Logger) ->
24
ConnsSup = ranch_server:get_connections_sup(Ref, AcceptorId),
25
Pid = spawn_link(?MODULE, init, [LSocket, Transport, Logger, ConnsSup]),
24
26
{ok, Pid}.
25
27
26
- -spec loop(inet:socket(), module(), module(), pid()) -> no_return().
27
- loop(LSocket, Transport, Logger, ConnsSup) ->
28
-spec init(inet:socket(), module(), module(), pid()) -> no_return().
29
init(LSocket, Transport, Logger, ConnsSup) ->
30
MonitorRef = monitor(process, ConnsSup),
31
loop(LSocket, Transport, Logger, ConnsSup, MonitorRef).
32
33
-spec loop(inet:socket(), module(), module(), pid(), reference()) -> no_return().
34
loop(LSocket, Transport, Logger, ConnsSup, MonitorRef) ->
28
35
_ = case Transport:accept(LSocket, infinity) of
29
36
{ok, CSocket} ->
30
37
case Transport:controlling_process(CSocket, ConnsSup) of
31
38
ok ->
32
39
%% This call will not return until process has been started
33
40
%% AND we are below the maximum number of connections.
34
- ranch_conns_sup:start_protocol(ConnsSup, CSocket);
41
ranch_conns_sup:start_protocol(ConnsSup, MonitorRef,
42
CSocket);
35
43
{error, _} ->
36
44
Transport:close(CSocket)
37
45
end;
 
@@ -51,7 59,7 @@ loop(LSocket, Transport, Logger, ConnsSup) ->
51
59
ok
52
60
end,
53
61
flush(Logger),
54
- ?MODULE:loop(LSocket, Transport, Logger, ConnsSup).
62
?MODULE:loop(LSocket, Transport, Logger, ConnsSup, MonitorRef).
55
63
56
64
flush(Logger) ->
57
65
receive Msg ->
changed src/ranch_acceptors_sup.erl
 
@@ -15,57 15,84 @@
15
15
-module(ranch_acceptors_sup).
16
16
-behaviour(supervisor).
17
17
18
- -export([start_link/2]).
18
-export([start_link/3]).
19
19
-export([init/1]).
20
20
21
- -spec start_link(ranch:ref(), module())
21
-spec start_link(ranch:ref(), module(), module())
22
22
-> {ok, pid()}.
23
- start_link(Ref, Transport) ->
24
- supervisor:start_link(?MODULE, [Ref, Transport]).
23
start_link(Ref, Transport, Logger) ->
24
supervisor:start_link(?MODULE, [Ref, Transport, Logger]).
25
25
26
- init([Ref, Transport]) ->
27
- ConnsSup = ranch_server:get_connections_sup(Ref),
26
-spec init([term()]) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
27
init([Ref, Transport, Logger]) ->
28
28
TransOpts = ranch_server:get_transport_options(Ref),
29
29
NumAcceptors = maps:get(num_acceptors, TransOpts, 10),
30
- Logger = maps:get(logger, TransOpts, error_logger),
31
- LSocket = case maps:get(socket, TransOpts, undefined) of
32
- undefined ->
33
- SocketOpts = maps:get(socket_opts, TransOpts, []),
34
- %% We temporarily put the logger in the process dictionary
35
- %% so that it can be used from ranch:filter_options. The
36
- %% interface as it currently is does not allow passing it
37
- %% down otherwise.
38
- put(logger, Logger),
39
- case Transport:listen(SocketOpts) of
40
- {ok, Socket} ->
41
- erase(logger),
42
- Socket;
43
- {error, Reason} ->
44
- listen_error(Ref, Transport, SocketOpts, Reason, Logger)
45
- end;
46
- Socket ->
47
- Socket
30
NumListenSockets = maps:get(num_listen_sockets, TransOpts, 1),
31
%% We temporarily put the logger in the process dictionary
32
%% so that it can be used from ranch:filter_options. The
33
%% interface as it currently is does not allow passing it
34
%% down otherwise.
35
LSockets = start_listen_sockets(Ref, NumListenSockets, Transport, TransOpts, Logger),
36
Procs = [begin
37
LSocketId = (AcceptorId rem NumListenSockets) 1,
38
{_, LSocket} = lists:keyfind(LSocketId, 1, LSockets),
39
#{
40
id => {acceptor, self(), AcceptorId},
41
start => {ranch_acceptor, start_link, [Ref, AcceptorId, LSocket, Transport, Logger]},
42
shutdown => brutal_kill
43
}
44
end || AcceptorId <- lists:seq(1, NumAcceptors)],
45
{ok, {#{intensity => 1 ceil(math:log2(NumAcceptors))}, Procs}}.
46
47
-spec start_listen_sockets(any(), pos_integer(), module(), map(), module())
48
-> [{pos_integer(), inet:socket()}].
49
start_listen_sockets(Ref, NumListenSockets, Transport, TransOpts0, Logger) when NumListenSockets > 0 ->
50
BaseSocket = start_listen_socket(Ref, Transport, TransOpts0, Logger),
51
{ok, Addr} = Transport:sockname(BaseSocket),
52
ExtraSockets = case Addr of
53
{local, _} when NumListenSockets > 1 ->
54
listen_error(Ref, Transport, TransOpts0, reuseport_local, Logger);
55
{local, _} ->
56
[];
57
{_, Port} ->
58
SocketOpts = maps:get(socket_opts, TransOpts0, []),
59
SocketOpts1 = case lists:keyfind(port, 1, SocketOpts) of
60
{port, Port} ->
61
SocketOpts;
62
_ ->
63
[{port, Port}|lists:keydelete(port, 1, SocketOpts)]
64
end,
65
TransOpts1 = TransOpts0#{socket_opts => SocketOpts1},
66
[{N, start_listen_socket(Ref, Transport, TransOpts1, Logger)}
67
|| N <- lists:seq(2, NumListenSockets)]
48
68
end,
49
- {ok, Addr} = Transport:sockname(LSocket),
50
69
ranch_server:set_addr(Ref, Addr),
51
- Procs = [
52
- {{acceptor, self(), N}, {ranch_acceptor, start_link, [
53
- LSocket, Transport, Logger, ConnsSup
54
- ]}, permanent, brutal_kill, worker, []}
55
- || N <- lists:seq(1, NumAcceptors)],
56
- {ok, {{one_for_one, 1, 5}, Procs}}.
70
[{1, BaseSocket}|ExtraSockets].
71
72
-spec start_listen_socket(any(), module(), map(), module()) -> inet:socket().
73
start_listen_socket(Ref, Transport, TransOpts, Logger) ->
74
case Transport:listen(TransOpts) of
75
{ok, Socket} ->
76
Socket;
77
{error, Reason} ->
78
listen_error(Ref, Transport, TransOpts, Reason, Logger)
79
end.
57
80
58
81
-spec listen_error(any(), module(), any(), atom(), module()) -> no_return().
59
- listen_error(Ref, Transport, SocketOpts0, Reason, Logger) ->
82
listen_error(Ref, Transport, TransOpts0, Reason, Logger) ->
83
SocketOpts0 = maps:get(socket_opts, TransOpts0, []),
60
84
SocketOpts1 = [{cert, '...'}|proplists:delete(cert, SocketOpts0)],
61
85
SocketOpts2 = [{key, '...'}|proplists:delete(key, SocketOpts1)],
62
86
SocketOpts = [{cacerts, '...'}|proplists:delete(cacerts, SocketOpts2)],
87
TransOpts = TransOpts0#{socket_opts => SocketOpts},
63
88
ranch:log(error,
64
89
"Failed to start Ranch listener ~p in ~p:listen(~999999p) for reason ~p (~s)~n",
65
- [Ref, Transport, SocketOpts, Reason, format_error(Reason)], Logger),
90
[Ref, Transport, TransOpts, Reason, format_error(Reason)], Logger),
66
91
exit({listen_error, Ref, Reason}).
67
92
68
93
format_error(no_cert) ->
69
94
"no certificate provided; see cert, certfile, sni_fun or sni_hosts options";
95
format_error(reuseport_local) ->
96
"num_listen_sockets must be set to 1 for local sockets";
70
97
format_error(Reason) ->
71
98
inet:format_error(Reason).
changed src/ranch_app.erl
 
@@ -19,10 19,12 @@
19
19
-export([stop/1]).
20
20
-export([profile_output/0]).
21
21
22
-spec start(application:start_type(), term()) -> {ok, pid()} | {error, term()}.
22
23
start(_, _) ->
23
24
_ = consider_profiling(),
24
25
ranch_sup:start_link().
25
26
27
-spec stop(term()) -> ok.
26
28
stop(_) ->
27
29
ok.
changed src/ranch_conns_sup.erl
 
@@ -18,12 18,12 @@
18
18
-module(ranch_conns_sup).
19
19
20
20
%% API.
21
- -export([start_link/3]).
22
- -export([start_protocol/2]).
21
-export([start_link/6]).
22
-export([start_protocol/3]).
23
23
-export([active_connections/1]).
24
24
25
25
%% Supervisor internals.
26
- -export([init/4]).
26
-export([init/7]).
27
27
-export([system_continue/3]).
28
28
-export([system_terminate/4]).
29
29
-export([system_code_change/4]).
 
@@ -46,10 46,10 @@
46
46
47
47
%% API.
48
48
49
- -spec start_link(ranch:ref(), module(), module()) -> {ok, pid()}.
50
- start_link(Ref, Transport, Protocol) ->
49
-spec start_link(ranch:ref(), pos_integer(), module(), any(), module(), module()) -> {ok, pid()}.
50
start_link(Ref, Id, Transport, TransOpts, Protocol, Logger) ->
51
51
proc_lib:start_link(?MODULE, init,
52
- [self(), Ref, Transport, Protocol]).
52
[self(), Ref, Id, Transport, TransOpts, Protocol, Logger]).
53
53
54
54
%% We can safely assume we are on the same node as the supervisor.
55
55
%%
 
@@ -67,10 67,15 @@ start_link(Ref, Transport, Protocol) ->
67
67
%% We do not need the reply, we only need the ok from the supervisor
68
68
%% to continue. The supervisor sends its own pid when the acceptor can
69
69
%% continue.
70
- -spec start_protocol(pid(), inet:socket()) -> ok.
71
- start_protocol(SupPid, Socket) ->
70
-spec start_protocol(pid(), reference(), inet:socket()) -> ok.
71
start_protocol(SupPid, MonitorRef, Socket) ->
72
72
SupPid ! {?MODULE, start_protocol, self(), Socket},
73
- receive SupPid -> ok end.
73
receive
74
SupPid ->
75
ok;
76
{'DOWN', MonitorRef, process, SupPid, Reason} ->
77
error(Reason)
78
end.
74
79
75
80
%% We can't make the above assumptions here. This function might be
76
81
%% called from anywhere.
 
@@ -94,16 99,14 @@ active_connections(SupPid) ->
94
99
95
100
%% Supervisor internals.
96
101
97
- -spec init(pid(), ranch:ref(), module(), module()) -> no_return().
98
- init(Parent, Ref, Transport, Protocol) ->
102
-spec init(pid(), ranch:ref(), pos_integer(), module(), any(), module(), module()) -> no_return().
103
init(Parent, Ref, Id, Transport, TransOpts, Protocol, Logger) ->
99
104
process_flag(trap_exit, true),
100
- ok = ranch_server:set_connections_sup(Ref, self()),
105
ok = ranch_server:set_connections_sup(Ref, Id, self()),
101
106
MaxConns = ranch_server:get_max_connections(Ref),
102
- TransOpts = ranch_server:get_transport_options(Ref),
103
107
ConnType = maps:get(connection_type, TransOpts, worker),
104
108
Shutdown = maps:get(shutdown, TransOpts, 5000),
105
109
HandshakeTimeout = maps:get(handshake_timeout, TransOpts, 5000),
106
- Logger = maps:get(logger, TransOpts, error_logger),
107
110
ProtoOpts = ranch_server:get_protocol_options(Ref),
108
111
ok = proc_lib:init_ack(Parent, {ok, self()}),
109
112
loop(#state{parent=Parent, ref=Ref, conn_type=ConnType,
 
@@ -116,7 119,7 @@ loop(State=#state{parent=Parent, ref=Ref, conn_type=ConnType,
116
119
max_conns=MaxConns, logger=Logger}, CurConns, NbChildren, Sleepers) ->
117
120
receive
118
121
{?MODULE, start_protocol, To, Socket} ->
119
- try Protocol:start_link(Ref, Socket, Transport, Opts) of
122
try Protocol:start_link(Ref, Transport, Opts) of
120
123
{ok, Pid} ->
121
124
handshake(State, CurConns, NbChildren, Sleepers, To, Socket, Pid, Pid);
122
125
{ok, SupPid, ProtocolPid} when ConnType =:= supervisor ->
 
@@ -135,6 138,7 @@ loop(State=#state{parent=Parent, ref=Ref, conn_type=ConnType,
135
138
"Ranch listener ~p connection process start failure; "
136
139
"~p:start_link/4 crashed with reason: ~p:~999999p~n",
137
140
[Ref, Protocol, Class, Reason], Logger),
141
Transport:close(Socket),
138
142
loop(State, CurConns, NbChildren, Sleepers)
139
143
end;
140
144
{?MODULE, active_connections, To, Tag} ->
 
@@ -145,7 149,7 @@ loop(State=#state{parent=Parent, ref=Ref, conn_type=ConnType,
145
149
case put(Pid, removed) of
146
150
active ->
147
151
loop(State, CurConns - 1, NbChildren, Sleepers);
148
- remove ->
152
removed ->
149
153
loop(State, CurConns, NbChildren, Sleepers);
150
154
undefined ->
151
155
_ = erase(Pid),
 
@@ -160,8 164,11 @@ loop(State=#state{parent=Parent, ref=Ref, conn_type=ConnType,
160
164
{set_max_conns, MaxConns2} ->
161
165
loop(State#state{max_conns=MaxConns2},
162
166
CurConns, NbChildren, Sleepers);
167
%% Upgrade the transport options.
168
{set_transport_options, TransOpts} ->
169
set_transport_options(State, CurConns, NbChildren, Sleepers, TransOpts);
163
170
%% Upgrade the protocol options.
164
- {set_opts, Opts2} ->
171
{set_protocol_options, Opts2} ->
165
172
loop(State#state{opts=Opts2},
166
173
CurConns, NbChildren, Sleepers);
167
174
{'EXIT', Parent, Reason} ->
 
@@ -244,6 251,20 @@ handshake(State=#state{ref=Ref, transport=Transport, handshake_timeout=Handshake
244
251
loop(State, CurConns, NbChildren, Sleepers)
245
252
end.
246
253
254
set_transport_options(State=#state{max_conns=MaxConns0}, CurConns, NbChildren, Sleepers0, TransOpts) ->
255
MaxConns1 = maps:get(max_connections, TransOpts, 1024),
256
HandshakeTimeout = maps:get(handshake_timeout, TransOpts, 5000),
257
Shutdown = maps:get(shutdown, TransOpts, 5000),
258
Sleepers1 = case MaxConns1 > MaxConns0 of
259
true ->
260
_ = [To ! self() || To <- Sleepers0],
261
[];
262
false ->
263
Sleepers0
264
end,
265
loop(State#state{max_conns=MaxConns1, handshake_timeout=HandshakeTimeout, shutdown=Shutdown},
266
CurConns, NbChildren, Sleepers1).
267
247
268
-spec terminate(#state{}, any(), non_neg_integer()) -> no_return().
248
269
terminate(#state{shutdown=brutal_kill}, Reason, _) ->
249
270
kill_children(get_keys(active)),
 
@@ -286,7 307,7 @@ wait_children(0) ->
286
307
ok;
287
308
wait_children(NbChildren) ->
288
309
receive
289
- {'DOWN', _, process, Pid, _} ->
310
{'DOWN', _, process, Pid, _} ->
290
311
case erase(Pid) of
291
312
active -> wait_children(NbChildren - 1);
292
313
removed -> wait_children(NbChildren - 1);
 
@@ -300,6 321,7 @@ wait_children(NbChildren) ->
300
321
ok
301
322
end.
302
323
324
-spec system_continue(_, _, any()) -> no_return().
303
325
system_continue(_, _, {State, CurConns, NbChildren, Sleepers}) ->
304
326
loop(State, CurConns, NbChildren, Sleepers).
305
327
 
@@ -307,6 329,7 @@ system_continue(_, _, {State, CurConns, NbChildren, Sleepers}) ->
307
329
system_terminate(Reason, _, _, {State, _, NbChildren, _}) ->
308
330
terminate(State, Reason, NbChildren).
309
331
332
-spec system_code_change(any(), _, _, _) -> {ok, any()}.
310
333
system_code_change(Misc, _, _, _) ->
311
334
{ok, Misc}.
added src/ranch_conns_sup_sup.erl
 
@@ -0,0 1,40 @@
1
%% Copyright (c) 2019, Jan Uhlig <[email protected]>
2
%%
3
%% Permission to use, copy, modify, and/or distribute this software for any
4
%% purpose with or without fee is hereby granted, provided that the above
5
%% copyright notice and this permission notice appear in all copies.
6
%%
7
%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
15
-module(ranch_conns_sup_sup).
16
17
-behaviour(supervisor).
18
19
-export([start_link/4]).
20
-export([init/1]).
21
22
-spec start_link(ranch:ref(), module(), module(), module()) -> {ok, pid()}.
23
start_link(Ref, Transport, Protocol, Logger) ->
24
ok = ranch_server:cleanup_connections_sups(Ref),
25
supervisor:start_link(?MODULE, {
26
Ref, Transport, Protocol, Logger
27
}).
28
29
-spec init({ranch:ref(), module(), module(), module()})
30
-> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
31
init({Ref, Transport, Protocol, Logger}) ->
32
TransOpts = ranch_server:get_transport_options(Ref),
33
NumAcceptors = maps:get(num_acceptors, TransOpts, 10),
34
NumConnsSups = maps:get(num_conns_sups, TransOpts, NumAcceptors),
35
ChildSpecs = [#{
36
id => {ranch_conns_sup, N},
37
start => {ranch_conns_sup, start_link, [Ref, N, Transport, TransOpts, Protocol, Logger]},
38
type => supervisor
39
} || N <- lists:seq(1, NumConnsSups)],
40
{ok, {#{intensity => 1 ceil(math:log2(NumConnsSups))}, ChildSpecs}}.
added src/ranch_embedded_sup.erl
 
@@ -0,0 1,36 @@
1
%% Copyright (c) 2019, Jan Uhlig <[email protected]>
2
%%
3
%% Permission to use, copy, modify, and/or distribute this software for any
4
%% purpose with or without fee is hereby granted, provided that the above
5
%% copyright notice and this permission notice appear in all copies.
6
%%
7
%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
15
-module(ranch_embedded_sup).
16
17
-behavior(supervisor).
18
19
-export([start_link/5]).
20
-export([init/1]).
21
22
-spec start_link(ranch:ref(), module(), any(), module(), any())
23
-> {ok, pid()}.
24
start_link(Ref, Transport, TransOpts, Protocol, ProtoOpts) ->
25
supervisor:start_link(?MODULE, {Ref, Transport, TransOpts, Protocol, ProtoOpts}).
26
27
-spec init({ranch:ref(), module(), any(), module(), any()})
28
-> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
29
init({Ref, Transport, TransOpts, Protocol, ProtoOpts}) ->
30
Proxy = #{id => ranch_server_proxy,
31
start => {ranch_server_proxy, start_link, []},
32
shutdown => brutal_kill},
33
Listener = #{id => {ranch_listener_sup, Ref},
34
start => {ranch_listener_sup, start_link, [Ref, Transport, TransOpts, Protocol, ProtoOpts]},
35
type => supervisor},
36
{ok, {#{strategy => rest_for_one}, [Proxy, Listener]}}.
changed src/ranch_listener_sup.erl
 
@@ -22,20 22,27 @@
22
22
-> {ok, pid()}.
23
23
start_link(Ref, Transport, TransOpts, Protocol, ProtoOpts) ->
24
24
MaxConns = maps:get(max_connections, TransOpts, 1024),
25
Logger = maps:get(logger, TransOpts, logger),
25
26
ranch_server:set_new_listener_opts(Ref, MaxConns, TransOpts, ProtoOpts,
26
27
[Ref, Transport, TransOpts, Protocol, ProtoOpts]),
27
28
supervisor:start_link(?MODULE, {
28
- Ref, Transport, Protocol
29
Ref, Transport, Protocol, Logger
29
30
}).
30
31
31
- init({Ref, Transport, Protocol}) ->
32
-spec init({ranch:ref(), module(), module(), module()})
33
-> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
34
init({Ref, Transport, Protocol, Logger}) ->
32
35
ok = ranch_server:set_listener_sup(Ref, self()),
33
36
ChildSpecs = [
34
- {ranch_conns_sup, {ranch_conns_sup, start_link,
35
- [Ref, Transport, Protocol]},
36
- permanent, infinity, supervisor, [ranch_conns_sup]},
37
- {ranch_acceptors_sup, {ranch_acceptors_sup, start_link,
38
- [Ref, Transport]},
39
- permanent, infinity, supervisor, [ranch_acceptors_sup]}
37
#{
38
id => ranch_conns_sup_sup,
39
start => {ranch_conns_sup_sup, start_link, [Ref, Transport, Protocol, Logger]},
40
type => supervisor
41
},
42
#{
43
id => ranch_acceptors_sup,
44
start => {ranch_acceptors_sup, start_link, [Ref, Transport, Logger]},
45
type => supervisor
46
}
40
47
],
41
- {ok, {{rest_for_one, 1, 5}, ChildSpecs}}.
48
{ok, {#{strategy => rest_for_one}, ChildSpecs}}.
changed src/ranch_protocol.erl
 
@@ -17,7 17,6 @@
17
17
%% Start a new connection process for the given socket.
18
18
-callback start_link(
19
19
Ref::ranch:ref(),
20
- Socket::any(),
21
20
Transport::module(),
22
21
ProtocolOptions::any())
23
22
-> {ok, ConnectionPid::pid()}
changed src/ranch_server.erl
 
@@ -19,8 19,10 @@
19
19
-export([start_link/0]).
20
20
-export([set_new_listener_opts/5]).
21
21
-export([cleanup_listener_opts/1]).
22
- -export([set_connections_sup/2]).
23
- -export([get_connections_sup/1]).
22
-export([cleanup_connections_sups/1]).
23
-export([set_connections_sup/3]).
24
-export([get_connections_sup/2]).
25
-export([get_connections_sups/1]).
24
26
-export([get_connections_sups/0]).
25
27
-export([set_listener_sup/2]).
26
28
-export([get_listener_sup/1]).
 
@@ -68,29 70,43 @@ cleanup_listener_opts(Ref) ->
68
70
_ = ets:delete(?TAB, {trans_opts, Ref}),
69
71
_ = ets:delete(?TAB, {proto_opts, Ref}),
70
72
_ = ets:delete(?TAB, {listener_start_args, Ref}),
71
- %% We also remove the pid of the connections supervisor.
72
- %% Depending on the timing, it might already have been deleted
73
%% We also remove the pid of the connection supervisors.
74
%% Depending on the timing, they might already have been deleted
73
75
%% when we handled the monitor DOWN message. However, in some
74
76
%% cases when calling stop_listener followed by get_connections_sup,
75
77
%% we could end up with the pid still being returned, when we
76
78
%% expected a crash (because the listener was stopped).
77
79
%% Deleting it explictly here removes any possible confusion.
78
- _ = ets:delete(?TAB, {conns_sup, Ref}),
80
_ = ets:match_delete(?TAB, {{conns_sup, Ref, '_'}, '_'}),
79
81
%% Ditto for the listener supervisor.
80
82
_ = ets:delete(?TAB, {listener_sup, Ref}),
81
83
ok.
82
84
83
- -spec set_connections_sup(ranch:ref(), pid()) -> ok.
84
- set_connections_sup(Ref, Pid) ->
85
- gen_server:call(?MODULE, {set_connections_sup, Ref, Pid}).
85
-spec cleanup_connections_sups(ranch:ref()) -> ok.
86
cleanup_connections_sups(Ref) ->
87
_ = ets:match_delete(?TAB, {{conns_sup, Ref, '_'}, '_'}),
88
ok.
86
89
87
- -spec get_connections_sup(ranch:ref()) -> pid().
88
- get_connections_sup(Ref) ->
89
- ets:lookup_element(?TAB, {conns_sup, Ref}, 2).
90
-spec set_connections_sup(ranch:ref(), non_neg_integer(), pid()) -> ok.
91
set_connections_sup(Ref, Id, Pid) ->
92
gen_server:call(?MODULE, {set_connections_sup, Ref, Id, Pid}).
90
93
91
- -spec get_connections_sups() -> [{ranch:ref(), pid()}].
94
-spec get_connections_sup(ranch:ref(), pos_integer()) -> pid().
95
get_connections_sup(Ref, Id) ->
96
ConnsSups = get_connections_sups(Ref),
97
NConnsSups = length(ConnsSups),
98
{_, Pid} = lists:keyfind((Id rem NConnsSups) 1, 1, ConnsSups),
99
Pid.
100
101
-spec get_connections_sups(ranch:ref()) -> [{pos_integer(), pid()}].
102
get_connections_sups(Ref) ->
103
[{Id, Pid} ||
104
[Id, Pid] <- ets:match(?TAB, {{conns_sup, Ref, '$1'}, '$2'})].
105
106
-spec get_connections_sups() -> [{ranch:ref(), pos_integer(), pid()}].
92
107
get_connections_sups() ->
93
- [{Ref, Pid} || [Ref, Pid] <- ets:match(?TAB, {{conns_sup, '$1'}, '$2'})].
108
[{Ref, Id, Pid} ||
109
[Ref, Id, Pid] <- ets:match(?TAB, {{conns_sup, '$1', '$2'}, '$3'})].
94
110
95
111
-spec set_listener_sup(ranch:ref(), pid()) -> ok.
96
112
set_listener_sup(Ref, Pid) ->
 
@@ -104,11 120,13 @@ get_listener_sup(Ref) ->
104
120
get_listener_sups() ->
105
121
[{Ref, Pid} || [Ref, Pid] <- ets:match(?TAB, {{listener_sup, '$1'}, '$2'})].
106
122
107
- -spec set_addr(ranch:ref(), {inet:ip_address(), inet:port_number()} | {undefined, undefined}) -> ok.
123
-spec set_addr(ranch:ref(), {inet:ip_address(), inet:port_number()} |
124
{local, binary()} | {undefined, undefined}) -> ok.
108
125
set_addr(Ref, Addr) ->
109
126
gen_server:call(?MODULE, {set_addr, Ref, Addr}).
110
127
111
- -spec get_addr(ranch:ref()) -> {inet:ip_address(), inet:port_number()} | {undefined, undefined}.
128
-spec get_addr(ranch:ref()) -> {inet:ip_address(), inet:port_number()} |
129
{local, binary()} | {undefined, undefined}.
112
130
get_addr(Ref) ->
113
131
ets:lookup_element(?TAB, {addr, Ref}, 2).
114
132
 
@@ -142,25 160,32 @@ get_listener_start_args(Ref) ->
142
160
143
161
-spec count_connections(ranch:ref()) -> non_neg_integer().
144
162
count_connections(Ref) ->
145
- ranch_conns_sup:active_connections(get_connections_sup(Ref)).
163
lists:foldl(
164
fun ({_, ConnsSup}, Acc) ->
165
Acc ranch_conns_sup:active_connections(ConnsSup)
166
end,
167
0,
168
get_connections_sups(Ref)).
146
169
147
170
%% gen_server.
148
171
172
-spec init([]) -> {ok, #state{}}.
149
173
init([]) ->
150
- ConnMonitors = [{{erlang:monitor(process, Pid), Pid}, {conns_sup, Ref}} ||
151
- [Ref, Pid] <- ets:match(?TAB, {{conns_sup, '$1'}, '$2'})],
174
ConnMonitors = [{{erlang:monitor(process, Pid), Pid}, {conns_sup, Ref, Id}} ||
175
[Ref, Id, Pid] <- ets:match(?TAB, {{conns_sup, '$1', '$2'}, '$3'})],
152
176
ListenerMonitors = [{{erlang:monitor(process, Pid), Pid}, {listener_sup, Ref}} ||
153
177
[Ref, Pid] <- ets:match(?TAB, {{listener_sup, '$1'}, '$2'})],
154
178
{ok, #state{monitors=ConnMonitors ListenerMonitors}}.
155
179
180
-spec handle_call(term(), {pid(), reference()}, #state{}) -> {reply, ok | ignore, #state{}}.
156
181
handle_call({set_new_listener_opts, Ref, MaxConns, TransOpts, ProtoOpts, StartArgs}, _, State) ->
157
182
ets:insert_new(?TAB, {{max_conns, Ref}, MaxConns}),
158
183
ets:insert_new(?TAB, {{trans_opts, Ref}, TransOpts}),
159
184
ets:insert_new(?TAB, {{proto_opts, Ref}, ProtoOpts}),
160
185
ets:insert_new(?TAB, {{listener_start_args, Ref}, StartArgs}),
161
186
{reply, ok, State};
162
- handle_call({set_connections_sup, Ref, Pid}, _, State0) ->
163
- State = set_monitored_process({conns_sup, Ref}, Pid, State0),
187
handle_call({set_connections_sup, Ref, Id, Pid}, _, State0) ->
188
State = set_monitored_process({conns_sup, Ref, Id}, Pid, State0),
164
189
{reply, ok, State};
165
190
handle_call({set_listener_sup, Ref, Pid}, _, State0) ->
166
191
State = set_monitored_process({listener_sup, Ref}, Pid, State0),
 
@@ -170,23 195,23 @@ handle_call({set_addr, Ref, Addr}, _, State) ->
170
195
{reply, ok, State};
171
196
handle_call({set_max_conns, Ref, MaxConns}, _, State) ->
172
197
ets:insert(?TAB, {{max_conns, Ref}, MaxConns}),
173
- ConnsSup = get_connections_sup(Ref),
174
- ConnsSup ! {set_max_conns, MaxConns},
198
_ = [ConnsSup ! {set_max_conns, MaxConns} || {_, ConnsSup} <- get_connections_sups(Ref)],
175
199
{reply, ok, State};
176
200
handle_call({set_trans_opts, Ref, Opts}, _, State) ->
177
201
ets:insert(?TAB, {{trans_opts, Ref}, Opts}),
178
202
{reply, ok, State};
179
203
handle_call({set_proto_opts, Ref, Opts}, _, State) ->
180
204
ets:insert(?TAB, {{proto_opts, Ref}, Opts}),
181
- ConnsSup = get_connections_sup(Ref),
182
- ConnsSup ! {set_opts, Opts},
205
_ = [ConnsSup ! {set_protocol_options, Opts} || {_, ConnsSup} <- get_connections_sups(Ref)],
183
206
{reply, ok, State};
184
207
handle_call(_Request, _From, State) ->
185
208
{reply, ignore, State}.
186
209
210
-spec handle_cast(_, #state{}) -> {noreply, #state{}}.
187
211
handle_cast(_Request, State) ->
188
212
{noreply, State}.
189
213
214
-spec handle_info(term(), #state{}) -> {noreply, #state{}}.
190
215
handle_info({'DOWN', MonitorRef, process, Pid, Reason},
191
216
State=#state{monitors=Monitors}) ->
192
217
{_, TypeRef} = lists:keyfind({MonitorRef, Pid}, 1, Monitors),
 
@@ -206,9 231,11 @@ handle_info({'DOWN', MonitorRef, process, Pid, Reason},
206
231
handle_info(_Info, State) ->
207
232
{noreply, State}.
208
233
234
-spec terminate(_, #state{}) -> ok.
209
235
terminate(_Reason, _State) ->
210
236
ok.
211
237
238
-spec code_change(term() | {down, term()}, #state{}, term()) -> {ok, term()}.
212
239
code_change(_OldVsn, State, _Extra) ->
213
240
{ok, State}.
added src/ranch_server_proxy.erl
 
@@ -0,0 1,67 @@
1
%% Copyright (c) 2019, Jan Uhlig <[email protected]>
2
%%
3
%% Permission to use, copy, modify, and/or distribute this software for any
4
%% purpose with or without fee is hereby granted, provided that the above
5
%% copyright notice and this permission notice appear in all copies.
6
%%
7
%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
15
-module(ranch_server_proxy).
16
17
-behavior(gen_server).
18
19
-export([start_link/0]).
20
-export([init/1]).
21
-export([handle_call/3]).
22
-export([handle_cast/2]).
23
-export([handle_info/2]).
24
-export([code_change/3]).
25
26
-spec start_link() -> {ok, pid()} | {error, term()}.
27
start_link() ->
28
gen_server:start_link(?MODULE, [], []).
29
30
-spec init([]) -> {ok, pid()} | {stop, term()}.
31
init([]) ->
32
case wait_ranch_server(50) of
33
{ok, Monitor} ->
34
{ok, Monitor, hibernate};
35
{error, Reason} ->
36
{stop, Reason}
37
end.
38
39
-spec handle_call(_, _, reference()) -> {noreply, reference(), hibernate}.
40
handle_call(_, _, Monitor) ->
41
{noreply, Monitor, hibernate}.
42
43
-spec handle_cast(_, reference()) -> {noreply, reference(), hibernate}.
44
handle_cast(_, Monitor) ->
45
{noreply, Monitor, hibernate}.
46
47
-spec handle_info(term(), reference()) -> {noreply, reference(), hibernate} | {stop, term(), reference()}.
48
handle_info({'DOWN', Monitor, process, _, Reason}, Monitor) ->
49
{stop, Reason, Monitor};
50
handle_info(_, Monitor) ->
51
{noreply, Monitor, hibernate}.
52
53
-spec code_change(term() | {down, term()}, reference(), term()) -> {ok, reference()}.
54
code_change(_, Monitor, _) ->
55
{ok, Monitor}.
56
57
wait_ranch_server(N) ->
58
case whereis(ranch_server) of
59
undefined when N > 0 ->
60
receive after 100 -> ok end,
61
wait_ranch_server(N - 1);
62
undefined ->
63
{error, noproc};
64
Pid ->
65
Monitor = monitor(process, Pid),
66
{ok, Monitor}
67
end.
changed src/ranch_ssl.erl
 
@@ -21,7 21,6 @@
21
21
-export([listen/1]).
22
22
-export([disallowed_listen_options/0]).
23
23
-export([accept/2]).
24
- -export([accept_ack/2]).
25
24
-export([handshake/3]).
26
25
-export([connect/3]).
27
26
-export([connect/4]).
 
@@ -43,39 42,46 @@
43
42
44
43
-type ssl_opt() :: {alpn_preferred_protocols, [binary()]}
45
44
| {beast_mitigation, one_n_minus_one | zero_n | disabled}
46
- | {cacertfile, string()}
45
| {cacertfile, file:filename()}
47
46
| {cacerts, [public_key:der_encoded()]}
48
47
| {cert, public_key:der_encoded()}
49
- | {certfile, string()}
50
- | {ciphers, [ssl_cipher:erl_cipher_suite()]}
48
| {certfile, file:filename()}
49
| {ciphers, ssl:ciphers()}
51
50
| {client_renegotiation, boolean()}
52
- | {crl_cache, {module(), {internal | any(), list()}}}
51
| {crl_cache, [any()]}
53
52
| {crl_check, boolean() | peer | best_effort}
54
- | {depth, 0..255}
55
- | {dh, public_key:der_encoded()}
56
- | {dhfile, string()}
53
| {depth, integer()}
54
| {dh, binary()}
55
| {dhfile, file:filename()}
56
%% @todo Update when ssl exports named_curve().
57
| {eccs, [atom()]}
57
58
| {fail_if_no_peer_cert, boolean()}
58
- | {hibernate_after, integer() | undefined}
59
| {hibernate_after, timeout()}
59
60
| {honor_cipher_order, boolean()}
60
- | {key, {'RSAPrivateKey' | 'DSAPrivateKey' | 'PrivateKeyInfo', public_key:der_encoded()}}
61
- | {keyfile, string()}
61
| {honor_ecc_order, boolean()}
62
| {key, ssl:key()}
63
| {keyfile, file:filename()}
62
64
| {log_alert, boolean()}
65
| {log_level, logger:level()}
66
| {max_handshake_size, integer()}
63
67
| {next_protocols_advertised, [binary()]}
64
68
| {padding_check, boolean()}
65
- | {partial_chain, fun(([public_key:der_encoded()]) -> {trusted_ca, public_key:der_encoded()} | unknown_ca)}
69
| {partial_chain, fun()}
66
70
| {password, string()}
71
| {protocol, tls | dtls}
67
72
| {psk_identity, string()}
68
73
| {reuse_session, fun()}
69
74
| {reuse_sessions, boolean()}
70
75
| {secure_renegotiate, boolean()}
71
- | {signature_algs, [{atom(), atom()}]}
76
| {signature_algs, [{ssl:hash(), ssl:sign_algo()}]}
77
%% @todo Update when ssl exports sign_scheme().
78
| {signature_algs_cert, [atom()]}
72
79
| {sni_fun, fun()}
73
80
| {sni_hosts, [{string(), ssl_opt()}]}
74
81
| {user_lookup_fun, {fun(), any()}}
75
- | {v2_hello_compatible, boolean()}
76
82
| {verify, verify_none | verify_peer}
77
83
| {verify_fun, {fun(), any()}}
78
- | {versions, [atom()]}.
84
| {versions, [ssl:protocol_version()]}.
79
85
-export_type([ssl_opt/0]).
80
86
81
87
-type opt() :: ranch_tcp:opt() | ssl_opt().
 
@@ -84,39 90,44 @@
84
90
-type opts() :: [opt()].
85
91
-export_type([opts/0]).
86
92
93
-spec name() -> ssl.
87
94
name() -> ssl.
88
95
89
96
-spec secure() -> boolean().
90
97
secure() ->
91
- true.
98
true.
92
99
93
- messages() -> {ssl, ssl_closed, ssl_error}.
100
-spec messages() -> {ssl, ssl_closed, ssl_error, ssl_passive}.
101
messages() -> {ssl, ssl_closed, ssl_error, ssl_passive}.
94
102
95
- -spec listen(opts()) -> {ok, ssl:sslsocket()} | {error, atom()}.
96
- listen(Opts) ->
97
- case lists:keymember(cert, 1, Opts)
98
- orelse lists:keymember(certfile, 1, Opts)
99
- orelse lists:keymember(sni_fun, 1, Opts)
100
- orelse lists:keymember(sni_hosts, 1, Opts) of
103
-spec listen(ranch:transport_opts(opts())) -> {ok, ssl:sslsocket()} | {error, atom()}.
104
listen(TransOpts) ->
105
SocketOpts = maps:get(socket_opts, TransOpts, []),
106
case lists:keymember(cert, 1, SocketOpts)
107
orelse lists:keymember(certfile, 1, SocketOpts)
108
orelse lists:keymember(sni_fun, 1, SocketOpts)
109
orelse lists:keymember(sni_hosts, 1, SocketOpts) of
101
110
true ->
102
- do_listen(Opts);
111
Logger = maps:get(logger, TransOpts, logger),
112
do_listen(SocketOpts, Logger);
103
113
false ->
104
114
{error, no_cert}
105
115
end.
106
116
107
- do_listen(Opts0) ->
108
- Opts1 = ranch:set_option_default(Opts0, backlog, 1024),
109
- Opts2 = ranch:set_option_default(Opts1, nodelay, true),
110
- Opts3 = ranch:set_option_default(Opts2, send_timeout, 30000),
111
- Opts = ranch:set_option_default(Opts3, send_timeout_close, true),
117
do_listen(SocketOpts0, Logger) ->
118
SocketOpts1 = ranch:set_option_default(SocketOpts0, backlog, 1024),
119
SocketOpts2 = ranch:set_option_default(SocketOpts1, nodelay, true),
120
SocketOpts3 = ranch:set_option_default(SocketOpts2, send_timeout, 30000),
121
SocketOpts = ranch:set_option_default(SocketOpts3, send_timeout_close, true),
112
122
%% We set the port to 0 because it is given in the Opts directly.
113
123
%% The port in the options takes precedence over the one in the
114
124
%% first argument.
115
- ssl:listen(0, ranch:filter_options(Opts, disallowed_listen_options(),
116
- [binary, {active, false}, {packet, raw}, {reuseaddr, true}])).
125
ssl:listen(0, ranch:filter_options(SocketOpts, disallowed_listen_options(),
126
[binary, {active, false}, {packet, raw}, {reuseaddr, true}], Logger)).
117
127
118
128
%% 'binary' and 'list' are disallowed but they are handled
119
129
%% specifically as they do not have 2-tuple equivalents.
130
-spec disallowed_listen_options() -> [atom()].
120
131
disallowed_listen_options() ->
121
132
[alpn_advertised_protocols, client_preferred_next_protocols,
122
133
fallback, server_name_indication, srp_identity
 
@@ -127,11 138,6 @@ disallowed_listen_options() ->
127
138
accept(LSocket, Timeout) ->
128
139
ssl:transport_accept(LSocket, Timeout).
129
140
130
- -spec accept_ack(ssl:sslsocket(), timeout()) -> ok.
131
- accept_ack(CSocket, Timeout) ->
132
- {ok, _} = handshake(CSocket, [], Timeout),
133
- ok.
134
-
135
141
-spec handshake(inet:socket() | ssl:sslsocket(), opts(), timeout())
136
142
-> {ok, ssl:sslsocket()} | {error, any()}.
137
143
handshake(CSocket, Opts, Timeout) ->
 
@@ -224,12 230,12 @@ controlling_process(Socket, Pid) ->
224
230
ssl:controlling_process(Socket, Pid).
225
231
226
232
-spec peername(ssl:sslsocket())
227
- -> {ok, {inet:ip_address(), inet:port_number()}} | {error, atom()}.
233
-> {ok, {inet:ip_address(), inet:port_number()} | {local, binary()}} | {error, atom()}.
228
234
peername(Socket) ->
229
235
ssl:peername(Socket).
230
236
231
237
-spec sockname(ssl:sslsocket())
232
- -> {ok, {inet:ip_address(), inet:port_number()}} | {error, atom()}.
238
-> {ok, {inet:ip_address(), inet:port_number()} | {local, binary()}} | {error, atom()}.
233
239
sockname(Socket) ->
234
240
ssl:sockname(Socket).
changed src/ranch_sup.erl
 
@@ -22,6 22,7 @@
22
22
start_link() ->
23
23
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
24
24
25
-spec init([]) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
25
26
init([]) ->
26
27
Intensity = case application:get_env(ranch_sup_intensity) of
27
28
{ok, Value1} -> Value1;
 
@@ -34,7 35,6 @@ init([]) ->
34
35
ranch_server = ets:new(ranch_server, [
35
36
ordered_set, public, named_table]),
36
37
Procs = [
37
- {ranch_server, {ranch_server, start_link, []},
38
- permanent, 5000, worker, [ranch_server]}
38
#{id => ranch_server, start => {ranch_server, start_link, []}}
39
39
],
40
- {ok, {{one_for_one, Intensity, Period}, Procs}}.
40
{ok, {#{intensity => Intensity, period => Period}, Procs}}.
changed src/ranch_tcp.erl
 
@@ -21,7 21,6 @@
21
21
-export([listen/1]).
22
22
-export([disallowed_listen_options/0]).
23
23
-export([accept/2]).
24
- -export([accept_ack/2]).
25
24
-export([handshake/3]).
26
25
-export([connect/3]).
27
26
-export([connect/4]).
 
@@ -51,7 50,7 @@
51
50
| {high_watermark, non_neg_integer()}
52
51
| inet
53
52
| inet6
54
- | {ip, inet:ip_address()}
53
| {ip, inet:ip_address() | inet:local_address()}
55
54
| {ipv6_v6only, boolean()}
56
55
| {keepalive, boolean()}
57
56
| {linger, {boolean(), non_neg_integer()}}
 
@@ -71,28 70,33 @@
71
70
-type opts() :: [opt()].
72
71
-export_type([opts/0]).
73
72
73
-spec name() -> tcp.
74
74
name() -> tcp.
75
75
76
76
-spec secure() -> boolean().
77
77
secure() ->
78
- false.
78
false.
79
79
80
- messages() -> {tcp, tcp_closed, tcp_error}.
80
-spec messages() -> {tcp, tcp_closed, tcp_error, tcp_passive}.
81
messages() -> {tcp, tcp_closed, tcp_error, tcp_passive}.
81
82
82
- -spec listen(opts()) -> {ok, inet:socket()} | {error, atom()}.
83
- listen(Opts) ->
84
- Opts2 = ranch:set_option_default(Opts, backlog, 1024),
85
- Opts3 = ranch:set_option_default(Opts2, nodelay, true),
86
- Opts4 = ranch:set_option_default(Opts3, send_timeout, 30000),
87
- Opts5 = ranch:set_option_default(Opts4, send_timeout_close, true),
83
-spec listen(ranch:transport_opts(opts())) -> {ok, inet:socket()} | {error, atom()}.
84
listen(TransOpts) ->
85
Logger = maps:get(logger, TransOpts, logger),
86
SocketOpts0 = maps:get(socket_opts, TransOpts, []),
87
SocketOpts1 = ranch:set_option_default(SocketOpts0, backlog, 1024),
88
SocketOpts2 = ranch:set_option_default(SocketOpts1, nodelay, true),
89
SocketOpts3 = ranch:set_option_default(SocketOpts2, send_timeout, 30000),
90
SocketOpts4 = ranch:set_option_default(SocketOpts3, send_timeout_close, true),
88
91
%% We set the port to 0 because it is given in the Opts directly.
89
92
%% The port in the options takes precedence over the one in the
90
93
%% first argument.
91
- gen_tcp:listen(0, ranch:filter_options(Opts5, disallowed_listen_options(),
92
- [binary, {active, false}, {packet, raw}, {reuseaddr, true}])).
94
gen_tcp:listen(0, ranch:filter_options(SocketOpts4, disallowed_listen_options(),
95
[binary, {active, false}, {packet, raw}, {reuseaddr, true}], Logger)).
93
96
94
97
%% 'binary' and 'list' are disallowed but they are handled
95
98
%% specifically as they do not have 2-tuple equivalents.
99
-spec disallowed_listen_options() -> [atom()].
96
100
disallowed_listen_options() ->
97
101
[active, header, mode, packet, packet_size, line_delimiter, reuseaddr].
98
102
 
@@ -101,11 105,6 @@ disallowed_listen_options() ->
101
105
accept(LSocket, Timeout) ->
102
106
gen_tcp:accept(LSocket, Timeout).
103
107
104
- -spec accept_ack(inet:socket(), timeout()) -> ok.
105
- accept_ack(CSocket, Timeout) ->
106
- {ok, _} = handshake(CSocket, [], Timeout),
107
- ok.
108
-
109
108
-spec handshake(inet:socket(), opts(), timeout()) -> {ok, inet:socket()}.
110
109
handshake(CSocket, _, _) ->
111
110
{ok, CSocket}.
 
@@ -226,12 225,12 @@ controlling_process(Socket, Pid) ->
226
225
gen_tcp:controlling_process(Socket, Pid).
227
226
228
227
-spec peername(inet:socket())
229
- -> {ok, {inet:ip_address(), inet:port_number()}} | {error, atom()}.
228
-> {ok, {inet:ip_address(), inet:port_number()} | {local, binary()}} | {error, atom()}.
230
229
peername(Socket) ->
231
230
inet:peername(Socket).
232
231
233
232
-spec sockname(inet:socket())
234
- -> {ok, {inet:ip_address(), inet:port_number()}} | {error, atom()}.
233
-> {ok, {inet:ip_address(), inet:port_number()} | {local, binary()}} | {error, atom()}.
235
234
sockname(Socket) ->
236
235
inet:sockname(Socket).
changed src/ranch_transport.erl
 
@@ -26,8 26,8 @@
26
26
27
27
-callback name() -> atom().
28
28
-callback secure() -> boolean().
29
- -callback messages() -> {OK::atom(), Closed::atom(), Error::atom()}.
30
- -callback listen(opts()) -> {ok, socket()} | {error, atom()}.
29
-callback messages() -> {OK::atom(), Closed::atom(), Error::atom(), Passive::atom()}.
30
-callback listen(ranch:transport_opts(any())) -> {ok, socket()} | {error, atom()}.
31
31
-callback accept(socket(), timeout())
32
32
-> {ok, socket()} | {error, closed | timeout | atom()}.
33
33
-callback handshake(socket(), opts(), timeout()) -> {ok, socket()} | {error, any()}.
 
@@ -56,9 56,9 @@
56
56
-callback controlling_process(socket(), pid())
57
57
-> ok | {error, closed | not_owner | atom()}.
58
58
-callback peername(socket())
59
- -> {ok, {inet:ip_address(), inet:port_number()}} | {error, atom()}.
59
-> {ok, {inet:ip_address(), inet:port_number()} | {local, binary()}} | {error, atom()}.
60
60
-callback sockname(socket())
61
- -> {ok, {inet:ip_address(), inet:port_number()}} | {error, atom()}.
61
-> {ok, {inet:ip_address(), inet:port_number()} | {local, binary()}} | {error, atom()}.
62
62
-callback shutdown(socket(), read | write | read_write)
63
63
-> ok | {error, atom()}.
64
64
-callback close(socket()) -> ok.