Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ANSI pathname under windows #22395

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion vlib/v/builder/builder_test.v
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module main

import os
import encoding.iconv

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 +45,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___
}
12 changes: 10 additions & 2 deletions 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,8 +667,15 @@ 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 {
verror('Unable to write to C response file "${response_file}"')
$if windows {
// Windows use ANSI encoding for path/filename
// NOTE: use 'ANSI' encoding, not 'UTF-8'
iconv.write_file_encoding(response_file, response_file_content, 'ANSI',
false) or { verror('Unable to write to C response file "${response_file}"') }
} $else {
os.write_file(response_file, response_file_content) or {
verror('Unable to write to C response file "${response_file}"')
}
}
}
if !v.ccoptions.debug_mode {
Expand Down
4 changes: 3 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,8 @@ 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 {
// NOTE: use 'ANSI' encoding, not 'UTF-8'
iconv.write_file_encoding(out_name_cmd_line, args, 'ANSI', 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
Loading