Browse Source

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.
Loïc Hoguin 6 years ago
parent
commit
1a5852f675
3 changed files with 52 additions and 0 deletions
  1. 10 0
      core/deps.mk
  2. 1 0
      doc/src/guide/deps.asciidoc
  3. 41 0
      test/core_deps.mk

+ 10 - 0
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

+ 1 - 0
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

+ 41 - 0
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)"