mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
compiler: support storing temporary files under TMPDIR/v/
Fix for filepath.join not \0 terminating its result
This commit is contained in:

committed by
Alexander Medvednikov

parent
200fcd41ce
commit
be7cf3e812
@ -799,6 +799,7 @@ pub fn new_v(args[]string) &V {
|
||||
vgen_buf.writeln('module vgen\nimport strings')
|
||||
|
||||
joined_args := args.join(' ')
|
||||
|
||||
target_os := get_arg(joined_args, 'os', '')
|
||||
comptime_define := get_arg(joined_args, 'd', '')
|
||||
//println('comptimedefine=$comptime_define')
|
||||
@ -930,8 +931,8 @@ pub fn new_v(args[]string) &V {
|
||||
println('Go to https://vlang.io to install V.')
|
||||
exit(1)
|
||||
}
|
||||
// println('out_name:$out_name')
|
||||
mut out_name_c := os.realpath('${out_name}.tmp.c')
|
||||
|
||||
mut out_name_c := get_vtmp_filename( out_name, '.tmp.c')
|
||||
|
||||
cflags := get_cmdline_cflags(args)
|
||||
|
||||
@ -978,7 +979,7 @@ pub fn new_v(args[]string) &V {
|
||||
println('C compiler=$pref.ccompiler')
|
||||
}
|
||||
if pref.is_so {
|
||||
out_name_c = out_name.all_after(os.path_separator) + '_shared_lib.c'
|
||||
out_name_c = get_vtmp_filename( out_name, '.tmp.so.c')
|
||||
}
|
||||
$if !linux {
|
||||
if pref.is_bare && !out_name.ends_with('.c') {
|
||||
|
@ -28,6 +28,9 @@ pub const (
|
||||
You can set it like this: `export VFLAGS="-cc clang -debug"` on *nix,
|
||||
`set VFLAGS=-cc msvc` on Windows.
|
||||
|
||||
V respects the TMPDIR environment variable, and will put .tmp.c files in TMPDIR/v/ .
|
||||
If you have not set it, a suitable platform specific folder (like /tmp) will be used.
|
||||
|
||||
Options/commands:
|
||||
-h, help Display this information.
|
||||
-o <file> Write output to <file>.
|
||||
|
21
vlib/compiler/vtmp.v
Normal file
21
vlib/compiler/vtmp.v
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
module compiler
|
||||
|
||||
import os
|
||||
import filepath
|
||||
|
||||
pub fn get_vtmp_folder() string {
|
||||
vtmp := filepath.join(os.tmpdir(),'v')
|
||||
if !os.dir_exists( vtmp ) {
|
||||
os.mkdir(vtmp)
|
||||
}
|
||||
return vtmp
|
||||
}
|
||||
|
||||
pub fn get_vtmp_filename(base_file_name string, postfix string) string {
|
||||
vtmp := get_vtmp_folder()
|
||||
return os.realpath( filepath.join(vtmp, os.filename( base_file_name ) + postfix) )
|
||||
}
|
Reference in New Issue
Block a user