Skip to content

Commit

Permalink
Implement 'hex' for erlang.mk
Browse files Browse the repository at this point in the history
  • Loading branch information
artman41 committed Oct 8, 2024
1 parent 23e24a9 commit d141f2c
Show file tree
Hide file tree
Showing 19 changed files with 516 additions and 20 deletions.
3 changes: 2 additions & 1 deletion build.config
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ core/deps
# Core modules, continued.
core/beam-cache
core/erlc
core/hex
core/elixir
core/docs
core/rel
core/test
Expand All @@ -32,7 +34,6 @@ plugins/edoc
plugins/erlydtl
plugins/escript
plugins/eunit
plugins/hex
plugins/proper
plugins/protobuffs
plugins/relx
Expand Down
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 UNIQUE,$(filter-out $(firstword $1),$1)))

# Core targets.

all:: deps app rel
Expand Down
3 changes: 2 additions & 1 deletion core/deps-tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ endif
$$dep/GNUmakefile $$dep/makefile $$dep/Makefile; then \
$(MAKE) -C $$dep fetch-deps \
IS_DEP=1 \
ELIXIR_USE_SYSTEM=$(ELIXIR_USE_SYSTEM) \
ERLANG_MK_RECURSIVE_TMP_LIST=$(ERLANG_MK_RECURSIVE_TMP_LIST); \
fi \
fi \
Expand Down Expand Up @@ -119,7 +120,7 @@ endif
:; \
else \
echo $$$$dep >> $(ERLANG_MK_TMP)/query.log; \
$(MAKE) -C $(DEPS_DIR)/$$$$dep $$@ QUERY="$(QUERY)" IS_DEP=1 || true; \
$(MAKE) -C $(DEPS_DIR)/$$$$dep $$@ QUERY="$(QUERY)" IS_DEP=1 ELIXIR_USE_SYSTEM=$$(ELIXIR_USE_SYSTEM) || true; \
fi \
done)
ifeq ($(IS_APP)$(IS_DEP),)
Expand Down
24 changes: 14 additions & 10 deletions core/deps.mk
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ endif

# Core targets.

ALL_APPS_DIRS_TO_BUILD = $(if $(LOCAL_DEPS_DIRS)$(IS_APP),$(LOCAL_DEPS_DIRS),$(ALL_APPS_DIRS))
ALL_APPS_DIRS_TO_BUILD = $(if $(filter-out $(ELIXIR_BUILTINS),$(LOCAL_DEPS_DIRS))$(IS_APP),$(filter-out $(ELIXIR_BUILTINS),$(LOCAL_DEPS_DIRS)),$(ALL_APPS_DIRS))

apps:: $(ALL_APPS_DIRS) clean-tmp-deps.log | $(ERLANG_MK_TMP)
# Create ebin directory for all apps to make sure Erlang recognizes them
Expand All @@ -172,7 +172,7 @@ ifneq ($(ALL_APPS_DIRS_TO_BUILD),)
:; \
else \
echo $$dep >> $(ERLANG_MK_TMP)/apps.log; \
$(MAKE) -C $$dep $(if $(IS_TEST),test-build-app) IS_APP=1; \
$(MAKE) -C $$dep $(if $(IS_TEST),test-build-app) IS_APP=1 ELIXIR_USE_SYSTEM=$(ELIXIR_USE_SYSTEM); \
fi \
done
endif
Expand Down Expand Up @@ -214,10 +214,10 @@ ifneq ($(ALL_DEPS_DIRS),)
if [ -z "$(strip $(FULL))" ] $(if $(force_rebuild_dep),&& ! ($(call force_rebuild_dep,$$dep)),) && [ ! -L $$dep ] && [ -f $$dep/ebin/dep_built ]; then \
:; \
elif [ "$$dep" = "$(DEPS_DIR)/hut" -a "$(HUT_PATCH)" ]; then \
$(MAKE) -C $$dep app IS_DEP=1; \
$(MAKE) -C $$dep app IS_DEP=1 ELIXIR_USE_SYSTEM=$(ELIXIR_USE_SYSTEM); \
if [ ! -L $$dep ] && [ -d $$dep/ebin ]; then touch $$dep/ebin/dep_built; fi; \
elif [ -f $$dep/GNUmakefile ] || [ -f $$dep/makefile ] || [ -f $$dep/Makefile ]; then \
$(MAKE) -C $$dep IS_DEP=1; \
$(MAKE) -C $$dep IS_DEP=1 ELIXIR_USE_SYSTEM=$(ELIXIR_USE_SYSTEM); \
if [ ! -L $$dep ] && [ -d $$dep/ebin ]; then touch $$dep/ebin/dep_built; fi; \
else \
echo "Error: No Makefile to build dependency $$dep." >&2; \
Expand All @@ -238,6 +238,8 @@ define dep_autopatch
rm -rf $(DEPS_DIR)/$1/ebin/; \
$(call erlang,$(call dep_autopatch_appsrc.erl,$(1))); \
$(call dep_autopatch_erlang_mk,$(1)); \
elif [ -f $(DEPS_DIR)/$1/mix.exs ]; then \
$(call dep_autopatch_mix,$(1)); \
elif [ -f $(DEPS_DIR)/$(1)/Makefile ]; then \
if [ -f $(DEPS_DIR)/$1/rebar.lock ]; then \
$(call dep_autopatch2,$1); \
Expand Down Expand Up @@ -650,7 +652,7 @@ define dep_autopatch_rebar.erl
_ ->
Path = "$(call core_native_path,$(DEPS_DIR)/)" ++ atom_to_list(P),
io:format("~s", [os:cmd("$(MAKE) -C $(call core_native_path,$(DEPS_DIR)/$1) " ++ Path)]),
io:format("~s", [os:cmd("$(MAKE) -C " ++ Path ++ " IS_DEP=1")]),
io:format("~s", [os:cmd("$(MAKE) -C " ++ Path ++ " IS_DEP=1 ELIXIR_USE_SYSTEM=$(ELIXIR_USE_SYSTEM)")]),
code:add_patha(Path ++ "/ebin")
end
end
Expand Down Expand Up @@ -780,14 +782,16 @@ define dep_fetch_ln
ln -s $(call dep_repo,$(1)) $(DEPS_DIR)/$(call dep_name,$(1));
endef

HEX_REPO = https://repo.hex.pm

ifeq ($(CACHE_DEPS),1)

# Hex only has a package version. No need to look in the Erlang.mk packages.
define dep_fetch_hex
mkdir -p $(CACHE_DIR)/hex $(DEPS_DIR)/$1; \
$(eval hex_tar_name=$(if $(word 3,$(dep_$1)),$(word 3,$(dep_$1)),$1)-$(strip $(word 2,$(dep_$1))).tar) \
$(if $(wildcard $(CACHE_DIR)/hex/$(hex_tar_name)),,$(call core_http_get,$(CACHE_DIR)/hex/$(hex_tar_name),\
https://repo.hex.pm/tarballs/$(hex_tar_name);)) \
$(HEX_REPO)/tarballs/$(hex_tar_name);)) \
tar -xOf $(CACHE_DIR)/hex/$(hex_tar_name) contents.tar.gz | tar -C $(DEPS_DIR)/$1 -xzf -;
endef

Expand All @@ -797,7 +801,7 @@ else
define dep_fetch_hex
mkdir -p $(ERLANG_MK_TMP)/hex $(DEPS_DIR)/$1; \
$(call core_http_get,$(ERLANG_MK_TMP)/hex/$1.tar,\
https://repo.hex.pm/tarballs/$(if $(word 3,$(dep_$1)),$(word 3,$(dep_$1)),$1)-$(strip $(word 2,$(dep_$1))).tar); \
$(HEX_REPO)/tarballs/$(if $(word 3,$(dep_$1)),$(word 3,$(dep_$1)),$1)-$(strip $(word 2,$(dep_$1))).tar); \
tar -xOf $(ERLANG_MK_TMP)/hex/$1.tar contents.tar.gz | tar -C $(DEPS_DIR)/$1 -xzf -;
endef

Expand Down Expand Up @@ -841,7 +845,7 @@ endif
.PHONY: autopatch-$(call dep_name,$1)

autopatch-$(call dep_name,$1)::
$(verbose) if [ "$1" = "elixir" -a "$(ELIXIR_PATCH)" ]; then \
$(verbose) if [ "$1" = "elixir" ]; then \
ln -s lib/elixir/ebin $(DEPS_DIR)/elixir/; \
else \
$$(call dep_autopatch,$(call dep_name,$1)) \
Expand All @@ -855,14 +859,14 @@ clean:: clean-apps

clean-apps:
$(verbose) set -e; for dep in $(ALL_APPS_DIRS) ; do \
$(MAKE) -C $$dep clean IS_APP=1; \
$(MAKE) -C $$dep clean IS_APP=1 ELIXIR_USE_SYSTEM=$(ELIXIR_USE_SYSTEM); \
done

distclean:: distclean-apps

distclean-apps:
$(verbose) set -e; for dep in $(ALL_APPS_DIRS) ; do \
$(MAKE) -C $$dep distclean IS_APP=1; \
$(MAKE) -C $$dep distclean IS_APP=1 ELIXIR_USE_SYSTEM=$(ELIXIR_USE_SYSTEM); \
done
endif

Expand Down
2 changes: 1 addition & 1 deletion core/docs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ ifneq ($(SKIP_DEPS),)
doc-deps:
else
doc-deps: $(ALL_DOC_DEPS_DIRS)
$(verbose) set -e; for dep in $(ALL_DOC_DEPS_DIRS) ; do $(MAKE) -C $$dep IS_DEP=1; done
$(verbose) set -e; for dep in $(ALL_DOC_DEPS_DIRS) ; do $(MAKE) -C $$dep IS_DEP=1 ELIXIR_USE_SYSTEM=$(ELIXIR_USE_SYSTEM); done
endif
Loading

0 comments on commit d141f2c

Please sign in to comment.