mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
ci: extract ci/common/runner.v
, use it to simplify ci/macos_ci.vsh even more
This commit is contained in:
parent
ce1fbaa0bd
commit
ee957e8fa6
2 changed files with 61 additions and 59 deletions
54
ci/common/runner.v
Normal file
54
ci/common/runner.v
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
module common
|
||||||
|
|
||||||
|
import os
|
||||||
|
import log
|
||||||
|
import term
|
||||||
|
import time
|
||||||
|
|
||||||
|
// exec is a helper function, to execute commands and exit early, if they fail.
|
||||||
|
pub fn exec(command string) {
|
||||||
|
log.info('cmd: ${command}')
|
||||||
|
result := os.system(command)
|
||||||
|
if result != 0 {
|
||||||
|
exit(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const is_github_job = os.getenv('GITHUB_JOB') != ''
|
||||||
|
|
||||||
|
pub type Fn = fn ()
|
||||||
|
|
||||||
|
pub struct Task {
|
||||||
|
pub mut:
|
||||||
|
f Fn = unsafe { nil }
|
||||||
|
label string
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (t Task) run() {
|
||||||
|
log.info(term.colorize(term.yellow, t.label))
|
||||||
|
start := time.now()
|
||||||
|
t.f()
|
||||||
|
dt := time.now() - start
|
||||||
|
log.info('Finished ${term.colorize(term.yellow, t.label)} in ${dt.milliseconds()} ms')
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(all_tasks map[string]Task) {
|
||||||
|
if os.args.len < 2 {
|
||||||
|
println('Usage: v run macos_ci.vsh <task_name>')
|
||||||
|
println('Available tasks are: ${all_tasks.keys()}')
|
||||||
|
exit(0)
|
||||||
|
}
|
||||||
|
task_name := os.args[1]
|
||||||
|
if task_name == 'all' {
|
||||||
|
log.info(term.colorize(term.green, 'Run everything...'))
|
||||||
|
for _, t in all_tasks {
|
||||||
|
t.run()
|
||||||
|
}
|
||||||
|
exit(0)
|
||||||
|
}
|
||||||
|
t := all_tasks[task_name] or {
|
||||||
|
eprintln('Unknown task: ${task_name}')
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
t.run()
|
||||||
|
}
|
|
@ -1,57 +1,4 @@
|
||||||
import os
|
import common { Task, exec }
|
||||||
import log
|
|
||||||
import term
|
|
||||||
|
|
||||||
// Go to the end of this file to add/register new tasks.
|
|
||||||
|
|
||||||
const is_github_job = os.getenv('GITHUB_JOB') != ''
|
|
||||||
|
|
||||||
type Fn = fn ()
|
|
||||||
|
|
||||||
struct Task {
|
|
||||||
f Fn = unsafe { nil }
|
|
||||||
label string
|
|
||||||
}
|
|
||||||
|
|
||||||
fn (t Task) run() {
|
|
||||||
log.info(term.colorize(term.yellow, t.label))
|
|
||||||
t.f()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
if os.args.len < 2 {
|
|
||||||
println('Usage: v run macos_ci.vsh <task_name>')
|
|
||||||
println('Available tasks are: ${all_tasks.keys()}')
|
|
||||||
exit(0)
|
|
||||||
}
|
|
||||||
task_name := os.args[1]
|
|
||||||
t := all_tasks[task_name] or {
|
|
||||||
eprintln('Unknown task: ${task_name}')
|
|
||||||
exit(1)
|
|
||||||
}
|
|
||||||
t.run()
|
|
||||||
}
|
|
||||||
|
|
||||||
// exec is a helper function, to execute commands and exit if they fail
|
|
||||||
fn exec(command string) {
|
|
||||||
log.info('cmd: ${command}')
|
|
||||||
result := os.system(command)
|
|
||||||
if result != 0 {
|
|
||||||
exit(result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Task functions
|
|
||||||
|
|
||||||
fn all() {
|
|
||||||
for k, t in all_tasks {
|
|
||||||
// skip ourselves
|
|
||||||
if k == 'all' {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
t.run()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn test_symlink() {
|
fn test_symlink() {
|
||||||
exec('v symlink')
|
exec('v symlink')
|
||||||
|
@ -67,7 +14,7 @@ fn build_with_cstrict() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn all_code_is_formatted() {
|
fn all_code_is_formatted() {
|
||||||
if is_github_job {
|
if common.is_github_job {
|
||||||
exec('VJOBS=1 v test-cleancode')
|
exec('VJOBS=1 v test-cleancode')
|
||||||
} else {
|
} else {
|
||||||
exec('v -progress test-cleancode')
|
exec('v -progress test-cleancode')
|
||||||
|
@ -99,7 +46,7 @@ fn test_pure_v_math_module() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn self_tests() {
|
fn self_tests() {
|
||||||
if is_github_job {
|
if common.is_github_job {
|
||||||
exec('VJOBS=1 v test-self vlib')
|
exec('VJOBS=1 v test-self vlib')
|
||||||
} else {
|
} else {
|
||||||
exec('v -progress test-self vlib')
|
exec('v -progress test-self vlib')
|
||||||
|
@ -107,7 +54,7 @@ fn self_tests() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_examples() {
|
fn build_examples() {
|
||||||
if is_github_job {
|
if common.is_github_job {
|
||||||
exec('v build-examples')
|
exec('v build-examples')
|
||||||
} else {
|
} else {
|
||||||
exec('v -progress build-examples')
|
exec('v -progress build-examples')
|
||||||
|
@ -116,7 +63,7 @@ fn build_examples() {
|
||||||
|
|
||||||
fn build_examples_v_compiled_with_tcc() {
|
fn build_examples_v_compiled_with_tcc() {
|
||||||
exec('v -o vtcc -cc tcc cmd/v')
|
exec('v -o vtcc -cc tcc cmd/v')
|
||||||
if is_github_job {
|
if common.is_github_job {
|
||||||
// ensure that examples/veb/veb_example.v etc compiles
|
// ensure that examples/veb/veb_example.v etc compiles
|
||||||
exec('./vtcc build-examples')
|
exec('./vtcc build-examples')
|
||||||
} else {
|
} else {
|
||||||
|
@ -166,7 +113,6 @@ fn test_vlib_skip_unused() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const all_tasks = {
|
const all_tasks = {
|
||||||
'all': Task{all, 'Run all tasks'}
|
|
||||||
'test_symlink': Task{test_symlink, 'Test symlink'}
|
'test_symlink': Task{test_symlink, 'Test symlink'}
|
||||||
'test_cross_compilation': Task{test_cross_compilation, 'Test cross compilation to Linux'}
|
'test_cross_compilation': Task{test_cross_compilation, 'Test cross compilation to Linux'}
|
||||||
'build_with_cstrict': Task{build_with_cstrict, 'Build V with -cstrict'}
|
'build_with_cstrict': Task{build_with_cstrict, 'Build V with -cstrict'}
|
||||||
|
@ -189,3 +135,5 @@ const all_tasks = {
|
||||||
'test_readline': Task{test_readline, 'Test readline'}
|
'test_readline': Task{test_readline, 'Test readline'}
|
||||||
'test_vlib_skip_unused': Task{test_vlib_skip_unused, 'Test vlib modules with -skip-unused'}
|
'test_vlib_skip_unused': Task{test_vlib_skip_unused, 'Test vlib modules with -skip-unused'}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
common.run(all_tasks)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue