@@ -29,22 +29,20 @@ const (
29
29
30
30
struct Context {
31
31
mut :
32
- vgo vgit.VGitOptions
33
- commit_v string = 'master'
34
- // the commit from which you want to produce a working v compiler (this may be a commit-ish too)
35
- commit_vc string = 'master'
36
- // this will be derived from commit_v
32
+ vgo vgit.VGitOptions
33
+ vgcontext vgit.VGitContext
34
+ commit_v string = 'master' // the commit from which you want to produce a working v compiler (this may be a commit-ish too)
37
35
commit_v_hash string // this will be filled from the commit-ish commit_v using rev-list. It IS a commit hash.
38
36
path_v string // the full path to the v folder inside workdir.
39
37
path_vc string // the full path to the vc folder inside workdir.
40
38
cmd_to_run string // the command that you want to run *in* the oldv repo
41
- cc string = 'cc'
42
- // the C compiler to use for bootstrapping.
43
- cleanup bool // should the tool run a cleanup first
39
+ cc string = 'cc' // the C compiler to use for bootstrapping.
40
+ cleanup bool // should the tool run a cleanup first
41
+ use_cache bool // use local cached copies for --vrepo and --vcrepo in
44
42
}
45
43
46
44
fn (mut c Context) compile_oldv_if_needed () {
47
- mut vgit_context : = vgit.VGitContext{
45
+ c. vgcontext = vgit.VGitContext{
48
46
workdir: c.vgo.workdir
49
47
v_repo_url: c.vgo.v_repo_url
50
48
vc_repo_url: c.vgo.vc_repo_url
@@ -53,28 +51,91 @@ fn (mut c Context) compile_oldv_if_needed() {
53
51
path_v: c.path_v
54
52
path_vc: c.path_vc
55
53
}
56
- vgit_context .compile_oldv_if_needed ()
57
- c.commit_v_hash = vgit_context .commit_v__hash
58
- if ! os.exists (vgit_context .vexepath) && c.cmd_to_run.len > 0 {
54
+ c.vgcontext .compile_oldv_if_needed ()
55
+ c.commit_v_hash = c.vgcontext .commit_v__hash
56
+ if ! os.exists (c.vgcontext .vexepath) && c.cmd_to_run.len > 0 {
59
57
// NB: 125 is a special code, that git bisect understands as 'skip this commit'.
60
58
// it is used to inform git bisect that the current commit leads to a build failure.
61
59
exit (125 )
62
60
}
63
61
}
64
62
63
+ const cache_oldv_folder = os.join_path (os.cache_dir (), 'oldv' )
64
+
65
+ const cache_oldv_folder_v = os.join_path (cache_oldv_folder, 'v' )
66
+
67
+ const cache_oldv_folder_vc = os.join_path (cache_oldv_folder, 'vc' )
68
+
69
+ fn sync_cache () {
70
+ scripting.verbose_trace (@FN, 'start' )
71
+ if ! os.exists (cache_oldv_folder) {
72
+ scripting.verbose_trace (@FN, 'creating $cache_oldv_folder ' )
73
+ scripting.mkdir_all (cache_oldv_folder) or {
74
+ scripting.verbose_trace (@FN, '## failed.' )
75
+ exit (1 )
76
+ }
77
+ }
78
+ scripting.chdir (cache_oldv_folder)
79
+ for reponame in ['v' , 'vc' ] {
80
+ repofolder := os.join_path (cache_oldv_folder, reponame)
81
+ if ! os.exists (repofolder) {
82
+ scripting.verbose_trace (@FN, 'cloning to $repofolder ' )
83
+ scripting.exec ('git clone --quiet https://github.com/vlang/$reponame $repofolder ' ) or {
84
+ scripting.verbose_trace (@FN, '## error during clone: $err ' )
85
+ exit (1 )
86
+ }
87
+ }
88
+ scripting.chdir (repofolder)
89
+ scripting.exec ('git pull --quiet' ) or {
90
+ scripting.verbose_trace (@FN, 'pulling to $repofolder ' )
91
+ scripting.verbose_trace (@FN, '## error during pull: $err ' )
92
+ exit (1 )
93
+ }
94
+ }
95
+ scripting.verbose_trace (@FN, 'done' )
96
+ }
97
+
65
98
fn main () {
66
99
scripting.used_tools_must_exist (['git' , 'cc' ])
100
+ //
101
+ // Resetting VEXE here allows for `v run cmd/tools/oldv.v'.
102
+ // the parent V would have set VEXE, which later will
103
+ // affect the V's run from the tool itself.
104
+ os.setenv ('VEXE' , '' , true )
105
+ //
67
106
mut context := Context{}
107
+ context.vgo.workdir = cache_oldv_folder
68
108
mut fp := flag.new_flag_parser (os.args)
69
109
fp.application (os.file_name (os.executable ()))
70
110
fp.version (tool_version)
71
111
fp.description (tool_description)
72
112
fp.arguments_description ('VCOMMIT' )
73
113
fp.skip_executable ()
74
- fp.limit_free_args (1 , 1 )
75
- context.cleanup = fp.bool ('clean' , 0 , true , 'Clean before running (slower).' )
114
+ context.use_cache = fp.bool ('cache' , `u` , true , 'Use a cache of local repositories for --vrepo and --vcrepo in \$ HOME/.cache/oldv/' )
115
+ if context.use_cache {
116
+ context.vgo.v_repo_url = cache_oldv_folder_v
117
+ context.vgo.vc_repo_url = cache_oldv_folder_vc
118
+ } else {
119
+ context.vgo.v_repo_url = 'https://github.com/vlang/v'
120
+ context.vgo.vc_repo_url = 'https://github.com/vlang/vc'
121
+ }
122
+ should_sync := fp.bool ('cache-sync' , `s` , false , 'Update the local cache' )
123
+ if ! should_sync {
124
+ fp.limit_free_args (1 , 1 )
125
+ }
126
+ // //
127
+ context.cleanup = fp.bool ('clean' , 0 , false , 'Clean before running (slower).' )
76
128
context.cmd_to_run = fp.string ('command' , `c` , '' , 'Command to run in the old V repo.\n ' )
77
129
commits := vgit.add_common_tool_options (mut context.vgo, mut fp)
130
+ if should_sync {
131
+ sync_cache ()
132
+ exit (0 )
133
+ }
134
+ if context.use_cache {
135
+ if ! os.is_dir (cache_oldv_folder_v) || ! os.is_dir (cache_oldv_folder_vc) {
136
+ sync_cache ()
137
+ }
138
+ }
78
139
if commits.len > 0 {
79
140
context.commit_v = commits[0 ]
80
141
} else {
@@ -102,7 +163,9 @@ fn main() {
102
163
if context.cmd_to_run.len > 0 {
103
164
scripting.cprintln_strong ('# command: ${context.cmd_to_run:-34s} ' )
104
165
cmdres := os.execute_or_panic (context.cmd_to_run)
105
- scripting.cprintln_strong ('# exit code: ${cmdres.exit_code:-4d} ' )
166
+ if cmdres.exit_code != 0 {
167
+ scripting.cprintln_strong ('# exit code: ${cmdres.exit_code:-4d} ' )
168
+ }
106
169
scripting.cprint_strong ('# result: ' )
107
170
print (cmdres.output)
108
171
exit (cmdres.exit_code)
0 commit comments