2019-06-23 04:21:30 +02:00
|
|
|
// 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.
|
|
|
|
|
2019-06-22 20:20:28 +02:00
|
|
|
module main
|
|
|
|
|
2019-08-29 00:52:32 +02:00
|
|
|
import (
|
2019-10-13 15:37:43 +02:00
|
|
|
compiler
|
2019-09-16 16:29:06 +02:00
|
|
|
benchmark
|
2019-10-30 15:07:41 +01:00
|
|
|
os
|
2019-10-18 19:49:34 +02:00
|
|
|
//time
|
2019-08-29 00:52:32 +02:00
|
|
|
)
|
2019-06-22 20:20:28 +02:00
|
|
|
|
|
|
|
fn main() {
|
2019-10-18 19:49:34 +02:00
|
|
|
//t := time.ticks()
|
|
|
|
//defer { println(time.ticks() - t) }
|
2019-07-03 13:20:43 +02:00
|
|
|
// There's no `flags` module yet, so args have to be parsed manually
|
2019-10-13 15:37:43 +02:00
|
|
|
args := compiler.env_vflags_and_os_args()
|
2019-10-18 06:48:46 +02:00
|
|
|
options := args.filter(it.starts_with('-'))
|
tools/vget => tools/v , search, install, etc
* compiler: rename vget to tools/vpm, implement draft support for v vpm search, v vpm update, v vpm install, v vpm remove, v vpm help .
* compiler: use "v pm" instead of "v vpm" to reduce the redundancy of typing, as suggested by slapden
* Use 'v install modulename', 'v search keywords', 'v update modulename', 'v remove modulename' instead of the longer 'v pm install modulename' etc.
2019-11-01 13:19:04 +01:00
|
|
|
//NB: commands should be explicitly set by the command line (os.args)
|
|
|
|
// NOT passed through VFLAGS, otherwise the naked `v` invocation for
|
|
|
|
// the repl does not work when you have VFLAGS with -cc or -cflags set
|
|
|
|
// which may be surprising to v users.
|
|
|
|
stuff_after_executable := os.args[1..]
|
|
|
|
commands := stuff_after_executable.filter(!it.starts_with('-'))
|
|
|
|
|
2019-06-22 20:20:28 +02:00
|
|
|
// Print the version and exit.
|
2019-10-18 06:48:46 +02:00
|
|
|
if '-v' in options || '--version' in options || 'version' in commands {
|
2019-10-13 15:37:43 +02:00
|
|
|
version_hash := compiler.vhash()
|
|
|
|
println('V $compiler.Version $version_hash')
|
2019-06-22 20:20:28 +02:00
|
|
|
return
|
|
|
|
}
|
2019-11-04 03:05:26 +01:00
|
|
|
else if '-h' in options || '--help' in options || 'help' in commands {
|
|
|
|
println(compiler.help_text)
|
|
|
|
return
|
|
|
|
}
|
2019-10-18 06:48:46 +02:00
|
|
|
else if 'translate' in commands {
|
2019-08-17 21:19:37 +02:00
|
|
|
println('Translating C to V will be available in V 0.3')
|
|
|
|
return
|
|
|
|
}
|
2019-10-18 06:48:46 +02:00
|
|
|
else if 'up' in commands {
|
2019-11-01 11:14:59 +01:00
|
|
|
compiler.launch_tool('vup')
|
2019-08-17 21:19:37 +02:00
|
|
|
return
|
|
|
|
}
|
tools/vget => tools/v , search, install, etc
* compiler: rename vget to tools/vpm, implement draft support for v vpm search, v vpm update, v vpm install, v vpm remove, v vpm help .
* compiler: use "v pm" instead of "v vpm" to reduce the redundancy of typing, as suggested by slapden
* Use 'v install modulename', 'v search keywords', 'v update modulename', 'v remove modulename' instead of the longer 'v pm install modulename' etc.
2019-11-01 13:19:04 +01:00
|
|
|
else if ('search' in commands) || ('install' in commands) || ('update' in commands) || ('remove' in commands){
|
|
|
|
compiler.launch_tool('vpm')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
else if ('get' in commands) { // obsoleted
|
2019-09-11 12:35:03 +02:00
|
|
|
println('use `v install` to install modules from vpm.vlang.io ')
|
2019-08-17 21:19:37 +02:00
|
|
|
return
|
|
|
|
}
|
2019-10-18 06:48:46 +02:00
|
|
|
else if 'symlink' in commands {
|
2019-10-13 15:37:43 +02:00
|
|
|
compiler.create_symlink()
|
2019-08-27 18:35:48 +02:00
|
|
|
return
|
|
|
|
}
|
2019-10-13 15:37:43 +02:00
|
|
|
// TODO quit if the v compiler is too old
|
2019-07-02 00:00:27 +02:00
|
|
|
// u := os.file_last_mod_unix('v')
|
2019-06-22 22:00:38 +02:00
|
|
|
// If there's no tmp path with current version yet, the user must be using a pre-built package
|
2019-09-29 03:54:12 +02:00
|
|
|
//
|
2019-06-22 20:20:28 +02:00
|
|
|
// Just fmt and exit
|
2019-10-18 06:48:46 +02:00
|
|
|
else if 'fmt' in commands {
|
2019-10-13 15:37:43 +02:00
|
|
|
compiler.vfmt(args)
|
2019-06-22 20:20:28 +02:00
|
|
|
return
|
|
|
|
}
|
2019-10-18 06:48:46 +02:00
|
|
|
else if 'test' in commands {
|
2019-11-01 00:15:03 +01:00
|
|
|
compiler.launch_tool('vtest')
|
2019-09-16 16:29:06 +02:00
|
|
|
return
|
|
|
|
}
|
tools/vget => tools/v , search, install, etc
* compiler: rename vget to tools/vpm, implement draft support for v vpm search, v vpm update, v vpm install, v vpm remove, v vpm help .
* compiler: use "v pm" instead of "v vpm" to reduce the redundancy of typing, as suggested by slapden
* Use 'v install modulename', 'v search keywords', 'v update modulename', 'v remove modulename' instead of the longer 'v pm install modulename' etc.
2019-11-01 13:19:04 +01:00
|
|
|
// No args? REPL
|
|
|
|
else if 'runrepl' in commands || commands.len == 0 || (args.len == 2 && args[1] == '-') {
|
|
|
|
compiler.launch_tool('vrepl')
|
|
|
|
return
|
|
|
|
}
|
2019-10-18 06:48:46 +02:00
|
|
|
// Generate the docs and exit
|
|
|
|
else if 'doc' in commands {
|
2019-10-30 15:07:41 +01:00
|
|
|
vexe := os.executable()
|
|
|
|
vdir := os.dir(os.executable())
|
|
|
|
os.chdir(vdir)
|
|
|
|
mod := args.last()
|
|
|
|
os.system('$vexe build module vlib/' + args.last())
|
|
|
|
txt := os.read_file('$compiler.v_modules_path/vlib/${mod}.vh') or {
|
|
|
|
panic(err)
|
tools/vget => tools/v , search, install, etc
* compiler: rename vget to tools/vpm, implement draft support for v vpm search, v vpm update, v vpm install, v vpm remove, v vpm help .
* compiler: use "v pm" instead of "v vpm" to reduce the redundancy of typing, as suggested by slapden
* Use 'v install modulename', 'v search keywords', 'v update modulename', 'v remove modulename' instead of the longer 'v pm install modulename' etc.
2019-11-01 13:19:04 +01:00
|
|
|
}
|
2019-10-30 15:07:41 +01:00
|
|
|
println(txt)
|
2019-10-18 06:48:46 +02:00
|
|
|
exit(0)
|
2019-10-30 15:07:41 +01:00
|
|
|
// v.gen_doc_html_for_module(args.last())
|
tools/vget => tools/v , search, install, etc
* compiler: rename vget to tools/vpm, implement draft support for v vpm search, v vpm update, v vpm install, v vpm remove, v vpm help .
* compiler: use "v pm" instead of "v vpm" to reduce the redundancy of typing, as suggested by slapden
* Use 'v install modulename', 'v search keywords', 'v update modulename', 'v remove modulename' instead of the longer 'v pm install modulename' etc.
2019-11-01 13:19:04 +01:00
|
|
|
}
|
|
|
|
else {
|
2019-10-18 06:48:46 +02:00
|
|
|
//println('unknown command/argument\n')
|
|
|
|
//println(compiler.help_text)
|
tools/vget => tools/v , search, install, etc
* compiler: rename vget to tools/vpm, implement draft support for v vpm search, v vpm update, v vpm install, v vpm remove, v vpm help .
* compiler: use "v pm" instead of "v vpm" to reduce the redundancy of typing, as suggested by slapden
* Use 'v install modulename', 'v search keywords', 'v update modulename', 'v remove modulename' instead of the longer 'v pm install modulename' etc.
2019-11-01 13:19:04 +01:00
|
|
|
}
|
|
|
|
|
2019-10-09 05:01:43 +02:00
|
|
|
// Construct the V object from command line arguments
|
2019-10-13 15:37:43 +02:00
|
|
|
mut v := compiler.new_v(args)
|
2019-06-30 22:44:15 +02:00
|
|
|
if v.pref.is_verbose {
|
2019-06-22 20:20:28 +02:00
|
|
|
println(args)
|
|
|
|
}
|
2019-08-17 21:19:37 +02:00
|
|
|
|
2019-08-06 18:04:55 +02:00
|
|
|
if 'run' in args {
|
2019-08-09 22:37:31 +02:00
|
|
|
// always recompile for now, too error prone to skip recompilation otherwise
|
|
|
|
// for example for -repl usage, especially when piping lines to v
|
2019-08-17 21:19:37 +02:00
|
|
|
v.compile()
|
2019-08-06 18:04:55 +02:00
|
|
|
v.run_compiled_executable_and_exit()
|
|
|
|
}
|
2019-08-17 21:19:37 +02:00
|
|
|
|
2019-10-07 07:51:26 +02:00
|
|
|
mut tmark := benchmark.new_benchmark()
|
tools/vget => tools/v , search, install, etc
* compiler: rename vget to tools/vpm, implement draft support for v vpm search, v vpm update, v vpm install, v vpm remove, v vpm help .
* compiler: use "v pm" instead of "v vpm" to reduce the redundancy of typing, as suggested by slapden
* Use 'v install modulename', 'v search keywords', 'v update modulename', 'v remove modulename' instead of the longer 'v pm install modulename' etc.
2019-11-01 13:19:04 +01:00
|
|
|
v.compile()
|
2019-10-07 07:51:26 +02:00
|
|
|
if v.pref.is_stats {
|
|
|
|
tmark.stop()
|
|
|
|
println( 'compilation took: ' + tmark.total_duration().str() + 'ms')
|
|
|
|
}
|
2019-08-17 21:19:37 +02:00
|
|
|
|
2019-08-06 18:04:55 +02:00
|
|
|
if v.pref.is_test {
|
|
|
|
v.run_compiled_executable_and_exit()
|
|
|
|
}
|
2019-10-11 23:54:25 +02:00
|
|
|
|
2019-10-13 15:37:43 +02:00
|
|
|
v.finalize_compilation()
|
2019-10-11 23:54:25 +02:00
|
|
|
}
|
2019-10-14 04:18:48 +02:00
|
|
|
|