v / cmd / tools
Raw file | 79 loc (69 sloc) | 2.46 KB | Latest commit hash 017ace6ea
1import os
2import term
3import flag
4
5const tools_folder = os.real_path(os.dir(os.executable()))
6
7const oldvexe = fullpath(tools_folder, 'oldv')
8
9const oldv_source = fullpath(tools_folder, 'oldv.v')
10
11const vroot = os.real_path(os.dir(os.dir(tools_folder)))
12
13const vexe = fullpath(vroot, 'v')
14
15fn fullpath(folder string, fname string) string {
16 return os.real_path(os.join_path_single(folder, exename(fname)))
17}
18
19fn exename(n string) string {
20 if n.ends_with('.v') || os.user_os() != 'windows' {
21 return n
22 }
23 return '${n}.exe'
24}
25
26struct Context {
27mut:
28 old_commit string
29 new_commit string
30 command string
31}
32
33fn main() {
34 mut fp := flag.new_flag_parser(os.args)
35 mut context := Context{}
36 fp.application(os.file_name(os.executable()))
37 fp.version('0.0.2')
38 fp.description('\n Find at what commit a regression occurred.
39 To find when a regression happened (regression_bug.v should fail on master):
40 ./v run cmd/tools/regress.v --old a7019ac --command " ./v run /abs/path/to/regression_bug.v"
41 To find when a feature was implemented (feature.v should succeed on master):
42 ./v run cmd/tools/regress.v --old a7019ac --command "! ./v run /abs/path/to/feature.v"')
43 fp.skip_executable()
44 //
45 context.new_commit = fp.string('new', `n`, 'master', 'The new commit, by default: master.')
46 context.old_commit = fp.string('old', `o`, '', 'A known old commit, required (for it, COMMAND should exit with 0).')
47 context.command = fp.string('command', `c`, '', 'A command to execute. Should exit with 0 for the *old* commits.')
48 fp.finalize() or {}
49 if context.old_commit == '' {
50 eprintln('--old COMMIT is required')
51 exit(1)
52 }
53 if context.command == '' {
54 eprintln('--command "COMMAND" is required')
55 exit(2)
56 }
57 if !os.exists(oldvexe) {
58 if 0 != execute('${os.quoted_path(vexe)} -o ${os.quoted_path(oldvexe)} ${os.quoted_path(oldv_source)}') {
59 panic('can not compile ${oldvexe}')
60 }
61 }
62 os.execute('git checkout master')
63 os.execute('git bisect reset')
64 os.execute('git checkout ${context.new_commit}')
65 os.execute('git bisect start')
66 os.execute('git bisect new')
67 os.execute('git checkout ${context.old_commit}')
68 os.execute('git bisect old')
69 println(term.colorize(term.bright_yellow, term.header('', '-')))
70 execute('git bisect run ${os.quoted_path(oldvexe)} --bisect -c "${context.command}"')
71 println(term.colorize(term.bright_yellow, term.header('', '-')))
72 os.execute('git bisect reset')
73 os.execute('git checkout master')
74}
75
76fn execute(cmd string) int {
77 eprintln('### ${cmd}')
78 return os.system(cmd)
79}