From 3e324befd0dd85bf895372a1a7c3cffda53cdc30 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 18 Apr 2020 03:17:19 +0800 Subject: [PATCH] builder: clean up and simplify some methods --- vlib/v/builder/c.v | 20 +++++++++----------- vlib/v/builder/compile.v | 12 ++++-------- vlib/v/builder/js.v | 8 ++++---- vlib/v/builder/x64.v | 6 +++--- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/vlib/v/builder/c.v b/vlib/v/builder/c.v index 2f9a3181b6..11098fb19d 100644 --- a/vlib/v/builder/c.v +++ b/vlib/v/builder/c.v @@ -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() } - - diff --git a/vlib/v/builder/compile.v b/vlib/v/builder/compile.v index ac53cc6fc3..0d7c3e11d8 100644 --- a/vlib/v/builder/compile.v +++ b/vlib/v/builder/compile.v @@ -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') diff --git a/vlib/v/builder/js.v b/vlib/v/builder/js.v index 1965051556..7bb547a5f3 100644 --- a/vlib/v/builder/js.v +++ b/vlib/v/builder/js.v @@ -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 } diff --git a/vlib/v/builder/x64.v b/vlib/v/builder/x64.v index b1caff4c07..210a274850 100644 --- a/vlib/v/builder/x64.v +++ b/vlib/v/builder/x64.v @@ -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) } \ No newline at end of file