v.builder: use os.write_file/os.write_file_array for writing full files to disk.

pull/10922/head
Delyan Angelov 2021-07-24 08:29:35 +03:00
parent 0acb84d5a5
commit 72c56ccc85
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 3 additions and 10 deletions

View File

@ -21,14 +21,11 @@ pub fn (mut b Builder) build_c(v_files []string, out_file string) {
b.pref.out_name_c = os.real_path(out_file)
b.info('build_c($out_file)')
output2 := b.gen_c(v_files)
mut f := os.create(out_file) or { panic(err) }
f.writeln(output2) or { panic(err) }
f.close()
os.write_file(out_file, output2) or { panic(err) }
if b.pref.is_stats {
b.stats_lines = output2.count('\n') + 1
b.stats_bytes = output2.len
}
// os.write_file(out_file, b.gen_c(v_files))
}
pub fn (mut b Builder) compile_c() {

View File

@ -17,13 +17,11 @@ pub fn (mut b Builder) build_js(v_files []string, out_file string) {
b.out_name_js = out_file
b.info('build_js($out_file)')
output := b.gen_js(v_files)
mut f := os.create(out_file) or { panic(err) }
f.writeln(output) or { panic(err) }
os.write_file(out_file, output) or { panic(err) }
if b.pref.is_stats {
b.stats_lines = output.count('\n') + 1
b.stats_bytes = output.len
}
f.close()
}
pub fn (mut b Builder) compile_js() {

View File

@ -113,10 +113,8 @@ pub fn (mut g Gen) generate_header() {
pub fn (mut g Gen) create_executable() {
// Create the binary // should be .o ?
mut f := os.create(g.out_name) or { panic(err) }
os.write_file_array(g.out_name, g.buf) or { panic(err) }
os.chmod(g.out_name, 0o775) // make it executable
unsafe { f.write_ptr(g.buf.data, g.buf.len) }
f.close()
if g.pref.is_verbose {
println('\n$g.out_name: native binary has been successfully generated')
}