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

V shell scripts

This commit is contained in:
Alexander Medvednikov
2019-10-15 18:08:46 +03:00
parent 96152510e5
commit 5cd38ec91b
6 changed files with 66 additions and 23 deletions

View File

@ -556,6 +556,15 @@ pub fn (v mut V) add_v_files_to_compile() {
for file in v.get_user_files() {
mut p := v.new_parser_from_file(file)
p.parse(.imports)
if p.v_script {
v.log('imports0:')
println(v.table.imports)
println(v.files)
p.import_table.register_alias('os', 'os', 0)
p.table.imports << 'os'
p.table.register_module('os')
println('got v script')
}
//if p.pref.autofree { p.scanner.text.free() free(p.scanner) }
v.add_parser(p)
}
@ -609,12 +618,13 @@ pub fn (v &V) get_builtin_files() []string {
pub fn (v &V) get_user_files() []string {
mut dir := v.dir
v.log('get_v_files($dir)')
// Need to store user files separately, because they have to be added after libs, but we dont know
// which libs need to be added yet
// Need to store user files separately, because they have to be added after
// libs, but we dont know which libs need to be added yet
mut user_files := []string
if v.pref.is_test && v.pref.is_stats {
user_files << [v.vroot, 'vlib', 'benchmark', 'tests', 'always_imported.v'].join( os.path_separator )
user_files << os.join(v.vroot, 'vlib', 'benchmark', 'tests',
'always_imported.v')
}
// v volt/slack_test.v: compile all .v files to get the environment
@ -624,9 +634,9 @@ pub fn (v &V) get_user_files() []string {
if is_test_with_imports {
user_files << dir
pos := dir.last_index(os.path_separator)
dir = dir.left(pos) + os.path_separator// TODO WHY IS THIS .neEDED?
dir = dir.left(pos) + os.path_separator// TODO why is this needed
}
if dir.ends_with('.v') {
if dir.ends_with('.v') || dir.ends_with('.vsh') {
// Just compile one file and get parent dir
user_files << dir
dir = dir.all_before(os.path_separator)
@ -792,7 +802,7 @@ pub fn new_v(args[]string) &V {
*/
}
is_test := dir.ends_with('_test.v')
is_script := dir.ends_with('.v')
is_script := dir.ends_with('.v') || dir.ends_with('.vsh')
if is_script && !os.file_exists(dir) {
println('`$dir` does not exist')
exit(1)