Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native Elixir Fixes #1021

Open
wants to merge 7 commits into
base: native-elixir
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions core/elixir.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2024, Tyler Hughes <[email protected]>
# Copyright (c) 2024, Tyler Hughes <[email protected]>
# Copyright (c) 2024, Loïc Hoguin <[email protected]>
# This file is part of erlang.mk and subject to the terms of the ISC License.

Expand All @@ -16,7 +16,7 @@ else
ERL_LIBS := $(ERL_LIBS):$(DEPS_DIR)/elixir/lib/
endif

elixirc_verbose_0 = @echo " EXC $(words $(EX_FILES)) files"
elixirc_verbose_0 = @echo " EXC $(words $(EX_FILES)) files";
elixirc_verbose_2 = set -x;
elixirc_verbose = $(elixirc_verbose_$(V))

Expand All @@ -25,13 +25,17 @@ define dep_autopatch_mix.erl
{ok, _} = application:ensure_all_started(elixir),
{ok, _} = application:ensure_all_started(mix),
MixFile = <<"$(call core_native_path,$(DEPS_DIR)/$1/mix.exs)">>,
[{Mod, Bin}] = elixir_compiler:file(MixFile, fun(_File, _LexerPid) -> ok end),
{Mod, Bin} =
case elixir_compiler:file(MixFile, fun(_File, _LexerPid) -> ok end) of
[{T = {_, _}, _CheckerPid}] -> T
[T = {_, _}] -> T;
end,
{module, Mod} = code:load_binary(Mod, binary_to_list(MixFile), Bin),
Project = Mod:project(),
Application = try Mod:application() catch error:undef -> [] end,
StartMod = case lists:keyfind(mod, 1, Application) of
{mod, {StartMod0, _StartArgs}} ->
StartMod0;
atom_to_list(StartMod0);
_ ->
""
end,
Expand Down Expand Up @@ -139,7 +143,15 @@ define compile_ex.erl
ModCode = list_to_atom("Elixir.Code"),
ModCode:put_compiler_option(ignore_module_conflict, true),
ModComp = list_to_atom("Elixir.Kernel.ParallelCompiler"),
{ok, Modules, _} = ModComp:compile_to_path([$(call comma_list,$(patsubst %,<<"%">>,$(EX_FILES)))], <<"ebin/">>),
lists:foreach(fun(E) -> io:format("~p ", [E]) end, Modules),
halt()
ModMixProject = list_to_atom("Elixir.Mix.Project"),
ModMixProject:in_project($(PROJECT), ".", [], fun(_MixFile) ->
case ModComp:compile_to_path([$(call comma_list,$(patsubst %,<<"%">>,$(EX_FILES)))], <<"ebin/">>) of
{ok, Modules, _} ->
halt(0);
{error, [], _WarnedModules} ->
halt(0);
{error, _ErroredModules, _WarnedModules} ->
halt(1)
end
end)
endef
4 changes: 2 additions & 2 deletions core/erlc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,11 @@ endef
ebin/$(PROJECT).app:: $(ERL_FILES) $(CORE_FILES) $(wildcard src/$(PROJECT).app.src) $(EX_FILES)
$(eval FILES_TO_COMPILE := $(filter-out $(EX_FILES) src/$(PROJECT).app.src,$?))
$(if $(strip $(FILES_TO_COMPILE)),$(call compile_erl,$(FILES_TO_COMPILE)))
$(if $(filter $?,$(EX_FILES)),$(elixirc_verbose) $(eval MODULES := $(shell $(call erlang,$(call compile_ex.erl,$(EX_FILES))))))
$(if $(filter $?,$(EX_FILES)),$(elixirc_verbose) $(call erlang,$(call compile_ex.erl,$(EX_FILES))))
# Older git versions do not have the --first-parent flag. Do without in that case.
$(eval GITDESCRIBE := $(shell git describe --dirty --abbrev=7 --tags --always --first-parent 2>/dev/null \
|| git describe --dirty --abbrev=7 --tags --always 2>/dev/null || true))
$(eval MODULES := $(MODULES) $(patsubst %,'%',$(sort $(notdir $(basename \
$(eval MODULES := $(MODULES) $(notdir $(basename $(wildcard ebin/Elixir.*))) $(patsubst %,'%',$(sort $(notdir $(basename \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't do that, the wildcard function operates on cache that is updated at the start of executing the target, so it won't know about the new Elixir beam files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, leave it with me and I'll double check against what I have locally - could be the case that I need to rollback that change

$(filter-out $(ERLC_EXCLUDE_PATHS),$(ERL_FILES) $(CORE_FILES) $(BEAM_FILES)))))))
ifeq ($(wildcard src/$(PROJECT).app.src),)
$(app_verbose) printf '$(subst %,%%,$(subst $(newline),\n,$(subst ','\'',$(call app_file,$(GITDESCRIBE),$(MODULES)))))' \
Expand Down
Loading