| 1 | // compare with version.c from the user's pacman checkout, without linking libalpm. |
| 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(true)! |
| 16 | mut source := os.read_file(os.join_path(args.pacman, 'lib/libalpm/version.c'))! |
| 17 | include := '#include "util.h"' |
| 18 | if source.count(include) != 1 { |
| 19 | return error('version.c no longer has the expected util.h include') |
| 20 | } |
| 21 | source = source.replace(include, '#include <stdlib.h>\n#define SYMEXPORT\n#define alpm_pkg_vercmp reference_vercmp') |
| 22 | base := tooling.temporary('alpm-version-parity')! |
| 23 | defer { os.rmdir_all(base) or { eprintln(err) } } |
| 24 | implementation := os.join_path(base, 'reference.c') |
| 25 | header := os.join_path(base, 'reference.h') |
| 26 | os.write_file(implementation, source)! |
| 27 | os.write_file(header, 'int reference_vercmp(const char *, const char *);\n')! |
| 28 | program := os.join_path(base, 'parity.v') |
| 29 | os.write_file(program, os.read_file(os.join_path(@VMODROOT, 'tests', 'version_parity.v.in'))!.replace('@REFERENCE_C@', implementation).replace('@REFERENCE_H@', header))! |
| 30 | print(tooling.command(args.compiler, ['-path', '${@VMODROOT}|@vlib|@vmodules', 'run', program])!) |
| 31 | } |
| 32 | |