all: use arguments() instead of os.args in some files

This commit is contained in:
Alexander Medvednikov 2025-02-20 03:07:05 +03:00
parent 0dd7698fd1
commit a045bb0132
4 changed files with 20 additions and 21 deletions

View File

@ -6,6 +6,7 @@ import time
import arrays import arrays
import log import log
const args = arguments()
const warmup_samples = 2 const warmup_samples = 2
const max_samples = 20 const max_samples = 20
@ -54,7 +55,7 @@ fn main() {
if vdir.contains('/tmp/cirrus-ci-build') { if vdir.contains('/tmp/cirrus-ci-build') {
ccompiler_path = 'clang' ccompiler_path = 'clang'
} }
if os.args.contains('-clang') { if args.contains('-clang') {
ccompiler_path = 'clang' ccompiler_path = 'clang'
} }
elog('fast_dir: ${fast_dir} | vdir: ${vdir} | compiler: ${ccompiler_path}') elog('fast_dir: ${fast_dir} | vdir: ${vdir} | compiler: ${ccompiler_path}')
@ -68,7 +69,7 @@ fn main() {
os.create('table.html')! os.create('table.html')!
} }
if !os.args.contains('-noupdate') { if !args.contains('-noupdate') {
elog('Fetching updates...') elog('Fetching updates...')
ret := lsystem('${vdir}/v up') ret := lsystem('${vdir}/v up')
if ret != 0 { if ret != 0 {
@ -83,7 +84,7 @@ fn main() {
uploaded_index := os.read_file('fast.vlang.io/index.html')! uploaded_index := os.read_file('fast.vlang.io/index.html')!
if uploaded_index.contains('>${commit}<') { if uploaded_index.contains('>${commit}<') {
elog('NOTE: commit ${commit} had been benchmarked already.') elog('NOTE: commit ${commit} had been benchmarked already.')
if !os.args.contains('-force') { if !args.contains('-force') {
elog('nothing more to do') elog('nothing more to do')
return return
} }
@ -98,21 +99,21 @@ fn main() {
elog('Benchmarking commit ${commit} , with commit message: "${message}", commit_date: ${commit_date}, date: ${date}') elog('Benchmarking commit ${commit} , with commit message: "${message}", commit_date: ${commit_date}, date: ${date}')
// build an optimized V // build an optimized V
if os.args.contains('-do-not-rebuild-vprod') { if args.contains('-do-not-rebuild-vprod') {
if !os.exists('vprod') { if !os.exists('vprod') {
elog('Exiting, since if you use `-do-not-rebuild-vprod`, you should already have a `${vdir}/vprod` executable, but it is missing!') elog('Exiting, since if you use `-do-not-rebuild-vprod`, you should already have a `${vdir}/vprod` executable, but it is missing!')
return return
} }
} else { } else {
elog(' Building vprod...') elog(' Building vprod...')
if os.args.contains('-noprod') { if args.contains('-noprod') {
lexec('./v -o vprod cmd/v') // for faster debugging lexec('./v -o vprod cmd/v') // for faster debugging
} else { } else {
lexec('./v -o vprod -prod -prealloc cmd/v') lexec('./v -o vprod -prod -prealloc cmd/v')
} }
} }
if !os.args.contains('-do-not-rebuild-caches') { if !args.contains('-do-not-rebuild-caches') {
elog('clearing caches...') elog('clearing caches...')
// cache vlib modules // cache vlib modules
lexec('${vdir}/v wipe-cache') lexec('${vdir}/v wipe-cache')
@ -163,7 +164,7 @@ fn main() {
res.close() res.close()
// upload the result to github pages // upload the result to github pages
if os.args.contains('-upload') { if args.contains('-upload') {
$if freebsd { $if freebsd {
// Note: tcc currently can not compile vpm on FreeBSD, due to its dependence on net.ssl and net.mbedtls, so force using clang instead: // Note: tcc currently can not compile vpm on FreeBSD, due to its dependence on net.ssl and net.mbedtls, so force using clang instead:
elog('FreeBSD: compiling the VPM tool with clang...') elog('FreeBSD: compiling the VPM tool with clang...')

View File

@ -4,7 +4,8 @@ import os
import os.cmdline import os.cmdline
import v.util.recompilation import v.util.recompilation
const is_debug = os.args.contains('-debug') const args_ = arguments()
const is_debug = args_.contains('-debug')
// support a renamed `v` executable too: // support a renamed `v` executable too:
const vexe = os.getenv_opt('VEXE') or { @VEXE } const vexe = os.getenv_opt('VEXE') or { @VEXE }
@ -24,7 +25,7 @@ fn main() {
recompilation.must_be_enabled(vroot, 'Please install V from source, to use `${vexe_name} self` .') recompilation.must_be_enabled(vroot, 'Please install V from source, to use `${vexe_name} self` .')
os.chdir(vroot)! os.chdir(vroot)!
os.setenv('VCOLORS', 'always', true) os.setenv('VCOLORS', 'always', true)
mut args := os.args[1..].filter(it != 'self') mut args := args_[1..].filter(it != 'self')
if args.len == 0 || ('-cc' !in args && '-prod' !in args && '-parallel-cc' !in args) { if args.len == 0 || ('-cc' !in args && '-prod' !in args && '-parallel-cc' !in args) {
// compiling by default, i.e. `v self`: // compiling by default, i.e. `v self`:
uos := os.user_os() uos := os.user_os()

View File

@ -18,14 +18,16 @@ struct App {
skip_current bool // skip the current hash check, enabling easier testing on the same commit, without using docker etc skip_current bool // skip the current hash check, enabling easier testing on the same commit, without using docker etc
} }
const args = arguments()
fn new_app() App { fn new_app() App {
return App{ return App{
is_verbose: '-v' in os.args is_verbose: '-v' in args
is_prod: '-prod' in os.args is_prod: '-prod' in args
vexe: vexe vexe: vexe
vroot: vroot vroot: vroot
skip_v_self: '-skip_v_self' in os.args skip_v_self: '-skip_v_self' in args
skip_current: '-skip_current' in os.args skip_current: '-skip_current' in args
} }
} }

View File

@ -1,23 +1,19 @@
// This program displays the fibonacci sequence // This program displays the fibonacci sequence
import os const args = arguments()
fn main() { fn main() {
// Check for user input // Check for user input
if os.args.len != 2 { if args.len != 2 {
println('usage: fibonacci [rank]') println('usage: fibonacci [rank]')
return return
} }
// Parse first argument and cast it to int // Parse first argument and cast it to int
stop := args[1].int()
stop := os.args[1].int()
// Can only calculate correctly until rank 92 // Can only calculate correctly until rank 92
if stop > 92 { if stop > 92 {
println('rank must be 92 or less') println('rank must be 92 or less')
return return
} }
// Three consecutive terms of the sequence // Three consecutive terms of the sequence
mut a := i64(0) mut a := i64(0)
mut b := i64(0) mut b := i64(0)
@ -29,7 +25,6 @@ fn main() {
b = c b = c
// Compute the new term // Compute the new term
c = a + b c = a + b
// Print the new term // Print the new term
println(c) println(c)
} }