From 1ccf7ba03083d58bd77307f1fabae31c16f2e766 Mon Sep 17 00:00:00 2001 From: Jonathon Anderson Date: Fri, 12 Jul 2024 14:55:16 -0500 Subject: [PATCH] Add bzip2 --- releases.json | 8 ++ subprojects/bzip2.wrap | 9 ++ subprojects/packagefiles/bzip2/meson.build | 101 +++++++++++++++++++++ subprojects/packagefiles/bzip2/test.py | 36 ++++++++ tools/sanity_checks.py | 3 + 5 files changed, 157 insertions(+) create mode 100644 subprojects/bzip2.wrap create mode 100644 subprojects/packagefiles/bzip2/meson.build create mode 100644 subprojects/packagefiles/bzip2/test.py diff --git a/releases.json b/releases.json index 4ce2b776c..e256357f2 100644 --- a/releases.json +++ b/releases.json @@ -228,6 +228,14 @@ "3.3.0-1" ] }, + "bzip2": { + "dependency_names": [ + "bzip2" + ], + "versions": [ + "1.0.8-1" + ] + }, "c-ares": { "dependency_names": [ "libcares" diff --git a/subprojects/bzip2.wrap b/subprojects/bzip2.wrap new file mode 100644 index 000000000..58909a15c --- /dev/null +++ b/subprojects/bzip2.wrap @@ -0,0 +1,9 @@ +[wrap-file] +directory = bzip2-1.0.8 +source_url = https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz +source_filename = bzip2-1.0.8.tar.gz +source_hash = ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269 +patch_directory = bzip2 + +[provide] +dependency_names = bzip2 diff --git a/subprojects/packagefiles/bzip2/meson.build b/subprojects/packagefiles/bzip2/meson.build new file mode 100644 index 000000000..be3eb7df1 --- /dev/null +++ b/subprojects/packagefiles/bzip2/meson.build @@ -0,0 +1,101 @@ +project('bzip2', 'c', version: '1.0.8', meson_version: '>=1.0.0') + +libbz2_lib = static_library( + 'bz2', + 'blocksort.c', + 'huffman.c', + 'crctable.c', + 'randtable.c', + 'compress.c', + 'decompress.c', + 'bzlib.c', + pic: true, + install: true, +) + +bzip2_exe = executable('bzip2', 'bzip2.c', link_with: libbz2_lib) + +if meson.can_run_host_binaries() + python = find_program('python3', native: true, version: ['>=3.5', '<4']) + _testargs = [files('test.py')] + test( + 'compress sample1', + python, + args: [ + _testargs, + files('sample1.ref'), + files('sample1.bz2'), + '--', + bzip2_exe, + '-1', + ], + ) + test( + 'compress sample2', + python, + args: [ + _testargs, + files('sample2.ref'), + files('sample2.bz2'), + '--', + bzip2_exe, + '-2', + ], + ) + test( + 'compress sample3', + python, + args: [ + _testargs, + files('sample3.ref'), + files('sample3.bz2'), + '--', + bzip2_exe, + '-3', + ], + ) + test( + 'decompress sample1', + python, + args: [ + _testargs, + files('sample1.bz2'), + files('sample1.ref'), + '--', + bzip2_exe, + '-d', + ], + ) + test( + 'decompress sample2', + python, + args: [ + _testargs, + files('sample2.bz2'), + files('sample2.ref'), + '--', + bzip2_exe, + '-d', + ], + ) + test( + 'decompress sample3', + python, + args: [ + _testargs, + files('sample3.bz2'), + files('sample3.ref'), + '--', + bzip2_exe, + '-ds', + ], + ) +endif + +install_headers('bzlib.h') + +bzip2_dep = declare_dependency( + link_with: libbz2_lib, + include_directories: include_directories('.'), +) +meson.override_dependency('bzip2', bzip2_dep) diff --git a/subprojects/packagefiles/bzip2/test.py b/subprojects/packagefiles/bzip2/test.py new file mode 100644 index 000000000..3eb8c887e --- /dev/null +++ b/subprojects/packagefiles/bzip2/test.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +import subprocess +import argparse +from pathlib import Path +import tempfile +import os +import shlex +import sys + + +def run_command(command, stdinfile): + if "MESON_EXE_WRAPPER" in os.environ: + command = shlex.split(os.environ["MESON_EXE_WRAPPER"]) + command + with tempfile.TemporaryFile("w+b") as outf: + with open(stdinfile, "rb") as inf: + subprocess.run(command, stdin=inf, stdout=outf) + outf.seek(0) + return outf.read() + + +def compare(result, reffile): + with open(reffile, "rb") as reff: + return result == reff.read() + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("input", type=Path) + parser.add_argument("reference", type=Path) + parser.add_argument("command", nargs="+") + args = parser.parse_args() + + if not compare(run_command(args.command, args.input), args.reference): + print("Output did not match reference file!") + sys.exit(1) diff --git a/tools/sanity_checks.py b/tools/sanity_checks.py index 22b9cc403..a432f4a6e 100755 --- a/tools/sanity_checks.py +++ b/tools/sanity_checks.py @@ -34,6 +34,9 @@ 'box2d': [ 'doctest.h' ], + 'bzip2': [ + 'test.py', + ], 'curl': [ 'extract.mk', 'rewrite.mk',