From a3d769bac08087bf2d9ab8c0733ae5b6fa832244 Mon Sep 17 00:00:00 2001 From: sulincix Date: Fri, 24 Nov 2023 18:30:46 +0000 Subject: [PATCH] libzstd disable support added. --- meson.build | 7 ++++++- meson_options.txt | 5 +++++ src/as-metadata.c | 8 +++++++- src/as-utils.c | 8 ++++++-- src/as-validator.c | 8 +++++++- src/meson.build | 13 +++++++++---- 6 files changed, 40 insertions(+), 9 deletions(-) diff --git a/meson.build b/meson.build index 5e7f57d57..6dc298979 100644 --- a/meson.build +++ b/meson.build @@ -159,9 +159,14 @@ yaml_dep = dependency('yaml-0.1') xmlb_dep = dependency('xmlb', version: '>= 0.3.14', fallback: ['libxmlb', 'libxmlb_dep'], default_options: ['gtkdoc=false', 'introspection=false']) -zstd_dep = dependency('libzstd') libsystemd_dep = dependency('libsystemd', required: get_option('systemd')) +if get_option('zstd') + zstd_dep = dependency('libzstd', required: get_option('zstd')) +else + add_project_arguments('-DNO_ZSTD', language: 'c') +endif + if get_option ('gir') # ensure we have a version of GIR that isn't broken with Meson # (prior versions failed when any non-GObject library was linked) diff --git a/meson_options.txt b/meson_options.txt index ca903a856..4ab0afb3c 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -23,6 +23,11 @@ option('qt5', value : false, description: 'Build libappstream-qt5 for Qt5' ) +option('zstd', + type : 'boolean', + value : true, + description: 'Zstd support' +) option('compose', type : 'boolean', value : false, diff --git a/src/as-metadata.c b/src/as-metadata.c index 4c54174a3..dfc3d9b79 100644 --- a/src/as-metadata.c +++ b/src/as-metadata.c @@ -45,7 +45,9 @@ #include "as-release-list-private.h" #include "as-context-private.h" #include "as-desktop-entry.h" +#ifndef NO_ZSTD #include "as-zstd-decompressor.h" +#endif #include "as-xml.h" #include "as-yaml.h" @@ -750,7 +752,7 @@ as_metadata_parse_file (AsMetadata *metad, GFile *file, AsFormatKind format, GEr g_propagate_error (error, tmp_error); return FALSE; } - + #ifndef NO_ZSTD if (as_str_equal0 (content_type, "application/zstd")) { /* decompress the Zstd stream */ conv = G_CONVERTER (as_zstd_decompressor_new ()); @@ -758,6 +760,10 @@ as_metadata_parse_file (AsMetadata *metad, GFile *file, AsFormatKind format, GEr } else if (as_str_equal0 (content_type, "application/gzip") || as_str_equal0 (content_type, "application/x-gzip")) { + #else + if (as_str_equal0 (content_type, "application/gzip") || + as_str_equal0 (content_type, "application/x-gzip")) { + #endif /* decompress the GZip stream */ conv = G_CONVERTER (g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP)); stream_data = g_converter_input_stream_new (file_stream, conv); diff --git a/src/as-utils.c b/src/as-utils.c index 6bf85926e..8da694b3c 100644 --- a/src/as-utils.c +++ b/src/as-utils.c @@ -47,8 +47,9 @@ #include "as-metadata.h" #include "as-component-private.h" #include "as-desktop-env-data.h" +#ifndef NO_ZSTD #include "as-zstd-decompressor.h" - +#endif /** * SECTION:as-utils * @short_description: Helper functions that are used inside libappstream @@ -2260,12 +2261,15 @@ as_utils_extract_tarball (const gchar *filename, const gchar *target_dir, GError if (tarz_stream == NULL) return FALSE; + #ifndef NO_ZSTD if (g_str_has_suffix (filename, "tar.zst")) { /* decompress the Zstd stream */ conv = G_CONVERTER (as_zstd_decompressor_new ()); tar_stream = g_converter_input_stream_new (tarz_stream, conv); - } else if (g_str_has_suffix (filename, "tar.gz")) { + #else + if (g_str_has_suffix (filename, "tar.gz")) { + #endif /* decompress the GZip stream */ conv = G_CONVERTER (g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP)); tar_stream = g_converter_input_stream_new (tarz_stream, conv); diff --git a/src/as-validator.c b/src/as-validator.c index 1c3bc8fd5..dfab18366 100644 --- a/src/as-validator.c +++ b/src/as-validator.c @@ -50,7 +50,9 @@ #include "as-yaml.h" #include "as-desktop-entry.h" #include "as-content-rating-private.h" +#ifndef NO_ZSTD #include "as-zstd-decompressor.h" +#endif typedef struct { GHashTable *issue_tags; /* of utf8:AsValidatorIssueTag */ @@ -3531,7 +3533,7 @@ as_validator_validate_file (AsValidator *validator, GFile *metadata_file) } if (file_stream == NULL) return FALSE; - + #ifndef NO_ZSTD if (as_str_equal0 (content_type, "application/zstd")) { /* decompress the Zstd stream */ conv = G_CONVERTER (as_zstd_decompressor_new ()); @@ -3539,6 +3541,10 @@ as_validator_validate_file (AsValidator *validator, GFile *metadata_file) } else if (as_str_equal0 (content_type, "application/gzip") || as_str_equal0 (content_type, "application/x-gzip")) { + #else + if (as_str_equal0 (content_type, "application/gzip") || + as_str_equal0 (content_type, "application/x-gzip")) { + #endif /* decompress the GZip stream */ conv = G_CONVERTER (g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP)); stream_data = g_converter_input_stream_new (file_stream, conv); diff --git a/src/meson.build b/src/meson.build index ef5c62880..9cc86e45d 100644 --- a/src/meson.build +++ b/src/meson.build @@ -16,7 +16,6 @@ aslib_src = [ 'as-tag.c', 'as-xml.c', 'as-yaml.c', - 'as-zstd-decompressor.c', # (mostly) public 'as-agreement.c', 'as-agreement-section.c', @@ -137,7 +136,6 @@ aslib_priv_headers = [ 'as-validator-issue-tag.h', 'as-xml.h', 'as-yaml.h', - 'as-zstd-decompressor.h', ] as_version_h = configure_file( @@ -190,12 +188,19 @@ aslib_deps = [glib_dep, xmlb_dep, xml2_dep, yaml_dep, - libsystemd_dep, - zstd_dep] + libsystemd_dep] if get_option ('stemming') aslib_deps += [stemmer_lib] endif +if get_option ('zstd') + aslib_deps += [zstd_dep] + aslib_src += ['as-zstd-decompressor.c'] + aslib_priv_headers += ['as-zstd-decompressor.h'] +endif + + + appstream_lib = library ('appstream', [aslib_src, aslib_pub_headers,