From 913abe51cfcf3b0b81e814c49445c326705c2230 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 17 May 2024 15:49:37 +0200 Subject: [PATCH 1/8] Correctly set LIBZIM_EXPORT_DLL `static_linkage` is about how we link with dependency libraries. We must set `LIBZIM_EXPORT_DLL` depending of how we build libzim library. --- meson.build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index f9ae9706..fad5bf96 100644 --- a/meson.build +++ b/meson.build @@ -37,7 +37,9 @@ static_linkage = static_linkage or get_option('default_library')=='static' lzma_dep = dependency('liblzma', static:static_linkage) if static_linkage add_project_arguments('-DLZMA_API_STATIC', language: 'cpp') -else +endif + +if get_option('default_library') == 'shared' public_conf.set('LIBZIM_EXPORT_DLL', true) endif From c8f2c6787ea2173e1117799134814988d5c68ff8 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Thu, 23 May 2024 09:44:40 +0200 Subject: [PATCH 2/8] Make internal classes LIBZIM_PRIVATE_API. While they are internal (and not part of public API), unittest are testing them and so we need to link to them. --- include/zim/archive.h | 2 +- meson.build | 1 + src/_dirent.h | 3 ++- src/buffer.h | 2 +- src/buffer_reader.h | 2 +- src/cluster.h | 2 +- src/compression.h | 4 ++-- src/config.h.in | 10 ++++++++++ src/dirent_accessor.h | 3 ++- src/direntreader.h | 2 +- src/file_compound.h | 4 +++- src/file_reader.h | 6 +++--- src/fileheader.h | 4 +++- src/fs_windows.h | 5 +++-- src/istreamreader.h | 2 +- src/tools.h | 14 +++++++------- src/writer/_dirent.h | 2 +- src/writer/cluster.h | 3 ++- src/xapian/htmlparse.h | 5 ++++- src/xapian/myhtmlparse.h | 3 ++- 20 files changed, 51 insertions(+), 28 deletions(-) diff --git a/include/zim/archive.h b/include/zim/archive.h index c0617bbc..36242ccd 100644 --- a/include/zim/archive.h +++ b/include/zim/archive.h @@ -729,7 +729,7 @@ namespace zim * @param checksToRun The set of checks to perform. * @return False if any check fails, true otherwise. */ - bool validate(const std::string& zimPath, IntegrityCheckList checksToRun); + bool LIBZIM_API validate(const std::string& zimPath, IntegrityCheckList checksToRun); } #endif // ZIM_ARCHIVE_H diff --git a/meson.build b/meson.build index fad5bf96..a769abff 100644 --- a/meson.build +++ b/meson.build @@ -41,6 +41,7 @@ endif if get_option('default_library') == 'shared' public_conf.set('LIBZIM_EXPORT_DLL', true) + add_project_arguments('-DLIBZIM_EXPORT_PRIVATE_DLL', language: 'cpp') endif zstd_dep = dependency('libzstd', static:static_linkage, default_options:['werror=false']) diff --git a/src/_dirent.h b/src/_dirent.h index 0fdfbc59..e6ee1445 100644 --- a/src/_dirent.h +++ b/src/_dirent.h @@ -27,12 +27,13 @@ #include #include "zim_types.h" +#include "config.h" namespace zim { class Buffer; class InvalidSize : public std::exception {}; - class Dirent + class LIBZIM_PRIVATE_API Dirent { protected: uint16_t mimeType; diff --git a/src/buffer.h b/src/buffer.h index 339c0da5..9c59647e 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -29,7 +29,7 @@ namespace zim { -class Buffer { +class LIBZIM_PRIVATE_API Buffer { public: // types typedef std::shared_ptr DataPtr; diff --git a/src/buffer_reader.h b/src/buffer_reader.h index 938aecc0..de346944 100644 --- a/src/buffer_reader.h +++ b/src/buffer_reader.h @@ -24,7 +24,7 @@ namespace zim { -class BufferReader : public Reader { +class LIBZIM_PRIVATE_API BufferReader : public Reader { public: BufferReader(const Buffer& source) : source(source) {} diff --git a/src/cluster.h b/src/cluster.h index 6d2932d3..9d5e44ba 100644 --- a/src/cluster.h +++ b/src/cluster.h @@ -38,7 +38,7 @@ namespace zim class Reader; class IStreamReader; - class Cluster : public std::enable_shared_from_this { + class LIBZIM_PRIVATE_API Cluster : public std::enable_shared_from_this { typedef std::vector BlobOffsets; typedef std::vector> BlobReaders; diff --git a/src/compression.h b/src/compression.h index b8c89893..4daba33b 100644 --- a/src/compression.h +++ b/src/compression.h @@ -68,8 +68,8 @@ struct LZMA_INFO { }; -struct ZSTD_INFO { - struct stream_t +struct LIBZIM_PRIVATE_API ZSTD_INFO { + struct LIBZIM_PRIVATE_API stream_t { const unsigned char* next_in; size_t avail_in; diff --git a/src/config.h.in b/src/config.h.in index 77991c3f..b3018333 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -1,3 +1,11 @@ +#ifndef ZIM_CONFIG_H +#define ZIM_CONFIG_H + +#if defined(_MSC_VER) && defined(LIBZIM_EXPORT_PRIVATE_DLL) + #define LIBZIM_PRIVATE_API __declspec(dllexport) +#else + #define LIBZIM_PRIVATE_API +#endif #mesondefine VERSION @@ -20,3 +28,5 @@ #mesondefine ENV64BIT #mesondefine ENV32BIT + +#endif // ZIM_CONFIG_H diff --git a/src/dirent_accessor.h b/src/dirent_accessor.h index c11116d3..fb1bc3ec 100644 --- a/src/dirent_accessor.h +++ b/src/dirent_accessor.h @@ -22,6 +22,7 @@ #include "zim_types.h" #include "lrucache.h" +#include "config.h" #include #include @@ -42,7 +43,7 @@ class DirentReader; * */ -class DirectDirentAccessor +class LIBZIM_PRIVATE_API DirectDirentAccessor { public: // functions DirectDirentAccessor(std::shared_ptr direntReader, diff --git a/src/direntreader.h b/src/direntreader.h index 2dc84ed6..7c1ea276 100644 --- a/src/direntreader.h +++ b/src/direntreader.h @@ -33,7 +33,7 @@ namespace zim // Unlke FileReader and MemoryReader (which read data from a file and memory, // respectively), DirentReader is a helper class that reads Dirents (rather // than from a Dirent). -class DirentReader +class LIBZIM_PRIVATE_API DirentReader { public: // functions explicit DirentReader(std::shared_ptr zimReader) diff --git a/src/file_compound.h b/src/file_compound.h index 5fe94159..f50d672b 100644 --- a/src/file_compound.h +++ b/src/file_compound.h @@ -24,6 +24,8 @@ #include "file_part.h" #include "zim_types.h" #include "debug.h" +#include "config.h" + #include #include #include @@ -48,7 +50,7 @@ struct less_range } }; -class FileCompound : private std::map { +class LIBZIM_PRIVATE_API FileCompound : private std::map { typedef std::map ImplType; public: // types diff --git a/src/file_reader.h b/src/file_reader.h index ae366c76..248df152 100644 --- a/src/file_reader.h +++ b/src/file_reader.h @@ -28,7 +28,7 @@ namespace zim { class FileCompound; -class BaseFileReader : public Reader { +class LIBZIM_PRIVATE_API BaseFileReader : public Reader { public: // functions BaseFileReader(offset_t offset, zsize_t size) : _offset(offset), _size(size) {} @@ -45,7 +45,7 @@ class BaseFileReader : public Reader { zsize_t _size; }; -class FileReader : public BaseFileReader { +class LIBZIM_PRIVATE_API FileReader : public BaseFileReader { public: // types typedef std::shared_ptr FileHandle; @@ -66,7 +66,7 @@ class FileReader : public BaseFileReader { FileHandle _fhandle; }; -class MultiPartFileReader : public BaseFileReader { +class LIBZIM_PRIVATE_API MultiPartFileReader : public BaseFileReader { public: explicit MultiPartFileReader(std::shared_ptr source); ~MultiPartFileReader() {}; diff --git a/src/fileheader.h b/src/fileheader.h index 15561e3e..40325a98 100644 --- a/src/fileheader.h +++ b/src/fileheader.h @@ -23,6 +23,8 @@ #include #include +#include "config.h" + #include // max may be defined as a macro by window includes @@ -33,7 +35,7 @@ namespace zim { class Reader; - class Fileheader + class LIBZIM_PRIVATE_API Fileheader { public: static const uint32_t zimMagic; diff --git a/src/fs_windows.h b/src/fs_windows.h index 25521545..009092ec 100644 --- a/src/fs_windows.h +++ b/src/fs_windows.h @@ -21,6 +21,7 @@ #define ZIM_FS_WINDOWS_H_ #include "zim_types.h" +#include "config.h" #include @@ -34,7 +35,7 @@ using path_t = const std::string&; struct ImplFD; -class FD { +class LIBZIM_PRIVATE_API FD { public: typedef HANDLE fd_t; private: @@ -55,7 +56,7 @@ class FD { bool close(); }; -struct FS { +struct LIBZIM_PRIVATE_API FS { using FD = zim::windows::FD; static std::string join(path_t base, path_t name); static std::unique_ptr toWideChar(path_t path); diff --git a/src/istreamreader.h b/src/istreamreader.h index 0d55186c..a0a5349b 100644 --- a/src/istreamreader.h +++ b/src/istreamreader.h @@ -44,7 +44,7 @@ namespace zim // } // } // -class IStreamReader +class LIBZIM_PRIVATE_API IStreamReader { public: // functions virtual ~IStreamReader() = default; diff --git a/src/tools.h b/src/tools.h index 4776b0d0..014f828f 100644 --- a/src/tools.h +++ b/src/tools.h @@ -37,19 +37,19 @@ namespace Xapian { #endif // ENABLE_XAPIAN namespace zim { bool isCompressibleMimetype(const std::string& mimetype); - uint32_t countWords(const std::string& text); - void microsleep(int microseconds); + uint32_t LIBZIM_PRIVATE_API countWords(const std::string& text); + void LIBZIM_PRIVATE_API microsleep(int microseconds); - std::tuple parseLongPath(const std::string& longPath); + std::tuple LIBZIM_PRIVATE_API parseLongPath(const std::string& longPath); // Parse a illustration path ("Illustration_x@1") to a size. - unsigned int parseIllustrationPathToSize(const std::string& s); + unsigned int LIBZIM_PRIVATE_API parseIllustrationPathToSize(const std::string& s); /** Return a random number from range [0, max] * * This function is threadsafe **/ - uint32_t randomNumber(uint32_t max); + uint32_t LIBZIM_PRIVATE_API randomNumber(uint32_t max); std::vector split(const std::string & str, const std::string & delims=" *-"); @@ -57,7 +57,7 @@ namespace zim { std::map read_valuesmap(const std::string& s); using MimeCounterType = std::map; - MimeCounterType parseMimetypeCounter(const std::string& counterData); + MimeCounterType LIBZIM_PRIVATE_API parseMimetypeCounter(const std::string& counterData); template entry_index_type countMimeType(const std::string& counterData, Filter filter) { @@ -72,7 +72,7 @@ namespace zim { // Xapian based tools #if defined(ENABLE_XAPIAN) - std::string removeAccents(const std::string& text); + std::string LIBZIM_PRIVATE_API removeAccents(const std::string& text); bool getDbFromAccessInfo(Item::DirectAccessInfo accessInfo, Xapian::Database& database); #endif } diff --git a/src/writer/_dirent.h b/src/writer/_dirent.h index 42a5fd23..dd04007d 100644 --- a/src/writer/_dirent.h +++ b/src/writer/_dirent.h @@ -148,7 +148,7 @@ namespace zim enum : char {DIRECT, REDIRECT, RESOLVED} tag; } PACKED; - class Dirent + class LIBZIM_PRIVATE_API Dirent { static const uint16_t redirectMimeType = 0xffff; static const uint32_t version = 0; diff --git a/src/writer/cluster.h b/src/writer/cluster.h index ce6aa3a4..c4f9634c 100644 --- a/src/writer/cluster.h +++ b/src/writer/cluster.h @@ -30,6 +30,7 @@ #include #include "../zim_types.h" #include "../debug.h" +#include "config.h" namespace zim { @@ -38,7 +39,7 @@ namespace writer { using writer_t = std::function; class ContentProvider; -class Cluster { +class LIBZIM_PRIVATE_API Cluster { typedef std::vector Offsets; typedef std::vector> ClusterProviders; diff --git a/src/xapian/htmlparse.h b/src/xapian/htmlparse.h index a884b2ac..1239eae0 100644 --- a/src/xapian/htmlparse.h +++ b/src/xapian/htmlparse.h @@ -22,6 +22,9 @@ #ifndef OMEGA_INCLUDED_HTMLPARSE_H #define OMEGA_INCLUDED_HTMLPARSE_H +#include +#include "config.h" + #include #include @@ -30,7 +33,7 @@ using std::map; namespace zim { -class HtmlParser { +class LIBZIM_PRIVATE_API HtmlParser { map parameters; protected: void decode_entities(string &s); diff --git a/src/xapian/myhtmlparse.h b/src/xapian/myhtmlparse.h index a1f2101d..ab8569c6 100644 --- a/src/xapian/myhtmlparse.h +++ b/src/xapian/myhtmlparse.h @@ -22,6 +22,7 @@ #ifndef OMEGA_INCLUDED_MYHTMLPARSE_H #define OMEGA_INCLUDED_MYHTMLPARSE_H +#include #include "htmlparse.h" // FIXME: Should we include \xa0 which is non-breaking space in iso-8859-1, but @@ -31,7 +32,7 @@ namespace zim { -class MyHtmlParser : public HtmlParser { +class LIBZIM_PRIVATE_API MyHtmlParser : public HtmlParser { public: bool in_script_tag; bool in_style_tag; From 3588aa889a27d3f4aa00d1bc75b43b6f301bb7b0 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Thu, 23 May 2024 10:33:48 +0200 Subject: [PATCH 3/8] Implement Cluster desctructor when IStreamReader is complete. --- src/cluster.cpp | 2 ++ src/cluster.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cluster.cpp b/src/cluster.cpp index f0e38429..9c19433f 100644 --- a/src/cluster.cpp +++ b/src/cluster.cpp @@ -95,6 +95,8 @@ getClusterReader(const Reader& zimReader, offset_t offset, Cluster::Compression* } } + Cluster::~Cluster() = default; + /* This return the number of char read */ template void Cluster::read_header() diff --git a/src/cluster.h b/src/cluster.h index 9d5e44ba..db1be37c 100644 --- a/src/cluster.h +++ b/src/cluster.h @@ -30,7 +30,6 @@ #include #include -#include "zim_types.h" namespace zim { @@ -79,6 +78,7 @@ namespace zim public: Cluster(std::unique_ptr reader, Compression comp, bool isExtended); + ~Cluster(); Compression getCompression() const { return compression; } bool isCompressed() const { return compression != Compression::None; } From 6099dfadeb6aca3495b4b90da6066f3f8517734d Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Thu, 23 May 2024 11:04:10 +0200 Subject: [PATCH 4/8] Do not use static member (zimMajorVersion) in inlined constructor. On Windows, static members are not exported in dll. So we must not use them in inlined method/constructor. --- src/fileheader.cpp | 13 +++++++++++++ src/fileheader.h | 14 +------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/fileheader.cpp b/src/fileheader.cpp index 0a711044..444be55f 100644 --- a/src/fileheader.cpp +++ b/src/fileheader.cpp @@ -44,6 +44,19 @@ namespace zim const uint16_t Fileheader::zimMinorVersion = 2; const offset_type Fileheader::size = 80; // This is also mimeListPos (so an offset) + Fileheader::Fileheader() + : majorVersion(zimMajorVersion), + minorVersion(zimMinorVersion), + articleCount(0), + titleIdxPos(0), + pathPtrPos(0), + clusterCount(0), + clusterPtrPos(0), + mainPage(std::numeric_limits::max()), + layoutPage(std::numeric_limits::max()), + checksumPos(std::numeric_limits::max()) + {} + void Fileheader::write(int out_fd) const { char header[Fileheader::size]; diff --git a/src/fileheader.h b/src/fileheader.h index 40325a98..0dd311b4 100644 --- a/src/fileheader.h +++ b/src/fileheader.h @@ -59,19 +59,7 @@ namespace zim offset_type checksumPos; public: - Fileheader() - : majorVersion(zimMajorVersion), - minorVersion(zimMinorVersion), - articleCount(0), - titleIdxPos(0), - pathPtrPos(0), - clusterCount(0), - clusterPtrPos(0), - mainPage(std::numeric_limits::max()), - layoutPage(std::numeric_limits::max()), - checksumPos(std::numeric_limits::max()) - {} - + Fileheader(); void write(int out_fd) const; void read(const Reader& reader); From b51eb32c6930cf607cef802380e2e16dba4493c2 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Thu, 23 May 2024 11:27:49 +0200 Subject: [PATCH 5/8] Remove template feature --- src/meson.build | 1 - src/template.cpp | 142 ---------------------------------------------- src/template.h | 82 -------------------------- test/meson.build | 1 - test/template.cpp | 78 ------------------------- 5 files changed, 304 deletions(-) delete mode 100644 src/template.cpp delete mode 100644 src/template.h delete mode 100644 test/template.cpp diff --git a/src/meson.build b/src/meson.build index 4529b7ca..e2fde822 100644 --- a/src/meson.build +++ b/src/meson.build @@ -22,7 +22,6 @@ common_sources = [ 'blob.cpp', 'buffer.cpp', 'md5.c', - 'template.cpp', 'uuid.cpp', 'tools.cpp', 'compression.cpp', diff --git a/src/template.cpp b/src/template.cpp deleted file mode 100644 index 75e4bb8b..00000000 --- a/src/template.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (C) 2009 Tommi Maekitalo - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied - * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and - * NON-INFRINGEMENT. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include "template.h" - -namespace zim -{ - void TemplateParser::state_data(char ch) - { - data += ch; - - if (ch == '<') - { - state = &TemplateParser::state_lt; - save = data.size() - 1; - } - } - - void TemplateParser::state_lt(char ch) - { - data += ch; - - if (ch == '%') - state = &TemplateParser::state_token0; - else - state = &TemplateParser::state_data; - } - - void TemplateParser::state_token0(char ch) - { - data += ch; - - if (ch == '/') - state = &TemplateParser::state_link0; - else - { - token = data.size() - 1; - state = &TemplateParser::state_token; - } - } - - void TemplateParser::state_token(char ch) - { - data += ch; - - if (ch == '%') - state = &TemplateParser::state_token_end; - } - - void TemplateParser::state_token_end(char ch) - { - if (ch == '>') - { - if (event) - { - event->onData(data.substr(0, save)); - event->onToken(data.substr(token, data.size() - token - 1)); - data.clear(); - } - - state = &TemplateParser::state_data; - } - else - { - data += ch; - state = &TemplateParser::state_data; - } - } - - void TemplateParser::state_link0(char ch) - { - data += ch; - - ns = ch; - state = &TemplateParser::state_link; - } - - void TemplateParser::state_link(char ch) - { - data += ch; - - if (ch == '/') - { - token = data.size(); - state = &TemplateParser::state_title; - } - else - state = &TemplateParser::state_data; - } - - void TemplateParser::state_title(char ch) - { - data += ch; - - if (ch == '%') - { - token_e = data.size() - 1; - state = &TemplateParser::state_title_end; - } - } - - void TemplateParser::state_title_end(char ch) - { - data += ch; - - if (ch == '>') - { - if (event) - { - event->onData(data.substr(0, save)); - event->onLink(ns, data.substr(token, token_e - token)); - } - - data.clear(); - state = &TemplateParser::state_data; - } - } - - void TemplateParser::flush() - { - if (event) - event->onData(data); - data.clear(); - state = &TemplateParser::state_data; - } -} diff --git a/src/template.h b/src/template.h deleted file mode 100644 index e163251c..00000000 --- a/src/template.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2009 Tommi Maekitalo - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied - * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and - * NON-INFRINGEMENT. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef ZIM_TEMPLATE_H -#define ZIM_TEMPLATE_H - -#include - -namespace zim -{ - class TemplateParser - { - public: - class Event - { - public: - virtual void onData(const std::string& data) = 0; - virtual void onToken(const std::string& token) = 0; - virtual void onLink(char ns, const std::string &path) = 0; - virtual ~Event() = default; - }; - - private: - Event* event; - - std::string data; - std::string::size_type save; - std::string::size_type token; - std::string::size_type token_e; - char ns; - typedef void (TemplateParser::*state_type)(char); - - state_type state; - - void state_data(char ch); - void state_lt(char ch); - void state_token0(char ch); - void state_token(char ch); - void state_token_end(char ch); - void state_link0(char ch); - void state_link(char ch); - void state_title(char ch); - void state_title_end(char ch); - - public: - explicit TemplateParser(Event* ev) - : event(ev), - state(&TemplateParser::state_data) - { } - - void parse(char ch) - { - (this->*state)(ch); - } - - void parse(const std::string& s) - { - for (std::string::const_iterator ch = s.begin(); ch != s.end(); ++ch) - parse(*ch); - } - - void flush(); - }; -} - -#endif // ZIM_TEMPLATE_H diff --git a/test/meson.build b/test/meson.build index 20545b17..8018a02d 100644 --- a/test/meson.build +++ b/test/meson.build @@ -6,7 +6,6 @@ tests = [ 'error_in_creator', 'header', 'uuid', - 'template', 'archive', 'iterator', 'reader', diff --git a/test/template.cpp b/test/template.cpp deleted file mode 100644 index f0a606ed..00000000 --- a/test/template.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2009 Tommi Maekitalo - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied - * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and - * NON-INFRINGEMENT. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include "../src/template.h" - -#include "gtest/gtest.h" - -namespace -{ -class TemplateTest : public ::testing::Test, private zim::TemplateParser::Event -{ - public: - std::string result; - zim::TemplateParser parser; - - TemplateTest() : parser(this) {} - - private: - void onData(const std::string& data) { result += data; } - - void onToken(const std::string& token) - { - result += "T("; - result += token; - result += ')'; - } - - void onLink(char ns, const std::string& title) - { - result += "L("; - result += ns; - result += ", "; - result += title; - result += ')'; - } -}; - -TEST_F(TemplateTest, ZeroTemplate) -{ - parser.parse("

Hi

"); - parser.flush(); - - ASSERT_EQ(result, "

Hi

"); -} - -TEST_F(TemplateTest, Token) -{ - parser.parse("<%content%>"); - parser.flush(); - - ASSERT_EQ(result, "T(content)"); -} - -TEST_F(TemplateTest, Link) -{ - parser.parse("<%/A/Article%>"); - parser.flush(); - - ASSERT_EQ(result, "L(A, Article)"); -} - -} // namespace From 34415e185c73ebc2a3aa4cd8a401beed1a9138bc Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 29 May 2024 15:04:50 +0200 Subject: [PATCH 6/8] Do not unconditionally include search/xapian features On Windows, if we declare a exported class, the implementation of this class is expected in the dll. When compiling without xapian we must not include headers for which we don't compile the implementation. --- src/writer/defaultIndexData.h | 4 ++++ test/archive.cpp | 2 ++ test/indexing_criteria.cpp | 6 ++++-- test/tools.h | 1 - 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/writer/defaultIndexData.h b/src/writer/defaultIndexData.h index f9397353..12891615 100644 --- a/src/writer/defaultIndexData.h +++ b/src/writer/defaultIndexData.h @@ -22,7 +22,11 @@ #include #include + +#include "config.h" +#if defined(ENABLE_XAPIAN) #include "xapian/myhtmlparse.h" +#endif #include "../tools.h" #include diff --git a/test/archive.cpp b/test/archive.cpp index a0487936..6a87b9af 100644 --- a/test/archive.cpp +++ b/test/archive.cpp @@ -21,7 +21,9 @@ #include #include #include +#if defined(ENABLE_XAPIAN) #include +#endif #include #include diff --git a/test/indexing_criteria.cpp b/test/indexing_criteria.cpp index 163046ee..ea7c9e42 100644 --- a/test/indexing_criteria.cpp +++ b/test/indexing_criteria.cpp @@ -20,7 +20,9 @@ #define ZIM_PRIVATE #include #include +#if defined(LIBZIM_WITH_XAPIAN) #include +#endif #include #include @@ -64,7 +66,7 @@ class IndexDataItem : public TestItem { std::shared_ptr mp_indexData; }; -#if defined(ENABLE_XAPIAN) +#if defined(LIBZIM_WITH_XAPIAN) TEST(IndexCriteria, defaultIndexingBaseOnMimeType) { @@ -145,7 +147,7 @@ TEST(IndexCriteria, specificIndexData) ASSERT_EQ(++begin, result.end()); } -#endif // ENABLE_XAPIAN +#endif // LIBZIM_WITH_XAPIAN TEST(IndexCriteria, suggestion) { TempZimArchive tza("testZim"); diff --git a/test/tools.h b/test/tools.h index f228d284..6a93a02c 100644 --- a/test/tools.h +++ b/test/tools.h @@ -40,7 +40,6 @@ typedef SSIZE_T ssize_t; #define ZIM_PRIVATE #include -#include #include #include #include From 98573d9f6a5b06e7c65337e223c5fb03941cf02d Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 7 Jun 2024 10:29:58 +0200 Subject: [PATCH 7/8] Use dependency archive build by kiwix-build --- .github/workflows/ci.yml | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1cd615c2..59c42134 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -111,21 +111,36 @@ jobs: - name: Install packages run: - choco install ninja + choco install pkgconfiglite ninja - name: Install python modules run: pip3 install meson + - name: Setup MSVC compiler + uses: bus1/cabuild/action/msdevshell@v1 + with: + architecture: x64 + + - name: Install dependencies + uses: kiwix/kiwix-build/actions/dl_deps_archive@804193835086c0bed79f55d4c373302ab729db3d # main + with: + target_platform: win-x86_64-dyn + - name: Compile shell: cmd - run: .github\script\build_libzim.cmd + run: | + set PKG_CONFIG_PATH=%cd%\BUILD_win-amd64\INSTALL\lib\pkgconfig + dir %PKG_CONFIG_PATH% + meson.exe setup . build -Dwith_xapian=false + cd build + ninja.exe - name: Test shell: cmd run: | cd build - ninja download_test_data - meson test --verbose + ninja.exe download_test_data + meson.exe test --verbose env: WAIT_TIME_FACTOR_TEST: 10 From 0a1d2c3d446449fcc170dd5b2e7d33532905b433 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 17 May 2024 17:20:40 +0200 Subject: [PATCH 8/8] No werror=true MSVC throw a lot of warning because we also must re-export stl symbols used in our exported class. See [1] and [2] (and links inside) for more information. Especially [3] which seems to say that we should have issue at link time if it compatibility issue occurs (and so easily catchable). So I just remove the `werror=true` for now. [1] https://stackoverflow.com/questions/16419318/one-way-of-eliminating-c4251-warning-when-using-stl-classes-in-the-dll-interface [2] https://stackoverflow.com/questions/2132747/warning-c4251-when-building-a-dll-that-exports-a-class-containing-an-atlcstrin [3] https://stackoverflow.com/questions/2132747/warning-c4251-when-building-a-dll-that-exports-a-class-containing-an-atlcstrin#comment66255284_4563701 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 59c42134..97f68bfc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -131,7 +131,7 @@ jobs: run: | set PKG_CONFIG_PATH=%cd%\BUILD_win-amd64\INSTALL\lib\pkgconfig dir %PKG_CONFIG_PATH% - meson.exe setup . build -Dwith_xapian=false + meson.exe setup . build -Dwith_xapian=false -Dwerror=false cd build ninja.exe