mirror of
https://github.com/vlang/v.git
synced 2025-08-03 09:47:15 -04:00
Revert "os: deprecate os.getwd
in favor of os.get_current_dir
(part 1) (#22966)"
This reverts commit 93009823f992176166bf5e5d90c9627adb46bdc0.
This commit is contained in:
parent
93009823f9
commit
b801083f13
@ -109,7 +109,7 @@ fn (mut c Context) amalgamate() ! {
|
||||
if c.config.input_files.len == 0 {
|
||||
// source += '/* ########## stdin */\n'
|
||||
// if there are no input files, read from stdin
|
||||
local_dir := os.get_current_dir()
|
||||
local_dir := os.getwd()
|
||||
source += c.handle_includes(local_dir, os.get_raw_lines_joined())!
|
||||
// source += '/* ########## stdin end */\n'
|
||||
} else {
|
||||
|
@ -14,7 +14,7 @@ step := os.args[3] or { '500_000' }.int()
|
||||
os.chdir(os.dir(@VEXE))!
|
||||
vcmd := 'v ${flags} cmd/tools/bench/map_clear.v'
|
||||
|
||||
println('>> start: ${start} | end: ${end} | step: ${step} | workdir: "${os.get_current_dir()}" | flags: "${flags}" | vcmd: "${vcmd}"')
|
||||
println('>> start: ${start} | end: ${end} | step: ${step} | workdir: "${os.getwd()}" | flags: "${flags}" | vcmd: "${vcmd}"')
|
||||
assert os.system(vcmd) == 0
|
||||
|
||||
println('running...')
|
||||
|
@ -53,7 +53,7 @@ fn main() {
|
||||
elog('fast_job PATH: ${os.getenv('PATH')}')
|
||||
|
||||
os.chdir(fast_dir)!
|
||||
elog('fast_job start in os.get_current_dir(): ${os.get_current_dir()}')
|
||||
elog('fast_job start in os.getwd(): ${os.getwd()}')
|
||||
|
||||
defer {
|
||||
elog('fast_job end')
|
||||
|
@ -370,7 +370,7 @@ pub fn (mut ts TestSession) add(file string) {
|
||||
pub fn (mut ts TestSession) test() {
|
||||
// Ensure that .tmp.c files generated from compiling _test.v files,
|
||||
// are easy to delete at the end, *without* affecting the existing ones.
|
||||
current_wd := os.get_current_dir()
|
||||
current_wd := os.getwd()
|
||||
if current_wd == os.wd_at_startup && current_wd == ts.vroot {
|
||||
ts.root_relative = true
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ mut:
|
||||
|
||||
fn new_context() Context {
|
||||
return Context{
|
||||
cwd: os.get_current_dir()
|
||||
cwd: os.getwd()
|
||||
commit_after: 'master'
|
||||
warmups: 4
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ fn main() {
|
||||
eprintln('> args: ${args} | context: ${ctx}')
|
||||
}
|
||||
if ctx.show_wd {
|
||||
ctx.println('WORK_DIR=${os.get_current_dir()}')
|
||||
ctx.println('WORK_DIR=${os.getwd()}')
|
||||
}
|
||||
if ctx.show_env {
|
||||
all := os.environ()
|
||||
|
@ -87,9 +87,9 @@ fn get_abs_path(path string) string {
|
||||
if os.is_abs_path(path) {
|
||||
return path
|
||||
} else if path.starts_with('./') {
|
||||
return os.join_path(os.get_current_dir(), path[2..])
|
||||
return os.join_path(os.getwd(), path[2..])
|
||||
} else {
|
||||
return os.join_path(os.get_current_dir(), path)
|
||||
return os.join_path(os.getwd(), path)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ fn get_vdoctor_output(is_verbose bool) string {
|
||||
fn get_v_build_output(is_verbose bool, is_yes bool, file_path string) string {
|
||||
mut vexe := os.getenv('VEXE')
|
||||
// prepare a V compiler with -g to have better backtraces if possible
|
||||
wd := os.get_current_dir()
|
||||
wd := os.getwd()
|
||||
os.chdir(vroot) or {}
|
||||
verbose_flag := if is_verbose { '-v' } else { '' }
|
||||
vdbg_path := $if windows { '${vroot}/vdbg.exe' } $else { '${vroot}/vdbg' }
|
||||
|
@ -149,7 +149,7 @@ fn normalize_path(path string) string {
|
||||
|
||||
fn main() {
|
||||
mut ctx := Context{}
|
||||
ctx.working_folder = normalize_path(os.real_path(os.get_current_dir()))
|
||||
ctx.working_folder = normalize_path(os.real_path(os.getwd()))
|
||||
mut fp := flag.new_flag_parser(os.args#[1..])
|
||||
fp.application('v cover')
|
||||
fp.version('0.0.2')
|
||||
|
@ -131,7 +131,7 @@ fn init_project(cmd Command) ! {
|
||||
mut c := Create{
|
||||
template: get_template(cmd)
|
||||
}
|
||||
dir_name := check_name(os.file_name(os.get_current_dir()))
|
||||
dir_name := check_name(os.file_name(os.getwd()))
|
||||
if !os.exists('v.mod') {
|
||||
mod_dir_has_hyphens := dir_name.contains('-')
|
||||
c.name = if mod_dir_has_hyphens { dir_name.replace('-', '_') } else { dir_name }
|
||||
|
@ -99,13 +99,13 @@ fn (mut a App) collect_info() {
|
||||
a.line('OS', '${os_kind}, ${os_details}')
|
||||
a.line('Processor', arch_details.join(', '))
|
||||
a.println('')
|
||||
get_current_dir := os.get_current_dir()
|
||||
getwd := os.getwd()
|
||||
vmodules := os.vmodules_dir()
|
||||
vtmp_dir := os.vtmp_dir()
|
||||
vexe := os.getenv('VEXE')
|
||||
vroot := os.dir(vexe)
|
||||
os.chdir(vroot) or {}
|
||||
a.line('get_current_dir', get_current_dir)
|
||||
a.line('getwd', getwd)
|
||||
a.line('vexe', vexe)
|
||||
a.line('vexe mtime', time.unix(os.file_last_mod_unix(vexe)).str())
|
||||
a.println('')
|
||||
|
@ -35,6 +35,6 @@ fn setup_symlink_github() {
|
||||
eprintln(' On windows, use `.\\v.exe symlink` instead.')
|
||||
exit(1)
|
||||
}
|
||||
content += '\n${os.get_current_dir()}\n'
|
||||
content += '\n${os.getwd()}\n'
|
||||
os.write_file(os.getenv('GITHUB_PATH'), content) or { panic('Failed to write to GITHUB_PATH.') }
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ pub fn is_abs_path(path string) bool {
|
||||
// with the given `path` (if the `path` is relative)
|
||||
// and returns the absolute path representation.
|
||||
pub fn abs_path(path string) string {
|
||||
wd := get_current_dir()
|
||||
wd := getwd()
|
||||
if path == '' {
|
||||
return wd
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ fn test_norm_path() {
|
||||
}
|
||||
|
||||
fn test_abs_path() {
|
||||
wd := get_current_dir()
|
||||
wd := getwd()
|
||||
wd_w_sep := wd + path_separator
|
||||
$if windows {
|
||||
assert abs_path('path/to/file.v') == '${wd_w_sep}path\\to\\file.v'
|
||||
@ -147,7 +147,7 @@ fn test_abs_path() {
|
||||
}
|
||||
|
||||
fn test_existing_path() {
|
||||
wd := get_current_dir()
|
||||
wd := getwd()
|
||||
$if windows {
|
||||
assert existing_path('') or { '' } == ''
|
||||
assert existing_path('..') or { '' } == '..'
|
||||
|
@ -10,7 +10,7 @@ fn test_find_abs_path_of_executable() {
|
||||
}
|
||||
|
||||
original_path := os.getenv('PATH')
|
||||
original_wdir := os.get_current_dir()
|
||||
original_wdir := os.getwd()
|
||||
defer {
|
||||
os.chdir(original_wdir) or {}
|
||||
}
|
||||
|
@ -756,16 +756,8 @@ pub fn chdir(path string) ! {
|
||||
}
|
||||
|
||||
// getwd returns the absolute path of the current directory.
|
||||
// @[deprecated: 'use `get_current_dir()` instead']
|
||||
// TODO: uncomment the deprecation here, after 2024-11-27
|
||||
@[deprecated_after: '2024-12-24']
|
||||
pub fn getwd() string {
|
||||
return get_current_dir()
|
||||
}
|
||||
|
||||
// get_current_dir returns the absolute path of the current directory.
|
||||
@[manualfree]
|
||||
pub fn get_current_dir() string {
|
||||
pub fn getwd() string {
|
||||
unsafe {
|
||||
buf := [max_path_buffer_size]u8{}
|
||||
$if windows {
|
||||
|
@ -7,7 +7,7 @@ import strings
|
||||
|
||||
pub const max_path_len = 4096
|
||||
|
||||
pub const wd_at_startup = get_current_dir()
|
||||
pub const wd_at_startup = getwd()
|
||||
|
||||
const f_ok = 0
|
||||
|
||||
|
@ -152,10 +152,6 @@ pub fn read_file(s string) !string {
|
||||
}
|
||||
|
||||
pub fn getwd() string {
|
||||
return get_current_dir()
|
||||
}
|
||||
|
||||
pub fn get_current_dir() string {
|
||||
res := ''
|
||||
#res.str = $process.cwd()
|
||||
|
||||
|
@ -445,7 +445,7 @@ fn test_realpath_removes_dots() {
|
||||
}
|
||||
|
||||
fn test_realpath_absolutizes_existing_relative_paths() {
|
||||
old_wd := os.get_current_dir()
|
||||
old_wd := os.getwd()
|
||||
defer {
|
||||
os.chdir(old_wd) or { panic(err) }
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ fn test_getpid() {
|
||||
|
||||
fn test_set_work_folder() {
|
||||
new_work_folder := os.real_path(os.temp_dir())
|
||||
parent_working_folder := os.get_current_dir()
|
||||
parent_working_folder := os.getwd()
|
||||
dump(new_work_folder)
|
||||
dump(parent_working_folder)
|
||||
if new_work_folder == parent_working_folder {
|
||||
@ -57,7 +57,7 @@ fn test_set_work_folder() {
|
||||
child_work_folder := output.find_between('stdout, WORK_DIR=', '\n').trim_space()
|
||||
dump(child_work_folder)
|
||||
assert child_work_folder == new_work_folder
|
||||
new_parent_work_folder := os.get_current_dir()
|
||||
new_parent_work_folder := os.getwd()
|
||||
dump(new_parent_work_folder)
|
||||
assert new_parent_work_folder == parent_working_folder
|
||||
assert new_parent_work_folder != child_work_folder
|
||||
|
@ -405,7 +405,7 @@ pub fn (b &Builder) find_module_path(mod string, fpath string) !string {
|
||||
module_lookup_paths << vmod_file_location.vmod_folder
|
||||
}
|
||||
module_lookup_paths << b.module_search_paths
|
||||
module_lookup_paths << os.get_current_dir()
|
||||
module_lookup_paths << os.getwd()
|
||||
// go up through parents looking for modules a folder.
|
||||
// we need a proper solution that works most of the time. look at vdoc.get_parent_mod
|
||||
if fpath.contains(os.path_separator + 'modules' + os.path_separator) {
|
||||
|
@ -636,7 +636,7 @@ pub fn (mut v Builder) cc() {
|
||||
vdir := os.dir(vexe)
|
||||
mut tried_compilation_commands := []string{}
|
||||
mut tcc_output := os.Result{}
|
||||
original_pwd := os.get_current_dir()
|
||||
original_pwd := os.getwd()
|
||||
for {
|
||||
// try to compile with the chosen compiler
|
||||
// if compilation fails, retry again with another
|
||||
@ -1109,7 +1109,7 @@ fn (mut v Builder) build_thirdparty_obj_file(mod string, path string, moduleflag
|
||||
println(rebuild_reason_message)
|
||||
}
|
||||
// prepare for tcc, it needs relative paths to thirdparty/tcc to work:
|
||||
current_folder := os.get_current_dir()
|
||||
current_folder := os.getwd()
|
||||
os.chdir(v.pref.vroot) or {}
|
||||
|
||||
mut all_options := []string{}
|
||||
|
@ -28,7 +28,7 @@ fn check_if_output_folder_is_writable(pref_ &pref.Preferences) {
|
||||
// without a folder component, just use the current folder instead:
|
||||
mut output_folder := odir
|
||||
if odir.len == pref_.out_name.len {
|
||||
output_folder = os.get_current_dir()
|
||||
output_folder = os.getwd()
|
||||
}
|
||||
os.ensure_folder_is_writable(output_folder) or {
|
||||
// An early error here, is better than an unclear C error later:
|
||||
|
@ -176,7 +176,7 @@ pub fn (mut b Builder) find_invalidated_modules_by_files(all_files []string) []s
|
||||
}
|
||||
|
||||
fn (mut b Builder) v_build_module(vexe string, imp_path string) {
|
||||
pwd := os.get_current_dir()
|
||||
pwd := os.getwd()
|
||||
defer {
|
||||
os.chdir(pwd) or {}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ fn (mut c Checker) ident_autocomplete(node ast.Ident) {
|
||||
// Mini LS hack (v -line-info "a.v:16")
|
||||
println(
|
||||
'checker.ident() info.line_nr=${c.pref.linfo.line_nr} node.line_nr=${node.pos.line_nr} ' +
|
||||
' pwd="${os.get_current_dir()}" file="${c.file.path}", ' +
|
||||
' pwd="${os.getwd()}" file="${c.file.path}", ' +
|
||||
' pref.linfo.path="${c.pref.linfo.path}" node.name="${node.name}" expr="${c.pref.linfo.expr}"')
|
||||
// Make sure this ident is on the same line as requeste, in the same file, and has the same name
|
||||
same_line := node.pos.line_nr in [c.pref.linfo.line_nr - 1, c.pref.linfo.line_nr + 1, c.pref.linfo.line_nr]
|
||||
@ -21,7 +21,7 @@ fn (mut c Checker) ident_autocomplete(node ast.Ident) {
|
||||
if !same_name {
|
||||
return
|
||||
}
|
||||
abs_path := os.join_path(os.get_current_dir(), c.file.path)
|
||||
abs_path := os.join_path(os.getwd(), c.file.path)
|
||||
if c.pref.linfo.path !in [c.file.path, abs_path] {
|
||||
return
|
||||
}
|
||||
|
@ -422,8 +422,7 @@ pub fn (mut c Checker) check_files(ast_files []&ast.File) {
|
||||
// After the main checker run, run the line info check, print line info, and exit (if it's present)
|
||||
if !c.pref.linfo.is_running && c.pref.line_info != '' { //'' && c.pref.linfo.line_nr == 0 {
|
||||
// c.do_line_info(c.pref.line_info, ast_files)
|
||||
println('setting is_running=true, pref.path=${c.pref.linfo.path} curdir' +
|
||||
os.get_current_dir())
|
||||
println('setting is_running=true, pref.path=${c.pref.linfo.path} curdir' + os.getwd())
|
||||
c.pref.linfo.is_running = true
|
||||
for i, file in ast_files {
|
||||
// println(file.path)
|
||||
@ -433,8 +432,7 @@ pub fn (mut c Checker) check_files(ast_files []&ast.File) {
|
||||
exit(0)
|
||||
} else if file.path.starts_with('./') {
|
||||
// Maybe it's a "./foo.v", linfo.path has an absolute path
|
||||
abs_path := os.join_path(os.get_current_dir(), file.path).replace('/./',
|
||||
'/') // TODO: join_path shouldn't have /./
|
||||
abs_path := os.join_path(os.getwd(), file.path).replace('/./', '/') // TODO: join_path shouldn't have /./
|
||||
if abs_path == c.pref.linfo.path {
|
||||
c.check_files([ast_files[i]])
|
||||
exit(0)
|
||||
|
@ -202,7 +202,7 @@ fn (mut p Parser) free_scanner() {
|
||||
}
|
||||
}
|
||||
|
||||
const normalised_working_folder = (os.real_path(os.get_current_dir()) + os.path_separator).replace('\\',
|
||||
const normalised_working_folder = (os.real_path(os.getwd()) + os.path_separator).replace('\\',
|
||||
'/')
|
||||
|
||||
pub fn (mut p Parser) set_path(path string) {
|
||||
|
@ -891,7 +891,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||
res.is_o = true
|
||||
}
|
||||
if !os.is_abs_path(res.out_name) {
|
||||
res.out_name = os.join_path(os.get_current_dir(), res.out_name)
|
||||
res.out_name = os.join_path(os.getwd(), res.out_name)
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ pub fn new_scanner_file(file_path string, comments_mode CommentsMode, pref_ &pre
|
||||
mut raw_text := util.read_file(file_path) or { return err }
|
||||
if pref_.line_info != '' {
|
||||
// Add line info expr to the scanner text
|
||||
abs_path := os.join_path(os.get_current_dir(), file_path)
|
||||
abs_path := os.join_path(os.getwd(), file_path)
|
||||
if pref_.linfo.path in [file_path, abs_path] {
|
||||
raw_text = pref.add_line_info_expr_to_program_text(raw_text, pref_.linfo)
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ pub fn full_path_to_v(dirs_in int) string {
|
||||
args := os.args
|
||||
vreal := os.real_path('v')
|
||||
myself := os.real_path( os.executable() )
|
||||
wd := os.get_current_dir()
|
||||
wd := os.getwd()
|
||||
println('args are: $args')
|
||||
println('vreal : $vreal')
|
||||
println('myself : $myself')
|
||||
@ -90,13 +90,13 @@ pub fn run_prod_file(wd string, vexec string, file string) !string {
|
||||
|
||||
pub fn new_options() RunnerOptions {
|
||||
vexec := full_path_to_v(5)
|
||||
mut wd := os.get_current_dir()
|
||||
mut wd := os.getwd()
|
||||
mut files := []string{}
|
||||
if os.args.len > 1 {
|
||||
files = os.args[1..].clone()
|
||||
} else {
|
||||
os.chdir(os.dir(vexec)) or {}
|
||||
wd = os.get_current_dir()
|
||||
wd = os.getwd()
|
||||
files = os.walk_ext('.', '.repl')
|
||||
}
|
||||
return RunnerOptions{
|
||||
@ -107,7 +107,7 @@ pub fn new_options() RunnerOptions {
|
||||
}
|
||||
|
||||
pub fn new_prod_options() RunnerOptions {
|
||||
wd := os.get_current_dir()
|
||||
wd := os.getwd()
|
||||
vexec := full_path_to_v(4)
|
||||
mut files := []string{}
|
||||
if os.args.len > 1 {
|
||||
|
@ -64,8 +64,8 @@ pub fn qualify_module(pref_ &pref.Preferences, mod string, file_path string) str
|
||||
// TODO: 2022-01-30: That makes lookup dependent on fragile environment factors.
|
||||
// TODO: 2022-01-30: The lookup should be relative to the folder, in which the current file is,
|
||||
// TODO: 2022-01-30: *NOT* to the working folder of the compiler, which can change easily.
|
||||
if clean_file_path.replace(os.get_current_dir() + os.path_separator, '') == mod {
|
||||
trace_qualify(@FN, mod, file_path, 'module_res 2', mod, 'clean_file_path - get_current_dir == mod, clean_file_path: ${clean_file_path}')
|
||||
if clean_file_path.replace(os.getwd() + os.path_separator, '') == mod {
|
||||
trace_qualify(@FN, mod, file_path, 'module_res 2', mod, 'clean_file_path - getwd == mod, clean_file_path: ${clean_file_path}')
|
||||
return mod
|
||||
}
|
||||
if m1 := mod_path_to_full_name(pref_, mod, clean_file_path) {
|
||||
|
@ -277,7 +277,7 @@ pub fn launch_tool(is_verbose bool, tool_name string, args []string) {
|
||||
println('Compiling ${tool_name} with: "${compilation_command}"')
|
||||
}
|
||||
|
||||
current_work_dir := os.get_current_dir()
|
||||
current_work_dir := os.getwd()
|
||||
tlog('recompiling ${tool_source}')
|
||||
lockfile := tool_exe + '.lock'
|
||||
tlog('lockfile: ${lockfile}')
|
||||
|
@ -56,7 +56,7 @@ pub fn (mut sh StaticHandler) handle_static(directory_path string, root bool) !b
|
||||
// ```
|
||||
pub fn (mut sh StaticHandler) host_handle_static(host string, directory_path string, root bool) !bool {
|
||||
if !os.exists(directory_path) {
|
||||
return error('directory `${directory_path}` does not exist. The directory should be relative to the current working directory: ${os.get_current_dir()}')
|
||||
return error('directory `${directory_path}` does not exist. The directory should be relative to the current working directory: ${os.getwd()}')
|
||||
}
|
||||
dir_path := directory_path.trim_space().trim_right('/')
|
||||
mut mount_path := ''
|
||||
@ -84,7 +84,7 @@ pub fn (mut sh StaticHandler) host_mount_static_folder_at(host string, directory
|
||||
if mount_path == '' || mount_path[0] != `/` {
|
||||
return error('invalid mount path! The path should start with `/`')
|
||||
} else if !os.exists(directory_path) {
|
||||
return error('directory `${directory_path}` does not exist. The directory should be relative to the current working directory: ${os.get_current_dir()}')
|
||||
return error('directory `${directory_path}` does not exist. The directory should be relative to the current working directory: ${os.getwd()}')
|
||||
}
|
||||
|
||||
dir_path := directory_path.trim_right('/')
|
||||
|
@ -56,7 +56,7 @@ pub fn (mut sh StaticHandler) handle_static(directory_path string, root bool) !b
|
||||
// ```
|
||||
pub fn (mut sh StaticHandler) host_handle_static(host string, directory_path string, root bool) !bool {
|
||||
if !os.exists(directory_path) {
|
||||
return error('directory `${directory_path}` does not exist. The directory should be relative to the current working directory: ${os.get_current_dir()}')
|
||||
return error('directory `${directory_path}` does not exist. The directory should be relative to the current working directory: ${os.getwd()}')
|
||||
}
|
||||
dir_path := directory_path.trim_space().trim_right('/')
|
||||
mut mount_path := ''
|
||||
@ -84,7 +84,7 @@ pub fn (mut sh StaticHandler) host_mount_static_folder_at(host string, directory
|
||||
if mount_path == '' || mount_path[0] != `/` {
|
||||
return error('invalid mount path! The path should start with `/`')
|
||||
} else if !os.exists(directory_path) {
|
||||
return error('directory `${directory_path}` does not exist. The directory should be relative to the current working directory: ${os.get_current_dir()}')
|
||||
return error('directory `${directory_path}` does not exist. The directory should be relative to the current working directory: ${os.getwd()}')
|
||||
}
|
||||
|
||||
dir_path := directory_path.trim_right('/')
|
||||
|
Loading…
x
Reference in New Issue
Block a user