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

builder: clean up and simplify some methods

This commit is contained in:
yuyi 2020-04-18 03:17:19 +08:00 committed by GitHub
parent 515da900e4
commit 3e324befd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 26 deletions

View File

@ -46,34 +46,32 @@ pub fn (b mut Builder) build_c(v_files []string, out_file string) {
// os.write_file(out_file, b.gen_c(v_files))
}
pub fn (b mut Builder) compile_c(files []string, pref &pref.Preferences) {
if os.user_os() != 'windows' && pref.ccompiler == 'msvc' {
pub fn (b mut Builder) compile_c() {
if os.user_os() != 'windows' && b.pref.ccompiler == 'msvc' {
verror('Cannot build with msvc on ${os.user_os()}')
}
// cgen.genln('// Generated by V')
// println('compile2()')
if pref.is_verbose {
if b.pref.is_verbose {
println('all .v files before:')
println(files)
//println(files)
}
// v1 compiler files
// v.add_v_files_to_compile()
// v.files << v.dir
// v2 compiler
// b.set_module_lookup_paths()
files << b.get_builtin_files()
mut files := b.get_builtin_files()
files << b.get_user_files()
b.set_module_lookup_paths()
if pref.is_verbose {
if b.pref.is_verbose {
println('all .v files:')
println(files)
}
mut out_name_c := get_vtmp_filename(pref.out_name, '.tmp.c')
if pref.is_so {
out_name_c = get_vtmp_filename(pref.out_name, '.tmp.so.c')
mut out_name_c := get_vtmp_filename(b.pref.out_name, '.tmp.c')
if b.pref.is_so {
out_name_c = get_vtmp_filename(b.pref.out_name, '.tmp.so.c')
}
b.build_c(files, out_name_c)
b.cc()
}

View File

@ -34,11 +34,10 @@ pub fn compile(command string, pref &pref.Preferences) {
// println(pref)
}
mut tmark := benchmark.new_benchmark()
mut files := []string
match pref.backend {
.c { b.compile_c(files, pref) }
.js { b.compile_js(files, pref) }
.x64 { b.compile_x64(files, pref) }
.c { b.compile_c() }
.js { b.compile_js() }
.x64 { b.compile_x64() }
else {
eprintln('backend not implemented `$pref.backend`')
exit(1)
@ -213,10 +212,7 @@ pub fn (v Builder) get_user_files() []string {
v.log('> add all .v files from directory "${dir}" ...')
}
// Add .v files from the directory being compiled
files := v.v_files_from_dir(dir)
for file in files {
user_files << file
}
user_files << v.v_files_from_dir(dir)
}
if user_files.len == 0 {
println('No input .v files')

View File

@ -40,14 +40,14 @@ pub fn (b mut Builder) build_js(v_files []string, out_file string) {
f.close()
}
pub fn (b mut Builder) compile_js(files []string, pref &pref.Preferences) {
pub fn (b mut Builder) compile_js() {
//TODO files << b.get_builtin_files()
files << b.get_user_files()
files := b.get_user_files()
b.set_module_lookup_paths()
if pref.is_verbose {
if b.pref.is_verbose {
println('all .v files:')
println(files)
}
b.build_js(files, pref.out_name + '.js')
b.build_js(files, b.pref.out_name + '.js')
//TODO run the file
}

View File

@ -30,9 +30,9 @@ pub fn (b mut Builder) build_x64(v_files []string, out_file string) {
b.info('x64 GEN: ${gen_time}ms')
}
pub fn (b mut Builder) compile_x64(files []string, pref &pref.Preferences) {
pub fn (b mut Builder) compile_x64() {
// v.files << v.v_files_from_dir(os.join_path(v.pref.vlib_path,'builtin','bare'))
files << pref.path
files := [b.pref.path]
b.set_module_lookup_paths()
b.build_x64(files, pref.out_name)
b.build_x64(files, b.pref.out_name)
}