Browse Source

core/erlc.mk: added src subfolders support in makedep.erl

Oleksiy Kebkal 8 years ago
parent
commit
094ece5472
2 changed files with 58 additions and 2 deletions
  1. 15 2
      core/erlc.mk
  2. 43 0
      test/core_makedep.mk

+ 15 - 2
core/erlc.mk

@@ -188,7 +188,12 @@ define makedep.erl
 		(F, Mod, include_lib, "$1/include/" ++ Hrl) -> AddHd(F, Mod, "include/" ++ Hrl);
 		(F, Mod, include_lib, Hrl) -> AddHd(F, Mod, "include/" ++ Hrl);
 		(F, Mod, import, {Imp, _}) ->
-			case filelib:is_file("src/" ++ atom_to_list(Imp) ++ ".erl") of
+			IsFile =
+				case lists:keyfind(Imp, 1, Modules) of
+					false -> false;
+					{_, FilePath} -> filelib:is_file(FilePath)
+				end,
+			case IsFile of
 				false -> ok;
 				true -> Add(Mod, Imp)
 			end;
@@ -212,9 +217,17 @@ define makedep.erl
 	end || F <- ErlFiles],
 	Depend = sofs:to_external(sofs:relation_to_family(sofs:relation(ets:tab2list(E)))),
 	CompileFirst = [X || X <- lists:reverse(digraph_utils:topsort(G)), [] =/= digraph:in_neighbours(G, X)],
+	TargetPath = fun(Target) ->
+		case lists:keyfind(Target, 1, Modules) of
+			false -> "";
+			{_, DepFile} ->
+				DirSubname = tl(string:tokens(filename:dirname(DepFile), "/")),
+				string:join(DirSubname ++ [atom_to_list(Target)], "/")
+		end
+	end,
 	ok = file:write_file("$(1)", [
 		[[F, "::", [[" ", D] || D <- Deps], "; @touch \$$@\n"] || {F, Deps} <- Depend],
-		"\nCOMPILE_FIRST +=", [[" ", atom_to_list(CF)] || CF <- CompileFirst], "\n"
+		"\nCOMPILE_FIRST +=", [[" ", TargetPath(CF)] || CF <- CompileFirst], "\n"
 	]),
 	halt()
 endef

+ 43 - 0
test/core_makedep.mk

@@ -0,0 +1,43 @@
+# Core: COMPILE_FIRST dependencies generation.
+
+CORE_MAKEDEP_CASES = behaviour import
+CORE_MAKEDEP_TARGETS = $(addprefix core-makedep-,$(CORE_MAKEDEP_CASES))
+
+.PHONY: core-makedep $(CORE_MAKEDEP_TARGETS)
+
+core-makedep: $(CORE_MAKEDEP_TARGETS)
+
+core-makedep-behaviour: 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 $(APP)/src/core
+	$i "Generate related .erl files"
+	$t printf "%s\n" "-module(human)." "-callback live() -> 'ok'." > $(APP)/src/core/human.erl
+	$t printf "%s\n" "-module(boy)." "-behaviour(human)." "-export([live/0])." "live() -> ok." > $(APP)/src/boy.erl
+	$t $(MAKE) -C $(APP) $v
+	$i "Check that all compiled files exist"
+	$t test -f $(APP)/$(APP).d
+	$t test -f $(APP)/ebin/$(APP).app
+	$t test -f $(APP)/ebin/boy.beam
+	$t test -f $(APP)/ebin/human.beam
+
+core-makedep-import: 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 $(APP)/src/core
+	$i "Generate related .erl files"
+	$t printf "%s\n" "-module(human)." "-export([live/0])." "live() -> ok." > $(APP)/src/core/human.erl
+	$t printf "%s\n" "-module(boy)." "-import(human,[live/0])." > $(APP)/src/boy.erl
+	$t $(MAKE) -C $(APP) $v
+	$i "Check that all compiled files exist"
+	$t test -f $(APP)/$(APP).d
+	$t test -f $(APP)/ebin/$(APP).app
+	$t test -f $(APP)/ebin/boy.beam
+	$t test -f $(APP)/ebin/human.beam
+	$t grep COMPILE  $(APP)/$(APP).d | grep core
+
+