From f5b2b613ff08dddf178889fc22210b07db4e90d3 Mon Sep 17 00:00:00 2001 From: Tyler Hughes Date: Mon, 3 Jul 2023 00:16:59 +0100 Subject: [PATCH] Use the System Install if available, unless specified otherwise --- core/core.mk | 2 ++ core/elixir.mk | 28 ++++++++++----- test/core_elixir.mk | 84 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 104 insertions(+), 10 deletions(-) diff --git a/core/core.mk b/core/core.mk index 250a2eb3..e9c51d47 100644 --- a/core/core.mk +++ b/core/core.mk @@ -98,6 +98,8 @@ endif export PLATFORM endif +UNIQUE = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) + # Core targets. all:: deps app rel diff --git a/core/elixir.mk b/core/elixir.mk index 5c29a2ef..209a57d3 100644 --- a/core/elixir.mk +++ b/core/elixir.mk @@ -2,7 +2,17 @@ ifeq ($(pkg_elixir_commit),master) pkg_elixir_commit = main endif +ELIXIR_USE_SYSTEM := 1 + +ifeq ($(ELIXIR_USE_SYSTEM),1) +ELIXIRC = $(shell which elixirc) +endif + +ifeq ($(ELIXIRC),) ELIXIRC = $(DEPS_DIR)/$(call dep_name,elixir)/bin/elixirc +endif + +ELIXIR_PATH = $(if $(ELIXIRC),$(abspath $(shell $(dir $(ELIXIRC))/elixir -e 'IO.puts(:code.lib_dir(:elixir))')/../../),$(DEPS_DIR)/$(call dep_name,elixir)) ELIXIR_COMPILE_FIRST_PATHS = $(addprefix src/,$(addsuffix .ex,$(COMPILE_FIRST))) $(addprefix lib/,$(addsuffix .ex,$(COMPILE_FIRST))) ELIXIRC_EXCLUDE_PATHS = $(addprefix src/,$(addsuffix .ex,$(ERLC_EXCLUDE))) $(addprefix lib/,$(addsuffix .ex,$(ERLC_EXCLUDE))) @@ -16,11 +26,11 @@ elixirc_verbose = $(elixirc_verbose_$(V)) ALL_LIB_FILES := $(sort $(call core_find,lib/,*)) EX_FILES := $(filter-out lib/mix/%,$(filter %.ex,$(ALL_SRC_FILES) $(ALL_LIB_FILES))) -ELIXIR_BUILTINS = $(addprefix $(DEPS_DIR)/$(call dep_name,elixir)/lib/,eex elixir logger mix) +ELIXIR_BUILTINS = $(addprefix $(ELIXIR_PATH)/lib/,eex elixir logger mix) USES_ELIXIR = $(if $(EX_FILES)$(shell find $(DEPS_DIR) -name '*.ex' 2>/dev/null),1,) ifneq ($(USES_ELIXIR),) -ERL_LIBS := $(ERL_LIBS):$(DEPS_DIR)/$(call dep_name,elixir)/lib/ +ERL_LIBS := $(ERL_LIBS):$(ELIXIR_PATH)/lib/ export ERL_LIBS define app_file @@ -250,10 +260,10 @@ LOCAL_DEPS += eex elixir logger mix ebin/$(PROJECT).app:: $(ELIXIRC) endif -$(ELIXIRC): $(DEPS_DIR)/$(call dep_name,elixir)/lib/elixir/ebin/elixir.app +$(ELIXIRC): $(ELIXIR_PATH)/lib/elixir/ebin/elixir.app -$(addsuffix /ebin,$(ELIXIR_BUILTINS)): $(DEPS_DIR)/$(call dep_name,elixir) - make -C $(DEPS_DIR)/elixir IS_DEP=1 +$(addsuffix /ebin,$(ELIXIR_BUILTINS)): $(ELIXIR_PATH) + $(verbose) $(if $(ELIXIR_USE_SYSTEM),@,$(MAKE) -C $(DEPS_DIR)/elixir IS_DEP=1) define compile_ex ERL_COMPILER_OPTIONS="[$(call comma_list,$(patsubst '%',%,$(patsubst +%,%,$(filter +%,$(ELIXIRC_OPTS)))))]" $(ELIXIRC) \ @@ -275,10 +285,10 @@ ebin/$(PROJECT).app:: $(EX_FILES) || git describe --dirty --abbrev=7 --tags --always 2>/dev/null || true)) $(eval MODULES := $(patsubst %,'%',$(sort $(notdir $(basename \ $(filter-out $(ELIXIRC_EXCLUDE_PATHS), $(ERL_FILES) $(CORE_FILES) $(BEAM_FILES))))))) - $(eval MODULES := $(MODULES) $(foreach file, \ + $(eval MODULES := $(call UNIQUE,$(MODULES) $(foreach file, \ $(EX_FILES), \ $(call get_elixir_mod,$(file)) \ - )) + ))) ifeq ($(wildcard src/$(PROJECT).app.src),) $(app_verbose) printf "$(subst %,%%,$(subst $(newline),\n,$(subst ",\",$(call app_file,$(GITDESCRIBE),$(MODULES)))))" \ > ebin/$(PROJECT).app @@ -300,8 +310,8 @@ ifneq ($(wildcard src/$(PROJECT).appup),) $(verbose) cp src/$(PROJECT).appup ebin/ endif -$(DEPS_DIR)/$(call dep_name,elixir)/lib/elixir/ebin/elixir.app: $(DEPS_DIR)/$(call dep_name,elixir) - $(MAKE) -C $(DEPS_DIR)/elixir -f Makefile.orig compile +$(ELIXIR_PATH)/lib/elixir/ebin/elixir.app: $(ELIXIR_PATH) + $(verbose) $(if $(ELIXIR_USE_SYSTEM),@,$(MAKE) -C $(DEPS_DIR)/elixir -f Makefile.orig compile) # We need the original makefile so that we can compile the elixir compiler autopatch-elixir:: diff --git a/test/core_elixir.mk b/test/core_elixir.mk index 08cd24b3..4475334a 100644 --- a/test/core_elixir.mk +++ b/test/core_elixir.mk @@ -8,8 +8,53 @@ CORE_ELIXIR_TARGETS = $(call list_targets,core-elixir) core-elixir: $(CORE_ELIXIR_TARGETS) -core-elixir-test-project: init +core-elixir-test-project_library: init + $i "Bootstrap a new OTP library named $(APP)" + $t mkdir $(APP)/ + $t cp ../erlang.mk $(APP)/ + $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v + + $i "Configure Makefile" + $t echo "ERLC_OPTS += +debug_info +'{parse_transform,lager_transform}'" >> $(APP)/Makefile + $t echo "ELIXIR_USE_SYSTEM = 0" >> $(APP)/Makefile + $t echo "DEPS += lager" >> $(APP)/Makefile + $t echo "DEPS += jason" >> $(APP)/Makefile + $t echo "DEPS += phoenix" >> $(APP)/Makefile + $t echo "dep_jason = git https://github.com/michalmuskala/jason.git master" >> $(APP)/Makefile + $t echo "dep_phoenix = hex 1.7.2" >> $(APP)/Makefile + $t echo "$$(grep -v 'include erlang.mk' $(APP)/Makefile)" > $(APP)/Makefile + $t echo "include erlang.mk" >> $(APP)/Makefile + $i "Make deps" + $t $(MAKE) -C $(APP) deps $v + + $i "Check deps have compiled" + $t test -d $(APP)/deps/lager/ebin + $t test -d $(APP)/deps/jason/ebin + $t test -d $(APP)/deps/phoenix/ebin + + $i "Make the app" + $t $(MAKE) -C $(APP) app $v + + $i "Get started apps" + $t $(MAKE) -C $(APP) shell SHELL_OPTS="$(filter-out erl,$(ERL)) -pa $(APP)/deps/*/ebin/ $(APP)/ebin/ $(APP)/apps/*/ebin/ -eval \" \ + {ok, Apps} = application:ensure_all_started('$(APP)'), \ + true = lists:member(lager, Apps), \ + true = lists:member(jason, Apps), \ + true = lists:member(phoenix, Apps), \ + halt()\"" + + $i "Check modules aren't duplicated" + $t $(MAKE) -C $(APP) shell SHELL_OPTS="$(filter-out erl,$(ERL)) -pa $(APP)/deps/*/ebin/ $(APP)/ebin/ $(APP)/apps/*/ebin/ -eval \" \ + {ok, Apps} = application:ensure_all_started('$(APP)'), \ + [begin \ + {ok, Mods} = application:get_key(App, modules), \ + true = lists:sort(Mods) =:= lists:usort(Mods) \ + end || App <- Apps], \ + halt()\"" + +core-elixir-test-project_system: init +ifneq ($(shell which elixirc),) $i "Bootstrap a new OTP library named $(APP)" $t mkdir $(APP)/ $t cp ../erlang.mk $(APP)/ @@ -17,6 +62,7 @@ core-elixir-test-project: init $i "Configure Makefile" $t echo "ERLC_OPTS += +debug_info +'{parse_transform,lager_transform}'" >> $(APP)/Makefile + $t echo "ELIXIR_USE_SYSTEM = 1" >> $(APP)/Makefile $t echo "DEPS += lager" >> $(APP)/Makefile $t echo "DEPS += jason" >> $(APP)/Makefile $t echo "DEPS += phoenix" >> $(APP)/Makefile @@ -44,6 +90,42 @@ core-elixir-test-project: init true = lists:member(phoenix, Apps), \ halt()\"" + $i "Check modules aren't duplicated" + $t $(MAKE) -C $(APP) shell SHELL_OPTS="$(filter-out erl,$(ERL)) -pa $(APP)/deps/*/ebin/ $(APP)/ebin/ $(APP)/apps/*/ebin/ -eval \" \ + {ok, Apps} = application:ensure_all_started('$(APP)'), \ + [begin \ + {ok, Mods} = application:get_key(App, modules), \ + true = lists:sort(Mods) =:= lists:usort(Mods) \ + end || App <- Apps], \ + halt()\"" +else + $i "Test depends on a System Install of Elixir, skipping." +endif + +core-elixir-test-project-rel: init + $i "Bootstrap a new OTP library named $(APP)" + $t mkdir $(APP)/ + $t cp ../erlang.mk $(APP)/ + $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v + + $i "Configure Makefile" + $t echo "ERLC_OPTS += +debug_info +'{parse_transform,lager_transform}'" >> $(APP)/Makefile + $t echo "ELIXIR_USE_SYSTEM = 1" >> $(APP)/Makefile + $t echo "DEPS += lager" >> $(APP)/Makefile + $t echo "DEPS += jason" >> $(APP)/Makefile + $t echo "DEPS += phoenix" >> $(APP)/Makefile + $t echo "dep_jason = git https://github.com/michalmuskala/jason.git master" >> $(APP)/Makefile + $t echo "dep_phoenix = hex 1.7.2" >> $(APP)/Makefile + $t echo "$$(grep -v 'include erlang.mk' $(APP)/Makefile)" > $(APP)/Makefile + $t echo "include erlang.mk" >> $(APP)/Makefile + + $i "Make deps" + $t $(MAKE) -C $(APP) deps $v + + $i "Check a release can be made" + $t $(MAKE) -C $(APP) bootstrap-rel + $t $(MAKE) -C $(APP) rel + core-elixir-nif: init ifneq ($(shell which cpp >/dev/null && echo '#include "sodium.h"' | cpp -H -o /dev/null 2>&1 | head -n1 | grep -v 'No such file or directory'),) $i "Bootstrap a new OTP library named $(APP)"