Skip to content

Commit cdd312b

Browse files
committed
Support proper encoding in releases config (#10012)
1 parent 0cc5373 commit cdd312b

File tree

6 files changed

+18
-14
lines changed

6 files changed

+18
-14
lines changed

lib/elixir/lib/config/provider.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ defmodule Config.Provider do
350350
defp write_config!(config, path) do
351351
contents = :io_lib.format("%% coding: utf-8~n~tw.~n", [config])
352352

353-
case File.write(path, contents, [:utf8]) do
353+
case File.write(path, IO.chardata_to_string(contents)) do
354354
:ok ->
355355
:ok
356356

lib/elixir/test/elixir/config/provider_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ defmodule Config.ProviderTest do
8383
assert config[@config_app] == [config_providers_booted: {:booted, nil}]
8484
end
8585

86-
@tag sys_config: [my_app: [encoding: {:"£", "£", '£'}]]
86+
@tag sys_config: [my_app: [encoding: {:time_μs, :"£", "£", '£'}]]
8787
test "writes sys_config with encoding" do
8888
init_and_assert_boot()
8989
config = consult(@sys_config)
90-
assert config[:my_app][:encoding] == {:"£", "£", '£'}
90+
assert config[:my_app][:encoding] == {:time_μs, :"£", "£", '£'}
9191
end
9292

9393
@tag sys_config: [my_app: [key: :old_value, sys_key: :sys_value, extra_config: :old_value]]
@@ -185,6 +185,6 @@ defmodule Config.ProviderTest do
185185
end
186186

187187
defp write_sys_config!(data) do
188-
File.write!(@sys_config, :io_lib.format("~tw.~n", [data]), [:utf8])
188+
File.write!(@sys_config, IO.chardata_to_string(:io_lib.format("~tw.~n", [data])))
189189
end
190190
end

lib/mix/lib/mix/release.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ defmodule Mix.Release do
402402
args = [runtime_config?, sys_config]
403403
format = "%% coding: utf-8~n%% RUNTIME_CONFIG=~s~n~tw.~n"
404404
File.mkdir_p!(Path.dirname(path))
405-
File.write!(path, :io_lib.format(format, args), [:utf8])
405+
File.write!(path, IO.chardata_to_string(:io_lib.format(format, args)))
406406

407407
case :file.consult(path) do
408408
{:ok, _} ->
@@ -512,7 +512,7 @@ defmodule Mix.Release do
512512
:ok | {:error, String.t()}
513513
def make_boot_script(release, path, modes, prepend_paths \\ []) do
514514
with {:ok, rel_spec} <- build_release_spec(release, modes) do
515-
File.write!(path <> ".rel", consultable(rel_spec), [:utf8])
515+
File.write!(path <> ".rel", consultable(rel_spec))
516516

517517
sys_path = String.to_charlist(path)
518518

@@ -535,7 +535,7 @@ defmodule Mix.Release do
535535
|> prepend_paths_to_script(prepend_paths)
536536

537537
script = {:script, rel_info, instructions}
538-
File.write!(script_path, consultable(script), [:utf8])
538+
File.write!(script_path, consultable(script))
539539
:ok = :systools.script2boot(sys_path)
540540

541541
{:error, module, info} ->
@@ -657,7 +657,7 @@ defmodule Mix.Release do
657657
end
658658

659659
defp consultable(term) do
660-
:io_lib.format("%% coding: utf-8~n~tp.~n", [term])
660+
IO.chardata_to_string(:io_lib.format("%% coding: utf-8~n~tp.~n", [term]))
661661
end
662662

663663
@doc """
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import Config
22

33
config :release_test, :static, :was_set
4-
config :release_test, :encoding, {:"£", "£", '£'}
4+
config :release_test, :encoding, {:time_μs, :"£", "£", '£'}

lib/mix/test/mix/release_test.exs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,15 @@ defmodule Mix.ReleaseTest do
488488
end
489489

490490
test "writes sys_config with encoding" do
491-
assert make_sys_config(release([]), [encoding: {:"£", "£", '£'}], "unused/runtime/path") ==
491+
assert make_sys_config(
492+
release([]),
493+
[encoding: {:time_μs, :"£", "£", '£'}],
494+
"unused/runtime/path"
495+
) ==
492496
:ok
493497

494498
{:ok, contents} = :file.consult(@sys_config)
495-
assert contents == [[encoding: {:"£", "£", '£'}]]
499+
assert contents == [[encoding: {:time_μs, :"£", "£", '£'}]]
496500
end
497501

498502
test "writes the given sys_config with config providers" do

lib/mix/test/mix/tasks/release_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ defmodule Mix.Tasks.ReleaseTest do
281281
assert %{
282282
app_dir: app_dir,
283283
cookie_env: ^cookie,
284-
encoding: {:"£", "£", '£'},
284+
encoding: {:time_μs, :"£", "£", '£'},
285285
mode: :embedded,
286286
node: release_node("release_test"),
287287
protocols_consolidated?: true,
@@ -322,7 +322,7 @@ defmodule Mix.Tasks.ReleaseTest do
322322
File.write!("config/releases.exs", """
323323
import Config
324324
config :release_test, :runtime, :was_set
325-
config :release_test, :encoding, {:runtime, :"£", "£", '£'}
325+
config :release_test, :encoding, {:runtime, :time_μs, :"£", "£", '£'}
326326
""")
327327

328328
root = Path.absname("_build/dev/rel/runtime_config")
@@ -348,7 +348,7 @@ defmodule Mix.Tasks.ReleaseTest do
348348
open_port(Path.join(root, "bin/runtime_config"), ['start'])
349349

350350
assert %{
351-
encoding: {:runtime, :"£", "£", '£'},
351+
encoding: {:runtime, :time_μs, :"£", "£", '£'},
352352
mode: :embedded,
353353
node: release_node("runtime_config"),
354354
protocols_consolidated?: true,

0 commit comments

Comments
 (0)