ci: fix v -o v2 -usecache cmd/v after ad5b829

This commit is contained in:
Delyan Angelov 2025-04-21 21:11:04 +03:00
parent 0a50715b03
commit a0a83248e0
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED

View file

@ -1,7 +1,6 @@
// Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
@[has_globals]
module main
import os
@ -60,7 +59,15 @@ const external_tools = [
]
const list_of_flags_that_allow_duplicates = ['cc', 'd', 'define', 'cf', 'cflags']
__global timers = &util.Timers(unsafe { nil })
@[unsafe]
fn timers_pointer(p &util.Timers) &util.Timers {
// TODO: the static variable here is used as a workaround for the current incompatibility of -usecache and globals in the main module:
mut static ptimers := unsafe { &util.Timers(nil) }
if p != unsafe { nil } {
ptimers = p
}
return ptimers
}
fn main() {
unbuffer_stdout()
@ -71,12 +78,18 @@ fn main() {
if '-show-timings' in os.args {
timers_should_print = true
}
timers = util.new_timers(should_print: timers_should_print, label: 'main')
mut timers := unsafe {
timers_pointer(util.new_timers(
should_print: timers_should_print
label: 'main'
))
}
timers.start('v start')
timers.show('v start')
timers.start('TOTAL')
// use at_exit here, instead of defer, since some code paths later do early exit(0) or exit(1), for showing errors, or after `v run`
at_exit(fn () {
mut timers := unsafe { timers_pointer(nil) }
timers.show('TOTAL')
})!
timers.start('v parsing CLI args')