1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vfmt: change all '$expr' to '${expr}' (#16428)

This commit is contained in:
yuyi
2022-11-15 21:53:13 +08:00
committed by GitHub
parent 56239b4a23
commit 017ace6ea7
859 changed files with 7156 additions and 7135 deletions

View File

@ -50,19 +50,19 @@ pub fn cprintln_strong(omessage string) {
pub fn verbose_trace(label string, message string) {
if os.getenv('VERBOSE').len > 0 {
slabel := '$time.now().format_ss_milli() $label'
cprintln('# ${slabel:-43s} : $message')
slabel := '${time.now().format_ss_milli()} ${label}'
cprintln('# ${slabel:-43s} : ${message}')
}
}
pub fn verbose_trace_strong(label string, omessage string) {
if os.getenv('VERBOSE').len > 0 {
slabel := '$time.now().format_ss_milli() $label'
slabel := '${time.now().format_ss_milli()} ${label}'
mut message := omessage
if scripting.term_colors {
message = term.bright_green(message)
}
cprintln('# ${slabel:-43s} : $message')
cprintln('# ${slabel:-43s} : ${message}')
}
}
@ -76,7 +76,7 @@ pub fn verbose_trace_exec_result(x os.Result) {
if scripting.term_colors {
line = term.bright_green(line)
}
cprintln('# ${lnum:3d}: $line')
cprintln('# ${lnum:3d}: ${line}')
lnum++
}
cprintln('# ----------------------------------------------------------------------')
@ -84,11 +84,11 @@ pub fn verbose_trace_exec_result(x os.Result) {
}
fn modfn(mname string, fname string) string {
return '${mname}.$fname'
return '${mname}.${fname}'
}
pub fn chdir(path string) {
verbose_trace_strong(modfn(@MOD, @FN), 'cd $path')
verbose_trace_strong(modfn(@MOD, @FN), 'cd ${path}')
os.chdir(path) or {
verbose_trace(modfn(@MOD, @FN), '## failed.')
return
@ -96,7 +96,7 @@ pub fn chdir(path string) {
}
pub fn mkdir(path string) ? {
verbose_trace_strong(modfn(@MOD, @FN), 'mkdir $path')
verbose_trace_strong(modfn(@MOD, @FN), 'mkdir ${path}')
os.mkdir(path) or {
verbose_trace(modfn(@MOD, @FN), '## failed.')
return err
@ -104,7 +104,7 @@ pub fn mkdir(path string) ? {
}
pub fn mkdir_all(path string) ? {
verbose_trace_strong(modfn(@MOD, @FN), 'mkdir -p $path')
verbose_trace_strong(modfn(@MOD, @FN), 'mkdir -p ${path}')
os.mkdir_all(path) or {
verbose_trace(modfn(@MOD, @FN), '## failed.')
return err
@ -112,7 +112,7 @@ pub fn mkdir_all(path string) ? {
}
pub fn rmrf(path string) {
verbose_trace_strong(modfn(@MOD, @FN), 'rm -rf $path')
verbose_trace_strong(modfn(@MOD, @FN), 'rm -rf ${path}')
if os.exists(path) {
if os.is_dir(path) {
os.rmdir_all(path) or { panic(err) }
@ -165,10 +165,10 @@ pub fn exit_0_status(cmd string) bool {
pub fn tool_must_exist(toolcmd string) {
verbose_trace(modfn(@MOD, @FN), toolcmd)
if exit_0_status('type $toolcmd') {
if exit_0_status('type ${toolcmd}') {
return
}
eprintln('Missing tool: $toolcmd')
eprintln('Missing tool: ${toolcmd}')
eprintln('Please try again after you install it.')
exit(1)
}
@ -182,6 +182,6 @@ pub fn used_tools_must_exist(tools []string) {
pub fn show_sizes_of_files(files []string) {
for f in files {
size := os.file_size(f)
println('$size $f') // println('${size:10d} $f')
println('${size} ${f}') // println('${size:10d} $f')
}
}

View File

@ -80,7 +80,7 @@ pub fn (mut ts TestSession) add_failed_cmd(cmd string) {
pub fn (mut ts TestSession) show_list_of_failed_tests() {
for i, cmd in ts.failed_cmds {
eprintln(term.failed('Failed command ${i + 1}:') + ' $cmd')
eprintln(term.failed('Failed command ${i + 1}:') + ' ${cmd}')
}
}
@ -132,12 +132,12 @@ pub fn (mut ts TestSession) print_messages() {
if ts.progress_mode {
// progress mode, the last line is rewritten many times:
if is_ok && !ts.silent_mode {
print('\r$empty\r$msg')
print('\r${empty}\r${msg}')
flush_stdout()
} else {
// the last \n is needed, so SKIP/FAIL messages
// will not get overwritten by the OK ones
eprint('\r$empty\r$msg\n')
eprint('\r${empty}\r${msg}\n')
}
continue
}
@ -393,10 +393,10 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
mut status := os.system(cmd)
if status != 0 {
details := get_test_details(file)
os.setenv('VTEST_RETRY_MAX', '$details.retry', true)
os.setenv('VTEST_RETRY_MAX', '${details.retry}', true)
for retry := 1; retry <= details.retry; retry++ {
ts.append_message(.info, ' [stats] retrying $retry/$details.retry of $relative_file ; known flaky: $details.flaky ...')
os.setenv('VTEST_RETRY', '$retry', true)
ts.append_message(.info, ' [stats] retrying ${retry}/${details.retry} of ${relative_file} ; known flaky: ${details.flaky} ...')
os.setenv('VTEST_RETRY', '${retry}', true)
status = os.system(cmd)
if status == 0 {
unsafe {
@ -406,7 +406,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
time.sleep(500 * time.millisecond)
}
if details.flaky && !testing.fail_flaky {
ts.append_message(.info, ' *FAILURE* of the known flaky test file $relative_file is ignored, since VTEST_FAIL_FLAKY is 0 . Retry count: $details.retry .')
ts.append_message(.info, ' *FAILURE* of the known flaky test file ${relative_file} is ignored, since VTEST_FAIL_FLAKY is 0 . Retry count: ${details.retry} .')
unsafe {
goto test_passed_system
}
@ -422,7 +422,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
}
} else {
if testing.show_start {
ts.append_message(.info, ' starting $relative_file ...')
ts.append_message(.info, ' starting ${relative_file} ...')
}
mut r := os.execute(cmd)
if r.exit_code < 0 {
@ -434,10 +434,10 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
}
if r.exit_code != 0 {
details := get_test_details(file)
os.setenv('VTEST_RETRY_MAX', '$details.retry', true)
os.setenv('VTEST_RETRY_MAX', '${details.retry}', true)
for retry := 1; retry <= details.retry; retry++ {
ts.append_message(.info, ' retrying $retry/$details.retry of $relative_file ; known flaky: $details.flaky ...')
os.setenv('VTEST_RETRY', '$retry', true)
ts.append_message(.info, ' retrying ${retry}/${details.retry} of ${relative_file} ; known flaky: ${details.flaky} ...')
os.setenv('VTEST_RETRY', '${retry}', true)
r = os.execute(cmd)
if r.exit_code == 0 {
unsafe {
@ -446,7 +446,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
}
}
if details.flaky && !testing.fail_flaky {
ts.append_message(.info, ' *FAILURE* of the known flaky test file $relative_file is ignored, since VTEST_FAIL_FLAKY is 0 . Retry count: $details.retry .')
ts.append_message(.info, ' *FAILURE* of the known flaky test file ${relative_file} is ignored, since VTEST_FAIL_FLAKY is 0 . Retry count: ${details.retry} .')
unsafe {
goto test_passed_execute
}
@ -454,7 +454,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
ts.benchmark.fail()
tls_bench.fail()
ending_newline := if r.output.ends_with('\n') { '\n' } else { '' }
ts.append_message(.fail, tls_bench.step_message_fail('$normalised_relative_file\n$r.output.trim_space()$ending_newline'))
ts.append_message(.fail, tls_bench.step_message_fail('${normalised_relative_file}\n${r.output.trim_space()}${ending_newline}'))
ts.add_failed_cmd(cmd)
} else {
test_passed_execute:
@ -474,7 +474,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
pub fn vlib_should_be_present(parent_dir string) {
vlib_dir := os.join_path_single(parent_dir, 'vlib')
if !os.is_dir(vlib_dir) {
eprintln('$vlib_dir is missing, it must be next to the V executable')
eprintln('${vlib_dir} is missing, it must be next to the V executable')
exit(1)
}
}
@ -486,7 +486,7 @@ pub fn prepare_test_session(zargs string, folder string, oskipped []string, main
vargs := zargs.replace(vexe, '')
eheader(main_label)
if vargs.len > 0 {
eprintln('v compiler args: "$vargs"')
eprintln('v compiler args: "${vargs}"')
}
mut session := new_test_session(vargs, true)
files := os.walk_ext(os.join_path_single(parent_dir, folder), '.v')
@ -532,8 +532,8 @@ pub fn prepare_test_session(zargs string, folder string, oskipped []string, main
pub type FnTestSetupCb = fn (mut session TestSession)
pub fn v_build_failing_skipped(zargs string, folder string, oskipped []string, cb FnTestSetupCb) bool {
main_label := 'Building $folder ...'
finish_label := 'building $folder'
main_label := 'Building ${folder} ...'
finish_label := 'building ${folder}'
mut session := prepare_test_session(zargs, folder, oskipped, main_label)
cb(mut session)
session.test()
@ -562,22 +562,22 @@ pub fn building_any_v_binaries_failed() bool {
vlib_should_be_present(parent_dir)
os.chdir(parent_dir) or { panic(err) }
mut failed := false
v_build_commands := ['$vexe -o v_g -g cmd/v', '$vexe -o v_prod_g -prod -g cmd/v',
'$vexe -o v_cg -cg cmd/v', '$vexe -o v_prod_cg -prod -cg cmd/v',
'$vexe -o v_prod -prod cmd/v']
v_build_commands := ['${vexe} -o v_g -g cmd/v',
'${vexe} -o v_prod_g -prod -g cmd/v', '${vexe} -o v_cg -cg cmd/v',
'${vexe} -o v_prod_cg -prod -cg cmd/v', '${vexe} -o v_prod -prod cmd/v']
mut bmark := benchmark.new_benchmark()
for cmd in v_build_commands {
bmark.step()
if build_v_cmd_failed(cmd) {
bmark.fail()
failed = true
eprintln(bmark.step_message_fail('command: $cmd . See details above ^^^^^^^'))
eprintln(bmark.step_message_fail('command: ${cmd} . See details above ^^^^^^^'))
eprintln('')
continue
}
bmark.ok()
if !testing.hide_oks {
eprintln(bmark.step_message_ok('command: $cmd'))
eprintln(bmark.step_message_ok('command: ${cmd}'))
}
}
bmark.stop()
@ -600,7 +600,7 @@ pub fn header(msg string) {
// The new nested folder, and its contents, will get removed after all tests/programs succeed.
pub fn setup_new_vtmp_folder() string {
now := time.sys_mono_now()
new_vtmp_dir := os.join_path(os.vtmp_dir(), 'tsession_${sync.thread_id().hex()}_$now')
new_vtmp_dir := os.join_path(os.vtmp_dir(), 'tsession_${sync.thread_id().hex()}_${now}')
os.mkdir_all(new_vtmp_dir) or { panic(err) }
os.setenv('VTMP', new_vtmp_dir, true)
return new_vtmp_dir
@ -632,5 +632,5 @@ pub fn find_started_process(pname string) ?string {
return line
}
}
return error('could not find process matching $pname')
return error('could not find process matching ${pname}')
}

View File

@ -22,9 +22,9 @@ pub fn validate_commit_exists(commit string) {
if commit.len == 0 {
return
}
cmd := "git cat-file -t '$commit' "
cmd := "git cat-file -t '${commit}' "
if !scripting.exit_0_status(cmd) {
eprintln('Commit: "$commit" does not exist in the current repository.')
eprintln('Commit: "${commit}" does not exist in the current repository.')
exit(3)
}
}
@ -50,25 +50,25 @@ pub fn prepare_vc_source(vcdir string, cdir string, commit string) (string, stri
// Building a historic v with the latest vc is not always possible ...
// It is more likely, that the vc *at the time of the v commit*,
// or slightly before that time will be able to build the historic v:
vline := scripting.run('git rev-list -n1 --timestamp "$commit" ')
vline := scripting.run('git rev-list -n1 --timestamp "${commit}" ')
v_timestamp, v_commithash := line_to_timestamp_and_commit(vline)
scripting.verbose_trace(@FN, 'v_timestamp: $v_timestamp | v_commithash: $v_commithash')
scripting.verbose_trace(@FN, 'v_timestamp: ${v_timestamp} | v_commithash: ${v_commithash}')
check_v_commit_timestamp_before_self_rebuilding(v_timestamp)
scripting.chdir(vcdir)
scripting.run('git checkout --quiet master')
//
mut vccommit := ''
vcbefore_subject_match := scripting.run('git rev-list HEAD -n1 --timestamp --grep=${v_commithash[0..7]} ')
scripting.verbose_trace(@FN, 'vcbefore_subject_match: $vcbefore_subject_match')
scripting.verbose_trace(@FN, 'vcbefore_subject_match: ${vcbefore_subject_match}')
if vcbefore_subject_match.len > 3 {
_, vccommit = line_to_timestamp_and_commit(vcbefore_subject_match)
} else {
scripting.verbose_trace(@FN, 'the v commit did not match anything in the vc log; try --timestamp instead.')
vcbefore := scripting.run('git rev-list HEAD -n1 --timestamp --before=$v_timestamp ')
vcbefore := scripting.run('git rev-list HEAD -n1 --timestamp --before=${v_timestamp} ')
_, vccommit = line_to_timestamp_and_commit(vcbefore)
}
scripting.verbose_trace(@FN, 'vccommit: $vccommit')
scripting.run('git checkout --quiet "$vccommit" ')
scripting.verbose_trace(@FN, 'vccommit: ${vccommit}')
scripting.run('git checkout --quiet "${vccommit}" ')
scripting.run('wc *.c')
scripting.chdir(cdir)
return v_commithash, vccommit
@ -78,11 +78,11 @@ pub fn clone_or_pull(remote_git_url string, local_worktree_path string) {
// Note: after clone_or_pull, the current repo branch is === HEAD === master
if os.is_dir(local_worktree_path) && os.is_dir(os.join_path_single(local_worktree_path, '.git')) {
// Already existing ... Just pulling in this case is faster usually.
scripting.run('git -C "$local_worktree_path" checkout --quiet master')
scripting.run('git -C "$local_worktree_path" pull --quiet ')
scripting.run('git -C "${local_worktree_path}" checkout --quiet master')
scripting.run('git -C "${local_worktree_path}" pull --quiet ')
} else {
// Clone a fresh
scripting.run('git clone --quiet "$remote_git_url" "$local_worktree_path" ')
scripting.run('git clone --quiet "${remote_git_url}" "${local_worktree_path}" ')
}
}
@ -111,17 +111,17 @@ pub fn (mut vgit_context VGitContext) compile_oldv_if_needed() {
mut command_for_building_v_from_c_source := ''
mut command_for_selfbuilding := ''
if 'windows' == os.user_os() {
command_for_building_v_from_c_source = '$vgit_context.cc -std=c99 -I ./thirdparty/stdatomic/win -municode -w -o cv.exe "$vgit_context.path_vc/v_win.c" '
command_for_selfbuilding = './cv.exe -o $vgit_context.vexename {SOURCE}'
command_for_building_v_from_c_source = '${vgit_context.cc} -std=c99 -I ./thirdparty/stdatomic/win -municode -w -o cv.exe "${vgit_context.path_vc}/v_win.c" '
command_for_selfbuilding = './cv.exe -o ${vgit_context.vexename} {SOURCE}'
} else {
command_for_building_v_from_c_source = '$vgit_context.cc -std=gnu11 -I ./thirdparty/stdatomic/nix -w -o cv "$vgit_context.path_vc/v.c" -lm -lpthread'
command_for_selfbuilding = './cv -o $vgit_context.vexename {SOURCE}'
command_for_building_v_from_c_source = '${vgit_context.cc} -std=gnu11 -I ./thirdparty/stdatomic/nix -w -o cv "${vgit_context.path_vc}/v.c" -lm -lpthread'
command_for_selfbuilding = './cv -o ${vgit_context.vexename} {SOURCE}'
}
scripting.chdir(vgit_context.workdir)
clone_or_pull(vgit_context.v_repo_url, vgit_context.path_v)
clone_or_pull(vgit_context.vc_repo_url, vgit_context.path_vc)
scripting.chdir(vgit_context.path_v)
scripting.run('git checkout --quiet $vgit_context.commit_v')
scripting.run('git checkout --quiet ${vgit_context.commit_v}')
if os.is_dir(vgit_context.path_v) && os.exists(vgit_context.vexepath) {
// already compiled, so no need to compile v again
vgit_context.commit_v__hash = get_current_folder_commit_hash()
@ -163,7 +163,7 @@ pub mut:
pub fn add_common_tool_options(mut context VGitOptions, mut fp flag.FlagParser) []string {
tdir := os.temp_dir()
context.workdir = os.real_path(fp.string('workdir', `w`, context.workdir, 'A writable base folder. Default: $tdir'))
context.workdir = os.real_path(fp.string('workdir', `w`, context.workdir, 'A writable base folder. Default: ${tdir}'))
context.v_repo_url = fp.string('vrepo', 0, context.v_repo_url, 'The url of the V repository. You can clone it locally too. See also --vcrepo below.')
context.vc_repo_url = fp.string('vcrepo', 0, context.vc_repo_url, 'The url of the vc repository. You can clone it
${flag.space}beforehand, and then just give the local folder
@ -187,7 +187,7 @@ ${flag.space}to script it/run it in a restrictive vps/docker.
context.vc_repo_url = os.real_path(context.vc_repo_url)
}
commits := fp.finalize() or {
eprintln('Error: $err')
eprintln('Error: ${err}')
exit(1)
}
for commit in commits {

View File

@ -7,7 +7,7 @@ pub fn show_topic(topic string) {
vroot := os.dir(vexe)
target_topic := os.join_path(vroot, 'cmd', 'v', 'help', '${topic}.txt')
content := os.read_file(target_topic) or {
eprintln('Unknown topic: $topic')
eprintln('Unknown topic: ${topic}')
exit(1)
}
println(content)