vfmt: run fmt over cmd/tools/*.v

pull/6665/head
Delyan Angelov 2020-10-21 14:36:16 +03:00
parent 1aa6c125d9
commit 8bc2f8ccda
4 changed files with 99 additions and 52 deletions

View File

@ -30,13 +30,16 @@ const (
struct Context {
mut:
vgo vgit.VGitOptions
commit_v string = 'master' // the commit from which you want to produce a working v compiler (this may be a commit-ish too)
commit_vc string = 'master' // this will be derived from commit_v
commit_v string = 'master'
// the commit from which you want to produce a working v compiler (this may be a commit-ish too)
commit_vc string = 'master'
// this will be derived from commit_v
commit_v_hash string // this will be filled from the commit-ish commit_v using rev-list. It IS a commit hash.
path_v string // the full path to the v folder inside workdir.
path_vc string // the full path to the vc folder inside workdir.
cmd_to_run string // the command that you want to run *in* the oldv repo
cc string = 'cc' // the C compiler to use for bootstrapping.
cc string = 'cc'
// the C compiler to use for bootstrapping.
cleanup bool // should the tool run a cleanup first
}

View File

@ -237,7 +237,7 @@ fn (mut context Context) show_diff_summary() {
if r.icmd == 0 {
first_cmd_percentage = cpercent
}
println(' $first_marker${(i+1):3} | ${cpercent:6.1f}% slower | ${r.cmd:-55s} | $r.atiming')
println(' $first_marker${(i + 1):3} | ${cpercent:6.1f}% slower | ${r.cmd:-55s} | $r.atiming')
}
$if debugcontext ? {
println('context: $context')

View File

@ -377,7 +377,8 @@ fn doc_node_html(dd doc.DocNode, link string, head bool, tb &table.Table) string
md_content := markdown.to_html(dd.comment)
hlighted_code := html_highlight(dd.content, tb)
node_class := if dd.kind == .const_group { ' const' } else { '' }
sym_name := if dd.parent_name.len > 0 && dd.parent_name != 'void' { dd.parent_name + '.' + dd.name } else { dd.name }
sym_name := if dd.parent_name.len > 0 && dd.parent_name != 'void' { dd.parent_name + '.' +
dd.name } else { dd.name }
node_id := slug(sym_name)
hash_link := if !head { ' <a href="#$node_id">#</a>' } else { '' }
dnw.writeln('<section id="$node_id" class="doc-node$node_class">')
@ -461,8 +462,7 @@ fn (cfg DocConfig) gen_html(idx int) string {
}
names := doc.head.name.split('.')
submod_prefix = if names.len > 1 { names[0] } else { doc.head.name }
href_name := if (dcs.is_vlib &&
doc.head.name == 'builtin' && !cfg.include_readme) ||
href_name := if (dcs.is_vlib && doc.head.name == 'builtin' && !cfg.include_readme) ||
doc.head.name == 'README' {
'./index.html'
} else if submod_prefix !in cfg.docs.map(it.head.name) {
@ -572,8 +572,7 @@ fn (cfg DocConfig) gen_footer_text(idx int) string {
fn (cfg DocConfig) render_doc(doc doc.Doc, i int) (string, string) {
// since builtin is generated first, ignore it
mut name := if (doc.is_vlib &&
doc.head.name == 'builtin' && !cfg.include_readme) ||
mut name := if (doc.is_vlib && doc.head.name == 'builtin' && !cfg.include_readme) ||
doc.head.name == 'README' {
'index'
} else if !cfg.is_multi && !os.is_dir(cfg.output_path) {
@ -604,7 +603,7 @@ fn (cfg DocConfig) work_processor(mut work sync.Channel, mut wg sync.WaitGroup)
}
file_name, content := cfg.render_doc(pdoc.d, pdoc.i)
output_path := os.join_path(cfg.output_path, file_name)
println('Generating ${output_path}')
println('Generating $output_path')
os.write_file(output_path, content)
}
wg.done()
@ -637,14 +636,16 @@ fn (cfg DocConfig) render() map[string]string {
}
fn (mut cfg DocConfig) render_static() {
if cfg.output_type != .html { return }
if cfg.output_type != .html {
return
}
cfg.assets = {
'doc_css': cfg.get_resource(css_js_assets[0], true),
'normalize_css': cfg.get_resource(css_js_assets[1], true),
'doc_js': cfg.get_resource(css_js_assets[2], !cfg.serve_http),
'light_icon': cfg.get_resource('light.svg', true),
'dark_icon': cfg.get_resource('dark.svg', true),
'menu_icon': cfg.get_resource('menu.svg', true),
'doc_css': cfg.get_resource(css_js_assets[0], true)
'normalize_css': cfg.get_resource(css_js_assets[1], true)
'doc_js': cfg.get_resource(css_js_assets[2], !cfg.serve_http)
'light_icon': cfg.get_resource('light.svg', true)
'dark_icon': cfg.get_resource('dark.svg', true)
'menu_icon': cfg.get_resource('menu.svg', true)
'arrow_icon': cfg.get_resource('arrow.svg', true)
}
}
@ -674,8 +675,7 @@ fn (cfg DocConfig) emit_generate_err(err string, errcode int) {
mod_list := get_modules_list(cfg.input_path, []string{})
println('Available modules:\n==================')
for mod in mod_list {
println(mod.all_after('vlib/').all_after('modules/').replace('/',
'.'))
println(mod.all_after('vlib/').all_after('modules/').replace('/', '.'))
}
err_msg += ' Use the `-m` flag when generating docs from a directory that has multiple modules.'
}
@ -732,7 +732,7 @@ fn (mut cfg DocConfig) generate_docs_from_file() {
is_local_and_single := cfg.is_local && !cfg.is_multi
for dirpath in dirs {
mut dcs := doc.Doc{}
cfg.vprintln('Generating docs for ${dirpath}')
cfg.vprintln('Generating docs for $dirpath')
if is_local_and_single {
dcs = doc.generate_from_pos(dirpath, cfg.local_filename, cfg.local_pos) or {
cfg.emit_generate_err(err, errcode)
@ -752,7 +752,7 @@ fn (mut cfg DocConfig) generate_docs_from_file() {
readme_contents := cfg.get_readme(dirpath)
dcs.head.comment = readme_contents
}
mut new_contents := map[string]doc.DocNode
mut new_contents := map[string]doc.DocNode{}
if cfg.pub_only {
for name, oc in dcs.contents {
mut c := oc
@ -919,7 +919,7 @@ fn (cfg DocConfig) get_resource(name string, minify bool) string {
} else {
output_path := os.join_path(cfg.output_path, name)
if !os.exists(output_path) {
println('Generating ${output_path}')
println('Generating $output_path')
os.write_file(output_path, res)
}
return name

View File

@ -16,7 +16,7 @@ fn (mut a App) println(s string) {
fn (mut a App) collect_info() {
mut os_kind := os.user_os()
mut arch_details := []string{}
arch_details << '${runtime.nr_cpus()} cpus'
arch_details << '$runtime.nr_cpus() cpus'
if runtime.is_32bit() {
arch_details << '32bit'
}
@ -30,7 +30,9 @@ fn (mut a App) collect_info() {
arch_details << 'little endian'
}
if os_kind == 'macos' {
arch_details << a.cmd(command:'sysctl -n machdep.cpu.brand_string')
arch_details << a.cmd({
command: 'sysctl -n machdep.cpu.brand_string'
})
}
if os_kind == 'linux' {
info := a.cpu_info()
@ -41,7 +43,10 @@ fn (mut a App) collect_info() {
}
}
if os_kind == 'windows' {
arch_details << a.cmd(command:'wmic cpu get name /format:table', line: 1)
arch_details << a.cmd({
command: 'wmic cpu get name /format:table'
line: 1
})
}
//
mut os_details := ''
@ -49,7 +54,9 @@ fn (mut a App) collect_info() {
os_details = a.get_linux_os_name()
info := a.cpu_info()
if 'hypervisor' in info['flags'] {
if 'microsoft' in a.cmd(command: 'cat /proc/sys/kernel/osrelease') {
if 'microsoft' in a.cmd({
command: 'cat /proc/sys/kernel/osrelease'
}) {
os_details += ' (WSL)'
} else {
os_details += ' (VM)'
@ -61,12 +68,21 @@ fn (mut a App) collect_info() {
}
} else if os_kind == 'macos' {
mut details := []string{}
details << a.cmd(command: 'sw_vers -productName')
details << a.cmd(command: 'sw_vers -productVersion')
details << a.cmd(command: 'sw_vers -buildVersion')
details << a.cmd({
command: 'sw_vers -productName'
})
details << a.cmd({
command: 'sw_vers -productVersion'
})
details << a.cmd({
command: 'sw_vers -buildVersion'
})
os_details = details.join(', ')
} else if os_kind == 'windows' {
wmic_info := a.cmd(command:'wmic os get * /format:value', line: -1)
wmic_info := a.cmd({
command: 'wmic os get * /format:value'
line: -1
})
p := a.parse(wmic_info, '=')
caption, build_number, os_arch := p['caption'], p['buildnumber'], p['osarchitecture']
os_details = '$caption v$build_number $os_arch'
@ -76,7 +92,9 @@ fn (mut a App) collect_info() {
}
a.line('OS', '$os_kind, $os_details')
a.line('Processor', arch_details.join(', '))
a.line('CC version', a.cmd(command:'cc --version'))
a.line('CC version', a.cmd({
command: 'cc --version'
}))
a.println('')
vexe := os.getenv('VEXE')
vroot := os.dir(vexe)
@ -84,7 +102,9 @@ fn (mut a App) collect_info() {
a.line('vroot', vroot)
a.line('vexe', vexe)
a.line('vexe mtime', time.unix(os.file_last_mod_unix(vexe)).str())
is_writable_vroot := os.is_writable_folder(vroot) or { false }
is_writable_vroot := os.is_writable_folder(vroot) or {
false
}
a.line('is vroot writable', is_writable_vroot.str())
a.line('V full version', util.full_v_version(true))
vtmp := os.getenv('VTMP')
@ -96,7 +116,9 @@ fn (mut a App) collect_info() {
a.line('env VFLAGS', '"$vflags"')
}
a.println('')
a.line('Git version', a.cmd(command:'git --version'))
a.line('Git version', a.cmd({
command: 'git --version'
}))
a.line('Git vroot status', a.git_info())
a.line('.git/config present', os.is_file('.git/config').str())
//
@ -107,7 +129,7 @@ fn (mut a App) collect_info() {
}
struct CmdConfig {
line int
line int
command string
}
@ -116,7 +138,9 @@ fn (mut a App) cmd(c CmdConfig) string {
return 'N/A'
}
if x.exit_code == 0 {
if c.line < 0 { return x.output }
if c.line < 0 {
return x.output
}
output := x.output.split_into_lines()
if output.len > 0 && output.len > c.line {
return output[c.line]
@ -130,7 +154,7 @@ fn (mut a App) line(label string, value string) {
}
fn (app &App) parse(config string, sep string) map[string]string {
mut m := map[string]string
mut m := map[string]string{}
for line in config.split_into_lines() {
sline := line.trim_space()
if sline.len == 0 || sline[0] == `#` {
@ -154,26 +178,35 @@ fn (mut a App) get_linux_os_name() string {
if !os.is_file('/etc/os-release') {
continue
}
lines := os.read_file('/etc/os-release') or { continue }
lines := os.read_file('/etc/os-release') or {
continue
}
vals := a.parse(lines, '=')
if vals['PRETTY_NAME'] == '' { continue }
if vals['PRETTY_NAME'] == '' {
continue
}
os_details = vals['PRETTY_NAME']
break
}
'lsb_release' {
exists := a.cmd(command:'type lsb_release')
exists := a.cmd({
command: 'type lsb_release'
})
if exists.starts_with('Error') {
continue
}
os_details = a.cmd(command: 'lsb_release -d -s')
os_details = a.cmd({
command: 'lsb_release -d -s'
})
break
}
'kernel' {
if !os.is_file('/proc/version') {
continue
}
os_details = a.cmd(command: 'cat /proc/version')
os_details = a.cmd({
command: 'cat /proc/version'
})
break
}
'uname' {
@ -191,19 +224,26 @@ fn (mut a App) cpu_info() map[string]string {
if a.cached_cpuinfo.len > 0 {
return a.cached_cpuinfo
}
info := os.exec('cat /proc/cpuinfo') or { return a.cached_cpuinfo }
info := os.exec('cat /proc/cpuinfo') or {
return a.cached_cpuinfo
}
vals := a.parse(info.output, ':')
a.cached_cpuinfo = vals
return vals
}
fn (mut a App) git_info() string {
mut out := a.cmd(command:'git -C . describe --abbrev=8 --dirty --always --tags').trim_space()
os.exec('git -C . remote add V_REPO https://github.com/vlang/v') or {} // ignore failure (i.e. remote exists)
os.exec('git -C . fetch V_REPO') or {}
commit_count := a.cmd(command:'git rev-list @{0}...V_REPO/master --right-only --count').int()
if commit_count > 0 { out += ' ($commit_count commit(s) behind V master)' }
mut out := a.cmd({
command: 'git -C . describe --abbrev=8 --dirty --always --tags'
}).trim_space()
os.exec('git -C . remote add V_REPO https://github.com/vlang/v') or { } // ignore failure (i.e. remote exists)
os.exec('git -C . fetch V_REPO') or { }
commit_count := a.cmd({
command: 'git rev-list @{0}...V_REPO/master --right-only --count'
}).int()
if commit_count > 0 {
out += ' ($commit_count commit(s) behind V master)'
}
return out
}
@ -212,8 +252,12 @@ fn (mut a App) report_tcc_version(tccfolder string) {
a.line(tccfolder, 'N/A')
return
}
tcc_branch_name := a.cmd(command:'git -C $tccfolder rev-parse --abbrev-ref HEAD')
tcc_commit := a.cmd(command:'git -C $tccfolder describe --abbrev=8 --dirty --always --tags')
tcc_branch_name := a.cmd({
command: 'git -C $tccfolder rev-parse --abbrev-ref HEAD'
})
tcc_commit := a.cmd({
command: 'git -C $tccfolder describe --abbrev=8 --dirty --always --tags'
})
a.line('$tccfolder status', '$tcc_branch_name $tcc_commit')
}
@ -223,7 +267,7 @@ fn (mut a App) report_info() {
}
}
fn main(){
fn main() {
mut app := App{}
app.collect_info()
app.report_info()