mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
filepath: path separator (#3756)
This commit is contained in:
@ -182,7 +182,7 @@ fn (v mut V) new_parser_from_file(path string) Parser {
|
||||
p |
|
||||
file_path:path,
|
||||
file_path_dir:filepath.dir( path ),
|
||||
file_name:path.all_after(os.path_separator),
|
||||
file_name:path.all_after(filepath.separator),
|
||||
file_platform:path_platform,
|
||||
file_pcguard:path_pcguard,
|
||||
is_vh:path.ends_with('.vh'),
|
||||
|
@ -47,7 +47,7 @@ fn (v mut V) cc() {
|
||||
eprintln(format_result.output)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ends_with_c || ends_with_js {
|
||||
// Translating V code to JS by launching vjs.
|
||||
// Using a separate process for V.js is for performance mostly,
|
||||
@ -152,8 +152,8 @@ fn (v mut V) cc() {
|
||||
}
|
||||
if v.pref.build_mode == .build_module {
|
||||
// Create the modules & out directory if it's not there.
|
||||
mut out_dir := if v.pref.path.starts_with('vlib') { '$v_modules_path${os.path_separator}cache${os.path_separator}$v.pref.path' } else { '$v_modules_path${os.path_separator}$v.pref.path' }
|
||||
pdir := out_dir.all_before_last(os.path_separator)
|
||||
mut out_dir := if v.pref.path.starts_with('vlib') { '$v_modules_path${filepath.separator}cache${filepath.separator}$v.pref.path' } else { '$v_modules_path${filepath.separator}$v.pref.path' }
|
||||
pdir := out_dir.all_before_last(filepath.separator)
|
||||
if !os.is_dir(pdir) {
|
||||
os.mkdir_all(pdir)
|
||||
}
|
||||
@ -223,7 +223,7 @@ fn (v mut V) cc() {
|
||||
}
|
||||
else {
|
||||
println('$builtin_o_path not found... building module builtin')
|
||||
os.system('$vexe build module vlib${os.path_separator}builtin')
|
||||
os.system('$vexe build module vlib${filepath.separator}builtin')
|
||||
}
|
||||
for imp in v.table.imports {
|
||||
if imp.contains('vweb') {
|
||||
@ -232,8 +232,8 @@ fn (v mut V) cc() {
|
||||
if imp == 'webview' {
|
||||
continue
|
||||
}
|
||||
imp_path := imp.replace('.', os.path_separator)
|
||||
path := '$v_modules_path${os.path_separator}cache${os.path_separator}vlib${os.path_separator}${imp_path}.o'
|
||||
imp_path := imp.replace('.', filepath.separator)
|
||||
path := '$v_modules_path${filepath.separator}cache${filepath.separator}vlib${filepath.separator}${imp_path}.o'
|
||||
// println('adding ${imp_path}.o')
|
||||
if os.exists(path) {
|
||||
libs += ' ' + path
|
||||
@ -250,7 +250,7 @@ fn (v mut V) cc() {
|
||||
}
|
||||
}
|
||||
else {
|
||||
os.system('$vexe build module vlib${os.path_separator}$imp_path')
|
||||
os.system('$vexe build module vlib${filepath.separator}$imp_path')
|
||||
}
|
||||
}
|
||||
if path.ends_with('vlib/ui.o') {
|
||||
@ -554,4 +554,3 @@ fn missing_compiler_info() string {
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
|
@ -285,7 +285,7 @@ fn (v &V) build_thirdparty_obj_file(path string, moduleflags []CFlag) {
|
||||
mut cfiles := ''
|
||||
for file in files {
|
||||
if file.ends_with('.c') {
|
||||
cfiles += '"' + os.realpath(parent + os.path_separator + file) + '" '
|
||||
cfiles += '"' + os.realpath(parent + filepath.separator + file) + '" '
|
||||
}
|
||||
}
|
||||
btarget := moduleflags.c_options_before_target()
|
||||
@ -503,4 +503,3 @@ fn (v &V) interface_table() string {
|
||||
}
|
||||
return sb.str()
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ module compiler
|
||||
|
||||
import (
|
||||
os
|
||||
filepath
|
||||
term
|
||||
)
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -156,7 +157,7 @@ fn (s &Scanner) get_error_filepath() string {
|
||||
else {
|
||||
s.print_rel_paths_on_error}}
|
||||
if use_relative_paths {
|
||||
workdir := os.getwd() + os.path_separator
|
||||
workdir := os.getwd() + filepath.separator
|
||||
if s.file_path.starts_with(workdir) {
|
||||
return s.file_path.replace(workdir, '')
|
||||
}
|
||||
@ -315,4 +316,3 @@ const (
|
||||
and_or_error = 'use `()` to make the boolean expression clear\n' + 'for example: `(a && b) || c` instead of `a && b || c`'
|
||||
err_modify_bitfield = 'to modify a bitfield flag use the methods: set, clear, toggle. and to check for flag use: has'
|
||||
)
|
||||
|
||||
|
@ -681,8 +681,8 @@ pub fn (v mut V) add_v_files_to_compile() {
|
||||
}
|
||||
// use cached built module if exists
|
||||
if v.pref.vpath != '' && v.pref.build_mode != .build_module && !mod.contains('vweb') {
|
||||
mod_path := mod.replace('.', os.path_separator)
|
||||
vh_path := '$v_modules_path${os.path_separator}vlib${os.path_separator}${mod_path}.vh'
|
||||
mod_path := mod.replace('.', filepath.separator)
|
||||
vh_path := '$v_modules_path${filepath.separator}vlib${filepath.separator}${mod_path}.vh'
|
||||
if v.pref.is_cache && os.exists(vh_path) {
|
||||
eprintln('using cached module `$mod`: $vh_path')
|
||||
v.cached_mods << mod
|
||||
@ -924,5 +924,5 @@ pub fn set_vroot_folder(vroot_path string) {
|
||||
// VEXE env variable is needed so that compiler.vexe_path()
|
||||
// can return it later to whoever needs it:
|
||||
vname := if os.user_os() == 'windows' { 'v.exe' } else { 'v' }
|
||||
os.setenv('VEXE', os.realpath([vroot_path, vname].join(os.path_separator)), true)
|
||||
os.setenv('VEXE', os.realpath([vroot_path, vname].join(filepath.separator)), true)
|
||||
}
|
||||
|
@ -30,9 +30,9 @@ fn generate_vh(mod string) {
|
||||
println('\n\n\n\nGenerating a V header file for module `$mod`')
|
||||
vexe := vexe_path()
|
||||
full_mod_path := filepath.join(filepath.dir(vexe),mod)
|
||||
dir := if mod.starts_with('vlib') { '$compiler.v_modules_path${os.path_separator}$mod' } else { mod }
|
||||
dir := if mod.starts_with('vlib') { '$compiler.v_modules_path${filepath.separator}$mod' } else { mod }
|
||||
path := dir + '.vh'
|
||||
pdir := dir.all_before_last(os.path_separator)
|
||||
pdir := dir.all_before_last(filepath.separator)
|
||||
if !os.is_dir(pdir) {
|
||||
os.mkdir_all(pdir)
|
||||
// os.mkdir(os.realpath(dir)) or { panic(err) }
|
||||
@ -50,7 +50,7 @@ fn generate_vh(mod string) {
|
||||
// mut vfiles := os.ls(full_mod_path) or {
|
||||
// exit(1)
|
||||
// }
|
||||
filtered := vfiles.filter(it.ends_with('.v') && !it.ends_with('test.v') && !it.ends_with('_windows.v') && !it.ends_with('_win.v') && !it.ends_with('_lin.v') && !it.contains('${os.path_separator}examples') && !it.contains('_js.v') && !it.contains('_bare.v') && !it.contains('${os.path_separator}js')) // TODO merge once filter allows it
|
||||
filtered := vfiles.filter(it.ends_with('.v') && !it.ends_with('test.v') && !it.ends_with('_windows.v') && !it.ends_with('_win.v') && !it.ends_with('_lin.v') && !it.contains('${filepath.separator}examples') && !it.contains('_js.v') && !it.contains('_bare.v') && !it.contains('${filepath.separator}js')) // TODO merge once filter allows it
|
||||
// println('f:')
|
||||
// println(filtered)
|
||||
mut pref := &pref.Preferences {
|
||||
|
@ -25,7 +25,7 @@ fn (table &Table) qualify_module(mod string, file_path string) string {
|
||||
for m in table.imports {
|
||||
if m.contains('.') && m.contains(mod) {
|
||||
m_parts := m.split('.')
|
||||
m_path := m_parts.join(os.path_separator)
|
||||
m_path := m_parts.join(filepath.separator)
|
||||
if mod == m_parts[m_parts.len - 1] && file_path.contains(m_path) {
|
||||
return m
|
||||
}
|
||||
@ -147,7 +147,7 @@ pub fn (graph &DepGraph) imports() []string {
|
||||
[inline]
|
||||
fn (v &V) module_path(mod string) string {
|
||||
// submodule support
|
||||
return mod.replace('.', os.path_separator)
|
||||
return mod.replace('.', filepath.separator)
|
||||
}
|
||||
|
||||
// 'strings' => 'VROOT/vlib/strings'
|
||||
@ -208,4 +208,3 @@ fn mod_gen_name(mod string) string {
|
||||
fn mod_gen_name_rev(mod string) string {
|
||||
return mod.replace('_dot_', '.')
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ fn find_msvc() ?MsvcResult {
|
||||
return error('Unable to find visual studio')
|
||||
}
|
||||
return MsvcResult{
|
||||
full_cl_exe_path: os.realpath(vs.exe_path + os.path_separator + 'cl.exe')
|
||||
full_cl_exe_path: os.realpath(vs.exe_path + filepath.separator + 'cl.exe')
|
||||
exe_path: vs.exe_path
|
||||
um_lib_path: wk.um_lib_path
|
||||
ucrt_lib_path: wk.ucrt_lib_path
|
||||
@ -321,7 +321,7 @@ fn build_thirdparty_obj_file_with_msvc(path string, moduleflags []CFlag) {
|
||||
mut cfiles := ''
|
||||
for file in files {
|
||||
if file.ends_with('.c') {
|
||||
cfiles += '"' + os.realpath(parent + os.path_separator + file) + '" '
|
||||
cfiles += '"' + os.realpath(parent + filepath.separator + file) + '" '
|
||||
}
|
||||
}
|
||||
include_string := '-I "$msvc.ucrt_include_path" -I "$msvc.vs_include_path" -I "$msvc.um_include_path" -I "$msvc.shared_include_path"'
|
||||
@ -376,7 +376,7 @@ fn (cflags []CFlag) msvc_string_flags() MsvcStringFlags {
|
||||
}
|
||||
else if flag.name == '-L' {
|
||||
lib_paths << flag.value
|
||||
lib_paths << flag.value + os.path_separator + 'msvc'
|
||||
lib_paths << flag.value + filepath.separator + 'msvc'
|
||||
// The above allows putting msvc specific .lib files in a subfolder msvc/ ,
|
||||
// where gcc will NOT find them, but cl will do...
|
||||
// NB: gcc is smart enough to not need .lib files at all in most cases, the .dll is enough.
|
||||
@ -398,4 +398,3 @@ fn (cflags []CFlag) msvc_string_flags() MsvcStringFlags {
|
||||
return MsvcStringFlags{
|
||||
real_libs,inc_paths,lpaths,other_flags}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ module compiler
|
||||
|
||||
import (
|
||||
os
|
||||
filepath
|
||||
// strings
|
||||
)
|
||||
|
||||
@ -850,7 +851,7 @@ fn (s mut Scanner) debug_tokens() {
|
||||
s.pos = 0
|
||||
s.started = false
|
||||
s.debug = true
|
||||
fname := s.file_path.all_after(os.path_separator)
|
||||
fname := s.file_path.all_after(filepath.separator)
|
||||
println('\n===DEBUG TOKENS $fname===')
|
||||
for {
|
||||
res := s.scan()
|
||||
@ -941,4 +942,3 @@ fn (s &Scanner) validate_var_name(name string) {
|
||||
s.error('bad variable name `$name`\n' + 'looks like you have a multi-word name without separating them with `_`' + '\nfor example, use `registration_date` instead of `registrationdate` ')
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ pub fn full_path_to_v(dirs_in int) string {
|
||||
println('vreal : $vreal')
|
||||
println('myself : $myself')
|
||||
println('wd : $wd')
|
||||
*/
|
||||
*/
|
||||
return vexec
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ fn diff_files( file_result, file_expected string ) string {
|
||||
|
||||
pub fn run_repl_file(wd string, vexec string, file string) ?string {
|
||||
fcontent := os.read_file(file) or { return error('Could not read file ${file}') }
|
||||
content := fcontent.replace('\r', '')
|
||||
content := fcontent.replace('\r', '')
|
||||
input := content.all_before('===output===\n')
|
||||
output := content.all_after('===output===\n')
|
||||
|
||||
@ -67,13 +67,13 @@ pub fn run_repl_file(wd string, vexec string, file string) ?string {
|
||||
return error('Could not execute: $rcmd')
|
||||
}
|
||||
os.rm(input_temporary_filename)
|
||||
|
||||
|
||||
result := r.output.replace('\r','')
|
||||
.replace('>>> ', '')
|
||||
.replace('>>>', '')
|
||||
.replace('... ', '')
|
||||
.all_after('Use Ctrl-C or `exit` to exit\n')
|
||||
.replace(wd + os.path_separator, '' )
|
||||
.replace(wd + filepath.separator, '' )
|
||||
|
||||
if result != output {
|
||||
file_result := '${file}.result.txt'
|
||||
@ -97,7 +97,7 @@ $diff
|
||||
pub fn run_prod_file(wd string, vexec string, file string) ?string {
|
||||
file_expected := '${file}.expected.txt'
|
||||
f_expected_content := os.read_file(file_expected) or { return error('Could not read file ${file}') }
|
||||
expected_content := f_expected_content.replace('\r', '')
|
||||
expected_content := f_expected_content.replace('\r', '')
|
||||
|
||||
cmd := '"$vexec" -prod run "${file}"'
|
||||
r := os.exec(cmd) or {
|
||||
@ -160,4 +160,3 @@ pub fn new_prod_options() RunnerOptions {
|
||||
files: files
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user