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:
parent
fcd97f513a
commit
d51019dd77
@ -7,6 +7,7 @@ import (
|
|||||||
filepath
|
filepath
|
||||||
runtime
|
runtime
|
||||||
sync
|
sync
|
||||||
|
v.pref
|
||||||
)
|
)
|
||||||
|
|
||||||
pub struct TestSession {
|
pub struct TestSession {
|
||||||
@ -25,7 +26,7 @@ pub mut:
|
|||||||
|
|
||||||
pub fn new_test_session(vargs string) TestSession {
|
pub fn new_test_session(vargs string) TestSession {
|
||||||
return TestSession{
|
return TestSession{
|
||||||
vexe: vexe_path()
|
vexe: pref.vexe_path()
|
||||||
vargs: vargs
|
vargs: vargs
|
||||||
|
|
||||||
ntask: 0
|
ntask: 0
|
||||||
@ -36,14 +37,6 @@ pub fn new_test_session(vargs string) TestSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
pub fn (ts mut TestSession) init() {
|
||||||
ts.benchmark = benchmark.new_benchmark()
|
ts.benchmark = benchmark.new_benchmark()
|
||||||
}
|
}
|
||||||
@ -192,7 +185,7 @@ pub fn vlib_should_be_present(parent_dir string) {
|
|||||||
pub fn v_build_failing(zargs string, folder string) bool {
|
pub fn v_build_failing(zargs string, folder string) bool {
|
||||||
main_label := 'Building $folder ...'
|
main_label := 'Building $folder ...'
|
||||||
finish_label := 'building $folder'
|
finish_label := 'building $folder'
|
||||||
vexe := vexe_path()
|
vexe := pref.vexe_path()
|
||||||
parent_dir := filepath.dir(vexe)
|
parent_dir := filepath.dir(vexe)
|
||||||
vlib_should_be_present(parent_dir)
|
vlib_should_be_present(parent_dir)
|
||||||
vargs := zargs.replace(vexe, '')
|
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 {
|
pub fn building_any_v_binaries_failed() bool {
|
||||||
eheader('Building V binaries...')
|
eheader('Building V binaries...')
|
||||||
eprintln('VFLAGS is: "' + os.getenv('VFLAGS') + '"')
|
eprintln('VFLAGS is: "' + os.getenv('VFLAGS') + '"')
|
||||||
vexe := testing.vexe_path()
|
vexe := pref.vexe_path()
|
||||||
parent_dir := filepath.dir(vexe)
|
parent_dir := filepath.dir(vexe)
|
||||||
testing.vlib_should_be_present(parent_dir)
|
testing.vlib_should_be_present(parent_dir)
|
||||||
os.chdir(parent_dir)
|
os.chdir(parent_dir)
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
testing
|
testing
|
||||||
benchmark
|
benchmark
|
||||||
filepath
|
filepath
|
||||||
|
v.pref
|
||||||
)
|
)
|
||||||
|
|
||||||
pub const (
|
pub const (
|
||||||
@ -18,7 +19,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn v_test_compiler(vargs string) {
|
fn v_test_compiler(vargs string) {
|
||||||
vexe := testing.vexe_path()
|
vexe := pref.vexe_path()
|
||||||
parent_dir := filepath.dir(vexe)
|
parent_dir := filepath.dir(vexe)
|
||||||
testing.vlib_should_be_present(parent_dir)
|
testing.vlib_should_be_present(parent_dir)
|
||||||
// Changing the current directory is needed for some of the compiler tests,
|
// Changing the current directory is needed for some of the compiler tests,
|
||||||
|
@ -24,7 +24,7 @@ pub fn new_v(args []string) &compiler.V {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vroot := filepath.dir(vexe_path())
|
vroot := filepath.dir(pref.vexe_path())
|
||||||
// optional, custom modules search path
|
// optional, custom modules search path
|
||||||
user_mod_path := cmdline.option(args, '-user_mod_path', '')
|
user_mod_path := cmdline.option(args, '-user_mod_path', '')
|
||||||
vlib_path := cmdline.option(args, '-vlib-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
|
is_repl := '-repl' in args
|
||||||
ccompiler := cmdline.option(args, '-cc', '')
|
ccompiler := cmdline.option(args, '-cc', '')
|
||||||
mut pref := &pref.Preferences{
|
mut prefs := &pref.Preferences{
|
||||||
os: pref.os_from_string(target_os)
|
os: pref.os_from_string(target_os)
|
||||||
is_so: '-shared' in args
|
is_so: '-shared' in args
|
||||||
is_solive: '-solive' 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
|
compile_defines_all: compile_defines_all
|
||||||
mod: mod
|
mod: mod
|
||||||
}
|
}
|
||||||
if pref.is_verbose || pref.is_debug {
|
if prefs.is_verbose || prefs.is_debug {
|
||||||
println('C compiler=$pref.ccompiler')
|
println('C compiler=$prefs.ccompiler')
|
||||||
}
|
}
|
||||||
$if !linux {
|
$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')
|
println('V error: -freestanding only works on Linux for now')
|
||||||
os.flush_stdout()
|
os.flush_stdout()
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pref.fill_with_defaults()
|
prefs.fill_with_defaults()
|
||||||
|
|
||||||
// v.exe's parent directory should contain vlib
|
// 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...')
|
// println('vlib not found, downloading it...')
|
||||||
/*
|
/*
|
||||||
ret := os.system('git clone --depth=1 https://github.com/vlang/v .')
|
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('vlib not found. It should be next to the V executable.')
|
||||||
println('Go to https://vlang.io to install V.')
|
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)
|
exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if pref.is_script && !os.exists(dir) {
|
if prefs.is_script && !os.exists(dir) {
|
||||||
println('`$dir` does not exist')
|
println('`$dir` does not exist')
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return compiler.new_v(pref)
|
return compiler.new_v(prefs)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_c_compiler_thirdparty_options(args []string) string {
|
fn find_c_compiler_thirdparty_options(args []string) string {
|
||||||
|
10
cmd/v/flag.v
10
cmd/v/flag.v
@ -66,13 +66,3 @@ fn join_flags_and_argument() []string {
|
|||||||
|
|
||||||
return non_empty(os.args)
|
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
|
|
||||||
}
|
|
||||||
|
@ -7,10 +7,11 @@ import (
|
|||||||
compiler
|
compiler
|
||||||
filepath
|
filepath
|
||||||
os
|
os
|
||||||
|
v.pref
|
||||||
)
|
)
|
||||||
|
|
||||||
fn launch_tool(is_verbose bool, tname string, cmdname string) {
|
fn launch_tool(is_verbose bool, tname string, cmdname string) {
|
||||||
vexe := vexe_path()
|
vexe := pref.vexe_path()
|
||||||
vroot := filepath.dir(vexe)
|
vroot := filepath.dir(vexe)
|
||||||
compiler.set_vroot_folder(vroot)
|
compiler.set_vroot_folder(vroot)
|
||||||
|
|
||||||
|
@ -3,13 +3,16 @@
|
|||||||
// that can be found in the LICENSE file.
|
// that can be found in the LICENSE file.
|
||||||
module main
|
module main
|
||||||
|
|
||||||
import os
|
import (
|
||||||
|
os
|
||||||
|
v.pref
|
||||||
|
)
|
||||||
|
|
||||||
fn create_symlink() {
|
fn create_symlink() {
|
||||||
$if windows {
|
$if windows {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vexe := vexe_path()
|
vexe := pref.vexe_path()
|
||||||
mut link_path := '/usr/local/bin/v'
|
mut link_path := '/usr/local/bin/v'
|
||||||
mut ret := os.exec('ln -sf $vexe $link_path') or { panic(err) }
|
mut ret := os.exec('ln -sf $vexe $link_path') or { panic(err) }
|
||||||
if ret.exit_code == 0 {
|
if ret.exit_code == 0 {
|
||||||
@ -28,4 +31,3 @@ fn create_symlink() {
|
|||||||
println('Failed to create symlink "$link_path". Try again with sudo.')
|
println('Failed to create symlink "$link_path". Try again with sudo.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ fn (v mut V) cc() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
v.build_thirdparty_obj_files()
|
v.build_thirdparty_obj_files()
|
||||||
vexe := vexe_path()
|
vexe := pref.vexe_path()
|
||||||
vdir := filepath.dir(vexe)
|
vdir := filepath.dir(vexe)
|
||||||
// Just create a C/JavaScript file and exit
|
// Just create a C/JavaScript file and exit
|
||||||
// for example: `v -o v.c compiler`
|
// for example: `v -o v.c compiler`
|
||||||
|
@ -733,7 +733,7 @@ pub fn (v &V) get_user_files() []string {
|
|||||||
mut user_files := []string
|
mut user_files := []string
|
||||||
|
|
||||||
// See cmd/tools/preludes/README.md for more info about what preludes are
|
// 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')
|
preludes_path := filepath.join(vroot,'cmd','tools','preludes')
|
||||||
if v.pref.is_live {
|
if v.pref.is_live {
|
||||||
user_files << filepath.join(preludes_path,'live_main.v')
|
user_files << filepath.join(preludes_path,'live_main.v')
|
||||||
@ -844,16 +844,6 @@ pub fn (v &V) log(s string) {
|
|||||||
println(s)
|
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) {
|
pub fn verror(s string) {
|
||||||
println('V error: $s')
|
println('V error: $s')
|
||||||
os.flush_stdout()
|
os.flush_stdout()
|
||||||
|
@ -28,7 +28,7 @@ mut:
|
|||||||
// `mod` == "vlib/os"
|
// `mod` == "vlib/os"
|
||||||
fn generate_vh(mod string) {
|
fn generate_vh(mod string) {
|
||||||
println('\n\n\n\nGenerating a V header file for module `$mod`')
|
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)
|
full_mod_path := filepath.join(filepath.dir(vexe),mod)
|
||||||
dir := if mod.starts_with('vlib') { '$compiler.v_modules_path${filepath.separator}$mod' } else { mod }
|
dir := if mod.starts_with('vlib') { '$compiler.v_modules_path${filepath.separator}$mod' } else { mod }
|
||||||
path := dir + '.vh'
|
path := dir + '.vh'
|
||||||
|
@ -3,7 +3,7 @@ module doc
|
|||||||
import (
|
import (
|
||||||
strings
|
strings
|
||||||
// v.builder
|
// v.builder
|
||||||
// v.pref
|
v.pref
|
||||||
v.table
|
v.table
|
||||||
v.parser
|
v.parser
|
||||||
v.ast
|
v.ast
|
||||||
@ -25,7 +25,7 @@ pub fn doc(mod string, table &table.Table) string {
|
|||||||
table: table
|
table: table
|
||||||
mod: mod
|
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)
|
path := filepath.join(mods_path,mod).replace('.', filepath.separator)
|
||||||
if !os.exists(path) {
|
if !os.exists(path) {
|
||||||
println('module "$mod" not found')
|
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
|
|
||||||
}
|
|
||||||
|
@ -66,8 +66,7 @@ fn default_c_compiler() string {
|
|||||||
return 'cc'
|
return 'cc'
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Remove code duplication
|
pub fn vexe_path() string {
|
||||||
fn vexe_path() string {
|
|
||||||
vexe := os.getenv('VEXE')
|
vexe := os.getenv('VEXE')
|
||||||
if vexe != '' {
|
if vexe != '' {
|
||||||
return vexe
|
return vexe
|
||||||
|
Loading…
Reference in New Issue
Block a user