2019-11-01 00:15:03 +01:00
|
|
|
module compiler
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
pub fn launch_tool(tname string){
|
|
|
|
vexe := vexe_path()
|
|
|
|
vroot := os.dir(vexe)
|
|
|
|
mut oargs := os.args
|
2019-11-17 12:36:05 +01:00
|
|
|
oargs[0] = '"$vexe"' // make it more explicit
|
2019-11-01 00:15:03 +01:00
|
|
|
tool_exe := os.realpath('$vroot/tools/$tname')
|
|
|
|
tool_source := os.realpath('$vroot/tools/${tname}.v')
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
tool_args := oargs.join(' ')
|
2019-11-17 12:36:05 +01:00
|
|
|
tool_command := '"$tool_exe" $tool_args'
|
2019-11-01 00:15:03 +01:00
|
|
|
//println('Launching: "$tool_command" ...')
|
2019-11-28 09:46:52 +01:00
|
|
|
|
2019-11-01 00:15:03 +01:00
|
|
|
mut tool_should_be_recompiled := false
|
2019-12-04 21:03:12 +01:00
|
|
|
if !os.exists( tool_exe ) {
|
2019-11-01 00:15:03 +01:00
|
|
|
// fresh checkout
|
|
|
|
tool_should_be_recompiled = true
|
|
|
|
}else{
|
|
|
|
if os.file_last_mod_unix( tool_exe ) <= os.file_last_mod_unix( vexe ) {
|
|
|
|
// v was recompiled, maybe after v up ...
|
|
|
|
// rebuild the tool too just in case
|
|
|
|
tool_should_be_recompiled = true
|
|
|
|
}
|
|
|
|
if os.file_last_mod_unix( tool_exe ) <= os.file_last_mod_unix( tool_source ) {
|
|
|
|
// the user changed the source code of the tool
|
|
|
|
tool_should_be_recompiled = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if tool_should_be_recompiled {
|
2019-11-17 12:36:05 +01:00
|
|
|
compilation_command := '"$vexe" "$tool_source"'
|
2019-11-01 00:15:03 +01:00
|
|
|
//println('Compiling $tname with: "$compilation_command"')
|
|
|
|
tool_compilation := os.exec(compilation_command) or { panic(err) }
|
|
|
|
if tool_compilation.exit_code != 0 {
|
2019-11-07 14:17:32 +01:00
|
|
|
panic('V tool "$tool_source" could not be compiled\n' + tool_compilation.output)
|
2019-11-01 00:15:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
exit( os.system(tool_command) )
|
|
|
|
}
|