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

unify vexe_path

This commit is contained in:
yuyi 2020-02-20 18:33:01 +08:00 committed by GitHub
parent fcd97f513a
commit d51019dd77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 39 additions and 73 deletions

View File

@ -7,6 +7,7 @@ import (
filepath
runtime
sync
v.pref
)
pub struct TestSession {
@ -16,7 +17,7 @@ pub mut:
vargs string
failed bool
benchmark benchmark.Benchmark
ntask int // writing to this should be locked by mu.
ntask_mtx &sync.Mutex
waitgroup &sync.WaitGroup
@ -25,25 +26,17 @@ pub mut:
pub fn new_test_session(vargs string) TestSession {
return TestSession{
vexe: vexe_path()
vexe: pref.vexe_path()
vargs: vargs
ntask: 0
ntask_mtx: sync.new_mutex()
waitgroup: sync.new_waitgroup()
show_ok_tests: !vargs.contains('-silent')
}
}
pub fn vexe_path() string {
// NB: tools extracted from v require that the VEXE
// environment variable contains the path to the v executable location.
// They are usually launched by cmd/v/simple_tool.v,
// launch_tool/1 , which provides it.
return os.getenv('VEXE')
}
pub fn (ts mut TestSession) init() {
ts.benchmark = benchmark.new_benchmark()
}
@ -76,7 +69,7 @@ pub fn (ts mut TestSession) test() {
}
remaining_files << dot_relative_file
}
ts.files = remaining_files
ts.benchmark.set_total_expected_steps(remaining_files.len)
@ -107,7 +100,7 @@ fn process_in_thread(ts mut TestSession){
fn (ts mut TestSession) process_files() {
tmpd := os.tmpdir()
show_stats := '-stats' in ts.vargs.split(' ')
mut tls_bench := benchmark.new_benchmark() // tls_bench is used to format the step messages/timings
tls_bench.set_total_expected_steps( ts.benchmark.nexpected_steps )
for {
@ -116,11 +109,11 @@ fn (ts mut TestSession) process_files() {
ts.ntask++
idx := ts.ntask-1
ts.ntask_mtx.unlock()
if idx >= ts.files.len { break }
tls_bench.cstep = idx
dot_relative_file := ts.files[ idx ]
dot_relative_file := ts.files[ idx ]
relative_file := dot_relative_file.replace('./', '')
file := os.realpath(relative_file)
// Ensure that the generated binaries will be stored in the temporary folder.
@ -192,7 +185,7 @@ pub fn vlib_should_be_present(parent_dir string) {
pub fn v_build_failing(zargs string, folder string) bool {
main_label := 'Building $folder ...'
finish_label := 'building $folder'
vexe := vexe_path()
vexe := pref.vexe_path()
parent_dir := filepath.dir(vexe)
vlib_should_be_present(parent_dir)
vargs := zargs.replace(vexe, '')
@ -233,7 +226,7 @@ pub fn build_v_cmd_failed(cmd string) bool {
pub fn building_any_v_binaries_failed() bool {
eheader('Building V binaries...')
eprintln('VFLAGS is: "' + os.getenv('VFLAGS') + '"')
vexe := testing.vexe_path()
vexe := pref.vexe_path()
parent_dir := filepath.dir(vexe)
testing.vlib_should_be_present(parent_dir)
os.chdir(parent_dir)

View File

@ -5,6 +5,7 @@ import (
testing
benchmark
filepath
v.pref
)
pub const (
@ -18,7 +19,7 @@ fn main() {
}
fn v_test_compiler(vargs string) {
vexe := testing.vexe_path()
vexe := pref.vexe_path()
parent_dir := filepath.dir(vexe)
testing.vlib_should_be_present(parent_dir)
// Changing the current directory is needed for some of the compiler tests,

View File

@ -24,7 +24,7 @@ pub fn new_v(args []string) &compiler.V {
panic(err)
}
}
vroot := filepath.dir(vexe_path())
vroot := filepath.dir(pref.vexe_path())
// optional, custom modules search path
user_mod_path := cmdline.option(args, '-user_mod_path', '')
vlib_path := cmdline.option(args, '-vlib-path', '')
@ -108,7 +108,7 @@ pub fn new_v(args []string) &compiler.V {
}
is_repl := '-repl' in args
ccompiler := cmdline.option(args, '-cc', '')
mut pref := &pref.Preferences{
mut prefs := &pref.Preferences{
os: pref.os_from_string(target_os)
is_so: '-shared' in args
is_solive: '-solive' in args
@ -155,20 +155,20 @@ pub fn new_v(args []string) &compiler.V {
compile_defines_all: compile_defines_all
mod: mod
}
if pref.is_verbose || pref.is_debug {
println('C compiler=$pref.ccompiler')
if prefs.is_verbose || prefs.is_debug {
println('C compiler=$prefs.ccompiler')
}
$if !linux {
if pref.is_bare && !out_name.ends_with('.c') {
if prefs.is_bare && !out_name.ends_with('.c') {
println('V error: -freestanding only works on Linux for now')
os.flush_stdout()
exit(1)
}
}
pref.fill_with_defaults()
prefs.fill_with_defaults()
// v.exe's parent directory should contain vlib
if !os.is_dir(pref.vlib_path) || !os.is_dir(pref.vlib_path + filepath.separator + 'builtin') {
if !os.is_dir(prefs.vlib_path) || !os.is_dir(prefs.vlib_path + filepath.separator + 'builtin') {
// println('vlib not found, downloading it...')
/*
ret := os.system('git clone --depth=1 https://github.com/vlang/v .')
@ -180,16 +180,16 @@ pub fn new_v(args []string) &compiler.V {
*/
println('vlib not found. It should be next to the V executable.')
println('Go to https://vlang.io to install V.')
println('(os.executable=${os.executable()} vlib_path=$pref.vlib_path vexe_path=${vexe_path()}')
println('(os.executable=${os.executable()} vlib_path=$prefs.vlib_path vexe_path=${pref.vexe_path()}')
exit(1)
}
if pref.is_script && !os.exists(dir) {
if prefs.is_script && !os.exists(dir) {
println('`$dir` does not exist')
exit(1)
}
return compiler.new_v(pref)
return compiler.new_v(prefs)
}
fn find_c_compiler_thirdparty_options(args []string) string {

View File

@ -66,13 +66,3 @@ fn join_flags_and_argument() []string {
return non_empty(os.args)
}
fn vexe_path() string {
vexe := os.getenv('VEXE')
if vexe != '' {
return vexe
}
real_vexe_path := os.realpath(os.executable())
os.setenv('VEXE', real_vexe_path, true)
return real_vexe_path
}

View File

@ -7,10 +7,11 @@ import (
compiler
filepath
os
v.pref
)
fn launch_tool(is_verbose bool, tname string, cmdname string) {
vexe := vexe_path()
vexe := pref.vexe_path()
vroot := filepath.dir(vexe)
compiler.set_vroot_folder(vroot)
@ -55,7 +56,7 @@ fn launch_tool(is_verbose bool, tname string, cmdname string) {
compilation_args := compilation_options.join(' ')
compilation_command := '"$vexe" $compilation_args "$tool_source"'
if is_verbose {
eprintln('Compiling $tname with: "$compilation_command"')
eprintln('Compiling $tname with: "$compilation_command"')
}
tool_compilation := os.exec(compilation_command) or { panic(err) }
if tool_compilation.exit_code != 0 {
@ -65,7 +66,7 @@ fn launch_tool(is_verbose bool, tname string, cmdname string) {
if is_verbose {
eprintln('launch_tool running tool command: $tool_command ...')
}
exit(os.system(tool_command))
}

View File

@ -3,13 +3,16 @@
// that can be found in the LICENSE file.
module main
import os
import (
os
v.pref
)
fn create_symlink() {
$if windows {
return
}
vexe := vexe_path()
vexe := pref.vexe_path()
mut link_path := '/usr/local/bin/v'
mut ret := os.exec('ln -sf $vexe $link_path') or { panic(err) }
if ret.exit_code == 0 {
@ -28,4 +31,3 @@ fn create_symlink() {
println('Failed to create symlink "$link_path". Try again with sudo.')
}
}

View File

@ -30,7 +30,7 @@ fn (v mut V) cc() {
return
}
v.build_thirdparty_obj_files()
vexe := vexe_path()
vexe := pref.vexe_path()
vdir := filepath.dir(vexe)
// Just create a C/JavaScript file and exit
// for example: `v -o v.c compiler`

View File

@ -733,7 +733,7 @@ pub fn (v &V) get_user_files() []string {
mut user_files := []string
// See cmd/tools/preludes/README.md for more info about what preludes are
vroot := filepath.dir(vexe_path())
vroot := filepath.dir(pref.vexe_path())
preludes_path := filepath.join(vroot,'cmd','tools','preludes')
if v.pref.is_live {
user_files << filepath.join(preludes_path,'live_main.v')
@ -844,16 +844,6 @@ pub fn (v &V) log(s string) {
println(s)
}
pub fn vexe_path() string {
vexe := os.getenv('VEXE')
if '' != vexe {
return vexe
}
real_vexe_path := os.realpath(os.executable())
os.setenv('VEXE', real_vexe_path, true)
return real_vexe_path
}
pub fn verror(s string) {
println('V error: $s')
os.flush_stdout()

View File

@ -28,7 +28,7 @@ mut:
// `mod` == "vlib/os"
fn generate_vh(mod string) {
println('\n\n\n\nGenerating a V header file for module `$mod`')
vexe := vexe_path()
vexe := pref.vexe_path()
full_mod_path := filepath.join(filepath.dir(vexe),mod)
dir := if mod.starts_with('vlib') { '$compiler.v_modules_path${filepath.separator}$mod' } else { mod }
path := dir + '.vh'

View File

@ -3,7 +3,7 @@ module doc
import (
strings
// v.builder
// v.pref
v.pref
v.table
v.parser
v.ast
@ -25,7 +25,7 @@ pub fn doc(mod string, table &table.Table) string {
table: table
mod: mod
}
mods_path := filepath.dir(vexe_path()) + '/vlib'
mods_path := filepath.dir(pref.vexe_path()) + '/vlib'
path := filepath.join(mods_path,mod).replace('.', filepath.separator)
if !os.exists(path) {
println('module "$mod" not found')
@ -92,13 +92,3 @@ fn (d mut Doc) print_methods() {
}
}
}
pub fn vexe_path() string {
vexe := os.getenv('VEXE')
if '' != vexe {
return vexe
}
real_vexe_path := os.realpath(os.executable())
os.setenv('VEXE', real_vexe_path, true)
return real_vexe_path
}

View File

@ -66,8 +66,7 @@ fn default_c_compiler() string {
return 'cc'
}
//TODO Remove code duplication
fn vexe_path() string {
pub fn vexe_path() string {
vexe := os.getenv('VEXE')
if vexe != '' {
return vexe