Skip to content

Commit

Permalink
fix non-ASCII pathname under Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kbkpbot committed Oct 4, 2024
1 parent 5b1581d commit cd01e3e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
33 changes: 32 additions & 1 deletion vlib/v/builder/builder_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import os

const vexe = @VEXE
const test_path = os.join_path(os.vtmp_dir(), 'run_check')
const test_path2 = os.join_path(test_path, '测试目录')

fn testsuite_begin() {
os.mkdir_all(test_path) or {}
os.mkdir_all(test_path2) or {}
}

fn testsuite_end() {
Expand Down Expand Up @@ -43,3 +44,33 @@ fn test_conditional_executable_removal() {
dump(after_second_run___)
assert executable in after_second_run___
}

fn test_windows_ansi_path_name() {
os.chdir(test_path2)!
os.write_file('测试.v', 'fn main(){\n\tprintln("Hello World!")\n}\n')!

mut executable := '测试'
$if windows {
executable += '.exe'
}

original_file_list_ := os.ls(test_path2)!
dump(original_file_list_)
assert executable !in original_file_list_

assert os.execute('${os.quoted_path(vexe)} run .').output.trim_space() == 'Hello World!'
after_run_file_list := os.ls(test_path2)!.filter(os.exists(it))
dump(after_run_file_list)
assert executable !in after_run_file_list

assert os.execute('${os.quoted_path(vexe)} . -o ${executable}').exit_code == 0
assert os.execute('./${executable}').output.trim_space() == 'Hello World!'
after_compilation__ := os.ls(test_path2)!
dump(after_compilation__)
assert executable in after_compilation__

assert os.execute('${os.quoted_path(vexe)} run .').output.trim_space() == 'Hello World!'
after_second_run___ := os.ls(test_path2)!
dump(after_second_run___)
assert executable in after_second_run___
}
5 changes: 4 additions & 1 deletion vlib/v/builder/cc.v
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import v.pref
import v.util
import v.vcache
import term
import encoding.iconv

const c_std = 'c99'
const c_std_gnu = 'gnu99'
Expand Down Expand Up @@ -666,7 +667,9 @@ pub fn (mut v Builder) cc() {
response_file_content = str_args.replace('\\', '\\\\')
rspexpr := '@${response_file}'
cmd = '${v.quote_compiler_name(ccompiler)} ${os.quoted_path(rspexpr)}'
os.write_file(response_file, response_file_content) or {
// `LOCAL` encoding: ANSI/CP_ACP for Windows; UTF-8 for Linux
// Windows use ANSI encoding for path/filename
iconv.write_file_encoding(response_file, response_file_content, 'LOCAL', false) or {
verror('Unable to write to C response file "${response_file}"')
}
}
Expand Down
5 changes: 4 additions & 1 deletion vlib/v/builder/msvc_windows.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import os
import time
import v.util
import v.cflag
import encoding.iconv

#flag windows -l shell32
#flag windows -l dbghelp
Expand Down Expand Up @@ -357,7 +358,9 @@ pub fn (mut v Builder) cc_msvc() {
v.dump_c_options(a)
args := a.join(' ')
// write args to a file so that we dont smash createprocess
os.write_file(out_name_cmd_line, args) or {
// `LOCAL` encoding: ANSI/CP_ACP for Windows; UTF-8 for Linux
// Windows use ANSI encoding for path/filename
iconv.write_file_encoding(out_name_cmd_line, args, 'LOCAL', false) or {
verror('Unable to write response file to "${out_name_cmd_line}"')
}
cmd := '"${r.full_cl_exe_path}" "@${out_name_cmd_line}"'
Expand Down

0 comments on commit cd01e3e

Please sign in to comment.