From 5401192f38ff407a749fccfdb8f2f9aab012efea Mon Sep 17 00:00:00 2001 From: Krister Svanlund Date: Mon, 11 Jul 2016 16:45:26 +0200 Subject: Build apps/* only once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replicating the behavior for deps/*. With refactoring from Loïc. --- core/core.mk | 2 +- core/deps.mk | 30 +++++++++++++++++++++++------- test/core_deps.mk | 38 +++++++++++++++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 9 deletions(-) diff --git a/core/core.mk b/core/core.mk index 8188bc3..6af2db9 100644 --- a/core/core.mk +++ b/core/core.mk @@ -12,7 +12,7 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -.PHONY: all app deps search rel docs install-docs check tests clean distclean help erlang-mk +.PHONY: all app apps deps search rel docs install-docs check tests clean distclean help erlang-mk ERLANG_MK_FILENAME := $(realpath $(lastword $(MAKEFILE_LIST))) diff --git a/core/deps.mk b/core/deps.mk index 2527c03..ac8eaaa 100644 --- a/core/deps.mk +++ b/core/deps.mk @@ -48,19 +48,35 @@ dep_verbose = $(dep_verbose_$(V)) # Core targets. -ifneq ($(SKIP_DEPS),) -deps:: +ifdef IS_APP +apps:: else -deps:: $(ALL_DEPS_DIRS) -ifndef IS_APP +apps:: $(ALL_APPS_DIRS) +ifeq ($(IS_APP)$(IS_DEP),) + $(verbose) rm -f $(ERLANG_MK_TMP)/apps.log +endif + $(verbose) mkdir -p $(ERLANG_MK_TMP) +# Create ebin directory for all apps to make sure Erlang recognizes them +# as proper OTP applications when using -include_lib. This is a temporary +# fix, a proper fix would be to compile apps/* in the right order. $(verbose) for dep in $(ALL_APPS_DIRS) ; do \ - mkdir -p $$dep/ebin; \ + mkdir -p $$dep/ebin || exit $$?; \ done $(verbose) for dep in $(ALL_APPS_DIRS) ; do \ - $(MAKE) -C $$dep IS_APP=1 || exit $$?; \ + if grep -qs ^$$dep$$ $(ERLANG_MK_TMP)/apps.log; then \ + :; \ + else \ + echo $$dep >> $(ERLANG_MK_TMP)/apps.log; \ + $(MAKE) -C $$dep IS_APP=1 || exit $$?; \ + fi \ done endif -ifneq ($(IS_DEP),1) + +ifneq ($(SKIP_DEPS),) +deps:: +else +deps:: $(ALL_DEPS_DIRS) apps +ifeq ($(IS_APP)$(IS_DEP),) $(verbose) rm -f $(ERLANG_MK_TMP)/deps.log endif $(verbose) mkdir -p $(ERLANG_MK_TMP) diff --git a/test/core_deps.mk b/test/core_deps.mk index 490f3d8..767b66b 100644 --- a/test/core_deps.mk +++ b/test/core_deps.mk @@ -1,6 +1,6 @@ # Core: Packages and dependencies. -CORE_DEPS_CASES = apps apps-conflict apps-deep-conflict apps-dir apps-dir-include-lib apps-new-app apps-new-lib apps-new-tpl apps-only autopatch-rebar build-c-8cc build-c-imagejs build-erl build-js dep-commit dir doc fetch-cp fetch-custom fetch-fail-bad fetch-fail-unknown fetch-git fetch-git-submodule fetch-hex fetch-hg fetch-legacy fetch-svn ignore mv mv-rebar no-autopatch no-autopatch-erlang-mk no-autopatch-rebar order-first order-top otp pkg rel search shell skip test +CORE_DEPS_CASES = apps apps-build-count apps-conflict apps-deep-conflict apps-dir apps-dir-include-lib apps-new-app apps-new-lib apps-new-tpl apps-only autopatch-rebar build-c-8cc build-c-imagejs build-erl build-js dep-commit dir doc fetch-cp fetch-custom fetch-fail-bad fetch-fail-unknown fetch-git fetch-git-submodule fetch-hex fetch-hg fetch-legacy fetch-svn ignore mv mv-rebar no-autopatch no-autopatch-erlang-mk no-autopatch-rebar order-first order-top otp pkg rel search shell skip test CORE_DEPS_TARGETS = $(addprefix core-deps-,$(CORE_DEPS_CASES)) .PHONY: core-deps $(CORE_DEPS_TARGETS) @@ -101,6 +101,42 @@ endif [{module, M} = code:load_file(M) || M <- Mods], \ halt()" +core-deps-apps-build-count: build clean + + $i "Bootstrap a new OTP library named $(APP)" + $t mkdir $(APP)/ + $t cp ../erlang.mk $(APP)/ + $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v + + $t mkdir -p "$(APP)/priv/dep" + $t echo "PROJECT = fake_dep" > $(APP)/priv/dep/Makefile + $t echo "include ../../erlang.mk" >> $(APP)/priv/dep/Makefile + + $i "Bootstrap a repository-local application my_app" + $t echo "DEPS = dep1 dep2 dep3 dep4" > $(APP)/Makefile + $t echo "dep_dep1 = cp ./priv/dep" >> $(APP)/Makefile + $t echo "dep_dep2 = cp ./priv/dep" >> $(APP)/Makefile + $t echo "dep_dep3 = cp ./priv/dep" >> $(APP)/Makefile + $t echo "dep_dep4 = cp ./priv/dep" >> $(APP)/Makefile + $t echo "include erlang.mk" >> $(APP)/Makefile + + $i "Create a new application app_one" + $t $(MAKE) -C $(APP) new-app in=app_one $v + $t echo "all::" >> $(APP)/apps/app_one/Makefile + $t echo " @echo -n '#' >> count" >> $(APP)/apps/app_one/Makefile + + $i "Create a new application app_two" + $t $(MAKE) -C $(APP) new-app in=app_two $v + $t echo "all::" >> $(APP)/apps/app_two/Makefile + $t echo " @echo -n '#' >> count" >> $(APP)/apps/app_two/Makefile + + $i "Build the application" + $t $(MAKE) -C $(APP) $v + + $i "Check the number of times each app was compiled" + $t test "`wc -c $(APP)/apps/app_one/count | awk '{printf $$1}'`" -eq 1 + $t test "`wc -c $(APP)/apps/app_two/count | awk '{printf $$1}'`" -eq 1 + core-deps-apps-conflict: build clean $i "Bootstrap a new OTP library named $(APP)" -- cgit v1.2.3