// compare with version.c from the user's pacman checkout, without linking libalpm. module main import nspkg.tests.tooling import os fn main() { run() or { eprintln(err) exit(1) } } fn run() ! { args := tooling.options(true)! mut source := os.read_file(os.join_path(args.pacman, 'lib/libalpm/version.c'))! include := '#include "util.h"' if source.count(include) != 1 { return error('version.c no longer has the expected util.h include') } source = source.replace(include, '#include \n#define SYMEXPORT\n#define alpm_pkg_vercmp reference_vercmp') base := tooling.temporary('alpm-version-parity')! defer { os.rmdir_all(base) or { eprintln(err) } } implementation := os.join_path(base, 'reference.c') header := os.join_path(base, 'reference.h') os.write_file(implementation, source)! os.write_file(header, 'int reference_vercmp(const char *, const char *);\n')! program := os.join_path(base, 'parity.v') os.write_file(program, os.read_file(os.join_path(@VMODROOT, 'tests', 'version_parity.v.in'))!.replace('@REFERENCE_C@', implementation).replace('@REFERENCE_H@', header))! print(tooling.command(args.compiler, ['-path', '${@VMODROOT}|@vlib|@vmodules', 'run', program])!) }