Skip to content

Commit ddda949

Browse files
committed
Add patch for UTF-8 CLI from ruby-core PR 12377
ruby/ruby#12377 This is proposed and asked since one year, but Ruby core team seems too busy to care about it.
1 parent 2dfd199 commit ddda949

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
From fc347d3c3571264b7e35ebcac36762c084b01825 Mon Sep 17 00:00:00 2001
2+
From: Lars Kanis <lars@greiz-reinsdorf.de>
3+
Date: Wed, 2 Oct 2024 22:44:21 +0200
4+
Subject: [PATCH] Windows: Change command line interface to UTF-8
5+
6+
- script name
7+
- include paths
8+
- script input from stdin
9+
---
10+
ruby.c | 25 ++++---------------------
11+
test/ruby/test_rubyoptions.rb | 14 +++-----------
12+
2 files changed, 7 insertions(+), 32 deletions(-)
13+
14+
diff --git a/ruby.c b/ruby.c
15+
index 61de5cdcbe..e79d4b69da 100644
16+
--- a/ruby.c
17+
+++ b/ruby.c
18+
@@ -2168,7 +2168,7 @@ prism_script(ruby_cmdline_options_t *opt, pm_parse_result_t *result)
19+
const bool read_stdin = (strcmp(opt->script, "-") == 0);
20+
21+
if (read_stdin) {
22+
- pm_options_encoding_set(options, rb_enc_name(rb_locale_encoding()));
23+
+ pm_options_encoding_set(options, rb_enc_name(IF_UTF8_PATH(rb_utf8_encoding(), rb_locale_encoding())));
24+
}
25+
if (opt->src.enc.name != 0) {
26+
pm_options_encoding_set(options, StringValueCStr(opt->src.enc.name));
27+
@@ -2443,14 +2443,8 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
28+
#endif
29+
}
30+
rb_enc_associate(opt->script_name, IF_UTF8_PATH(uenc, lenc));
31+
-#if UTF8_PATH
32+
- if (uenc != lenc) {
33+
- opt->script_name = str_conv_enc(opt->script_name, uenc, lenc);
34+
- opt->script = RSTRING_PTR(opt->script_name);
35+
- }
36+
-#endif
37+
rb_obj_freeze(opt->script_name);
38+
- if (IF_UTF8_PATH(uenc != lenc, 1)) {
39+
+ {
40+
long i;
41+
VALUE load_path = vm->load_path;
42+
const ID id_initial_load_path_mark = INITIAL_LOAD_PATH_MARK;
43+
@@ -2460,13 +2454,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
44+
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
45+
VALUE path = RARRAY_AREF(load_path, i);
46+
int mark = rb_attr_get(path, id_initial_load_path_mark) == path;
47+
-#if UTF8_PATH
48+
- VALUE newpath = rb_str_conv_enc(path, uenc, lenc);
49+
- if (newpath == path) continue;
50+
- path = newpath;
51+
-#else
52+
- if (!(path = copy_str(path, lenc, !mark))) continue;
53+
-#endif
54+
+ if (!(path = copy_str(path, IF_UTF8_PATH(uenc, lenc), !mark))) continue;
55+
if (mark) rb_ivar_set(path, id_initial_load_path_mark, path);
56+
if (!modifiable) {
57+
rb_ary_modify(load_path);
58+
@@ -2594,11 +2582,6 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
59+
VALUE path = Qnil;
60+
if (!opt->e_script && strcmp(opt->script, "-")) {
61+
path = rb_realpath_internal(Qnil, opt->script_name, 1);
62+
-#if UTF8_PATH
63+
- if (uenc != lenc) {
64+
- path = str_conv_enc(path, uenc, lenc);
65+
- }
66+
-#endif
67+
if (!ENCODING_GET(path)) { /* ASCII-8BIT */
68+
rb_enc_copy(path, opt->script_name);
69+
}
70+
@@ -2760,7 +2743,7 @@ load_file_internal(VALUE argp_v)
71+
enc = rb_enc_from_index(opt->src.enc.index);
72+
}
73+
else if (f == rb_stdin) {
74+
- enc = rb_locale_encoding();
75+
+ enc = IF_UTF8_PATH(rb_utf8_encoding(), rb_locale_encoding());
76+
}
77+
else {
78+
enc = rb_utf8_encoding();
79+
diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb
80+
index ac4b5870eb..fac0901fdf 100644
81+
--- a/test/ruby/test_rubyoptions.rb
82+
+++ b/test/ruby/test_rubyoptions.rb
83+
@@ -1082,19 +1082,11 @@ def test_command_line_glob_nonascii
84+
85+
def test_command_line_progname_nonascii
86+
bug10555 = '[ruby-dev:48752] [Bug #10555]'
87+
- name = expected = nil
88+
- unless (0x80..0x10000).any? {|c|
89+
- name = c.chr(Encoding::UTF_8)
90+
- expected = name.encode("locale") rescue nil
91+
- }
92+
- omit "can't make locale name"
93+
- end
94+
- name << ".rb"
95+
- expected << ".rb"
96+
+ name = "\u{20ac}.rb"
97+
with_tmpchdir do |dir|
98+
open(name, "w") {|f| f.puts "puts File.basename($0)"}
99+
- assert_in_out_err([name], "", [expected], [],
100+
- bug10555, encoding: "locale")
101+
+ assert_in_out_err([name], "", [name], [],
102+
+ bug10555, encoding: "utf-8")
103+
end
104+
end
105+
106+
--
107+
2.47.1.windows.1
108+

mingw-w64-ruby-head/PKGBUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ options=('staticlibs' 'strip')
2525
source=("https://cache.ruby-lang.org/pub/ruby/snapshot/snapshot-master.tar.xz"
2626
0001-Add-C-ext-win32-dll_directory-as-an-alternative-to-f.patch
2727
0002-Use-autoconf-2.72.patch
28+
0015-Windows-Change-command-line-interface-to-UTF-8.patch
2829
ruby.ico
2930
rubyw.ico
3031
placeholder.manifest.xml)
@@ -36,6 +37,7 @@ noextract=("snapshot-master.tar.xz")
3637
sha256sums=('SKIP'
3738
'a50c81ab8c178689485257f8eaa70bd8184b878a798780084668f838912e2832'
3839
'f26122cca5e289801c0dde1f54643a960246a69691c6c8b9bccb27e536344f69'
40+
'840955023a6829ed862ee626f4f3e337be1203c3facb49e62e7f04bb826229e0'
3941
'6c80ba2ca49840e387a08b7fedc6e7acd298ac2ec853155209efb2af20397b22'
4042
'c30fb04ac0e88ba634daaa811a81ea5a75027646617b895acd14df9518a4a55a'
4143
'c7a555d4826453efe7e33a2ebf78462b1fa665dffd7e4972143b48b1c9c71375')
@@ -46,6 +48,7 @@ prepare() {
4648
rm -rf ext/win32/dll_directory
4749
patch -p1 -i ${srcdir}/0001-Add-C-ext-win32-dll_directory-as-an-alternative-to-f.patch
4850
patch -p1 -i ${srcdir}/0002-Use-autoconf-2.72.patch
51+
patch -p1 -i ${srcdir}/0015-Windows-Change-command-line-interface-to-UTF-8.patch
4952
autoreconf -fi
5053
}
5154

0 commit comments

Comments
 (0)