Browse Source

Autopatch: better handle COMPILE_FIRST/erl_first_files

This is still a bit hackish but it appears that some projects
have wrong erl_first_files entries (module exists but not at
the location configured) and so we have to do a bit of
manipulation before we can find the module. We also need
to be cautious about .yrl/.xrl because their corresponding
.erl files may not exist in the repository before compilation
yet can be listed in erl_first_files.
Loïc Hoguin 2 years ago
parent
commit
dcc2741b60
2 changed files with 58 additions and 2 deletions
  1. 5 2
      core/deps.mk
  2. 53 0
      test/core_app.mk

+ 5 - 2
core/deps.mk

@@ -468,13 +468,16 @@ define dep_autopatch_rebar.erl
 	fun() ->
 	fun() ->
 		case lists:keyfind(erl_first_files, 1, Conf) of
 		case lists:keyfind(erl_first_files, 1, Conf) of
 			false -> ok;
 			false -> ok;
-			{_, Files} ->
+			{_, Files0} ->
+				Files = [begin
+					hd(filelib:wildcard("$(call core_native_path,$(DEPS_DIR)/$1/src/**/" ++ filename:rootname(F) ++ ".*rl")))
+				end || "src/" ++ F <- Files0],
 				Names = [[" ", case lists:reverse(F) of
 				Names = [[" ", case lists:reverse(F) of
 					"lre." ++ Elif -> lists:reverse(Elif);
 					"lre." ++ Elif -> lists:reverse(Elif);
 					"lrx." ++ Elif -> lists:reverse(Elif);
 					"lrx." ++ Elif -> lists:reverse(Elif);
 					"lry." ++ Elif -> lists:reverse(Elif);
 					"lry." ++ Elif -> lists:reverse(Elif);
 					Elif -> lists:reverse(Elif)
 					Elif -> lists:reverse(Elif)
-				end] || "src/" ++ F <- Files],
+				end] || "$(call core_native_path,$(DEPS_DIR)/$1/src/)" ++ F <- Files],
 				Write(io_lib:format("COMPILE_FIRST +=~s\n", [Names]))
 				Write(io_lib:format("COMPILE_FIRST +=~s\n", [Names]))
 		end
 		end
 	end(),
 	end(),

+ 53 - 0
test/core_app.mk

@@ -274,6 +274,59 @@ endif
 		true = ID =/= [], \
 		true = ID =/= [], \
 		halt()"
 		halt()"
 
 
+core-app-compile-first: init
+
+	$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 "Generate .erl files"
+	$t echo "-module(boy)." > $(APP)/src/boy.erl
+	$t echo "-module(girl)." > $(APP)/src/girl.erl
+	$t echo "-module(first)." > $(APP)/src/first.erl
+
+	$i "Define COMPILE_FIRST"
+	$t echo "COMPILE_FIRST = first" >> $(APP)/Makefile
+
+	$i "Build the application"
+	$t $(MAKE) -C $(APP) $v
+
+	$i "Check that the application was compiled correctly"
+	$t $(ERL) -pa $(APP)/ebin/ -eval " \
+		ok = application:start($(APP)), \
+		{ok, Mods = [boy, first, girl]} \
+			= application:get_key($(APP), modules), \
+		[{module, M} = code:load_file(M) || M <- Mods], \
+		halt()"
+
+core-app-compile-first-sub-directory: init
+
+	$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 "Generate .erl files"
+	$t echo "-module(boy)." > $(APP)/src/boy.erl
+	$t echo "-module(girl)." > $(APP)/src/girl.erl
+	$t mkdir $(APP)/src/sub/
+	$t echo "-module(first)." > $(APP)/src/sub/first.erl
+
+	$i "Define COMPILE_FIRST with a module in a sub-directory"
+	$t echo "COMPILE_FIRST = sub/first" >> $(APP)/Makefile
+
+	$i "Build the application"
+	$t $(MAKE) -C $(APP) $v
+
+	$i "Check that the application was compiled correctly"
+	$t $(ERL) -pa $(APP)/ebin/ -eval " \
+		ok = application:start($(APP)), \
+		{ok, Mods = [boy, first, girl]} \
+			= application:get_key($(APP), modules), \
+		[{module, M} = code:load_file(M) || M <- Mods], \
+		halt()"
+
 ifndef LEGACY
 ifndef LEGACY
 core-app-env: init
 core-app-env: init