| 1 | // execute the public API with libalpm headers forbidden and check its ELF dependencies. |
| 2 | module main |
| 3 | |
| 4 | import nspkg.tests.tooling |
| 5 | import os |
| 6 | |
| 7 | fn main() { |
| 8 | run() or { |
| 9 | eprintln(err) |
| 10 | exit(1) |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | fn run() ! { |
| 15 | args := tooling.options(false)! |
| 16 | base := tooling.temporary('alpm-native-api')! |
| 17 | defer { os.rmdir_all(base) or { eprintln(err) } } |
| 18 | for name in ['alpm.h', 'alpm_list.h'] { |
| 19 | os.write_file(os.join_path(base, name), '#error "production must not include libalpm headers"\n')! |
| 20 | } |
| 21 | executable := os.join_path(base, 'public-api') |
| 22 | // Resolve this checkout by its import name without using installed modules. |
| 23 | os.symlink(@VMODROOT, os.join_path(base, 'nspkg'))! |
| 24 | mut flags := ['-path', '${base}|@vlib', '-cflags', '-I${base}'] |
| 25 | $if nspkg_libcurl ? { |
| 26 | flags << ['-d', 'nspkg_libcurl'] |
| 27 | } $else { |
| 28 | os.mkdir(os.join_path(base, 'curl'))! |
| 29 | os.write_file(os.join_path(base, 'curl', 'curl.h'), '#error "default build included curl.h"\n')! |
| 30 | } |
| 31 | flags << ['-o', executable, os.join_path(@VMODROOT, 'native_api_test.v')] |
| 32 | tooling.command(args.compiler, flags)! |
| 33 | tooling.command(executable, [])! |
| 34 | tooling.require_no_libalpm(executable)! |
| 35 | needed := tooling.command('readelf', ['-d', executable])! |
| 36 | uses_curl := needed.split_into_lines().any(it.contains('(NEEDED)') && it.contains('[libcurl.so')) |
| 37 | $if nspkg_libcurl ? { |
| 38 | assert uses_curl |
| 39 | } $else { |
| 40 | assert !uses_curl |
| 41 | } |
| 42 | println('Native public API passed with the expected downloader linkage') |
| 43 | } |
| 44 | |