From 1a5852f6750615f72e3523bb8685f98210f81e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sat, 24 Nov 2018 22:51:40 +0100 Subject: Add the git-subfolder fetch method It clones and checkouts like the git fetch method, but does so in the Erlang.mk temporary directory. It then creates a symbolic link to the subfolder for the dependency. --- core/deps.mk | 10 ++++++++++ doc/src/guide/deps.asciidoc | 1 + test/core_deps.mk | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/core/deps.mk b/core/deps.mk index 2b14c4f..19a2410 100644 --- a/core/deps.mk +++ b/core/deps.mk @@ -544,6 +544,16 @@ define dep_fetch_git cd $(DEPS_DIR)/$(call dep_name,$(1)) && git checkout -q $(call dep_commit,$(1)); endef +define dep_fetch_git-subfolder + mkdir -p $(ERLANG_MK_TMP)/git-subfolder; \ + git clone -q -n -- $(call dep_repo,$1) \ + $(ERLANG_MK_TMP)/git-subfolder/$(call dep_name,$1); \ + cd $(ERLANG_MK_TMP)/git-subfolder/$(call dep_name,$1) \ + && git checkout -q $(call dep_commit,$1); \ + ln -s $(ERLANG_MK_TMP)/git-subfolder/$(call dep_name,$1)/$(word 4,$(dep_$(1))) \ + $(DEPS_DIR)/$(call dep_name,$1); +endef + define dep_fetch_git-submodule git submodule update --init -- $(DEPS_DIR)/$1; endef diff --git a/doc/src/guide/deps.asciidoc b/doc/src/guide/deps.asciidoc index 84a53de..47e1bee 100644 --- a/doc/src/guide/deps.asciidoc +++ b/doc/src/guide/deps.asciidoc @@ -163,6 +163,7 @@ The following table lists all existing methods: |=== | Name | Format | Description | git | git repo commit | Clone the Git repository and checkout the given version +| git-subfolder | git repo commit subfolder | Clone the Git repository, checkout the given version and use one of its subfolders as a dependency | git-submodule | git-submodule | Initialize and update the Git submodule | hg | hg repo commit | Clone the Mercurial repository and update to the given version | svn | svn repo | Checkout the given SVN repository diff --git a/test/core_deps.mk b/test/core_deps.mk index 922c69b..3403f58 100644 --- a/test/core_deps.mk +++ b/test/core_deps.mk @@ -342,6 +342,47 @@ endif {ok, \"1.0.0\"} = application:get_key(cowboy, vsn), \ halt()" +core-deps-fetch-git-subfolder: 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 + + $i "Bootstrap a new OTP library named my_dep as a subfolder inside $(APP)" + $t mkdir -p $(APP)/git_repo/my_dep + $t cp ../erlang.mk $(APP)/git_repo/my_dep/ + $t $(MAKE) -C $(APP)/git_repo/my_dep/ -f erlang.mk bootstrap-lib $v +# Create an empty file so src/ gets committed. + $t touch $(APP)/git_repo/my_dep/src/README + $t cd $(APP)/git_repo && \ + git init -q && \ + git config user.email "testsuite@erlang.mk" && \ + git config user.name "test suite" && \ + git add . && \ + git commit -q --no-gpg-sign -m "Tests" + + $i "Add my_dep to the list of dependencies" + $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = my_dep\ndep_my_dep = git-subfolder file://$(abspath $(APP)/git_repo) master my_dep\n"}' $(APP)/Makefile + +ifdef LEGACY + $i "Add my_dep to the applications key in the .app.src file" + $t perl -ni.bak -e 'print;if ($$.==7) {print "\t\tmy_dep,\n"}' $(APP)/src/$(APP).app.src +endif + + $i "Build the application" + $t $(MAKE) -C $(APP) $v + + $i "Check that the dependency was fetched" + $t test -d $(APP)/deps/my_dep + + $i "Check that the application was compiled correctly" + $t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/*/ebin/ -eval " \ + [ok = application:load(App) || App <- [$(APP), my_dep]], \ + {ok, Deps} = application:get_key($(APP), applications), \ + true = lists:member(my_dep, Deps), \ + halt()" + core-deps-fetch-git-submodule: build clean $i "Bootstrap a new OTP library named $(APP)" -- cgit v1.2.3