Skip to content

Commit 94dba57

Browse files
committed
Avoid calling core_native_path in dep_fetch_hex many times
On Windows, this executes a shell to determine the native path, which is very expensive. The result is always the same, so make sure `core_native_path` is called once instead. For example, this saves a significant amount of time when compiling RabbitMQ on Windows.
1 parent 973ccc3 commit 94dba57

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

core/core.mk

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ gen_verbose_esc_0 = @echo " GEN " $$@;
5959
gen_verbose_esc_2 = set -x;
6060
gen_verbose_esc = $(gen_verbose_esc_$(V))
6161

62-
# Temporary files directory.
63-
64-
ERLANG_MK_TMP ?= $(CURDIR)/.erlang.mk
65-
export ERLANG_MK_TMP
66-
6762
# "erl" command.
6863

6964
ERL = erl -noinput -boot no_dot_erlang -kernel start_distribution false +P 1024 +Q 1024
@@ -98,6 +93,19 @@ endif
9893
export PLATFORM
9994
endif
10095

96+
ifeq ($(PLATFORM),msys2)
97+
core_native_path = $(shell cygpath -m $1)
98+
else
99+
core_native_path = $1
100+
endif
101+
102+
# Temporary files directory.
103+
104+
ERLANG_MK_TMP ?= $(CURDIR)/.erlang.mk
105+
export ERLANG_MK_TMP
106+
107+
NATIVE_ERLANG_MK_TMP = $(eval NATIVE_ERLANG_MK_TMP := $$(call core_native_path,$(ERLANG_MK_TMP)))$(NATIVE_ERLANG_MK_TMP)
108+
101109
# Core targets.
102110

103111
all:: deps app rel
@@ -174,12 +182,6 @@ define erlang
174182
$(ERL) $2 -pz $(ERLANG_MK_TMP)/rebar3/_build/prod/lib/*/ebin/ -eval "$(subst $(newline),,$(call escape_dquotes,$1))" -- erlang.mk
175183
endef
176184

177-
ifeq ($(PLATFORM),msys2)
178-
core_native_path = $(shell cygpath -m $1)
179-
else
180-
core_native_path = $1
181-
endif
182-
183185
core_http_get = curl -Lf$(if $(filter-out 0,$V),,s)o $(call core_native_path,$1) $2
184186

185187
core_eq = $(and $(findstring $1,$2),$(findstring $2,$1))

core/deps.mk

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ CACHE_DEPS ?= 0
3131
CACHE_DIR ?= $(if $(XDG_CACHE_HOME),$(XDG_CACHE_HOME),$(HOME)/.cache)/erlang.mk
3232
export CACHE_DIR
3333

34+
NATIVE_CACHE_DIR = $(eval NATIVE_CACHE_DIR := $$(call core_native_path,$(CACHE_DIR)))$(NATIVE_CACHE_DIR)
35+
3436
HEX_CONFIG ?=
3537

3638
define hex_config.erl
@@ -830,7 +832,7 @@ define hex_get_tarball.erl
830832
Config = $(hex_config.erl),
831833
case hex_repo:get_tarball(Config, <<"$1">>, <<"$(strip $2)">>) of
832834
{ok, {200, _, Tarball}} ->
833-
ok = file:write_file("$(call core_native_path,$3)", Tarball),
835+
ok = file:write_file("$3", Tarball),
834836
halt(0);
835837
{ok, {Status, _, Errors}} ->
836838
io:format("Error ~b: ~0p~n", [Status, Errors]),
@@ -846,7 +848,7 @@ define dep_fetch_hex
846848
$(eval hex_pkg_name := $(if $(word 3,$(dep_$1)),$(word 3,$(dep_$1)),$1)) \
847849
$(eval hex_tar_name := $(hex_pkg_name)-$(strip $(word 2,$(dep_$1))).tar) \
848850
$(if $(wildcard $(CACHE_DIR)/hex/$(hex_tar_name)),,\
849-
$(call erlang,$(call hex_get_tarball.erl,$(hex_pkg_name),$(word 2,$(dep_$1)),$(CACHE_DIR)/hex/$(hex_tar_name)));) \
851+
$(call erlang,$(call hex_get_tarball.erl,$(hex_pkg_name),$(word 2,$(dep_$1)),$(NATIVE_CACHE_DIR)/hex/$(hex_tar_name)));) \
850852
tar -xOf $(CACHE_DIR)/hex/$(hex_tar_name) contents.tar.gz | tar -C $(DEPS_DIR)/$1 -xzf -;
851853
endef
852854

@@ -855,7 +857,7 @@ else
855857
# Hex only has a package version. No need to look in the Erlang.mk packages.
856858
define dep_fetch_hex
857859
mkdir -p $(ERLANG_MK_TMP)/hex $(DEPS_DIR)/$1; \
858-
$(call erlang,$(call hex_get_tarball.erl,$(if $(word 3,$(dep_$1)),$(word 3,$(dep_$1)),$1),$(word 2,$(dep_$1)),$(ERLANG_MK_TMP)/hex/$1.tar)); \
860+
$(call erlang,$(call hex_get_tarball.erl,$(if $(word 3,$(dep_$1)),$(word 3,$(dep_$1)),$1),$(word 2,$(dep_$1)),$(NATIVE_ERLANG_MK_TMP)/hex/$1.tar)); \
859861
tar -xOf $(ERLANG_MK_TMP)/hex/$1.tar contents.tar.gz | tar -C $(DEPS_DIR)/$1 -xzf -;
860862
endef
861863

0 commit comments

Comments
 (0)