Skip to content

Commit

Permalink
Merge pull request #425 from openzim/fix_no_writer_test
Browse files Browse the repository at this point in the history
Introduce MS Windows CI
  • Loading branch information
kelson42 authored Sep 2, 2024
2 parents 06b9916 + 5a8c6df commit fd23466
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 235 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,51 @@ jobs:
cd build
ninja
Windows:
runs-on: windows-2022

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install packages
run:
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@main
with:
target_platform: win-x86_64-static

- name: Compile
shell: cmd
run: |
set PKG_CONFIG_PATH=%cd%\BUILD_win-amd64\INSTALL\lib\pkgconfig
set CPPFLAGS=-I%cd%\BUILD_win-amd64\INSTALL\include
meson.exe setup . build -Dstatic-linkage=true --buildtype=debug
cd build
ninja.exe
- name: Test
shell: cmd
run: |
cd build
meson.exe test --verbose
env:
WAIT_TIME_FACTOR_TEST: 10

Linux:
strategy:
Expand Down
4 changes: 1 addition & 3 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
project('zim-tools', ['c', 'cpp'],
version : '3.4.2',
license : 'GPLv3+',
default_options : ['c_std=c11', 'cpp_std=c++17', 'werror=true'])

add_global_arguments(['-Werror', '-Wall'], language:'cpp')
default_options : ['c_std=c11', 'cpp_std=c++17', 'werror=true', 'warning_level=1'])

add_global_arguments('-DVERSION="@0@"'.format(meson.project_version()), language : 'cpp')

Expand Down
18 changes: 16 additions & 2 deletions src/metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,21 @@ bool searchRegex(const std::string& regexStr, const std::string& text)

size_t getTextLength(const std::string& utf8EncodedString)
{
return icu::UnicodeString::fromUTF8(utf8EncodedString).length();
// For some unknown reason implicite convertion from std::string to icu::StringPiece
// is broken on Windows.
// Constructors are definde in stringpiece.h as
// ```
// StringPiece(const std::string& str)
// : ptr_(str.data()), length_(static_cast<int32_t>(str.size())) { }
// StringPiece(const char* offset, int32_t len) : ptr_(offset), length_(len) { }
// ```
// However using the first constructor ends with a corrupted StringPiece (wrong ptr)
// and using second one works. Don't ask me why
// This is broken
// icu::StringPiece stringPiece(utf8EncodedString);
// This is not
icu::StringPiece stringPiece(utf8EncodedString.data(), static_cast<int32_t>(utf8EncodedString.size()));
return icu::UnicodeString::fromUTF8(stringPiece).length();
}

class MetadataComplexCheckBase
Expand Down Expand Up @@ -125,7 +139,7 @@ std::string escapeNonPrintableChars(const std::string& s)
std::ostringstream os;
os << std::hex;
for (const char c : s) {
if (std::isprint(c)) {
if (std::isprint(static_cast<unsigned char>(c))) {
os << c;
} else {
const unsigned int charVal = static_cast<unsigned char>(c);
Expand Down
3 changes: 1 addition & 2 deletions src/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "tools.h"

#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
#include <cerrno>
Expand All @@ -31,14 +30,14 @@
#include <stdexcept>
#include <vector>
#include <memory>
#include <unistd.h>
#include <algorithm>
#include <regex>
#include <array>

#ifdef _WIN32
#define SEPARATOR "\\"
#else
#include <unistd.h>
#define SEPARATOR "/"
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/zimcheck/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ executable('zimcheck',
'../tools.cpp',
'../metadata.cpp',
include_directories : inc,
dependencies: [libzim_dep, icu_dep, thread_dep],
dependencies: [libzim_dep, icu_dep, thread_dep, docopt_dep],
install: true)


Loading

0 comments on commit fd23466

Please sign in to comment.