Skip to content

Commit

Permalink
Use the System Install if available, unless specified otherwise
Browse files Browse the repository at this point in the history
  • Loading branch information
artman41 committed Jul 2, 2023
1 parent 83dcc03 commit f5b2b61
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 10 deletions.
2 changes: 2 additions & 0 deletions core/core.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 19 additions & 9 deletions core/elixir.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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
Expand Down Expand Up @@ -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) \
Expand All @@ -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
Expand All @@ -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::
Expand Down
84 changes: 83 additions & 1 deletion test/core_elixir.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,61 @@ 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)/
$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
Expand Down Expand Up @@ -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)"
Expand Down

0 comments on commit f5b2b61

Please sign in to comment.