mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os.dir(); fix vroot on Windows
This commit is contained in:
parent
9177256726
commit
cc06fe7ae6
@ -933,7 +933,7 @@ fn new_v(args[]string) *V {
|
||||
'option.v',
|
||||
]
|
||||
// Location of all vlib files
|
||||
vroot := os.executable().all_before_last('/')
|
||||
vroot := os.dir(os.executable())
|
||||
println('VROOT=$vroot')
|
||||
// v.exe's parent directory should contain vlib
|
||||
if os.dir_exists(vroot) && os.dir_exists(vroot + '/vlib/builtin') {
|
||||
|
10
vlib/os/os.v
10
vlib/os/os.v
@ -382,6 +382,16 @@ pub fn ext(path string) string {
|
||||
return path.right(pos)
|
||||
}
|
||||
|
||||
|
||||
// dir returns all but the last element of path, typically the path's directory.
|
||||
pub fn dir(path string) string {
|
||||
pos := path.last_index(PathSeparator)
|
||||
if pos == -1 {
|
||||
return '.'
|
||||
}
|
||||
return path.left(pos)
|
||||
}
|
||||
|
||||
fn path_sans_ext(path string) string {
|
||||
pos := path.last_index('.')
|
||||
if pos == -1 {
|
||||
|
@ -1,3 +1,7 @@
|
||||
module os
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
const (
|
||||
PathSeparator = '/'
|
||||
)
|
||||
|
@ -34,6 +34,15 @@ fn test_write_and_read_string_to_file() {
|
||||
os.rm(filename)
|
||||
}
|
||||
|
||||
fn test_dir() {
|
||||
$if windows {
|
||||
assert os.dir('C:\a\b\c') == 'C:\a\b'
|
||||
|
||||
} $else {
|
||||
assert os.dir('/var/tmp/foo') == '/var/tmp'
|
||||
}
|
||||
}
|
||||
|
||||
//fn test_fork() {
|
||||
// pid := os.fork()
|
||||
// if pid == 0 {
|
||||
|
@ -1,5 +1,9 @@
|
||||
module os
|
||||
|
||||
const (
|
||||
PathSeparator = '/'
|
||||
)
|
||||
|
||||
// Ref - https://docs.microsoft.com/en-us/windows/desktop/winprog/windows-data-types
|
||||
// A handle to an object.
|
||||
type HANDLE voidptr
|
||||
|
Loading…
Reference in New Issue
Block a user