| 1 | module checker |
| 2 | |
| 3 | import os |
| 4 | import v.ast |
| 5 | import v.parser |
| 6 | import v.pref |
| 7 | |
| 8 | const pkgconfig_test_source = 'module main |
| 9 | #pkgconfig --cflags --libs sdl2 |
| 10 | |
| 11 | fn main() {} |
| 12 | ' |
| 13 | |
| 14 | fn test_pkgconfig_is_skipped_for_cross_compilation() { |
| 15 | sample_dir := os.join_path(@VEXEROOT, 'vlib', 'v', 'pkgconfig', 'test_samples') |
| 16 | old_path := os.getenv('PKG_CONFIG_PATH') |
| 17 | old_defaults := os.getenv('PKG_CONFIG_PATH_DEFAULTS') |
| 18 | defer { |
| 19 | os.setenv('PKG_CONFIG_PATH', old_path, true) |
| 20 | os.setenv('PKG_CONFIG_PATH_DEFAULTS', old_defaults, true) |
| 21 | } |
| 22 | os.setenv('PKG_CONFIG_PATH', sample_dir, true) |
| 23 | os.setenv('PKG_CONFIG_PATH_DEFAULTS', '', true) |
| 24 | |
| 25 | native_flags := checked_pkgconfig_flags(pref.get_host_os()) |
| 26 | assert native_flags.any(it == '-lSDL2') |
| 27 | assert native_flags.any(it.starts_with('-I') && it.contains('SDL2')) |
| 28 | |
| 29 | cross_target := if pref.get_host_os() == .windows { pref.OS.linux } else { pref.OS.windows } |
| 30 | cross_flags := checked_pkgconfig_flags(cross_target) |
| 31 | assert cross_flags.len == 0 |
| 32 | } |
| 33 | |
| 34 | fn checked_pkgconfig_flags(target_os pref.OS) []string { |
| 35 | mut table := ast.new_table() |
| 36 | mut pref_ := pref.new_preferences() |
| 37 | pref_.os = target_os |
| 38 | mut file := parser.parse_text(pkgconfig_test_source, os.join_path('/virtual', 'main.v'), mut |
| 39 | table, .skip_comments, pref_) |
| 40 | mut chk := new_checker(table, pref_) |
| 41 | chk.check(mut file) |
| 42 | return table.cflags.map(it.format() or { '' }).filter(it != '') |
| 43 | } |
| 44 | |