vgit: avoid generics; enables compilation of the performance_compare & oldv tools.
parent
dc8199709f
commit
7a03b18bfe
|
@ -133,7 +133,16 @@ pub fn (vgit_context mut VGitContext) compile_oldv_if_needed() {
|
|||
// which should be a valid working V executable.
|
||||
}
|
||||
|
||||
pub fn add_common_tool_options<T>(context mut T, fp mut flag.FlagParser) []string {
|
||||
pub struct VGitOptions {
|
||||
mut:
|
||||
workdir string // the working folder (typically /tmp), where the tool will write
|
||||
v_repo_url string // the url of the V repository. It can be a local folder path, if you want to eliminate network operations...
|
||||
vc_repo_url string // the url of the vc repository. It can be a local folder path, if you want to eliminate network operations...
|
||||
show_help bool // whether to show the usage screen
|
||||
verbose bool // should the tool be much more verbose
|
||||
}
|
||||
|
||||
pub fn add_common_tool_options(context mut VGitOptions, fp mut flag.FlagParser) []string {
|
||||
tdir := os.temp_dir()
|
||||
context.workdir = os.real_path(fp.string('workdir', `w`, tdir, 'A writable base folder. Default: $tdir'))
|
||||
context.v_repo_url = fp.string('vrepo', 0, vgit.remote_v_repo_url, 'The url of the V repository. You can clone it locally too. See also --vcrepo below.')
|
||||
|
|
|
@ -31,9 +31,7 @@ const (
|
|||
|
||||
struct Context {
|
||||
mut:
|
||||
v_repo_url string // the url of the V repository. It can be a local folder path, if you want to eliminate network operations...
|
||||
vc_repo_url string // the url of the vc repository. It can be a local folder path, if you want to eliminate network operations...
|
||||
workdir string // the working folder (typically /tmp), where the tool will write
|
||||
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_hash string // this will be filled from the commit-ish commit_v using rev-list. It IS a commit hash.
|
||||
|
@ -42,19 +40,17 @@ mut:
|
|||
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.
|
||||
cleanup bool // should the tool run a cleanup first
|
||||
verbose bool // should the tool be much more verbose
|
||||
show_help bool // whether to show the usage screen
|
||||
}
|
||||
|
||||
fn (c mut Context) compile_oldv_if_needed() {
|
||||
mut vgit_context := vgit.VGitContext{
|
||||
workdir: c.vgo.workdir
|
||||
v_repo_url: c.vgo.v_repo_url
|
||||
vc_repo_url: c.vgo.vc_repo_url
|
||||
cc: c.cc
|
||||
workdir: c.workdir
|
||||
commit_v: c.commit_v
|
||||
path_v: c.path_v
|
||||
path_vc: c.path_vc
|
||||
v_repo_url: c.v_repo_url
|
||||
vc_repo_url: c.vc_repo_url
|
||||
}
|
||||
vgit_context.compile_oldv_if_needed()
|
||||
c.commit_v_hash = vgit_context.commit_v__hash
|
||||
|
@ -79,18 +75,17 @@ fn main() {
|
|||
context.cleanup = fp.bool('clean', 0, true, 'Clean before running (slower).')
|
||||
context.cmd_to_run = fp.string('command', `c`, '', 'Command to run in the old V repo.\n')
|
||||
|
||||
commits := vgit.add_common_tool_options(mut context, mut fp)
|
||||
commits := vgit.add_common_tool_options(mut context.vgo, mut fp)
|
||||
if commits.len > 0 {
|
||||
context.commit_v = commits[0]
|
||||
} else {
|
||||
context.commit_v = scripting.run('git rev-list -n1 HEAD')
|
||||
}
|
||||
println('################# context.commit_v: $context.commit_v #####################')
|
||||
context.path_v = vgit.normalized_workpath_for_commit(context.workdir, context.commit_v)
|
||||
context.path_vc = vgit.normalized_workpath_for_commit(context.workdir, 'vc')
|
||||
if !os.is_dir(context.workdir) {
|
||||
msg := 'Work folder: ' + context.workdir + ' , does not exist.'
|
||||
eprintln(msg)
|
||||
context.path_v = vgit.normalized_workpath_for_commit(context.vgo.workdir, context.commit_v)
|
||||
context.path_vc = vgit.normalized_workpath_for_commit(context.vgo.workdir, 'vc')
|
||||
if !os.is_dir(context.vgo.workdir) {
|
||||
eprintln('Work folder: ${context.vgo.workdir} , does not exist.')
|
||||
exit(2)
|
||||
}
|
||||
ecc := os.getenv('CC')
|
||||
|
|
|
@ -16,17 +16,13 @@ const (
|
|||
struct Context {
|
||||
cwd string // current working folder
|
||||
mut:
|
||||
v_repo_url string // the url of the vc repository. It can be a local folder path, which is useful to eliminate network operations...
|
||||
vc_repo_url string // the url of the vc repository. It can be a local folder path, which is useful to eliminate network operations...
|
||||
workdir string // the working folder (typically /tmp), where the tool will write
|
||||
vgo vgit.VGitOptions
|
||||
a string // the full path to the 'after' folder inside workdir
|
||||
b string // the full path to the 'before' folder inside workdir
|
||||
vc string // the full path to the vc folder inside workdir. It is used during bootstrapping v from the C source.
|
||||
commit_before string // the git commit for the 'before' state
|
||||
commit_after string // the git commit for the 'after' state
|
||||
warmups int // how many times to execute a command before gathering stats
|
||||
verbose bool // whether to print even more stuff
|
||||
show_help bool // whether to show the usage screen
|
||||
hyperfineopts string // use for additional CLI options that will be given to the hyperfine command
|
||||
vflags string // other v options to pass to compared v commands
|
||||
}
|
||||
|
@ -42,14 +38,14 @@ fn new_context() Context {
|
|||
fn (c Context) compare_versions() {
|
||||
// Input is validated at this point...
|
||||
// Cleanup artifacts from previous runs of this tool:
|
||||
scripting.chdir(c.workdir)
|
||||
scripting.chdir(c.vgo.workdir)
|
||||
scripting.run('rm -rf "$c.a" "$c.b" "$c.vc" ')
|
||||
// clone the VC source *just once per comparison*, and reuse it:
|
||||
scripting.run('git clone --quiet "$c.vc_repo_url" "$c.vc" ')
|
||||
scripting.run('git clone --quiet "$c.vgo.vc_repo_url" "$c.vc" ')
|
||||
println('Comparing V performance of commit $c.commit_before (before) vs commit $c.commit_after (after) ...')
|
||||
c.prepare_v(c.b, c.commit_before)
|
||||
c.prepare_v(c.a, c.commit_after)
|
||||
scripting.chdir(c.workdir)
|
||||
scripting.chdir(c.vgo.workdir)
|
||||
|
||||
if c.vflags.len > 0 {
|
||||
os.setenv('VFLAGS', c.vflags, true)
|
||||
|
@ -95,12 +91,12 @@ fn (c &Context) prepare_v(cdir string, commit string) {
|
|||
}
|
||||
mut vgit_context := vgit.VGitContext{
|
||||
cc: cc
|
||||
workdir: c.workdir
|
||||
commit_v: commit
|
||||
path_v: cdir
|
||||
path_vc: c.vc
|
||||
v_repo_url: c.v_repo_url
|
||||
vc_repo_url: c.vc_repo_url
|
||||
workdir: c.vgo.workdir
|
||||
v_repo_url: c.vgo.v_repo_url
|
||||
vc_repo_url: c.vgo.vc_repo_url
|
||||
}
|
||||
vgit_context.compile_oldv_if_needed()
|
||||
scripting.chdir(cdir)
|
||||
|
@ -164,10 +160,10 @@ fn (c Context) compare_v_performance(label string, commands []string) string {
|
|||
hyperfine_commands_arguments << " \'cd ${c.a:-34s} ; ./$cmd \' ".replace_each(['@COMPILER@', source_location_a, '@DEBUG@', debug_option_a])
|
||||
}
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
cmd_stats_file := os.real_path([c.workdir, 'v_performance_stats_${label}.json'].join(os.path_separator))
|
||||
cmd_stats_file := os.real_path([c.vgo.workdir, 'v_performance_stats_${label}.json'].join(os.path_separator))
|
||||
comparison_cmd := 'hyperfine $c.hyperfineopts ' + '--export-json ${cmd_stats_file} ' + '--time-unit millisecond ' + '--style full --warmup $c.warmups ' + hyperfine_commands_arguments.join(' ')
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
if c.verbose {
|
||||
if c.vgo.verbose {
|
||||
println(comparison_cmd)
|
||||
}
|
||||
os.system(comparison_cmd)
|
||||
|
@ -193,16 +189,16 @@ fn main() {
|
|||
${flag.space}For example on linux, you may want to pass:
|
||||
${flag.space}--hyperfine_options "--prepare \'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches\'"
|
||||
')
|
||||
commits := vgit.add_common_tool_options(mut context, mut fp)
|
||||
commits := vgit.add_common_tool_options(mut context.vgo, mut fp)
|
||||
context.commit_before = commits[0]
|
||||
if commits.len > 1 {
|
||||
context.commit_after = commits[1]
|
||||
}
|
||||
context.b = vgit.normalized_workpath_for_commit(context.workdir, context.commit_before)
|
||||
context.a = vgit.normalized_workpath_for_commit(context.workdir, context.commit_after)
|
||||
context.vc = vgit.normalized_workpath_for_commit(context.workdir, 'vc')
|
||||
if !os.is_dir(context.workdir) {
|
||||
msg := 'Work folder: ' + context.workdir + ' , does not exist.'
|
||||
context.b = vgit.normalized_workpath_for_commit(context.vgo.workdir, context.commit_before)
|
||||
context.a = vgit.normalized_workpath_for_commit(context.vgo.workdir, context.commit_after)
|
||||
context.vc = vgit.normalized_workpath_for_commit(context.vgo.workdir, 'vc')
|
||||
if !os.is_dir(context.vgo.workdir) {
|
||||
msg := 'Work folder: ' + context.vgo.workdir + ' , does not exist.'
|
||||
eprintln(msg)
|
||||
exit(2)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue