Browse Source

core/erlc.mk: Support non-US-ASCII characters in paths

Internally, strings were stored using Unicode code points. However, when
being written to disk with the `file:write_file()` function, there were
converted to ISO-8859-1. According to the documentation, that is because
the file module is bytewise-oriented: the conversion to another encoding
than ISO-8859-1 is the responsibility of the caller.

Using unicode:character_to_binary() permits the script to convert the
Unicode string to an UTF-8-encoded binary.

Without this patch, the added testcase would fail with the following
error:

    gmake[3]: *** No rule to make target '(...)/erlang.mk/test/h��test_core_makedep_non_usascii_paths/deps/test_core_makedep_non_usascii_paths_dep/include/hello.hrl', needed by 'src/hello.erl'.  Stop.

In this case, the path (passed from the Makefile to the `makedep.erl`
script) contains UTF-8-encoded `é` characters but it was converted when
doing the final file I/O.
Jean-Sébastien Pédron 5 years ago
parent
commit
b0e0c1a4a8
2 changed files with 33 additions and 2 deletions
  1. 2 2
      core/erlc.mk
  2. 31 0
      test/core_makedep.mk

+ 2 - 2
core/erlc.mk

@@ -256,11 +256,11 @@ define makedep.erl
 				string:join(DirSubname ++ [atom_to_list(Target)], "/")
 		end
 	end,
-	ok = file:write_file("$(1)", [
+	ok = file:write_file("$(1)", unicode:characters_to_binary([
 		"# Generated by Erlang.mk. Edit at your own risk!\n\n",
 		[[F, "::", [[" ", D] || D <- Deps], "; @touch \$$@\n"] || {F, Deps} <- Depend],
 		"\nCOMPILE_FIRST +=", [[" ", TargetPath(CF)] || CF <- CompileFirst], "\n"
-	]),
+	])),
 	halt()
 endef
 

+ 31 - 0
test/core_makedep.mk

@@ -46,3 +46,34 @@ core-makedep-import: init
 
 	$i "Confirm the file was added by makedep"
 	$t grep COMPILE_FIRST $(APP)/$(APP).d | grep -q core/human
+
+core-makedep-non-usascii-paths: NON_USASCII_DIR = $(APP)/héhé
+core-makedep-non-usascii-paths: init
+
+	$i "Create working directory with non-US-ASCII characters"
+	$t mkdir -p $(NON_USASCII_DIR)
+
+	$i "Bootstrap a new OTP library named my_dep"
+	$t mkdir $(NON_USASCII_DIR)/my_dep/
+	$t cp ../erlang.mk $(NON_USASCII_DIR)/my_dep/
+	$t $(MAKE) -C $(NON_USASCII_DIR)/my_dep -f erlang.mk bootstrap-lib $v
+	$t mkdir $(NON_USASCII_DIR)/my_dep/include
+
+	$i "Bootstrap a new OTP application named my_app"
+	$t mkdir $(NON_USASCII_DIR)/my_app/
+	$t cp ../erlang.mk $(NON_USASCII_DIR)/my_app/
+	$t $(MAKE) -C $(NON_USASCII_DIR)/my_app -f erlang.mk bootstrap $v
+
+	$i "Add my_dep to the list of dependencies"
+	$t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = my_dep\ndep_my_dep = cp $(CURDIR)/$(NON_USASCII_DIR)/my_dep/\n"}' $(NON_USASCII_DIR)/my_app/Makefile
+
+	$i "Generate related .hrl/.erl files"
+	$t printf "%s\n" "-define(HELLO, hello)." > $(NON_USASCII_DIR)/my_dep/include/hello.hrl
+	$t printf "%s\n" "-module(hello)." "-include_lib(\"my_dep/include/hello.hrl\")." "-export([hello/0])." "hello() -> ?HELLO." > $(NON_USASCII_DIR)/my_app/src/hello.erl
+	$t $(MAKE) -C $(NON_USASCII_DIR)/my_app $v
+
+	$i "Check that all compiled files exist"
+	$t test -f $(NON_USASCII_DIR)/my_app/my_app.d
+	$t grep -qw $(NON_USASCII_DIR) $(NON_USASCII_DIR)/my_app/my_app.d
+	$t test -f $(NON_USASCII_DIR)/my_app/ebin/my_app.app
+	$t test -f $(NON_USASCII_DIR)/my_app/ebin/hello.beam