From 323215fc992c4b1e7f6c03b0804c66f4c8e9b7c0 Mon Sep 17 00:00:00 2001 From: yoshi~ Date: Tue, 3 Dec 2024 00:35:41 +0100 Subject: [PATCH] fix unicode bugs --- CHANGELOG.md | 4 ++++ compiler-cli/templates/gleam@@compile.erl | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 807b9365a5c..0cb8bbd5a47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -237,6 +237,10 @@ - Fixed a bug where the inferred variant of values was not properly cached, leading to incorrect errors on incremental builds and in the Language Server. ([Surya Rose](https://github.com/GearsDatapacks)) + + - Fixed a bug where Gleam would be unable to compile to BEAM bytecode if the + project path contains a non-ascii character. + ([yoshi](https://github.com/joshi-monster)) ## v1.6.1 - 2024-11-19 diff --git a/compiler-cli/templates/gleam@@compile.erl b/compiler-cli/templates/gleam@@compile.erl index 4622976100f..808eb0677fa 100644 --- a/compiler-cli/templates/gleam@@compile.erl +++ b/compiler-cli/templates/gleam@@compile.erl @@ -4,12 +4,15 @@ % TODO: Don't concurrently print warnings and errors % TODO: Some tests -main(_) -> compile_package_loop(). +main(_) -> + ok = io:setopts([binary, {encoding, utf8}]), + ok = configure_logging(), + compile_package_loop(). compile_package_loop() -> - case file:read_line(standard_io) of + case io:get_line("") of eof -> ok; - {ok, Line} -> + Line -> Chars = unicode:characters_to_list(Line), {ok, Tokens, _} = erl_scan:string(Chars), {ok, {Lib, Out, Modules}} = erl_parse:parse_term(Tokens), @@ -25,9 +28,8 @@ compile_package(Lib, Out, Modules) -> filename:extension(Module) =:= ".ex" end, {ElixirModules, ErlangModules} = lists:partition(IsElixirModule, Modules), - ok = configure_logging(), - ok = add_lib_to_erlang_path(Lib), ok = filelib:ensure_dir([Out, $/]), + ok = add_lib_to_erlang_path(Lib), {ErlangOk, _ErlangBeams} = compile_erlang(ErlangModules, Out), {ElixirOk, _ElixirBeams} = case ErlangOk of true -> compile_elixir(ElixirModules, Out); @@ -166,6 +168,6 @@ configure_logging() -> log(Term) -> case persistent_term:get(gleam_logging_enabled) of - true -> erlang:display(Term), ok; + true -> io:fwrite("~p~n", [Term]), ok; false -> ok end.