@@ -118,6 +118,21 @@ fn (mut v Builder) post_process_c_compiler_output(res os.Result) {
118
118
verror (c_error_info)
119
119
}
120
120
121
+ fn (mut v Builder) rebuild_cached_module (vexe string , imp_path string ) string {
122
+ res := v.pref.cache_manager.exists ('.o' , imp_path) or {
123
+ println ('Cached $imp_path .o file not found... Building .o file for $imp_path ' )
124
+ boptions := v.pref.build_options.join (' ' )
125
+ rebuild_cmd := '$vexe $boptions build-module $imp_path '
126
+ // eprintln('>> rebuild_cmd: $rebuild_cmd')
127
+ os.system (rebuild_cmd)
128
+ rebuilded_o := v.pref.cache_manager.exists ('.o' , imp_path) or {
129
+ panic ('could not rebuild cache module for $imp_path , error: $err ' )
130
+ }
131
+ return rebuilded_o
132
+ }
133
+ return res
134
+ }
135
+
121
136
fn (mut v Builder) cc () {
122
137
if os.executable ().contains ('vfmt' ) {
123
138
return
@@ -260,14 +275,9 @@ fn (mut v Builder) cc() {
260
275
linker_flags << '-nostdlib'
261
276
}
262
277
if v.pref.build_mode == .build_module {
263
- // Create the modules & out directory if it's not there.
264
- out_dir := os.join_path (pref.default_module_path, 'cache' , v.pref.path)
265
- pdir := out_dir.all_before_last (os.path_separator)
266
- if ! os.is_dir (pdir) {
267
- os.mkdir_all (pdir)
268
- }
269
- v.pref.out_name = '${out_dir} .o' // v.out_name
270
- println ('Building ${v.pref.out_name} ...' )
278
+ v.pref.out_name = v.pref.cache_manager.postfix_with_key2cpath ('.o' , v.pref.path) // v.out_name
279
+ println ('Building $v.pref.path to $v.pref.out_name ...' )
280
+ v.pref.cache_manager.save ('.description.txt' , v.pref.path, '${v.pref.path:-30} @ $v.pref.cache_manager.vopts \n ' )
271
281
// println('v.table.imports:')
272
282
// println(v.table.imports)
273
283
}
@@ -349,10 +359,7 @@ fn (mut v Builder) cc() {
349
359
args << '-c'
350
360
} else if v.pref.use_cache {
351
361
mut built_modules := []string {}
352
- builtin_obj_path := os.join_path (pref.default_module_path, 'cache' , 'vlib' , 'builtin.o' )
353
- if ! os.exists (builtin_obj_path) {
354
- os.system ('$vexe build-module vlib/builtin' )
355
- }
362
+ builtin_obj_path := v.rebuild_cached_module (vexe, 'vlib/builtin' )
356
363
libs + = ' ' + builtin_obj_path
357
364
for ast_file in v.parsed_files {
358
365
for imp_stmt in ast_file.imports {
@@ -382,14 +389,8 @@ fn (mut v Builder) cc() {
382
389
// continue
383
390
// }
384
391
imp_path := os.join_path ('vlib' , mod_path)
385
- cache_path := os.join_path (pref.default_module_path, 'cache' )
386
- obj_path := os.join_path (cache_path, '${imp_path} .o' )
387
- if os.exists (obj_path) {
388
- libs + = ' ' + obj_path
389
- } else {
390
- println ('$obj_path not found... building module $imp ' )
391
- os.system ('$vexe build-module $imp_path ' )
392
- }
392
+ obj_path := v.rebuild_cached_module (vexe, imp_path)
393
+ libs + = ' ' + obj_path
393
394
if obj_path.ends_with ('vlib/ui.o' ) {
394
395
args << '-framework Cocoa -framework Carbon'
395
396
}
@@ -777,21 +778,19 @@ fn (mut v Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CF
777
778
if v.pref.os == .windows {
778
779
// Cross compiling for Windows
779
780
$if ! windows {
780
- if os.exists (obj_path) {
781
- os.rm (obj_path)
782
- }
783
781
v.pref.ccompiler = mingw_cc
784
782
}
785
783
}
786
- if os.exists (obj_path) {
784
+ opath := v.pref.cache_manager.postfix_with_key2cpath ('.o' , obj_path)
785
+ if os.exists (opath) {
787
786
return
788
787
}
789
- println ('$obj_path not found, building it...' )
788
+ println ('$obj_path not found, building it in $opath ...' )
790
789
cfile := '${path[..path.len - 2]} .c'
791
790
btarget := moduleflags.c_options_before_target ()
792
791
atarget := moduleflags.c_options_after_target ()
793
792
cppoptions := if v.pref.ccompiler.contains ('++' ) { ' -fpermissive -w ' } else { '' }
794
- cmd := '$v.pref.ccompiler $cppoptions $v.pref.third_party_option $btarget -c -o "$obj_path " "$cfile " $atarget '
793
+ cmd := '$v.pref.ccompiler $cppoptions $v.pref.third_party_option $btarget -c -o "$opath " "$cfile " $atarget '
795
794
res := os.exec (cmd) or {
796
795
eprintln ('exec failed for thirdparty object build cmd:\n $cmd ' )
797
796
verror (err)
@@ -802,6 +801,7 @@ fn (mut v Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CF
802
801
verror (res.output)
803
802
return
804
803
}
804
+ v.pref.cache_manager.save ('.description.txt' , obj_path, '${obj_path:-30} @ $cmd \n ' )
805
805
println (res.output)
806
806
}
807
807
0 commit comments