| 1 | module builder |
| 2 | |
| 3 | import os |
| 4 | import v.cflag |
| 5 | import v.pref |
| 6 | |
| 7 | fn test_msvc_string_flags_uses_cached_thirdparty_obj_path() { |
| 8 | obj_file := os.join_path(@VEXEROOT, 'thirdparty', 'mbedtls', 'library', 'bignum.o') |
| 9 | mut builder := msvc_new_builder_for_args(['-cc', 'msvc', '-m32', msvc_hello_world_example()]) |
| 10 | cached_obj := builder.pref.cache_manager.mod_postfix_with_key2cpath('mbedtls', '.o', |
| 11 | os.real_path(obj_file)) |
| 12 | expected_obj := builder.msvc_thirdparty_obj_path('mbedtls', obj_file, cached_obj) |
| 13 | sflags := builder.msvc_string_flags([ |
| 14 | cflag.CFlag{ |
| 15 | mod: 'mbedtls' |
| 16 | value: obj_file |
| 17 | cached: cached_obj |
| 18 | }, |
| 19 | ]) |
| 20 | assert sflags.other_flags == ['"${expected_obj}"'] |
| 21 | } |
| 22 | |
| 23 | fn test_msvc_string_flags_rewrites_obj_flags_through_cached_path() { |
| 24 | test_dir := os.join_path(os.vtmp_dir(), 'builder_msvc_obj_flag_test_${os.getpid()}') |
| 25 | obj_file := os.join_path(test_dir, 'gc.obj') |
| 26 | os.mkdir_all(test_dir) or { panic(err) } |
| 27 | os.write_file(obj_file, '') or { panic(err) } |
| 28 | defer { |
| 29 | os.rmdir_all(test_dir) or {} |
| 30 | } |
| 31 | mut builder := msvc_new_builder_for_args(['-cc', 'msvc', '-m64', msvc_hello_world_example()]) |
| 32 | builder.table.cflags = [ |
| 33 | cflag.CFlag{ |
| 34 | mod: 'builtin' |
| 35 | value: obj_file |
| 36 | }, |
| 37 | ] |
| 38 | flags := builder.get_os_cflags() |
| 39 | expected_cached := builder.pref.cache_manager.mod_postfix_with_key2cpath('builtin', '.obj', |
| 40 | os.real_path(obj_file)) |
| 41 | assert flags.len == 1 |
| 42 | assert flags[0].cached == expected_cached |
| 43 | expected_obj := builder.msvc_thirdparty_obj_path('builtin', obj_file, expected_cached) |
| 44 | sflags := builder.msvc_string_flags(flags) |
| 45 | assert sflags.other_flags == ['"${expected_obj}"'] |
| 46 | } |
| 47 | |
| 48 | fn msvc_new_builder_for_args(args []string) Builder { |
| 49 | mut full_args := [''] |
| 50 | full_args << args |
| 51 | prefs, _ := pref.parse_args_and_show_errors([], full_args, false) |
| 52 | return new_builder(prefs) |
| 53 | } |
| 54 | |
| 55 | fn msvc_hello_world_example() string { |
| 56 | return os.join_path(@VEXEROOT, 'examples', 'hello_world.v') |
| 57 | } |
| 58 | |