aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornevar <[email protected]>2016-08-06 00:12:26 +0700
committerLoïc Hoguin <[email protected]>2016-10-19 17:51:57 +0200
commitfc7f6acd00331b09217fe733b89c620771fdabd5 (patch)
treefa7340acdaf4e76e57748bf70f5e7e782f5660c4
parent01ed1866afdbdfaa966bf5be5aab30d6525aa962 (diff)
downloaderlang.mk-fc7f6acd00331b09217fe733b89c620771fdabd5.tar.gz
erlang.mk-fc7f6acd00331b09217fe733b89c620771fdabd5.tar.bz2
erlang.mk-fc7f6acd00331b09217fe733b89c620771fdabd5.zip
Add PROJECT_ENV
Fix #587
-rw-r--r--core/core.mk1
-rw-r--r--core/erlc.mk8
-rw-r--r--doc/src/guide/app.asciidoc2
-rw-r--r--test/core_app.mk36
4 files changed, 43 insertions, 4 deletions
diff --git a/core/core.mk b/core/core.mk
index 6af2db9..f4a8921 100644
--- a/core/core.mk
+++ b/core/core.mk
@@ -25,6 +25,7 @@ PROJECT := $(strip $(PROJECT))
PROJECT_VERSION ?= rolling
PROJECT_MOD ?= $(PROJECT)_app
+PROJECT_ENV ?= []
# Verbosity.
diff --git a/core/erlc.mk b/core/erlc.mk
index 24b78d2..ed9aa88 100644
--- a/core/erlc.mk
+++ b/core/erlc.mk
@@ -67,7 +67,8 @@ define app_file
{id$(comma)$(space)"$(1)"}$(comma))
{modules, [$(call comma_list,$(2))]},
{registered, []},
- {applications, [$(call comma_list,kernel stdlib $(OTP_DEPS) $(LOCAL_DEPS) $(DEPS))]}
+ {applications, [$(call comma_list,kernel stdlib $(OTP_DEPS) $(LOCAL_DEPS) $(DEPS))]},
+ {env, $(subst \,\\,$(PROJECT_ENV))}
]}.
endef
else
@@ -79,7 +80,8 @@ define app_file
{modules, [$(call comma_list,$(2))]},
{registered, [$(call comma_list,$(PROJECT)_sup $(PROJECT_REGISTERED))]},
{applications, [$(call comma_list,kernel stdlib $(OTP_DEPS) $(LOCAL_DEPS) $(DEPS))]},
- {mod, {$(PROJECT_MOD), []}}
+ {mod, {$(PROJECT_MOD), []}},
+ {env, $(subst \,\\,$(PROJECT_ENV))}
]}.
endef
endif
@@ -241,7 +243,7 @@ ebin/$(PROJECT).app:: $(ERL_FILES) $(CORE_FILES) $(wildcard src/$(PROJECT).app.s
$(eval MODULES := $(patsubst %,'%',$(sort $(notdir $(basename \
$(filter-out $(ERLC_EXCLUDE_PATHS),$(ERL_FILES) $(CORE_FILES) $(BEAM_FILES)))))))
ifeq ($(wildcard src/$(PROJECT).app.src),)
- $(app_verbose) printf "$(subst $(newline),\n,$(subst ",\",$(call app_file,$(GITDESCRIBE),$(MODULES))))" \
+ $(app_verbose) printf '$(subst $(newline),\n,$(subst ','\'',$(call app_file,$(GITDESCRIBE),$(MODULES))))' \
> ebin/$(PROJECT).app
else
$(verbose) if [ -z "$$(grep -e '^[^%]*{\s*modules\s*,' src/$(PROJECT).app.src)" ]; then \
diff --git a/doc/src/guide/app.asciidoc b/doc/src/guide/app.asciidoc
index eef5d45..ca0a993 100644
--- a/doc/src/guide/app.asciidoc
+++ b/doc/src/guide/app.asciidoc
@@ -130,6 +130,8 @@ your situation.
The application callback module.
`PROJECT_REGISTERED`::
List of the names of all registered processes.
+`PROJECT_ENV`::
+ Configuration parameters used by the application.
`LOCAL_DEPS`::
List of Erlang/OTP applications this project depends on,
excluding `erts`, `kernel` and `stdlib`, or list of
diff --git a/test/core_app.mk b/test/core_app.mk
index 22424ee..e568947 100644
--- a/test/core_app.mk
+++ b/test/core_app.mk
@@ -1,6 +1,6 @@
# Core: Building applications.
-CORE_APP_CASES = appsrc-change asn1 auto-git-id erlc-exclude erlc-opts erlc-opts-filter error generate-erl generate-erl-include generate-erl-prepend hrl hrl-recursive makefile-change mib no-app no-makedep project-mod pt pt-erlc-opts xrl xrl-include yrl yrl-header yrl-include
+CORE_APP_CASES = appsrc-change asn1 auto-git-id env erlc-exclude erlc-opts erlc-opts-filter error generate-erl generate-erl-include generate-erl-prepend hrl hrl-recursive makefile-change mib no-app no-makedep project-mod pt pt-erlc-opts xrl xrl-include yrl yrl-header yrl-include
CORE_APP_TARGETS = $(addprefix core-app-,$(CORE_APP_CASES))
.PHONY: core-app $(CORE_APP_TARGETS)
@@ -197,6 +197,40 @@ endif
true = ID =/= [], \
halt()"
+ifndef LEGACY
+core-app-env: build clean
+
+ $i "Bootstrap a new OTP library named $(APP)"
+ $t mkdir $(APP)/
+ $t cp ../erlang.mk $(APP)/
+ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
+
+ $i "Define PROJECT_ENV"
+ $t echo "PROJECT_ENV = [{test_key, test_value}]" >> $(APP)/Makefile
+
+ $i "Build the application"
+ $t $(MAKE) -C $(APP) $v
+
+ $i "Check that the application was compiled correctly"
+ $t $(ERL) -pa $(APP)/ebin/ -eval " \
+ ok = application:load($(APP)), \
+ {ok, test_value} = application:get_env($(APP), test_key), \
+ halt()"
+
+ $i "Define PROJECT_ENV with escape in string, special char"
+ $t echo "PROJECT_ENV = [{test_atom, '\\\$$\$$test'}, {test_key, \"\\\"test_\\tvalue\\\"\"}]" >> $(APP)/Makefile
+
+ $i "Build the application"
+ $t $(MAKE) -C $(APP) $v
+
+ $i "Check that the application was compiled correctly"
+ $t $(ERL) -pa $(APP)/ebin/ -eval " \
+ ok = application:load($(APP)), \
+ {ok, \"\\\"test_\\tvalue\\\"\"} = application:get_env($(APP), test_key), \
+ {ok, '\\\$$test'} = application:get_env($(APP), test_atom), \
+ halt()"
+endif
+
core-app-erlc-exclude: build clean
$i "Bootstrap a new OTP library named $(APP)"